Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lib/ogl.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
static bool have_30 = false; | static bool have_30 = false; | ||||
static bool have_21 = false; | static bool have_21 = false; | ||||
static bool have_20 = false; | static bool have_20 = false; | ||||
static bool have_15 = false; | static bool have_15 = false; | ||||
static bool have_14 = false; | static bool have_14 = false; | ||||
static bool have_13 = false; | static bool have_13 = false; | ||||
static bool have_12 = false; | static bool have_12 = false; | ||||
#if KHR_DEBUG_ENABLED | |||||
static bool have_KHR = false; | |||||
#endif | |||||
// return a C string of unspecified length containing a space-separated | // return a C string of unspecified length containing a space-separated | ||||
// list of all extensions the OpenGL implementation advertises. | // list of all extensions the OpenGL implementation advertises. | ||||
// (useful for crash logs). | // (useful for crash logs). | ||||
const char* ogl_ExtensionString() | const char* ogl_ExtensionString() | ||||
{ | { | ||||
ENSURE(exts && "call ogl_Init before using this function"); | ENSURE(exts && "call ogl_Init before using this function"); | ||||
▲ Show 20 Lines • Show All 297 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). | ||||
// 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 104 Lines • ▼ Show 20 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 | |||||
have_KHR = is_core || ogl_HaveExtension("GL_KHR_debug"); | |||||
if (have_KHR) | |||||
{ | |||||
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; | ||||
if (ogl_HaveExtension("WGL_EXT_swap_control")) | if (ogl_HaveExtension("WGL_EXT_swap_control")) | ||||
wglSwapIntervalEXT(interval); | wglSwapIntervalEXT(interval); | ||||
#elif !CONFIG2_GLES && !OS_MACOSX && !OS_MAC | #elif !CONFIG2_GLES && !OS_MACOSX && !OS_MAC | ||||
int interval = enabled ? 1 : 0; | int interval = enabled ? 1 : 0; | ||||
if (ogl_HaveExtension("GLX_SGI_swap_control")) | if (ogl_HaveExtension("GLX_SGI_swap_control")) | ||||
glXSwapIntervalSGI(interval); | glXSwapIntervalSGI(interval); | ||||
#else | #else | ||||
UNUSED2(enabled); | UNUSED2(enabled); | ||||
#endif | #endif | ||||
} | } | ||||
#if KHR_DEBUG_ENABLED | |||||
ogl_DebugScopedGroup::ogl_DebugScopedGroup(const char* message) | |||||
{ | |||||
if (!have_KHR) | |||||
return; | |||||
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0x0ad, -1, message); | |||||
} | |||||
ogl_DebugScopedGroup::~ogl_DebugScopedGroup() | |||||
{ | |||||
if (!have_KHR) | |||||
return; | |||||
glPopDebugGroup(); | |||||
} | |||||
#endif |
Wildfire Games · Phabricator