From 07260cb76870253ac95ab230895990c86b36ba0c Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Tue, 16 Nov 2010 02:33:21 +0100
Subject: [PATCH] Added initial framebuffer sRGB support.
---
include/GL/glfw3.h | 11 ++++++-----
readme.html | 1 +
src/internal.h | 3 +++
src/win32/platform.h | 2 ++
src/win32/win32_window.c | 16 +++++++++++++++-
src/window.c | 12 ++++++++++++
src/x11/platform.h | 3 +++
src/x11/x11_window.c | 11 +++++++++++
8 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h
index d645e9fa..a8e3866c 100644
--- a/include/GL/glfw3.h
+++ b/include/GL/glfw3.h
@@ -329,11 +329,12 @@ extern "C" {
#define GLFW_STEREO 0x00020010
#define GLFW_WINDOW_NO_RESIZE 0x00020011
#define GLFW_FSAA_SAMPLES 0x00020012
-#define GLFW_OPENGL_VERSION_MAJOR 0x00020013
-#define GLFW_OPENGL_VERSION_MINOR 0x00020014
-#define GLFW_OPENGL_FORWARD_COMPAT 0x00020015
-#define GLFW_OPENGL_DEBUG_CONTEXT 0x00020016
-#define GLFW_OPENGL_PROFILE 0x00020017
+#define GLFW_SRGB_CAPABLE 0x00020013
+#define GLFW_OPENGL_VERSION_MAJOR 0x00020014
+#define GLFW_OPENGL_VERSION_MINOR 0x00020015
+#define GLFW_OPENGL_FORWARD_COMPAT 0x00020016
+#define GLFW_OPENGL_DEBUG_CONTEXT 0x00020017
+#define GLFW_OPENGL_PROFILE 0x00020018
/* GLFW_OPENGL_PROFILE bit tokens */
#define GLFW_OPENGL_CORE_PROFILE 0x00000001
diff --git a/readme.html b/readme.html
index 03df9905..19e7208f 100644
--- a/readme.html
+++ b/readme.html
@@ -272,6 +272,7 @@ version of GLFW.
Added glfwSetWindowIconifyCallback
function and GLFWwindowiconifyfun
type for receiving window iconification events
Added glfwGetCurrentWindow
function for retrieving the window whose OpenGL context is current
Added GLFW_OPENGL_ES2_PROFILE
profile for creating OpenGL ES 2.0 contexts using the GLX_EXT_create_context_es2_profile
and WGL_EXT_create_context_es2_profile
extensions
+ Added GLFW_SRGB_CAPABLE
hint for creating sRGB-capable contexts using the GL_ARB_framebuffer_sRGB
and GL_EXT_framebuffer_sRGB
extensions
Added windows
simple multi-window test program
Added sharing
simple OpenGL object sharing test program
Added a parameter to glfwOpenWindow
for specifying a context the new window's context will share objects with
diff --git a/src/internal.h b/src/internal.h
index bcd7408f..b7e14dcd 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -90,6 +90,7 @@ struct _GLFWhints
GLboolean stereo;
GLboolean windowNoResize;
int samples;
+ GLboolean sRGB;
int glMajor;
int glMinor;
GLboolean glForward;
@@ -141,6 +142,7 @@ struct _GLFWfbconfig
int auxBuffers;
GLboolean stereo;
int samples;
+ GLboolean sRGB;
GLFWintptr platformID;
};
@@ -186,6 +188,7 @@ struct _GLFWwindow
int auxBuffers;
GLboolean stereo;
int samples;
+ GLboolean sRGB;
// OpenGL extensions and context attributes
GLboolean accelerated; // GL_TRUE if OpenGL context is "accelerated"
diff --git a/src/win32/platform.h b/src/win32/platform.h
index 144ff75a..0bf8a48d 100644
--- a/src/win32/platform.h
+++ b/src/win32/platform.h
@@ -239,6 +239,8 @@ typedef struct _GLFWcontextWGL
PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB;
GLboolean has_WGL_EXT_swap_control;
GLboolean has_WGL_ARB_multisample;
+ GLboolean has_WGL_EXT_framebuffer_sRGB;
+ GLboolean has_WGL_ARB_framebuffer_sRGB;
GLboolean has_WGL_ARB_pixel_format;
GLboolean has_WGL_ARB_create_context;
GLboolean has_WGL_ARB_create_context_profile;
diff --git a/src/win32/win32_window.c b/src/win32/win32_window.c
index 81d4497c..1fcad004 100644
--- a/src/win32/win32_window.c
+++ b/src/win32/win32_window.c
@@ -251,6 +251,11 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
}
else
result[*found].samples = 0;
+
+ if (window->WGL.has_WGL_EXT_framebuffer_sRGB || window->WGL.has_WGL_ARB_framebuffer_sRGB)
+ result[*found].sRGB = getPixelFormatAttrib(window, i, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB);
+ else
+ result[*found].sRGB = GL_FALSE;
}
else
{
@@ -294,8 +299,9 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
result[*found].auxBuffers = pfd.cAuxBuffers;
result[*found].stereo = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE;
- // PFD pixel formats do not support FSAA
+ // PFD pixel formats do not support FSAA or sRGB
result[*found].samples = 0;
+ result[*found].sRGB = GL_FALSE;
}
result[*found].platformID = i;
@@ -1024,6 +1030,8 @@ static void initWGLExtensions(_GLFWwindow* window)
window->WGL.has_WGL_EXT_swap_control = GL_FALSE;
window->WGL.has_WGL_ARB_pixel_format = GL_FALSE;
window->WGL.has_WGL_ARB_multisample = GL_FALSE;
+ window->WGL.has_WGL_EXT_framebuffer_sRGB = GL_FALSE;
+ window->WGL.has_WGL_ARB_framebuffer_sRGB = GL_FALSE;
window->WGL.has_WGL_ARB_create_context = GL_FALSE;
window->WGL.has_WGL_ARB_create_context_profile = GL_FALSE;
@@ -1040,6 +1048,12 @@ static void initWGLExtensions(_GLFWwindow* window)
if (_glfwPlatformExtensionSupported("WGL_ARB_multisample"))
window->WGL.has_WGL_ARB_multisample = GL_TRUE;
+ if (_glfwPlatformExtensionSupported("WGL_EXT_framebuffer_sRGB"))
+ window->WGL.has_WGL_EXT_framebuffer_sRGB = GL_TRUE;
+
+ if (_glfwPlatformExtensionSupported("WGL_ARB_framebuffer_sRGB"))
+ window->WGL.has_WGL_ARB_framebuffer_sRGB = GL_TRUE;
+
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context"))
{
window->WGL.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
diff --git a/src/window.c b/src/window.c
index e9135b50..1add8d4f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -269,6 +269,12 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
continue;
}
+ if (desired->sRGB && !current->sRGB)
+ {
+ // sRGB framebuffer is a hard constraint
+ continue;
+ }
+
// Count number of missing buffers
{
missing = 0;
@@ -448,6 +454,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
fbconfig.auxBuffers = Max(_glfwLibrary.hints.auxBuffers, 0);
fbconfig.stereo = _glfwLibrary.hints.stereo ? GL_TRUE : GL_FALSE;
fbconfig.samples = Max(_glfwLibrary.hints.samples, 0);
+ fbconfig.sRGB = _glfwLibrary.hints.sRGB ? GL_TRUE : GL_FALSE;
// Set up desired window config
wndconfig.mode = mode;
@@ -731,6 +738,9 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
case GLFW_FSAA_SAMPLES:
_glfwLibrary.hints.samples = hint;
break;
+ case GLFW_SRGB_CAPABLE:
+ _glfwLibrary.hints.sRGB = hint;
+ break;
case GLFW_OPENGL_VERSION_MAJOR:
_glfwLibrary.hints.glMajor = hint;
break;
@@ -1040,6 +1050,8 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param)
return window->windowNoResize;
case GLFW_FSAA_SAMPLES:
return window->samples;
+ case GLFW_SRGB_CAPABLE:
+ return window->sRGB;
case GLFW_OPENGL_VERSION_MAJOR:
return window->glMajor;
case GLFW_OPENGL_VERSION_MINOR:
diff --git a/src/x11/platform.h b/src/x11/platform.h
index 05bc2544..a243bffd 100644
--- a/src/x11/platform.h
+++ b/src/x11/platform.h
@@ -110,6 +110,9 @@ typedef struct _GLFWcontextGLX
GLboolean has_GLX_SGI_swap_control;
GLboolean has_GLX_EXT_swap_control;
GLboolean has_GLX_ARB_multisample;
+ GLboolean has_GLX_ARB_fbconfig_float;
+ GLboolean has_GLX_ARB_framebuffer_sRGB;
+ GLboolean has_GLX_EXT_framebuffer_sRGB;
GLboolean has_GLX_ARB_create_context;
GLboolean has_GLX_ARB_create_context_profile;
GLboolean has_GLX_EXT_create_context_es2_profile;
diff --git a/src/x11/x11_window.c b/src/x11/x11_window.c
index 8ae0b256..0b026b16 100644
--- a/src/x11/x11_window.c
+++ b/src/x11/x11_window.c
@@ -461,6 +461,11 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
result[*found].auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS);
result[*found].stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO);
+ if (window->GLX.has_GLX_EXT_framebuffer_sRGB || window->GLX.has_GLX_ARB_framebuffer_sRGB)
+ result[*found].sRGB = getFBConfigAttrib(window, fbconfigs[i], GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB);
+ else
+ result[*found].sRGB = GL_FALSE;
+
if (window->GLX.has_GLX_ARB_multisample)
result[*found].samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES);
else
@@ -711,6 +716,12 @@ static void initGLXExtensions(_GLFWwindow* window)
if (_glfwPlatformExtensionSupported("GLX_ARB_multisample"))
window->GLX.has_GLX_ARB_multisample = GL_TRUE;
+ if (_glfwPlatformExtensionSupported("GLX_EXT_framebuffer_sRGB"))
+ window->GLX.has_GLX_EXT_framebuffer_sRGB = GL_TRUE;
+
+ if (_glfwPlatformExtensionSupported("GLX_ARB_framebuffer_sRGB"))
+ window->GLX.has_GLX_ARB_framebuffer_sRGB = GL_TRUE;
+
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context"))
{
window->GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)