Changeset View
Changeset View
Standalone View
Standalone View
source/lib/ogl.cpp
Show First 20 Lines • Show All 366 Lines • ▼ Show 20 Lines | for(;;) | ||||
error_enountered = true; | error_enountered = true; | ||||
dump_gl_error(err); | dump_gl_error(err); | ||||
} | } | ||||
if(error_enountered) | if(error_enountered) | ||||
debug_printf("%s:%d: OpenGL error(s) occurred: %s (%04x)\n", file, line, ogl_GetErrorName(first_error), (unsigned int)first_error); | debug_printf("%s:%d: OpenGL error(s) occurred: %s (%04x)\n", file, line, ogl_GetErrorName(first_error), (unsigned int)first_error); | ||||
} | } | ||||
void GLAD_API_PTR ogl_OnDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei UNUSED(length), const GLchar* message, const void* UNUSED(user_param)) | |||||
{ | |||||
std::string debugSource = "unknown"; | |||||
std::string debugType = "unknown"; | |||||
std::string debugSeverity = "unknown"; | |||||
switch (source) | |||||
{ | |||||
case GL_DEBUG_SOURCE_API: | |||||
debugSource = "the API"; | |||||
break; | |||||
case GL_DEBUG_SOURCE_WINDOW_SYSTEM: | |||||
debugSource = "the window system"; | |||||
break; | |||||
case GL_DEBUG_SOURCE_SHADER_COMPILER: | |||||
debugSource = "the shader compiler"; | |||||
break; | |||||
case GL_DEBUG_SOURCE_THIRD_PARTY: | |||||
debugSource = "a third party"; | |||||
break; | |||||
case GL_DEBUG_SOURCE_APPLICATION: | |||||
debugSource = "the application"; | |||||
break; | |||||
case GL_DEBUG_SOURCE_OTHER: | |||||
debugSource = "somewhere"; | |||||
break; | |||||
} | |||||
switch (type) | |||||
{ | |||||
case GL_DEBUG_TYPE_ERROR: | |||||
debugType = "error"; | |||||
break; | |||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: | |||||
debugType = "deprecated behaviour"; | |||||
break; | |||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: | |||||
debugType = "undefined behaviour"; | |||||
break; | |||||
case GL_DEBUG_TYPE_PORTABILITY: | |||||
debugType = "portability"; | |||||
break; | |||||
case GL_DEBUG_TYPE_PERFORMANCE: | |||||
debugType = "performance"; | |||||
break; | |||||
case GL_DEBUG_TYPE_OTHER: | |||||
debugType = "other"; | |||||
break; | |||||
case GL_DEBUG_TYPE_MARKER: | |||||
debugType = "marker"; | |||||
break; | |||||
case GL_DEBUG_TYPE_PUSH_GROUP: | |||||
debugType = "push group"; | |||||
break; | |||||
case GL_DEBUG_TYPE_POP_GROUP: | |||||
debugType = "pop group"; | |||||
break; | |||||
} | |||||
switch (severity) | |||||
{ | |||||
case GL_DEBUG_SEVERITY_HIGH: | |||||
debugSeverity = "high"; | |||||
break; | |||||
case GL_DEBUG_SEVERITY_MEDIUM: | |||||
debugSeverity = "medium"; | |||||
break; | |||||
case GL_DEBUG_SEVERITY_LOW: | |||||
debugSeverity = "low"; | |||||
break; | |||||
case GL_DEBUG_SEVERITY_NOTIFICATION: | |||||
debugSeverity = "notification"; | |||||
break; | |||||
} | |||||
debug_printf("OpenGL | %s: %s source: %s id %u: %s\n", debugSeverity.c_str(), debugType.c_str(), debugSource.c_str(), id, message); | |||||
} | |||||
// ignore and reset the specified error (as returned by glGetError). | // ignore and reset the specified error (as returned by glGetError). | ||||
vladislavbelov: Space. | |||||
// any other errors that have occurred are reported as ogl_WarnIfError would. | // any other errors that have occurred are reported as ogl_WarnIfError would. | ||||
// | // | ||||
// this is useful for suppressing annoying error messages, e.g. | // this is useful for suppressing annoying error messages, e.g. | ||||
// "invalid enum" for GL_CLAMP_TO_EDGE even though we've already | // "invalid enum" for GL_CLAMP_TO_EDGE even though we've already | ||||
Not Done Inline ActionsMaybe CC, Idr snake case for lib? vladislavbelov: Maybe CC, Idr snake case for `lib`? | |||||
// warned the user that their OpenGL implementation is too old. | // warned the user that their OpenGL implementation is too old. | ||||
bool ogl_SquelchError(GLenum err_to_ignore) | bool ogl_SquelchError(GLenum err_to_ignore) | ||||
{ | { | ||||
// glGetError may return multiple errors, so we poll it in a loop. | // glGetError may return multiple errors, so we poll it in a loop. | ||||
// the debug_printf should only happen once (if this is set), though. | // the debug_printf should only happen once (if this is set), though. | ||||
bool error_enountered = false; | bool error_enountered = false; | ||||
bool error_ignored = false; | bool error_ignored = false; | ||||
GLenum first_error = 0; | GLenum first_error = 0; | ||||
for(;;) | for(;;) | ||||
{ | { | ||||
GLenum err = glGetError(); | GLenum err = glGetError(); | ||||
if(err == GL_NO_ERROR) | if(err == GL_NO_ERROR) | ||||
break; | break; | ||||
if(err == err_to_ignore) | if(err == err_to_ignore) | ||||
{ | { | ||||
error_ignored = true; | error_ignored = true; | ||||
continue; | continue; | ||||
} | } | ||||
if(!error_enountered) | if(!error_enountered) | ||||
first_error = err; | first_error = err; | ||||
error_enountered = true; | error_enountered = true; | ||||
dump_gl_error(err); | dump_gl_error(err); | ||||
} | } | ||||
if(error_enountered) | if(error_enountered) | ||||
debug_printf("OpenGL error(s) occurred: %04x\n", (unsigned int)first_error); | debug_printf("OpenGL error(s) occurred: %04x\n", (unsigned int)first_error); | ||||
return error_ignored; | return error_ignored; | ||||
} | } | ||||
//---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- | ||||
// feature and limit detect | // feature and limit detect | ||||
//---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- | ||||
GLint ogl_max_tex_size = -1; // [pixels] | GLint ogl_max_tex_size = -1; // [pixels] | ||||
GLint ogl_max_tex_units = -1; // limit on GL_TEXTUREn | GLint ogl_max_tex_units = -1; // limit on GL_TEXTUREn | ||||
#if OS_WIN | #if OS_WIN | ||||
bool ogl_Init(void* (load)(const char*), void* hdc) | bool ogl_Init(void* (load)(const char*), void* hdc) | ||||
#elif !CONFIG2_GLES && !OS_MACOSX && !OS_MAC | #elif !CONFIG2_GLES && !OS_MACOSX && !OS_MAC | ||||
bool ogl_Init(void* (load)(const char*), void* display) | bool ogl_Init(void* (load)(const char*), void* display) | ||||
#else | #else | ||||
bool ogl_Init(void* (load)(const char*)) | bool ogl_Init(void* (load)(const char*)) | ||||
#endif | #endif | ||||
{ | { | ||||
GLADloadfunc loadFunc = reinterpret_cast<GLADloadfunc>(load); | GLADloadfunc loadFunc = reinterpret_cast<GLADloadfunc>(load); | ||||
if (!loadFunc) | if (!loadFunc) | ||||
return false; | return false; | ||||
#define LOAD_ERROR(ERROR_STRING) \ | #define LOAD_ERROR(ERROR_STRING) \ | ||||
if (g_Logger) \ | if (g_Logger) \ | ||||
LOGERROR(ERROR_STRING); \ | LOGERROR(ERROR_STRING); \ | ||||
else \ | else \ | ||||
debug_printf(ERROR_STRING); \ | debug_printf(ERROR_STRING); \ | ||||
#if !CONFIG2_GLES | #if !CONFIG2_GLES | ||||
GLVersion = gladLoadGL(loadFunc); | GLVersion = gladLoadGL(loadFunc); | ||||
if (!GLVersion) | if (!GLVersion) | ||||
{ | { | ||||
LOAD_ERROR("Failed to load OpenGL functions."); | LOAD_ERROR("Failed to load OpenGL functions."); | ||||
return false; | return false; | ||||
} | } | ||||
# if OS_WIN | # if OS_WIN | ||||
WGLVersion = gladLoadWGL(reinterpret_cast<HDC>(hdc), loadFunc); | WGLVersion = gladLoadWGL(reinterpret_cast<HDC>(hdc), loadFunc); | ||||
Not Done Inline ActionsMight use a macro to reduce the code duplication. vladislavbelov: Might use a macro to reduce the code duplication. | |||||
if (!WGLVersion) | if (!WGLVersion) | ||||
{ | { | ||||
Not Done Inline ActionsI suppose it won't be visible on Windows. But I might fix it later. vladislavbelov: I suppose it won't be visible on Windows. But I might fix it later. | |||||
LOAD_ERROR("Failed to load WGL functions."); | LOAD_ERROR("Failed to load WGL functions."); | ||||
return false; | return false; | ||||
} | } | ||||
# elif !OS_MACOSX && !OS_MAC | # elif !OS_MACOSX && !OS_MAC | ||||
GLXVersion = gladLoadGLX(reinterpret_cast<Display*>(display), DefaultScreen(display), loadFunc); | GLXVersion = gladLoadGLX(reinterpret_cast<Display*>(display), DefaultScreen(display), loadFunc); | ||||
if (!GLXVersion) | if (!GLXVersion) | ||||
{ | { | ||||
LOAD_ERROR("Failed to load GLX functions."); | LOAD_ERROR("Failed to load GLX functions."); | ||||
Show All 27 Lines | #undef LOAD_ERROR | ||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &ogl_max_tex_size); | glGetIntegerv(GL_MAX_TEXTURE_SIZE, &ogl_max_tex_size); | ||||
#if !CONFIG2_GLES | #if !CONFIG2_GLES | ||||
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &ogl_max_tex_units); | glGetIntegerv(GL_MAX_TEXTURE_UNITS, &ogl_max_tex_units); | ||||
#endif | #endif | ||||
glEnable(GL_TEXTURE_2D); | glEnable(GL_TEXTURE_2D); | ||||
#if KHR_DEBUG_ENABLED | |||||
#if CONFIG2_GLES | |||||
bool is_core = ogl_HaveVersion(3, 2); | |||||
#else | |||||
bool is_core = ogl_HaveVersion(4, 3); | |||||
#endif | |||||
if (is_core || ogl_HaveExtension("GL_KHR_debug")) | |||||
{ | |||||
glEnable(GL_DEBUG_OUTPUT); | |||||
glDebugMessageCallback(ogl_OnDebugMessage, nullptr); | |||||
// Filter out our own debug group messages | |||||
GLuint id = 0x0ad; | |||||
glDebugMessageControl(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PUSH_GROUP, GL_DONT_CARE, 1, &id, GL_FALSE); | |||||
glDebugMessageControl(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_POP_GROUP, GL_DONT_CARE, 1, &id, GL_FALSE); | |||||
} | |||||
#endif | |||||
return true; | return true; | ||||
} | } | ||||
void ogl_SetVsyncEnabled(bool enabled) | void ogl_SetVsyncEnabled(bool enabled) | ||||
{ | { | ||||
#if !CONFIG2_GLES && OS_WIN | #if !CONFIG2_GLES && OS_WIN | ||||
int interval = enabled ? 1 : 0; | int interval = enabled ? 1 : 0; | ||||
Show All 10 Lines |
Wildfire Games · Phabricator
Space.