Mild updates to Window and other pieces to match the rest
This commit is contained in:
@@ -16,9 +16,25 @@ static std::map<int, int> defailt_window_hints = {
|
||||
#endif
|
||||
};
|
||||
|
||||
GLError::GLError(const std::string& msg) : std::runtime_error(msg) {}
|
||||
using OpenGLErrorCodes = OpenGLError::Codes;
|
||||
const std::string OpenGLError::type = "nb::OpenGLError";
|
||||
const ErrorCodeMap OpenGLError::ErrorMessages = {
|
||||
{OpenGLErrorCodes::UNDEFINED, "Error"},
|
||||
{OpenGLErrorCodes::INIT_FAILED, "GLFW initialization failed"},
|
||||
{OpenGLErrorCodes::GLFW_INTIALIZED, "GLFW has already been initialized"},
|
||||
{OpenGLErrorCodes::GLAD_FAILED, "GLAD initialization failed"}
|
||||
};
|
||||
|
||||
WindowError::WindowError(const std::string &msg) : std::runtime_error(msg) {}
|
||||
using WindowErrorCodes = WindowError::Codes;
|
||||
const std::string WindowError::type = "nb::WindowError";
|
||||
const ErrorCodeMap WindowError::ErrorMessages = {
|
||||
{WindowErrorCodes::UNDEFINED, "Error"},
|
||||
{WindowErrorCodes::INITIALIZED_WINDOW, "Window already initialized"},
|
||||
{WindowErrorCodes::NO_GLFW, "GLFW has not been initialized"},
|
||||
{WindowErrorCodes::INIT_FAILED, "Could not intialized window"}
|
||||
};
|
||||
|
||||
GLError::GLError(const std::string& msg) : std::runtime_error(msg) {}
|
||||
|
||||
int Window::getGLFWHint(int hint_key) {
|
||||
if (GLFWHints.find(hint_key) == GLFWHints.end()) {
|
||||
@@ -30,7 +46,7 @@ int Window::getGLFWHint(int hint_key) {
|
||||
|
||||
int Window::setGLFWHint(int hint_key, int hint_val) {
|
||||
if (Window::_glfw_init) {
|
||||
throw GLError("Cannot set GLFW hint after window is initialized.");
|
||||
THROW(OpenGLError(OpenGLErrorCodes::GLFW_INTIALIZED));
|
||||
} else {
|
||||
GLFWHints[hint_key] = hint_val;
|
||||
}
|
||||
@@ -60,7 +76,7 @@ Window::Window(const uint16_t x, const uint16_t y, const char* initName, GLFWmon
|
||||
Window::_glfw_init = true;
|
||||
} else {
|
||||
if (Window::StrictInitialization) {
|
||||
throw GLError("Failed to load GLFW with glfwInit()="+std::to_string(glfwResponse)+".");
|
||||
THROW(OpenGLError(OpenGLErrorCodes::INIT_FAILED));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,7 +119,7 @@ int Window::getWindowHint(int hint_key) const {
|
||||
|
||||
int Window::setWindowHint(int hint_key, int hint_val) {
|
||||
if (_init) {
|
||||
throw WindowError("Cannot set window hint after window is initialized.");
|
||||
THROW(WindowError(WindowErrorCodes::INITIALIZED_WINDOW));
|
||||
} else {
|
||||
windowHints[hint_key] = hint_val;
|
||||
}
|
||||
@@ -112,7 +128,7 @@ int Window::setWindowHint(int hint_key, int hint_val) {
|
||||
|
||||
int Window::init() {
|
||||
if (!_glfw_init) {
|
||||
throw GLError("GLFW has not been initialized.");
|
||||
THROW(WindowError(WindowErrorCodes::NO_GLFW));
|
||||
}
|
||||
for (const auto& hint : windowHints) {
|
||||
glfwWindowHint(hint.first, hint.second);
|
||||
@@ -123,7 +139,7 @@ int Window::init() {
|
||||
Window::WindowContexts.erase(window);
|
||||
if (Window::WindowContexts.size()==0 && Window::_glfw_init) { glfwTerminate(); }
|
||||
if (Window::StrictInitialization) {
|
||||
throw WindowError("Could not create window in glfwCreateWindow().");
|
||||
THROW(WindowError(WindowErrorCodes::INIT_FAILED));
|
||||
}
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
@@ -133,10 +149,7 @@ int Window::init() {
|
||||
if (!gladResponse) {
|
||||
Window::checkKillGLFW();
|
||||
if (Window::StrictInitialization) {
|
||||
throw GLError("Failed to load GLAD with \
|
||||
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)="+\
|
||||
std::to_string(gladResponse)+"."
|
||||
);
|
||||
THROW(OpenGLError(OpenGLErrorCodes::GLAD_FAILED));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user