Added client API window hint.

This commit is contained in:
Camilla Berglund
2012-07-22 01:10:59 +02:00
parent e9c82a82b2
commit 3b6ec4e775
10 changed files with 274 additions and 163 deletions
+7
View File
@@ -717,6 +717,13 @@ static GLboolean createContext(_GLFWwindow* window,
else if (colorBits < 15)
colorBits = 15;
if (wndconfig->clientAPI != GLFW_OPENGL_ES_API)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"Cocoa/NSOpenGL: NSOpenGL does not support OpenGL ES");
return GL_FALSE;
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
// Fail if any OpenGL version above 2.1 other than 3.2 was requested
if (wndconfig->glMajor > 3 ||
+3
View File
@@ -110,6 +110,7 @@ struct _GLFWhints
GLboolean stereo;
GLboolean resizable;
int samples;
int clientAPI;
int glMajor;
int glMinor;
GLboolean glForward;
@@ -131,6 +132,7 @@ struct _GLFWwndconfig
const char* title;
int refreshRate;
GLboolean resizable;
int clientAPI;
int glMajor;
int glMinor;
GLboolean glForward;
@@ -212,6 +214,7 @@ struct _GLFWwindow
// OpenGL extensions and context attributes
GLboolean accelerated; // GL_TRUE if OpenGL context is "accelerated"
int clientAPI;
int glMajor, glMinor, glRevision;
GLboolean glForward, glDebug;
int glProfile;
+111 -72
View File
@@ -36,7 +36,7 @@
//========================================================================
// Parses the OpenGL version string and extracts the version number
// Parses the client API version string and extracts the version number
//========================================================================
static void parseGLVersion(int* major, int* minor, int* rev)
@@ -256,89 +256,125 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
//========================================================================
// Checks whether the OpenGL part of the window config is sane
// Checks whether the client API part of the window config is sane
// It blames glfwOpenWindow because that's the only caller
//========================================================================
GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
{
if (wndconfig->glMajor < 1 || wndconfig->glMinor < 0)
if (wndconfig->clientAPI != GLFW_OPENGL_API &&
wndconfig->clientAPI != GLFW_OPENGL_ES_API)
{
// OpenGL 1.0 is the smallest valid version
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Invalid OpenGL version requested");
_glfwSetError(GLFW_INVALID_ENUM,
"glfwOpenWindow: Invalid client API requested");
return GL_FALSE;
}
if (wndconfig->glMajor == 1 && wndconfig->glMinor > 5)
{
// OpenGL 1.x series ended with version 1.5
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Invalid OpenGL version requested");
return GL_FALSE;
}
else if (wndconfig->glMajor == 2 && wndconfig->glMinor > 1)
{
// OpenGL 2.x series ended with version 2.1
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Invalid OpenGL version requested");
return GL_FALSE;
}
else if (wndconfig->glMajor == 3 && wndconfig->glMinor > 3)
{
// OpenGL 3.x series ended with version 3.3
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Invalid OpenGL version requested");
return GL_FALSE;
}
else
{
// For now, let everything else through
}
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE)
if (wndconfig->clientAPI == GLFW_OPENGL_API)
{
if (wndconfig->glMajor != 2 || wndconfig->glMinor < 0)
if (wndconfig->glMajor < 1 || wndconfig->glMinor < 0)
{
// The OpenGL ES 2.0 profile is currently only defined for version
// 2.0 (see {WGL|GLX}_EXT_create_context_es2_profile), but for
// compatibility with future updates to OpenGL ES, we allow
// everything 2.x and let the driver report invalid 2.x versions
// OpenGL 1.0 is the smallest valid version
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Invalid OpenGL ES 2.x version requested");
"glfwOpenWindow: Invalid OpenGL version requested");
return GL_FALSE;
}
}
else if (wndconfig->glProfile)
{
if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE &&
wndconfig->glProfile != GLFW_OPENGL_COMPAT_PROFILE)
if (wndconfig->glMajor == 1 && wndconfig->glMinor > 5)
{
_glfwSetError(GLFW_INVALID_ENUM,
"glfwOpenWindow: Invalid OpenGL profile requested");
return GL_FALSE;
}
if (wndconfig->glMajor < 3 ||
(wndconfig->glMajor == 3 && wndconfig->glMinor < 2))
{
// Desktop OpenGL context profiles are only defined for version 3.2
// and above
// OpenGL 1.x series ended with version 1.5
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Context profiles only exist for "
"OpenGL version 3.2 and above");
"glfwOpenWindow: Invalid OpenGL version requested");
return GL_FALSE;
}
else if (wndconfig->glMajor == 2 && wndconfig->glMinor > 1)
{
// OpenGL 2.x series ended with version 2.1
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Invalid OpenGL version requested");
return GL_FALSE;
}
else if (wndconfig->glMajor == 3 && wndconfig->glMinor > 3)
{
// OpenGL 3.x series ended with version 3.3
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Invalid OpenGL version requested");
return GL_FALSE;
}
else
{
// For now, let everything else through
}
if (wndconfig->glProfile)
{
if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE &&
wndconfig->glProfile != GLFW_OPENGL_COMPAT_PROFILE)
{
_glfwSetError(GLFW_INVALID_ENUM,
"glfwOpenWindow: Invalid OpenGL profile requested");
return GL_FALSE;
}
if (wndconfig->glMajor < 3 ||
(wndconfig->glMajor == 3 && wndconfig->glMinor < 2))
{
// Desktop OpenGL context profiles are only defined for version 3.2
// and above
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Context profiles only exist for "
"OpenGL version 3.2 and above");
return GL_FALSE;
}
}
if (wndconfig->glForward && wndconfig->glMajor < 3)
{
// Forward-compatible contexts are only defined for OpenGL version 3.0 and above
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Forward compatibility only exist for "
"OpenGL version 3.0 and above");
return GL_FALSE;
}
}
if (wndconfig->glForward && wndconfig->glMajor < 3)
else if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
{
// Forward-compatible contexts are only defined for OpenGL version 3.0 and above
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Forward compatibility only exist for "
"OpenGL version 3.0 and above");
return GL_FALSE;
if (wndconfig->glMajor < 1 || wndconfig->glMinor < 0)
{
// OpenGL ES 1.0 is the smallest valid version
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Invalid OpenGL ES version requested");
return GL_FALSE;
}
if (wndconfig->glMajor == 1 && wndconfig->glMinor > 1)
{
// OpenGL ES 1.x series ended with version 1.1
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Invalid OpenGL ES version requested");
return GL_FALSE;
}
else
{
// For now, let everything else through
}
if (wndconfig->glProfile)
{
// OpenGL ES does not support profiles
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Context profiles are not supported "
"by OpenGL ES");
return GL_FALSE;
}
if (wndconfig->glForward)
{
// OpenGL ES does not support Forward-compatibility
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Forward compatibility is not "
"supported by OpenGL ES");
return GL_FALSE;
}
}
if (wndconfig->glRobustness)
@@ -347,7 +383,8 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
wndconfig->glRobustness != GLFW_OPENGL_LOSE_CONTEXT_ON_RESET)
{
_glfwSetError(GLFW_INVALID_VALUE,
"glfwOpenWindow: Invalid OpenGL robustness mode requested");
"glfwOpenWindow: Invalid OpenGL robustness mode "
"requested");
return GL_FALSE;
}
}
@@ -363,6 +400,8 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig)
{
window->clientAPI = wndconfig->clientAPI;
parseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision);
// Read back forward-compatibility flag
@@ -433,7 +472,7 @@ GLboolean _glfwIsValidContext(_GLFWwindow* window, _GLFWwndconfig* wndconfig)
//========================================================================
// Check if a string can be found in an OpenGL extension string
// Check if a string can be found in a client API extension string
//========================================================================
int _glfwStringInExtensionString(const char* string,
@@ -472,7 +511,7 @@ int _glfwStringInExtensionString(const char* string,
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Make the OpenGL context associated with the specified window current
// Make the context associated with the specified window current
//========================================================================
GLFWAPI void glfwMakeContextCurrent(GLFWwindow handle)
@@ -494,7 +533,7 @@ GLFWAPI void glfwMakeContextCurrent(GLFWwindow handle)
//========================================================================
// Returns the window whose OpenGL context is current
// Returns the window whose context is current
//========================================================================
GLFWAPI GLFWwindow glfwGetCurrentContext(void)
@@ -554,7 +593,7 @@ GLFWAPI void glfwSwapInterval(int interval)
//========================================================================
// Check if an OpenGL extension is available at runtime
// Check if a client API extension is available at runtime
//========================================================================
GLFWAPI int glfwExtensionSupported(const char* extension)
@@ -619,8 +658,8 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
//========================================================================
// Get the function pointer to an OpenGL function.
// This function can be used to get access to extended OpenGL functions.
// Get the function pointer to a client API function
// This can be used to get access to client API extension functions
//========================================================================
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname)
@@ -642,7 +681,7 @@ GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname)
//========================================================================
// Copies the specified OpenGL state categories from src to dst
// Copies the specified context state categories from src to dst
//========================================================================
GLFWAPI void glfwCopyContext(GLFWwindow hsrc, GLFWwindow hdst, unsigned long mask)
+15 -11
View File
@@ -336,6 +336,21 @@ static GLboolean createContext(_GLFWwindow* window,
attribs[i++] = wndconfig->glMinor;
}
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
{
if (!window->WGL.ARB_create_context_profile ||
!window->WGL.EXT_create_context_es2_profile)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"Win32/WGL: OpenGL ES 2.x requested but "
"WGL_EXT_create_context_es2_profile is unavailable");
return GL_FALSE;
}
attribs[i++] = WGL_CONTEXT_PROFILE_MASK_ARB;
attribs[i++] = WGL_CONTEXT_ES2_PROFILE_BIT_EXT;
}
if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness)
{
int flags = 0;
@@ -365,21 +380,10 @@ static GLboolean createContext(_GLFWwindow* window,
return GL_FALSE;
}
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE &&
!window->WGL.EXT_create_context_es2_profile)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"Win32/WGL: OpenGL ES 2.x profile requested but "
"WGL_EXT_create_context_es2_profile is unavailable");
return GL_FALSE;
}
if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE)
flags = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE)
flags = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
else if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE)
flags = WGL_CONTEXT_ES2_PROFILE_BIT_EXT;
attribs[i++] = WGL_CONTEXT_PROFILE_MASK_ARB;
attribs[i++] = flags;
+8 -1
View File
@@ -97,7 +97,8 @@ void _glfwSetDefaultWindowHints(void)
{
memset(&_glfwLibrary.hints, 0, sizeof(_glfwLibrary.hints));
// The default minimum OpenGL version is 1.0
// The default is OpenGL with minimum version 1.0
_glfwLibrary.hints.clientAPI = GLFW_OPENGL_API;
_glfwLibrary.hints.glMajor = 1;
_glfwLibrary.hints.glMinor = 0;
@@ -251,6 +252,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
wndconfig.title = title;
wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0);
wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE;
wndconfig.clientAPI = _glfwLibrary.hints.clientAPI;
wndconfig.glMajor = _glfwLibrary.hints.glMajor;
wndconfig.glMinor = _glfwLibrary.hints.glMinor;
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
@@ -429,6 +431,9 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
case GLFW_FSAA_SAMPLES:
_glfwLibrary.hints.samples = hint;
break;
case GLFW_CLIENT_API:
_glfwLibrary.hints.clientAPI = hint;
break;
case GLFW_OPENGL_VERSION_MAJOR:
_glfwLibrary.hints.glMajor = hint;
break;
@@ -714,6 +719,8 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
return window->resizable;
case GLFW_FSAA_SAMPLES:
return window->samples;
case GLFW_CLIENT_API:
return window->clientAPI;
case GLFW_OPENGL_VERSION_MAJOR:
return window->glMajor;
case GLFW_OPENGL_VERSION_MINOR:
+19 -16
View File
@@ -110,18 +110,23 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window,
continue;
}
if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES_BIT) &&
!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT))
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
{
// Only consider OpenGL ES context
continue;
if (wndconfig->glMajor == 1)
{
if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES_BIT))
continue;
}
else
{
if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT))
continue;
}
}
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE &&
!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT))
else if (wndconfig->clientAPI == GLFW_OPENGL_API)
{
// User requested only OpenGL ES 2.0 context
continue;
if (!(getConfigAttrib(configs[i], EGL_RENDERABLE_TYPE) & EGL_OPENGL_BIT))
continue;
}
f->redBits = getConfigAttrib(configs[i], EGL_RED_SIZE);
@@ -248,19 +253,17 @@ static int createContext(_GLFWwindow* window,
}
index = 0;
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE)
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
{
setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, 2);
eglBindAPI(EGL_OPENGL_ES_API);
setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, wndconfig->glMajor);
}
else
{
setEGLattrib(attribs, index, EGL_CONTEXT_CLIENT_VERSION, 1);
}
eglBindAPI(EGL_OPENGL_API);
setEGLattrib(attribs, index, EGL_NONE, EGL_NONE);
eglBindAPI(EGL_OPENGL_ES_API);
window->EGL.context = eglCreateContext(_glfwLibrary.EGL.display,
config, share, attribs);
+16 -11
View File
@@ -346,6 +346,22 @@ static int createContext(_GLFWwindow* window,
setGLXattrib(attribs, index, GLX_CONTEXT_MINOR_VERSION_ARB, wndconfig->glMinor);
}
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
{
if (!_glfwLibrary.GLX.ARB_create_context_profile ||
!_glfwLibrary.GLX.EXT_create_context_es2_profile)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"X11/GLX: OpenGL ES 2.x requested but "
"GLX_EXT_create_context_es2_profile is unavailable");
return GL_FALSE;
}
setGLXattrib(attribs, index,
GLX_CONTEXT_PROFILE_MASK_ARB,
GLX_CONTEXT_ES2_PROFILE_BIT_EXT);
}
if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness)
{
int flags = 0;
@@ -374,21 +390,10 @@ static int createContext(_GLFWwindow* window,
return GL_FALSE;
}
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE &&
!_glfwLibrary.GLX.EXT_create_context_es2_profile)
{
_glfwSetError(GLFW_VERSION_UNAVAILABLE,
"X11/GLX: OpenGL ES 2.x profile requested but "
"GLX_EXT_create_context_es2_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;
else if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE)
flags = GLX_CONTEXT_ES2_PROFILE_BIT_EXT;
setGLXattrib(attribs, index, GLX_CONTEXT_PROFILE_MASK_ARB, flags);
}