Use OpenGL to get default framebuffer properties.

This commit is contained in:
Camilla Berglund 2012-08-02 01:18:35 +02:00
parent 3a72f33541
commit 053737e660
6 changed files with 47 additions and 214 deletions

View File

@ -1042,63 +1042,6 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
void _glfwPlatformRefreshWindowParams(void)
{
GLint value;
_GLFWwindow* window = _glfwLibrary.currentWindow;
// Since GLFW doesn't understand screens, we use virtual screen zero
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAAlphaSize
forVirtualScreen:0];
window->alphaBits = value;
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAColorSize
forVirtualScreen:0];
// It seems that the color size includes the size of the alpha channel so
// we subtract it before splitting
_glfwSplitBPP(value - window->alphaBits,
&window->redBits,
&window->greenBits,
&window->blueBits);
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFADepthSize
forVirtualScreen:0];
window->depthBits = value;
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAStencilSize
forVirtualScreen:0];
window->stencilBits = value;
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAAccumSize
forVirtualScreen:0];
_glfwSplitBPP(value,
&window->accumRedBits,
&window->accumGreenBits,
&window->accumBlueBits);
// TODO: Figure out what to set this value to
window->accumAlphaBits = 0;
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAAuxBuffers
forVirtualScreen:0];
window->auxBuffers = value;
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFAStereo
forVirtualScreen:0];
window->stereo = value;
[window->NSGL.pixelFormat getValues:&value
forAttribute:NSOpenGLPFASamples
forVirtualScreen:0];
window->samples = value;
}

View File

@ -196,19 +196,19 @@ struct _GLFWwindow
char key[GLFW_KEY_LAST + 1];
// Framebuffer attributes
int redBits;
int greenBits;
int blueBits;
int alphaBits;
int depthBits;
int stencilBits;
int accumRedBits;
int accumGreenBits;
int accumBlueBits;
int accumAlphaBits;
int auxBuffers;
GLint redBits;
GLint greenBits;
GLint blueBits;
GLint alphaBits;
GLint depthBits;
GLint stencilBits;
GLint accumRedBits;
GLint accumGreenBits;
GLint accumBlueBits;
GLint accumAlphaBits;
GLint auxBuffers;
GLboolean stereo;
int samples;
GLint samples;
// OpenGL extensions and context attributes
int glMajor, glMinor, glRevision;
@ -363,6 +363,7 @@ int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);
const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
const _GLFWfbconfig* alternatives,
unsigned int count);
void _glfwRefreshContextParams(void);
GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig);
GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig);

View File

@ -347,12 +347,13 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
//========================================================================
// Checks whether the specified context fulfils the requirements
// It blames glfwOpenWindow because that's the only caller
// Reads back context properties
//========================================================================
GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig)
void _glfwRefreshContextParams(void)
{
_GLFWwindow* window = _glfwLibrary.currentWindow;
parseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision);
// Read back forward-compatibility flag
@ -387,8 +388,36 @@ GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig)
}
}
window->glRobustness = wndconfig->glRobustness;
glGetIntegerv(GL_RED_BITS, &window->redBits);
glGetIntegerv(GL_GREEN_BITS, &window->greenBits);
glGetIntegerv(GL_BLUE_BITS, &window->blueBits);
glGetIntegerv(GL_ALPHA_BITS, &window->alphaBits);
glGetIntegerv(GL_DEPTH_BITS, &window->depthBits);
glGetIntegerv(GL_STENCIL_BITS, &window->stencilBits);
glGetIntegerv(GL_ACCUM_RED_BITS, &window->accumRedBits);
glGetIntegerv(GL_ACCUM_GREEN_BITS, &window->accumGreenBits);
glGetIntegerv(GL_ACCUM_BLUE_BITS, &window->accumBlueBits);
glGetIntegerv(GL_ACCUM_ALPHA_BITS, &window->accumAlphaBits);
glGetIntegerv(GL_AUX_BUFFERS, &window->auxBuffers);
glGetBooleanv(GL_STEREO, &window->stereo);
if (_glfwPlatformExtensionSupported("GL_ARB_multisample"))
glGetIntegerv(GL_SAMPLES_ARB, &window->samples);
else
window->samples = 0;
}
//========================================================================
// Checks whether the specified context fulfils the requirements
// It blames glfwOpenWindow because that's the only caller
//========================================================================
GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig)
{
if (window->glMajor < wndconfig->glMajor ||
(window->glMajor == wndconfig->glMajor &&
window->glMinor < wndconfig->glMinor))

View File

@ -290,82 +290,6 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
}
//========================================================================
// Read back framebuffer parameters from the context
//========================================================================
static void refreshContextParams(_GLFWwindow* window, int pixelFormat)
{
PIXELFORMATDESCRIPTOR pfd;
if (window->WGL.ARB_pixel_format)
{
window->redBits =
getPixelFormatAttrib(window, pixelFormat, WGL_RED_BITS_ARB);
window->greenBits =
getPixelFormatAttrib(window, pixelFormat, WGL_GREEN_BITS_ARB);
window->blueBits =
getPixelFormatAttrib(window, pixelFormat, WGL_BLUE_BITS_ARB);
window->alphaBits =
getPixelFormatAttrib(window, pixelFormat, WGL_ALPHA_BITS_ARB);
window->depthBits =
getPixelFormatAttrib(window, pixelFormat, WGL_DEPTH_BITS_ARB);
window->stencilBits =
getPixelFormatAttrib(window, pixelFormat, WGL_STENCIL_BITS_ARB);
window->accumRedBits =
getPixelFormatAttrib(window, pixelFormat, WGL_ACCUM_RED_BITS_ARB);
window->accumGreenBits =
getPixelFormatAttrib(window, pixelFormat, WGL_ACCUM_GREEN_BITS_ARB);
window->accumBlueBits =
getPixelFormatAttrib(window, pixelFormat, WGL_ACCUM_BLUE_BITS_ARB);
window->accumAlphaBits =
getPixelFormatAttrib(window, pixelFormat, WGL_ACCUM_ALPHA_BITS_ARB);
window->auxBuffers =
getPixelFormatAttrib(window, pixelFormat, WGL_AUX_BUFFERS_ARB);
window->stereo =
getPixelFormatAttrib(window, pixelFormat, WGL_STEREO_ARB) ? GL_TRUE : GL_FALSE;
if (window->WGL.ARB_multisample)
{
window->samples = getPixelFormatAttrib(window, pixelFormat, WGL_SAMPLES_ARB);
// We force 1 to zero here because all the other APIs say zero when
// they really mean 1
if (window->samples == 1)
window->samples = 0;
}
else
window->samples = 0;
}
else
{
DescribePixelFormat(window->WGL.DC, pixelFormat,
sizeof(PIXELFORMATDESCRIPTOR), &pfd);
// "Standard" window parameters
window->redBits = pfd.cRedBits;
window->greenBits = pfd.cGreenBits;
window->blueBits = pfd.cBlueBits;
window->alphaBits = pfd.cAlphaBits;
window->depthBits = pfd.cDepthBits;
window->stencilBits = pfd.cStencilBits;
window->accumRedBits = pfd.cAccumRedBits;
window->accumGreenBits = pfd.cAccumGreenBits;
window->accumBlueBits = pfd.cAccumBlueBits;
window->accumAlphaBits = pfd.cAccumAlphaBits;
window->auxBuffers = pfd.cAuxBuffers;
window->stereo = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE;
// If we don't have WGL_ARB_pixel_format then we can't have created a
// multisampling context, so it's safe to hardcode zero here
window->samples = 0;
}
}
//========================================================================
// Creates an OpenGL context on the specified device context
//========================================================================
@ -516,7 +440,6 @@ static GLboolean createContext(_GLFWwindow* window,
glfwMakeContextCurrent(window);
initWGLExtensions(window);
refreshContextParams(window, pixelFormat);
return GL_TRUE;
}

View File

@ -320,6 +320,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
// Cache the actual (as opposed to desired) window parameters
glfwMakeContextCurrent(window);
_glfwRefreshContextParams();
_glfwPlatformRefreshWindowParams();
if (!_glfwIsValidContext(window, &wndconfig))

View File

@ -197,68 +197,6 @@ static int errorHandler(Display *display, XErrorEvent* event)
}
//========================================================================
// Read back framebuffer parameters from the context
//========================================================================
static void refreshContextParams(_GLFWwindow* window, GLXFBConfigID fbconfigID)
{
int dummy;
GLXFBConfig* fbconfig;
int attribs[] = { GLX_FBCONFIG_ID, fbconfigID, None };
if (_glfwLibrary.GLX.SGIX_fbconfig)
{
fbconfig = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
attribs,
&dummy);
}
else
{
fbconfig = glXChooseFBConfig(_glfwLibrary.X11.display,
_glfwLibrary.X11.screen,
attribs,
&dummy);
}
if (fbconfig == NULL)
{
// This should never ever happen
// TODO: Flag this as an error and propagate up
_glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Cannot find known "
"GLXFBConfig by ID. This cannot "
"happen. Have a nice day.\n");
abort();
}
window->redBits = getFBConfigAttrib(window, *fbconfig, GLX_RED_SIZE);
window->greenBits = getFBConfigAttrib(window, *fbconfig, GLX_GREEN_SIZE);
window->blueBits = getFBConfigAttrib(window, *fbconfig, GLX_BLUE_SIZE);
window->alphaBits = getFBConfigAttrib(window, *fbconfig, GLX_ALPHA_SIZE);
window->depthBits = getFBConfigAttrib(window, *fbconfig, GLX_DEPTH_SIZE);
window->stencilBits = getFBConfigAttrib(window, *fbconfig, GLX_STENCIL_SIZE);
window->accumRedBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_RED_SIZE);
window->accumGreenBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_GREEN_SIZE);
window->accumBlueBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_BLUE_SIZE);
window->accumAlphaBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_ALPHA_SIZE);
window->auxBuffers = getFBConfigAttrib(window, *fbconfig, GLX_AUX_BUFFERS);
window->stereo = getFBConfigAttrib(window, *fbconfig, GLX_STEREO) ? GL_TRUE : GL_FALSE;
// Get FSAA buffer sample count
if (_glfwLibrary.GLX.ARB_multisample)
window->samples = getFBConfigAttrib(window, *fbconfig, GLX_SAMPLES);
else
window->samples = 0;
XFree(fbconfig);
}
//========================================================================
// Create the actual OpenGL context
//========================================================================
@ -463,8 +401,6 @@ static int createContext(_GLFWwindow* window,
return GL_FALSE;
}
refreshContextParams(window, fbconfigID);
return GL_TRUE;
}