Changeset View
Changeset View
Standalone View
Standalone View
source/lib/ogl.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
▲ Show 20 Lines • Show All 407 Lines • ▼ Show 20 Lines | for(;;) | ||||
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 APIENTRY ogl_OnDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei UNUSED(length), const GLchar* message, const void* UNUSED(user_param)) | |||||
vladislavbelov: Space. | |||||
{ | |||||
std::string debugSource = "unknown"; | |||||
std::string debugType = "unknown"; | |||||
std::string debugSeverity = "unknown"; | |||||
Not Done Inline ActionsMaybe CC, Idr snake case for lib? vladislavbelov: Maybe CC, Idr snake case for `lib`? | |||||
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; | |||||
} | |||||
Not Done Inline ActionsMight use a macro to reduce the code duplication. vladislavbelov: Might use a macro to reduce the code duplication. | |||||
debug_printf("OpenGL | %s: %s source: %s id %u: %s\n", debugSeverity.c_str(), debugType.c_str(), debugSource.c_str(), id, message); | |||||
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. | |||||
} | |||||
// ignore and reset the specified error (as returned by glGetError). | // ignore and reset the specified error (as returned by glGetError). | ||||
// 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 | ||||
// 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) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | void ogl_Init() | ||||
have_30 = ogl_HaveVersion("3.0"); | have_30 = ogl_HaveVersion("3.0"); | ||||
importExtensionFunctions(); | importExtensionFunctions(); | ||||
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 | ||||
#ifndef NDEBUG | |||||
#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); | |||||
pglDebugMessageCallbackKHR(ogl_OnDebugMessage, nullptr); | |||||
// Filter out our own debug group messages | |||||
GLuint id = 0x0ad; | |||||
pglDebugMessageControlKHR(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_PUSH_GROUP, GL_DONT_CARE, 1, &id, GL_FALSE); | |||||
pglDebugMessageControlKHR(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_POP_GROUP, GL_DONT_CARE, 1, &id, GL_FALSE); | |||||
} | |||||
#endif | |||||
} | } |
Wildfire Games · Phabricator
Space.