From c9808586b3146f036e11efd7a07ca7757a240dc1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 24 Apr 2014 19:21:10 +0200 Subject: [PATCH] Added GLFW_DOUBLEBUFFER. --- README.md | 1 + docs/quick.dox | 2 +- docs/window.dox | 14 +++++++++++--- include/GLFW/glfw3.h | 1 + src/context.c | 6 ++++++ src/glx_context.c | 11 +++++++---- src/internal.h | 2 ++ src/nsgl_context.m | 4 +++- src/wgl_context.c | 23 ++++++++++++++++------- src/window.c | 20 +++++++++++++------- 10 files changed, 61 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index e6822bfc..520073d8 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ GLFW bundles a number of dependencies in the `deps/` directory. - Added `GLFW_AUTO_ICONIFY` for controlling whether full screen windows automatically iconify (and restore the previous video mode) on focus loss - Added `GLFW_DONT_CARE` for indicating that any value is acceptable + - Added `GLFW_DOUBLEBUFFER` for controlling whether to use double buffering - Added `GLFW_INCLUDE_ES31` for including the OpenGL ES 3.1 header - Added *partial and experimental* support for Wayland - Bugfix: The debug context attribute was set from `GL_ARB_debug_output` even diff --git a/docs/quick.dox b/docs/quick.dox index d0247304..b90a54da 100644 --- a/docs/quick.dox +++ b/docs/quick.dox @@ -250,7 +250,7 @@ double time = glfwGetTime(); @section quick_swap_buffers Swapping buffers -GLFW windows always use double-buffering. That means that you have two +GLFW windows by default use double buffering. That means that you have two rendering buffers; a front buffer and a back buffer. The front buffer is the one being displayed and the back buffer the one you render to. diff --git a/docs/window.dox b/docs/window.dox index eece9c8e..a80b698f 100644 --- a/docs/window.dox +++ b/docs/window.dox @@ -93,6 +93,7 @@ find out the actual attributes of the created window and context, use the The following hints are hard constraints: - `GLFW_STEREO` +- `GLFW_DOUBLEBUFFER` - `GLFW_CLIENT_API` The following additional hints are hard constraints if requesting an OpenGL @@ -137,7 +138,8 @@ application has no preference. The `GLFW_AUX_BUFFERS` hint specifies the desired number of auxiliary buffers. `GLFW_DONT_CARE` means the application has no preference. -The `GLFW_STEREO` hint specifies whether to use stereoscopic rendering. +The `GLFW_STEREO` hint specifies whether to use stereoscopic rendering. This is +a hard constraint. The `GLFW_SAMPLES` hint specifies the desired number of samples to use for multisampling. Zero disables multisampling. `GLFW_DONT_CARE` means the @@ -146,6 +148,10 @@ application has no preference. The `GLFW_SRGB_CAPABLE` hint specifies whether the framebuffer should be sRGB capable. +The `GLFW_DOUBLEBUFFER` hint specifies whether the framebuffer should be double +buffered. You nearly always want to use double buffering. This is a hard +constraint. + The `GLFW_REFRESH_RATE` hint specifies the desired refresh rate for full screen windows. If set to zero, the highest available refresh rate will be used. This hint is ignored for windowed mode windows. @@ -154,7 +160,8 @@ hint is ignored for windowed mode windows. @subsection window_hints_ctx Context related hints The `GLFW_CLIENT_API` hint specifies which client API to create the context -for. Possible values are `GLFW_OPENGL_API` and `GLFW_OPENGL_ES_API`. +for. Possible values are `GLFW_OPENGL_API` and `GLFW_OPENGL_ES_API`. This is +a hard constraint. The `GLFW_CONTEXT_VERSION_MAJOR` and `GLFW_CONTEXT_VERSION_MINOR` hints specify the client API version that the created context must be compatible @@ -219,6 +226,7 @@ a robustness strategy. | `GLFW_REFRESH_RATE` | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE` | | `GLFW_STEREO` | `GL_FALSE` | `GL_TRUE` or `GL_FALSE` | | `GLFW_SRGB_CAPABLE` | `GL_FALSE` | `GL_TRUE` or `GL_FALSE` | +| `GLFW_DOUBLEBUFFER` | `GL_TRUE` | `GL_TRUE` or `GL_FALSE` | | `GLFW_CLIENT_API` | `GLFW_OPENGL_API` | `GLFW_OPENGL_API` or `GLFW_OPENGL_ES_API` | | `GLFW_CONTEXT_VERSION_MAJOR` | 1 | Any valid major version number of the chosen client API | | `GLFW_CONTEXT_VERSION_MINOR` | 0 | Any valid minor version number of the chosen client API | @@ -468,7 +476,7 @@ used by the context. This is `GLFW_LOSE_CONTEXT_ON_RESET` or @section window_swap Swapping buffers -GLFW windows are always double buffered. That means that you have two +GLFW windows are by default double buffered. That means that you have two rendering buffers; a front buffer and a back buffer. The front buffer is the one being displayed and the back buffer the one you render to. diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 553aecbb..e72c7db3 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -514,6 +514,7 @@ extern "C" { #define GLFW_SAMPLES 0x0002100D #define GLFW_SRGB_CAPABLE 0x0002100E #define GLFW_REFRESH_RATE 0x0002100F +#define GLFW_DOUBLEBUFFER 0x00021010 #define GLFW_CLIENT_API 0x00022001 #define GLFW_CONTEXT_VERSION_MAJOR 0x00022002 diff --git a/src/context.c b/src/context.c index 6b53f792..61c3400d 100644 --- a/src/context.c +++ b/src/context.c @@ -222,6 +222,12 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired, continue; } + if (desired->doublebuffer != current->doublebuffer) + { + // Double buffering is a hard constraint + continue; + } + // Count number of missing buffers { missing = 0; diff --git a/src/glx_context.c b/src/glx_context.c index 076b7b3c..15e300be 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -85,10 +85,9 @@ static GLboolean chooseFBConfig(const _GLFWfbconfig* desired, GLXFBConfig* resul const GLXFBConfig n = nativeConfigs[i]; _GLFWfbconfig* u = usableConfigs + usableCount; - if (!getFBConfigAttrib(n, GLX_DOUBLEBUFFER) || - !getFBConfigAttrib(n, GLX_VISUAL_ID)) + if (!getFBConfigAttrib(n, GLX_VISUAL_ID)) { - // Only consider double-buffered GLXFBConfigs with associated visuals + // Only consider GLXFBConfigs with associated visuals continue; } @@ -121,7 +120,11 @@ static GLboolean chooseFBConfig(const _GLFWfbconfig* desired, GLXFBConfig* resul u->accumAlphaBits = getFBConfigAttrib(n, GLX_ACCUM_ALPHA_SIZE); u->auxBuffers = getFBConfigAttrib(n, GLX_AUX_BUFFERS); - u->stereo = getFBConfigAttrib(n, GLX_STEREO); + + if (getFBConfigAttrib(n, GLX_STEREO)) + u->stereo = GL_TRUE; + if (getFBConfigAttrib(n, GLX_DOUBLEBUFFER)) + u->doublebuffer = GL_TRUE; if (_glfw.glx.ARB_multisample) u->samples = getFBConfigAttrib(n, GLX_SAMPLES); diff --git a/src/internal.h b/src/internal.h index 7b31725a..f0d1d60b 100644 --- a/src/internal.h +++ b/src/internal.h @@ -200,6 +200,7 @@ struct _GLFWfbconfig int stereo; int samples; int sRGB; + int doublebuffer; // This is defined in the context API's context.h _GLFW_PLATFORM_FBCONFIG; @@ -325,6 +326,7 @@ struct _GLFWlibrary int samples; int sRGB; int refreshRate; + int doublebuffer; int api; int major; int minor; diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 5bd3e83f..5401f913 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -127,7 +127,6 @@ int _glfwCreateContext(_GLFWwindow* window, // Arbitrary array size here NSOpenGLPixelFormatAttribute attributes[40]; - ADD_ATTR(NSOpenGLPFADoubleBuffer); ADD_ATTR(NSOpenGLPFAClosestPolicy); #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 @@ -180,6 +179,9 @@ int _glfwCreateContext(_GLFWwindow* window, if (fbconfig->stereo) ADD_ATTR(NSOpenGLPFAStereo); + if (fbconfig->doublebuffer) + ADD_ATTR(NSOpenGLPFADoubleBuffer); + if (fbconfig->samples != GLFW_DONT_CARE) { if (fbconfig->samples == 0) diff --git a/src/wgl_context.c b/src/wgl_context.c index 038846c5..2fdb9a9a 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -181,8 +181,7 @@ static GLboolean choosePixelFormat(_GLFWwindow* window, { // Get pixel format attributes through WGL_ARB_pixel_format if (!getPixelFormatAttrib(window, n, WGL_SUPPORT_OPENGL_ARB) || - !getPixelFormatAttrib(window, n, WGL_DRAW_TO_WINDOW_ARB) || - !getPixelFormatAttrib(window, n, WGL_DOUBLE_BUFFER_ARB)) + !getPixelFormatAttrib(window, n, WGL_DRAW_TO_WINDOW_ARB)) { continue; } @@ -213,13 +212,20 @@ static GLboolean choosePixelFormat(_GLFWwindow* window, u->accumAlphaBits = getPixelFormatAttrib(window, n, WGL_ACCUM_ALPHA_BITS_ARB); u->auxBuffers = getPixelFormatAttrib(window, n, WGL_AUX_BUFFERS_ARB); - u->stereo = getPixelFormatAttrib(window, n, WGL_STEREO_ARB); + + if (getPixelFormatAttrib(window, n, WGL_STEREO_ARB)) + u->stereo = GL_TRUE; + if (getPixelFormatAttrib(window, n, WGL_DOUBLE_BUFFER_ARB)) + u->doublebuffer = GL_TRUE; if (window->wgl.ARB_multisample) u->samples = getPixelFormatAttrib(window, n, WGL_SAMPLES_ARB); if (window->wgl.ARB_framebuffer_sRGB) - u->sRGB = getPixelFormatAttrib(window, n, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB); + { + if (getPixelFormatAttrib(window, n, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB)) + u->sRGB = GL_TRUE; + } } else { @@ -236,8 +242,7 @@ static GLboolean choosePixelFormat(_GLFWwindow* window, } if (!(pfd.dwFlags & PFD_DRAW_TO_WINDOW) || - !(pfd.dwFlags & PFD_SUPPORT_OPENGL) || - !(pfd.dwFlags & PFD_DOUBLEBUFFER)) + !(pfd.dwFlags & PFD_SUPPORT_OPENGL)) { continue; } @@ -265,7 +270,11 @@ static GLboolean choosePixelFormat(_GLFWwindow* window, u->accumAlphaBits = pfd.cAccumAlphaBits; u->auxBuffers = pfd.cAuxBuffers; - u->stereo = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE; + + if (pfd.dwFlags & PFD_STEREO) + u->stereo = GL_TRUE; + if (pfd.dwFlags & PFD_DOUBLEBUFFER) + u->doublebuffer = GL_TRUE; } u->wgl = n; diff --git a/src/window.c b/src/window.c index 39b1c691..bafe0b70 100644 --- a/src/window.c +++ b/src/window.c @@ -157,6 +157,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, fbconfig.stereo = _glfw.hints.stereo; fbconfig.samples = _glfw.hints.samples; fbconfig.sRGB = _glfw.hints.sRGB; + fbconfig.doublebuffer = _glfw.hints.doublebuffer ? GL_TRUE : GL_FALSE; // Set up desired window config wndconfig.width = width; @@ -266,13 +267,15 @@ void glfwDefaultWindowHints(void) _glfw.hints.decorated = GL_TRUE; _glfw.hints.autoIconify = GL_TRUE; - // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil - _glfw.hints.redBits = 8; - _glfw.hints.greenBits = 8; - _glfw.hints.blueBits = 8; - _glfw.hints.alphaBits = 8; - _glfw.hints.depthBits = 24; - _glfw.hints.stencilBits = 8; + // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil, + // double buffered + _glfw.hints.redBits = 8; + _glfw.hints.greenBits = 8; + _glfw.hints.blueBits = 8; + _glfw.hints.alphaBits = 8; + _glfw.hints.depthBits = 24; + _glfw.hints.stencilBits = 8; + _glfw.hints.doublebuffer = GL_TRUE; } GLFWAPI void glfwWindowHint(int target, int hint) @@ -320,6 +323,9 @@ GLFWAPI void glfwWindowHint(int target, int hint) case GLFW_REFRESH_RATE: _glfw.hints.refreshRate = hint; break; + case GLFW_DOUBLEBUFFER: + _glfw.hints.doublebuffer = hint; + break; case GLFW_RESIZABLE: _glfw.hints.resizable = hint; break;