From 7be8209d1402c52619ee309ddcc69e66ec39cf2c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 10 Aug 2015 12:46:14 +0200 Subject: [PATCH] Add GLFW_CONTEXT_NO_ERROR window hint This adds support for the GL_KHR_no_error extension. --- README.md | 1 + docs/news.dox | 1 + docs/window.dox | 9 +++++++++ include/GLFW/glfw3.h | 1 + src/context.c | 3 +++ src/egl_context.c | 8 ++++++++ src/egl_context.h | 2 ++ src/glx_context.c | 2 ++ src/internal.h | 4 +++- src/wgl_context.c | 2 ++ src/window.c | 5 +++++ tests/glfwinfo.c | 11 ++++++++++- 12 files changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8e860707..d189474d 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ used by the tests and examples and are not required to build the library. - Added `glfwSetWindowSizeLimits` and `glfwSetWindowAspectRatio` for setting absolute and relative window size limits - Added `GLFW_NO_API` for creating window without contexts + - Added `GLFW_CONTEXT_NO_ERROR` context hint for `GL_KHR_no_error` support - Added `GLFW_TRUE` and `GLFW_FALSE` as client API independent boolean values - Removed dependency on external OpenGL or OpenGL ES headers - [Cocoa] Removed support for OS X 10.6 diff --git a/docs/news.dox b/docs/news.dox index bde1af0e..6c68839b 100644 --- a/docs/news.dox +++ b/docs/news.dox @@ -4,6 +4,7 @@ @section news_32 New features in 3.2 + @subsection news_32_sizelimits Window size limit support GLFW now supports setting both absolute and relative window size limits with diff --git a/docs/window.dox b/docs/window.dox index de53be9f..d934ecd9 100644 --- a/docs/window.dox +++ b/docs/window.dox @@ -293,6 +293,15 @@ Context release behaviors are described in detail by the [GL_KHR_context_flush_control](https://www.opengl.org/registry/specs/KHR/context_flush_control.txt) extension. +`GLFW_CONTEXT_NO_ERROR` specifies whether errors should be generated by the +context. If enabled, situations that would have generated errors instead cause +undefined behavior. + +@par +The no error mode for OpenGL and OpenGL ES is described in detail by the +[GL_KHR_no_error](https://www.opengl.org/registry/specs/KHR/no_error.txt) +extension. + @subsubsection window_hints_values Supported and default values diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index ccb72d0e..f8af3030 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -658,6 +658,7 @@ extern "C" { #define GLFW_OPENGL_DEBUG_CONTEXT 0x00022007 #define GLFW_OPENGL_PROFILE 0x00022008 #define GLFW_CONTEXT_RELEASE_BEHAVIOR 0x00022009 +#define GLFW_CONTEXT_NO_ERROR 0x0002200A #define GLFW_NO_API 0 #define GLFW_OPENGL_API 0x00030001 diff --git a/src/context.c b/src/context.c index 9db0b827..36840e55 100644 --- a/src/context.c +++ b/src/context.c @@ -403,6 +403,9 @@ GLFWbool _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig) // debug contexts window->context.debug = GLFW_TRUE; } + + if (flags & GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR) + window->context.noerror = GLFW_TRUE; } // Read back OpenGL context profile (OpenGL 3.2 and above) diff --git a/src/egl_context.c b/src/egl_context.c index 1912c803..759d13e0 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -264,6 +264,8 @@ int _glfwInitContextAPI(void) _glfw.egl.KHR_create_context = _glfwPlatformExtensionSupported("EGL_KHR_create_context"); + _glfw.egl.KHR_create_context_no_error = + _glfwPlatformExtensionSupported("EGL_KHR_create_context_no_error"); return GLFW_TRUE; } @@ -345,6 +347,12 @@ int _glfwCreateContext(_GLFWwindow* window, mask |= EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR; else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) mask |= EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; + + if (_glfw.egl.KHR_create_context_no_error) + { + if (ctxconfig->noerror) + flags |= EGL_CONTEXT_OPENGL_NO_ERROR_KHR; + } } if (ctxconfig->debug) diff --git a/src/egl_context.h b/src/egl_context.h index 6bcddd4a..47e155ca 100644 --- a/src/egl_context.h +++ b/src/egl_context.h @@ -88,6 +88,7 @@ #define EGL_CONTEXT_MINOR_VERSION_KHR 0x30fb #define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD #define EGL_CONTEXT_FLAGS_KHR 0x30fc +#define EGL_CONTEXT_OPENGL_NO_ERROR_KHR 0x31b3 #define EGL_NATIVE_VISUAL_ID 0x302e #define EGL_NO_SURFACE ((EGLSurface) 0) #define EGL_NO_DISPLAY ((EGLDisplay) 0) @@ -160,6 +161,7 @@ typedef struct _GLFWlibraryEGL EGLint major, minor; GLFWbool KHR_create_context; + GLFWbool KHR_create_context_no_error; void* handle; diff --git a/src/glx_context.c b/src/glx_context.c index fa604561..d369843b 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -380,6 +380,8 @@ int _glfwCreateContext(_GLFWwindow* window, if (ctxconfig->debug) flags |= GLX_CONTEXT_DEBUG_BIT_ARB; + if (ctxconfig->noerror) + flags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR; if (ctxconfig->robustness) { diff --git a/src/internal.h b/src/internal.h index 2ee3e4b4..a2fadba0 100644 --- a/src/internal.h +++ b/src/internal.h @@ -65,6 +65,7 @@ #define GL_NO_RESET_NOTIFICATION_ARB 0x8261 #define GL_CONTEXT_RELEASE_BEHAVIOR 0x82fb #define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82fc +#define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008 typedef int GLint; typedef unsigned int GLuint; @@ -195,6 +196,7 @@ struct _GLFWctxconfig int minor; GLFWbool forward; GLFWbool debug; + GLFWbool noerror; int profile; int robustness; int release; @@ -262,7 +264,7 @@ struct _GLFWwindow struct { int api; int major, minor, revision; - GLFWbool forward, debug; + GLFWbool forward, debug, noerror; int profile; int robustness; int release; diff --git a/src/wgl_context.c b/src/wgl_context.c index 2233d654..015c7040 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -382,6 +382,8 @@ int _glfwCreateContext(_GLFWwindow* window, if (ctxconfig->debug) flags |= WGL_CONTEXT_DEBUG_BIT_ARB; + if (ctxconfig->noerror) + flags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR; if (ctxconfig->robustness) { diff --git a/src/window.c b/src/window.c index 345bc14a..6eac705c 100644 --- a/src/window.c +++ b/src/window.c @@ -357,6 +357,9 @@ GLFWAPI void glfwWindowHint(int target, int hint) case GLFW_OPENGL_DEBUG_CONTEXT: _glfw.hints.context.debug = hint ? GLFW_TRUE : GLFW_FALSE; break; + case GLFW_CONTEXT_NO_ERROR: + _glfw.hints.context.noerror = hint ? GLFW_TRUE : GLFW_FALSE; + break; case GLFW_OPENGL_PROFILE: _glfw.hints.context.profile = hint; break; @@ -629,6 +632,8 @@ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib) return window->context.profile; case GLFW_CONTEXT_RELEASE_BEHAVIOR: return window->context.release; + case GLFW_CONTEXT_NO_ERROR: + return window->context.noerror; } _glfwInputError(GLFW_INVALID_ENUM, "Invalid window attribute"); diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index a0bfe653..c77a84de 100644 --- a/tests/glfwinfo.c +++ b/tests/glfwinfo.c @@ -88,6 +88,7 @@ static void usage(void) printf(" --stereo request stereo rendering\n"); printf(" --srgb request an sRGB capable framebuffer\n"); printf(" --singlebuffer request single-buffering\n"); + printf(" --no-error request a context that does not emit errors\n"); } static void error_callback(int error, const char* description) @@ -226,7 +227,7 @@ int main(int argc, char** argv) MAJOR, MINOR, PROFILE, ROBUSTNESS, VERSION, REDBITS, GREENBITS, BLUEBITS, ALPHABITS, DEPTHBITS, STENCILBITS, ACCUMREDBITS, ACCUMGREENBITS, ACCUMBLUEBITS, ACCUMALPHABITS, - AUXBUFFERS, SAMPLES, STEREO, SRGB, SINGLEBUFFER }; + AUXBUFFERS, SAMPLES, STEREO, SRGB, SINGLEBUFFER, NOERROR }; const struct option options[] = { { "behavior", 1, NULL, BEHAVIOR }, @@ -255,6 +256,7 @@ int main(int argc, char** argv) { "stereo", 0, NULL, STEREO }, { "srgb", 0, NULL, SRGB }, { "singlebuffer", 0, NULL, SINGLEBUFFER }, + { "no-error", 0, NULL, NOERROR }, { NULL, 0, NULL, 0 } }; @@ -447,6 +449,9 @@ int main(int argc, char** argv) case SINGLEBUFFER: glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_FALSE); break; + case NOERROR: + glfwWindowHint(GLFW_CONTEXT_NO_ERROR, GLFW_TRUE); + break; default: usage(); exit(EXIT_FAILURE); @@ -500,6 +505,8 @@ int main(int argc, char** argv) printf(" debug"); if (flags & GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB) printf(" robustness"); + if (flags & 8/*GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR*/) + printf(" no-error"); putchar('\n'); printf("%s context flags parsed by GLFW:", get_api_name(api)); @@ -510,6 +517,8 @@ int main(int argc, char** argv) printf(" debug"); if (glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS) == GLFW_LOSE_CONTEXT_ON_RESET) printf(" robustness"); + if (glfwGetWindowAttrib(window, GLFW_CONTEXT_NO_ERROR)) + printf(" no-error"); putchar('\n'); }