1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-30 05:58:52 -05:00

EGL context creation cleanup.

This commit is contained in:
Camilla Berglund 2012-12-16 17:04:43 +01:00
parent bd31ea0a69
commit b9acb777e5

View File

@ -175,7 +175,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window,
// Create the actual OpenGL(|ES) context // Create the actual OpenGL(|ES) context
//======================================================================== //========================================================================
#define setEGLattrib(attribs, index, attribName, attribValue) \ #define setEGLattrib(attribName, attribValue) \
{ \ { \
attribs[index++] = attribName; \ attribs[index++] = attribName; \
attribs[index++] = attribValue; \ attribs[index++] = attribValue; \
@ -186,7 +186,7 @@ static int createContext(_GLFWwindow* window,
EGLint fbconfigID) EGLint fbconfigID)
{ {
int attribs[40]; int attribs[40];
EGLint count, index; EGLint count;
EGLConfig config; EGLConfig config;
EGLContext share = NULL; EGLContext share = NULL;
@ -195,10 +195,10 @@ static int createContext(_GLFWwindow* window,
// Retrieve the previously selected EGLConfig // Retrieve the previously selected EGLConfig
{ {
index = 0; int index = 0;
setEGLattrib(attribs, index, EGL_CONFIG_ID, fbconfigID); setEGLattrib(EGL_CONFIG_ID, fbconfigID);
setEGLattrib(attribs, index, EGL_NONE, EGL_NONE); setEGLattrib(EGL_NONE, EGL_NONE);
eglChooseConfig(_glfwLibrary.EGL.display, attribs, &config, 1, &count); eglChooseConfig(_glfwLibrary.EGL.display, attribs, &config, 1, &count);
if (!count) if (!count)
@ -209,10 +209,8 @@ static int createContext(_GLFWwindow* window,
} }
} }
// Retrieve the corresponding visual
// NOTE: This is the only non-portable code in this file.
// Maybe it would not hurt too much to add #ifdefs for different platforms?
#if defined(_GLFW_X11) #if defined(_GLFW_X11)
// Retrieve the visual corresponding to the chosen EGL config
{ {
int mask; int mask;
EGLint redBits, greenBits, blueBits, alphaBits, visualID = 0; EGLint redBits, greenBits, blueBits, alphaBits, visualID = 0;
@ -264,8 +262,7 @@ static int createContext(_GLFWwindow* window,
{ {
if (!eglBindAPI(EGL_OPENGL_ES_API)) if (!eglBindAPI(EGL_OPENGL_ES_API))
{ {
_glfwSetError(GLFW_PLATFORM_ERROR, _glfwSetError(GLFW_PLATFORM_ERROR, "EGL: OpenGL ES is not supported");
"EGL: OpenGL ES is not supported");
return GL_FALSE; return GL_FALSE;
} }
} }
@ -273,66 +270,65 @@ static int createContext(_GLFWwindow* window,
{ {
if (!eglBindAPI(EGL_OPENGL_API)) if (!eglBindAPI(EGL_OPENGL_API))
{ {
_glfwSetError(GLFW_PLATFORM_ERROR, _glfwSetError(GLFW_PLATFORM_ERROR, "EGL: OpenGL is not supported");
"EGL: OpenGL is not supported");
return GL_FALSE; return GL_FALSE;
} }
} }
index = 0;
if (_glfwLibrary.EGL.KHR_create_context) if (_glfwLibrary.EGL.KHR_create_context)
{ {
setEGLattrib(attribs, index, EGL_CONTEXT_MAJOR_VERSION_KHR, wndconfig->glMajor); int index = 0, mask = 0, flags = 0, strategy = 0;
setEGLattrib(attribs, index, EGL_CONTEXT_MINOR_VERSION_KHR, wndconfig->glMinor);
if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) if (wndconfig->clientAPI == GLFW_OPENGL_API)
{ {
int flags = 0; if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE)
mask |= EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE)
mask |= EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
if (wndconfig->glForward) if (wndconfig->glForward)
flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
if (wndconfig->glDebug) if (wndconfig->glDebug)
flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
if (wndconfig->glRobustness)
flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR;
setEGLattrib(attribs, index, EGL_CONTEXT_FLAGS_KHR, flags);
} }
if (wndconfig->glProfile) if (wndconfig->glRobustness != GLFW_NO_ROBUSTNESS)
{ {
int flags = 0;
if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE)
flags = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE)
flags = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
setEGLattrib(attribs, index, EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, flags);
}
if (wndconfig->glRobustness)
{
int strategy;
if (wndconfig->glRobustness == GLFW_NO_RESET_NOTIFICATION) if (wndconfig->glRobustness == GLFW_NO_RESET_NOTIFICATION)
strategy = EGL_NO_RESET_NOTIFICATION_KHR; strategy = EGL_NO_RESET_NOTIFICATION_KHR;
else if (wndconfig->glRobustness == GLFW_LOSE_CONTEXT_ON_RESET) else if (wndconfig->glRobustness == GLFW_LOSE_CONTEXT_ON_RESET)
strategy = EGL_LOSE_CONTEXT_ON_RESET_KHR; strategy = EGL_LOSE_CONTEXT_ON_RESET_KHR;
setEGLattrib(attribs, index, EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, strategy); flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR;
} }
if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0)
{
setEGLattrib(EGL_CONTEXT_MAJOR_VERSION_KHR, wndconfig->glMajor);
setEGLattrib(EGL_CONTEXT_MINOR_VERSION_KHR, wndconfig->glMinor);
}
if (mask)
setEGLattrib(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, mask);
if (flags)
setEGLattrib(EGL_CONTEXT_FLAGS_KHR, flags);
if (strategy)
setEGLattrib(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR, strategy);
setEGLattrib(EGL_NONE, EGL_NONE);
} }
else else
{ {
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API) int index = 0;
setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, wndconfig->glMajor);
}
setEGLattrib(attribs, index, EGL_NONE, EGL_NONE); if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
setEGLattrib(EGL_CONTEXT_CLIENT_VERSION, wndconfig->glMajor);
setEGLattrib(EGL_NONE, EGL_NONE);
}
window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display, window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display,
config, share, attribs); config, share, attribs);
@ -341,8 +337,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, "EGL: Failed to create context");
"EGL: Failed to create context");
return GL_FALSE; return GL_FALSE;
} }