GLX context option cleanup.

This commit is contained in:
Camilla Berglund 2012-12-13 20:43:15 +01:00
parent 238da01770
commit cf38b34f45

View File

@ -221,7 +221,7 @@ static int errorHandler(Display *display, XErrorEvent* event)
// Create the actual OpenGL context // Create the actual OpenGL context
//======================================================================== //========================================================================
#define setGLXattrib(attribs, index, attribName, attribValue) \ #define setGLXattrib(attribName, attribValue) \
attribs[index++] = attribName; \ attribs[index++] = attribName; \
attribs[index++] = attribValue; attribs[index++] = attribValue;
@ -230,7 +230,6 @@ static int createContext(_GLFWwindow* window,
GLXFBConfigID fbconfigID) GLXFBConfigID fbconfigID)
{ {
int attribs[40]; int attribs[40];
int dummy, index;
GLXFBConfig* fbconfig; GLXFBConfig* fbconfig;
GLXContext share = NULL; GLXContext share = NULL;
@ -239,17 +238,18 @@ static int createContext(_GLFWwindow* window,
// Retrieve the previously selected GLXFBConfig // Retrieve the previously selected GLXFBConfig
{ {
index = 0; int dummy, index = 0;
setGLXattrib(attribs, index, GLX_FBCONFIG_ID, (int) fbconfigID); setGLXattrib(GLX_FBCONFIG_ID, (int) fbconfigID);
setGLXattrib(attribs, index, None, None); setGLXattrib(None, None);
if (_glfwLibrary.GLX.SGIX_fbconfig) if (_glfwLibrary.GLX.SGIX_fbconfig)
{ {
fbconfig = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, fbconfig =
_glfwLibrary.X11.screen, _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display,
attribs, _glfwLibrary.X11.screen,
&dummy); attribs,
&dummy);
} }
else else
{ {
@ -270,8 +270,9 @@ static int createContext(_GLFWwindow* window,
// Retrieve the corresponding visual // Retrieve the corresponding visual
if (_glfwLibrary.GLX.SGIX_fbconfig) if (_glfwLibrary.GLX.SGIX_fbconfig)
{ {
window->GLX.visual = _glfwLibrary.GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display, window->GLX.visual =
*fbconfig); _glfwLibrary.GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display,
*fbconfig);
} }
else else
{ {
@ -288,9 +289,77 @@ static int createContext(_GLFWwindow* window,
return GL_FALSE; return GL_FALSE;
} }
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
{
if (!_glfwLibrary.GLX.ARB_create_context ||
!_glfwLibrary.GLX.ARB_create_context_profile ||
!_glfwLibrary.GLX.EXT_create_context_es2_profile)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"GLX: OpenGL ES requested but "
"GLX_EXT_create_context_es2_profile is unavailable");
return GL_FALSE;
}
}
if (wndconfig->glForward)
{
if (!_glfwLibrary.GLX.ARB_create_context)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"GLX: Forward compatibility requested but "
"GLX_ARB_create_context_profile is unavailable");
return GL_FALSE;
}
}
if (wndconfig->glProfile)
{
if (!_glfwLibrary.GLX.ARB_create_context ||
!_glfwLibrary.GLX.ARB_create_context_profile)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"GLX: An OpenGL profile requested but "
"GLX_ARB_create_context_profile is unavailable");
return GL_FALSE;
}
}
if (_glfwLibrary.GLX.ARB_create_context) if (_glfwLibrary.GLX.ARB_create_context)
{ {
index = 0; int index = 0, mask = 0, flags = 0, strategy = 0;
if (wndconfig->clientAPI == GLFW_OPENGL_API)
{
if (wndconfig->glForward)
flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
if (wndconfig->glDebug)
flags |= GLX_CONTEXT_DEBUG_BIT_ARB;
if (wndconfig->glProfile)
{
if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE)
mask |= GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE)
mask |= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
}
}
else
mask |= GLX_CONTEXT_ES2_PROFILE_BIT_EXT;
if (wndconfig->glRobustness != GLFW_NO_ROBUSTNESS)
{
if (_glfwLibrary.GLX.ARB_create_context_robustness)
{
if (wndconfig->glRobustness == GLFW_NO_RESET_NOTIFICATION)
strategy = GLX_NO_RESET_NOTIFICATION_ARB;
else if (wndconfig->glRobustness == GLFW_LOSE_CONTEXT_ON_RESET)
strategy = GLX_LOSE_CONTEXT_ON_RESET_ARB;
flags |= GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB;
}
}
if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0) if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0)
{ {
@ -298,87 +367,20 @@ static int createContext(_GLFWwindow* window,
// necessary, as explicitly requesting version 1.0 does not always // necessary, as explicitly requesting version 1.0 does not always
// return the highest available version // return the highest available version
setGLXattrib(attribs, index, GLX_CONTEXT_MAJOR_VERSION_ARB, wndconfig->glMajor); setGLXattrib(GLX_CONTEXT_MAJOR_VERSION_ARB, wndconfig->glMajor);
setGLXattrib(attribs, index, GLX_CONTEXT_MINOR_VERSION_ARB, wndconfig->glMinor); setGLXattrib(GLX_CONTEXT_MINOR_VERSION_ARB, wndconfig->glMinor);
} }
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) if (mask)
{ setGLXattrib(GLX_CONTEXT_PROFILE_MASK_ARB, mask);
if (!_glfwLibrary.GLX.ARB_create_context_profile ||
!_glfwLibrary.GLX.EXT_create_context_es2_profile)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"GLX: OpenGL ES requested but "
"GLX_EXT_create_context_es2_profile is unavailable");
return GL_FALSE;
}
setGLXattrib(attribs, index, if (flags)
GLX_CONTEXT_PROFILE_MASK_ARB, setGLXattrib(GLX_CONTEXT_FLAGS_ARB, flags);
GLX_CONTEXT_ES2_PROFILE_BIT_EXT);
}
if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) if (strategy)
{ setGLXattrib(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, strategy);
int flags = 0;
if (wndconfig->glForward) setGLXattrib(None, None);
flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
if (wndconfig->glDebug)
flags |= GLX_CONTEXT_DEBUG_BIT_ARB;
if (wndconfig->glRobustness)
flags |= GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB;
setGLXattrib(attribs, index, GLX_CONTEXT_FLAGS_ARB, flags);
}
if (wndconfig->glProfile)
{
int flags = 0;
if (!_glfwLibrary.GLX.ARB_create_context_profile)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"GLX: An OpenGL profile requested but "
"GLX_ARB_create_context_profile is unavailable");
return GL_FALSE;
}
if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE)
flags = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE)
flags = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
setGLXattrib(attribs, index, GLX_CONTEXT_PROFILE_MASK_ARB, flags);
}
if (wndconfig->glRobustness)
{
int strategy;
if (!_glfwLibrary.GLX.ARB_create_context_robustness)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"GLX: An OpenGL robustness strategy was "
"requested but GLX_ARB_create_context_robustness "
"is unavailable");
return GL_FALSE;
}
if (wndconfig->glRobustness == GLFW_NO_RESET_NOTIFICATION)
strategy = GLX_NO_RESET_NOTIFICATION_ARB;
else if (wndconfig->glRobustness == GLFW_LOSE_CONTEXT_ON_RESET)
strategy = GLX_LOSE_CONTEXT_ON_RESET_ARB;
setGLXattrib(attribs,
index,
GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
strategy);
}
setGLXattrib(attribs, index, None, None);
// This is the only place we set an Xlib error handler, and we only do // This is the only place we set an Xlib error handler, and we only do
// it because glXCreateContextAttribsARB generates a BadMatch error if // it because glXCreateContextAttribsARB generates a BadMatch error if
@ -424,7 +426,7 @@ static int createContext(_GLFWwindow* window,
// TODO: Handle all the various error codes here // TODO: Handle all the various error codes here
_glfwSetError(GLFW_PLATFORM_ERROR, _glfwSetError(GLFW_PLATFORM_ERROR,
"GLX: Failed to create OpenGL context"); "GLX: Failed to create context");
return GL_FALSE; return GL_FALSE;
} }