2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
2011-03-06 00:46:39 +00:00
|
|
|
// GLFW - An OpenGL library
|
2010-09-07 15:34:51 +00:00
|
|
|
// Platform: Any
|
2010-09-07 15:41:26 +00:00
|
|
|
// API version: 3.0
|
2010-09-07 15:34:51 +00:00
|
|
|
// WWW: http://www.glfw.org/
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2002-2006 Marcus Geelnard
|
|
|
|
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
2012-08-02 12:48:06 +00:00
|
|
|
#include <stdio.h>
|
2010-09-08 15:01:39 +00:00
|
|
|
#include <string.h>
|
2011-03-07 12:56:28 +00:00
|
|
|
#include <limits.h>
|
2012-04-25 06:35:02 +00:00
|
|
|
#include <stdio.h>
|
2010-09-08 15:01:39 +00:00
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-03-07 13:55:11 +00:00
|
|
|
//========================================================================
|
2012-07-21 23:10:59 +00:00
|
|
|
// Parses the client API version string and extracts the version number
|
2011-03-07 13:55:11 +00:00
|
|
|
//========================================================================
|
|
|
|
|
2012-08-02 00:41:57 +00:00
|
|
|
static GLboolean parseGLVersion(int* api, int* major, int* minor, int* rev)
|
2011-03-07 13:55:11 +00:00
|
|
|
{
|
2012-08-02 00:41:57 +00:00
|
|
|
int i, _api = GLFW_OPENGL_API, _major, _minor = 0, _rev = 0;
|
2012-07-23 16:40:31 +00:00
|
|
|
const char* version;
|
2012-07-31 17:06:48 +00:00
|
|
|
const char* prefixes[] =
|
|
|
|
{
|
2012-07-31 23:05:57 +00:00
|
|
|
"OpenGL ES-CM ",
|
|
|
|
"OpenGL ES-CL ",
|
|
|
|
"OpenGL ES ",
|
|
|
|
NULL
|
2012-07-31 17:06:48 +00:00
|
|
|
};
|
2011-03-07 13:55:11 +00:00
|
|
|
|
2012-07-23 16:40:31 +00:00
|
|
|
version = (const char*) glGetString(GL_VERSION);
|
2011-03-07 13:55:11 +00:00
|
|
|
if (!version)
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Failed to retrieve context version string");
|
2012-07-23 16:40:31 +00:00
|
|
|
return GL_FALSE;
|
2011-03-07 13:55:11 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 17:06:48 +00:00
|
|
|
for (i = 0; prefixes[i]; i++)
|
2011-03-07 13:55:11 +00:00
|
|
|
{
|
2012-07-31 23:05:57 +00:00
|
|
|
const size_t length = strlen(prefixes[i]);
|
2012-04-25 06:35:02 +00:00
|
|
|
|
2012-07-31 23:05:57 +00:00
|
|
|
if (strncmp(version, prefixes[i], length) == 0)
|
|
|
|
{
|
|
|
|
version += length;
|
2012-08-02 00:41:57 +00:00
|
|
|
_api = GLFW_OPENGL_ES_API;
|
2012-07-31 23:05:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-07-31 17:06:48 +00:00
|
|
|
}
|
2012-07-23 16:40:31 +00:00
|
|
|
|
2012-07-31 17:06:48 +00:00
|
|
|
if (!sscanf(version, "%d.%d.%d", &_major, &_minor, &_rev))
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"No version found in context version string");
|
2012-07-31 17:06:48 +00:00
|
|
|
return GL_FALSE;
|
2012-07-23 16:40:31 +00:00
|
|
|
}
|
2011-03-07 13:55:11 +00:00
|
|
|
|
2012-08-02 00:41:57 +00:00
|
|
|
*api = _api;
|
2011-03-07 13:55:11 +00:00
|
|
|
*major = _major;
|
|
|
|
*minor = _minor;
|
|
|
|
*rev = _rev;
|
2012-07-23 16:40:31 +00:00
|
|
|
|
|
|
|
return GL_TRUE;
|
2011-03-07 13:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 18:59:50 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-03-07 13:55:11 +00:00
|
|
|
GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-07-21 23:10:59 +00:00
|
|
|
if (wndconfig->clientAPI != GLFW_OPENGL_API &&
|
|
|
|
wndconfig->clientAPI != GLFW_OPENGL_ES_API)
|
2011-03-07 13:55:11 +00:00
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_INVALID_ENUM, "Invalid client API requested");
|
2011-03-07 13:55:11 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-07-21 23:10:59 +00:00
|
|
|
if (wndconfig->clientAPI == GLFW_OPENGL_API)
|
2011-03-07 13:55:11 +00:00
|
|
|
{
|
2012-12-13 16:07:55 +00:00
|
|
|
if (wndconfig->glMajor < 1 || wndconfig->glMinor < 0 ||
|
|
|
|
(wndconfig->glMajor == 1 && wndconfig->glMinor > 5) ||
|
|
|
|
(wndconfig->glMajor == 2 && wndconfig->glMinor > 1) ||
|
|
|
|
(wndconfig->glMajor == 3 && wndconfig->glMinor > 3))
|
2012-07-21 23:10:59 +00:00
|
|
|
{
|
|
|
|
// OpenGL 1.0 is the smallest valid version
|
|
|
|
// OpenGL 1.x series ended with version 1.5
|
|
|
|
// OpenGL 2.x series ended with version 2.1
|
|
|
|
// OpenGL 3.x series ended with version 3.3
|
2012-12-13 16:07:55 +00:00
|
|
|
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_INVALID_VALUE,
|
|
|
|
"Invalid OpenGL version %i.%i requested",
|
|
|
|
wndconfig->glMajor, wndconfig->glMinor);
|
2012-07-21 23:10:59 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// For now, let everything else through
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wndconfig->glProfile)
|
2011-03-07 13:55:11 +00:00
|
|
|
{
|
2012-07-21 23:10:59 +00:00
|
|
|
if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE &&
|
|
|
|
wndconfig->glProfile != GLFW_OPENGL_COMPAT_PROFILE)
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_INVALID_ENUM,
|
|
|
|
"Invalid OpenGL profile requested");
|
2012-07-21 23:10:59 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-07-21 23:10:59 +00:00
|
|
|
if (wndconfig->glMajor < 3 ||
|
|
|
|
(wndconfig->glMajor == 3 && wndconfig->glMinor < 2))
|
|
|
|
{
|
|
|
|
// Desktop OpenGL context profiles are only defined for version 3.2
|
|
|
|
// and above
|
|
|
|
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_INVALID_VALUE,
|
|
|
|
"Context profiles only exist for "
|
|
|
|
"OpenGL version 3.2 and above");
|
2012-07-21 23:10:59 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wndconfig->glForward && wndconfig->glMajor < 3)
|
|
|
|
{
|
|
|
|
// Forward-compatible contexts are only defined for OpenGL version 3.0 and above
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_INVALID_VALUE,
|
|
|
|
"Forward compatibility only exist for OpenGL "
|
|
|
|
"version 3.0 and above");
|
2011-03-07 13:55:11 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2012-07-21 23:10:59 +00:00
|
|
|
else if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
|
2010-11-15 18:28:06 +00:00
|
|
|
{
|
2012-12-13 16:07:55 +00:00
|
|
|
if (wndconfig->glMajor < 1 || wndconfig->glMinor < 0 ||
|
|
|
|
(wndconfig->glMajor == 1 && wndconfig->glMinor > 1) ||
|
|
|
|
(wndconfig->glMajor == 2 && wndconfig->glMinor > 0))
|
2011-03-07 13:55:11 +00:00
|
|
|
{
|
2012-07-21 23:10:59 +00:00
|
|
|
// OpenGL ES 1.0 is the smallest valid version
|
|
|
|
// OpenGL ES 1.x series ended with version 1.1
|
2012-12-13 16:07:55 +00:00
|
|
|
// OpenGL ES 2.x series ended with version 2.0
|
|
|
|
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_INVALID_VALUE,
|
|
|
|
"Invalid OpenGL ES version %i.%i requested",
|
|
|
|
wndconfig->glMajor, wndconfig->glMinor);
|
2012-07-21 23:10:59 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// For now, let everything else through
|
|
|
|
}
|
2011-03-07 13:55:11 +00:00
|
|
|
|
2012-07-21 23:10:59 +00:00
|
|
|
if (wndconfig->glProfile)
|
|
|
|
{
|
|
|
|
// OpenGL ES does not support profiles
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_INVALID_VALUE,
|
|
|
|
"Context profiles are not supported by OpenGL ES");
|
2011-03-07 13:55:11 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2010-11-15 18:28:06 +00:00
|
|
|
|
2012-07-21 23:10:59 +00:00
|
|
|
if (wndconfig->glForward)
|
|
|
|
{
|
2012-07-31 17:13:27 +00:00
|
|
|
// OpenGL ES does not support forward-compatibility
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_INVALID_VALUE,
|
|
|
|
"Forward compatibility is not supported by OpenGL ES");
|
2012-07-21 23:10:59 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2011-03-07 13:55:11 +00:00
|
|
|
}
|
2011-03-07 12:58:02 +00:00
|
|
|
|
2011-03-07 19:51:34 +00:00
|
|
|
if (wndconfig->glRobustness)
|
|
|
|
{
|
2012-12-13 01:22:39 +00:00
|
|
|
if (wndconfig->glRobustness != GLFW_NO_RESET_NOTIFICATION &&
|
|
|
|
wndconfig->glRobustness != GLFW_LOSE_CONTEXT_ON_RESET)
|
2011-03-07 19:51:34 +00:00
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_INVALID_VALUE,
|
|
|
|
"Invalid context robustness mode requested");
|
2011-03-07 19:51:34 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-07 13:55:11 +00:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
2010-09-07 23:57:24 +00:00
|
|
|
|
2012-08-02 12:42:24 +00:00
|
|
|
GLboolean _glfwRefreshContextParams(void)
|
2011-03-07 13:55:11 +00:00
|
|
|
{
|
2012-08-12 12:13:18 +00:00
|
|
|
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
2012-07-21 23:10:59 +00:00
|
|
|
|
2012-08-02 00:41:57 +00:00
|
|
|
if (!parseGLVersion(&window->clientAPI,
|
|
|
|
&window->glMajor,
|
|
|
|
&window->glMinor,
|
|
|
|
&window->glRevision))
|
|
|
|
{
|
2012-08-02 12:42:24 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-15 03:26:11 +00:00
|
|
|
#if defined(_GLFW_USE_OPENGL)
|
2012-08-02 12:42:24 +00:00
|
|
|
if (window->glMajor > 2)
|
|
|
|
{
|
|
|
|
// OpenGL 3.0+ uses a different function for extension string retrieval
|
|
|
|
// We cache it here instead of in glfwExtensionSupported mostly to alert
|
|
|
|
// users as early as possible that their build may be broken
|
|
|
|
|
|
|
|
window->GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
|
|
|
|
if (!window->GetStringi)
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"Entry point retrieval is broken");
|
2012-08-02 12:42:24 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2012-08-02 00:41:57 +00:00
|
|
|
}
|
2011-03-07 13:55:11 +00:00
|
|
|
|
2012-12-13 18:07:19 +00:00
|
|
|
if (window->clientAPI == GLFW_OPENGL_API)
|
2011-07-27 16:20:15 +00:00
|
|
|
{
|
2012-12-13 18:07:19 +00:00
|
|
|
// Read back context flags (OpenGL 3.0 and above)
|
|
|
|
if (window->glMajor >= 3)
|
2012-12-13 16:22:19 +00:00
|
|
|
{
|
|
|
|
GLint flags;
|
|
|
|
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
|
|
|
|
|
|
|
|
if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
|
|
|
|
window->glForward = GL_TRUE;
|
2012-12-13 18:07:19 +00:00
|
|
|
|
2012-12-13 16:33:08 +00:00
|
|
|
if (flags & GL_CONTEXT_FLAG_DEBUG_BIT)
|
2012-12-13 16:22:19 +00:00
|
|
|
window->glDebug = GL_TRUE;
|
2012-12-13 18:07:19 +00:00
|
|
|
else if (glfwExtensionSupported("GL_ARB_debug_output"))
|
2012-12-13 16:33:08 +00:00
|
|
|
{
|
|
|
|
// HACK: This is a workaround for older drivers (pre KHR_debug)
|
|
|
|
// not setting the debug bit in the context flags for debug
|
|
|
|
// contexts
|
|
|
|
window->glDebug = GL_TRUE;
|
|
|
|
}
|
2012-12-13 16:22:19 +00:00
|
|
|
}
|
2011-07-27 16:20:15 +00:00
|
|
|
|
2012-12-13 18:07:19 +00:00
|
|
|
// Read back OpenGL context profile (OpenGL 3.2 and above)
|
|
|
|
if (window->glMajor > 3 ||
|
|
|
|
(window->glMajor == 3 && window->glMinor >= 2))
|
2012-12-13 16:22:19 +00:00
|
|
|
{
|
|
|
|
GLint mask;
|
|
|
|
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
|
|
|
|
|
|
|
|
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
|
|
|
|
window->glProfile = GLFW_OPENGL_COMPAT_PROFILE;
|
|
|
|
else if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
|
|
|
|
window->glProfile = GLFW_OPENGL_CORE_PROFILE;
|
|
|
|
}
|
2012-12-13 18:07:19 +00:00
|
|
|
|
|
|
|
// Read back robustness strategy
|
|
|
|
if (glfwExtensionSupported("GL_ARB_robustness"))
|
|
|
|
{
|
|
|
|
// NOTE: We avoid using the context flags for detection, as they are
|
|
|
|
// only present from 3.0 while the extension applies from 1.1
|
|
|
|
|
|
|
|
GLint strategy;
|
|
|
|
glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy);
|
|
|
|
|
|
|
|
if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
|
|
|
|
window->glRobustness = GLFW_LOSE_CONTEXT_ON_RESET;
|
|
|
|
else if (strategy == GL_NO_RESET_NOTIFICATION_ARB)
|
|
|
|
window->glRobustness = GLFW_NO_RESET_NOTIFICATION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Read back robustness strategy
|
|
|
|
if (glfwExtensionSupported("GL_EXT_robustness"))
|
|
|
|
{
|
|
|
|
// NOTE: The values of these constants match those of the OpenGL ARB
|
|
|
|
// one, so we can reuse them here
|
|
|
|
|
|
|
|
GLint strategy;
|
|
|
|
glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy);
|
|
|
|
|
|
|
|
if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
|
|
|
|
window->glRobustness = GLFW_LOSE_CONTEXT_ON_RESET;
|
|
|
|
else if (strategy == GL_NO_RESET_NOTIFICATION_ARB)
|
|
|
|
window->glRobustness = GLFW_NO_RESET_NOTIFICATION;
|
|
|
|
}
|
2011-07-27 16:20:15 +00:00
|
|
|
}
|
2013-01-15 03:26:11 +00:00
|
|
|
#endif // _GLFW_USE_OPENGL
|
2011-07-27 16:20:15 +00:00
|
|
|
|
2012-08-02 12:42:24 +00:00
|
|
|
return GL_TRUE;
|
2012-08-01 23:18:35 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 12:42:24 +00:00
|
|
|
GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig)
|
2012-08-01 23:18:35 +00:00
|
|
|
{
|
2012-08-12 12:13:18 +00:00
|
|
|
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
2012-08-02 12:42:24 +00:00
|
|
|
|
2011-03-07 13:55:11 +00:00
|
|
|
if (window->glMajor < wndconfig->glMajor ||
|
|
|
|
(window->glMajor == wndconfig->glMajor &&
|
|
|
|
window->glMinor < wndconfig->glMinor))
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2011-03-07 13:55:11 +00:00
|
|
|
// The desired OpenGL version is greater than the actual version
|
|
|
|
// This only happens if the machine lacks {GLX|WGL}_ARB_create_context
|
|
|
|
// /and/ the user has requested an OpenGL version greater than 1.0
|
2010-09-07 23:57:24 +00:00
|
|
|
|
2011-03-07 13:55:11 +00:00
|
|
|
// For API consistency, we emulate the behavior of the
|
|
|
|
// {GLX|WGL}_ARB_create_context extension and fail here
|
|
|
|
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE, NULL);
|
2011-03-07 13:55:11 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GL_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2013-01-23 18:47:05 +00:00
|
|
|
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 13:58:43 +00:00
|
|
|
const GLubyte* start;
|
|
|
|
GLubyte* where;
|
|
|
|
GLubyte* terminator;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// It takes a bit of care to be fool-proof about parsing the
|
|
|
|
// OpenGL extensions string. Don't be fooled by sub-strings,
|
|
|
|
// etc.
|
|
|
|
start = extensions;
|
2010-09-08 12:45:52 +00:00
|
|
|
for (;;)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 13:58:43 +00:00
|
|
|
where = (GLubyte*) strstr((const char*) start, string);
|
2010-09-08 12:45:52 +00:00
|
|
|
if (!where)
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
2010-09-07 23:57:24 +00:00
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
terminator = where + strlen(string);
|
|
|
|
if (where == start || *(where - 1) == ' ')
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
if (*terminator == ' ' || *terminator == '\0')
|
2010-09-07 15:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-09-07 23:57:24 +00:00
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
start = terminator;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 18:59:50 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW public API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
GLFWAPI void glfwMakeContextCurrent(GLFWwindow* handle)
|
2011-07-27 14:01:27 +00:00
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
|
2011-07-27 14:01:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-12 12:13:18 +00:00
|
|
|
if (_glfwPlatformGetCurrentContext() == window)
|
2011-07-27 14:01:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
_glfwPlatformMakeContextCurrent(window);
|
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
GLFWAPI GLFWwindow* glfwGetCurrentContext(void)
|
2011-07-27 14:01:27 +00:00
|
|
|
{
|
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
|
2012-08-27 11:52:10 +00:00
|
|
|
return NULL;
|
2011-07-27 14:01:27 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
return (GLFWwindow*) _glfwPlatformGetCurrentContext();
|
2011-07-27 14:01:27 +00:00
|
|
|
}
|
|
|
|
|
2013-01-05 20:13:28 +00:00
|
|
|
GLFWAPI void glfwSwapBuffers(GLFWwindow* handle)
|
2011-03-04 13:25:12 +00:00
|
|
|
{
|
2012-08-06 16:13:37 +00:00
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
|
|
|
|
2011-03-04 13:25:12 +00:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
|
2011-03-04 13:25:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-06 16:13:37 +00:00
|
|
|
_glfwPlatformSwapBuffers(window);
|
2011-03-04 13:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLFWAPI void glfwSwapInterval(int interval)
|
|
|
|
{
|
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
|
2011-03-04 13:25:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-12 12:13:18 +00:00
|
|
|
if (!_glfwPlatformGetCurrentContext())
|
2011-03-04 13:25:12 +00:00
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL);
|
2011-03-04 13:25:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_glfwPlatformSwapInterval(interval);
|
|
|
|
}
|
|
|
|
|
2010-09-08 13:58:43 +00:00
|
|
|
GLFWAPI int glfwExtensionSupported(const char* extension)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 13:58:43 +00:00
|
|
|
const GLubyte* extensions;
|
2010-09-13 22:17:00 +00:00
|
|
|
_GLFWwindow* window;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-09 19:34:42 +00:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
2010-09-09 19:34:42 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-08-12 12:13:18 +00:00
|
|
|
window = _glfwPlatformGetCurrentContext();
|
2010-09-13 22:17:00 +00:00
|
|
|
if (!window)
|
2010-09-09 19:34:42 +00:00
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL);
|
2010-09-09 19:34:42 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-02 13:29:13 +00:00
|
|
|
if (extension == NULL || *extension == '\0')
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_INVALID_VALUE, NULL);
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_FALSE;
|
2012-08-02 13:29:13 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-09 16:15:32 +00:00
|
|
|
if (window->glMajor < 3)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
// Check if extension is in the old style OpenGL extensions string
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
extensions = glGetString(GL_EXTENSIONS);
|
|
|
|
if (extensions != NULL)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 12:45:52 +00:00
|
|
|
if (_glfwStringInExtensionString(extension, extensions))
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2013-01-15 03:26:11 +00:00
|
|
|
#if defined(_GLFW_USE_OPENGL)
|
2010-09-07 15:34:51 +00:00
|
|
|
else
|
|
|
|
{
|
2012-08-02 13:31:08 +00:00
|
|
|
int i;
|
|
|
|
GLint count;
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
// Check if extension is in the modern OpenGL extensions string list
|
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
for (i = 0; i < count; i++)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 16:15:32 +00:00
|
|
|
if (strcmp((const char*) window->GetStringi(GL_EXTENSIONS, i),
|
2010-09-08 12:45:52 +00:00
|
|
|
extension) == 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-15 03:26:11 +00:00
|
|
|
#endif // _GLFW_USE_OPENGL
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-08-02 13:32:39 +00:00
|
|
|
// Check if extension is in the platform-specific string
|
|
|
|
return _glfwPlatformExtensionSupported(extension);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 22:16:40 +00:00
|
|
|
GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-09 19:34:42 +00:00
|
|
|
if (!_glfwInitialized)
|
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
|
2010-09-09 19:34:42 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-12 12:13:18 +00:00
|
|
|
if (!_glfwPlatformGetCurrentContext())
|
2010-09-09 19:34:42 +00:00
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_NO_CURRENT_CONTEXT, NULL);
|
2010-09-07 15:34:51 +00:00
|
|
|
return NULL;
|
2010-09-09 19:34:42 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-09-08 12:45:52 +00:00
|
|
|
return _glfwPlatformGetProcAddress(procname);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|