|
|
|
@ -29,18 +29,46 @@ |
|
|
|
|
|
|
|
|
|
#include "internal.h" |
|
|
|
|
|
|
|
|
|
#include <pthread.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
|
// The per-thread current context/window pointer |
|
|
|
|
// TODO: Implement pthreads TLS |
|
|
|
|
//======================================================================== |
|
|
|
|
_GLFWwindow* _glfwCurrentWindow = NULL; |
|
|
|
|
static pthread_key_t _glfwCurrentTLS; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////// |
|
|
|
|
////// GLFW platform API ////// |
|
|
|
|
////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
|
// Initialize OpenGL support |
|
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
int _glfwInitOpenGL(void) |
|
|
|
|
{ |
|
|
|
|
if (pthread_key_create(&_glfwCurrentTLS, NULL) != 0) |
|
|
|
|
{ |
|
|
|
|
_glfwSetError(GLFW_PLATFORM_ERROR, |
|
|
|
|
"Cocoa/NSGL: Failed to create context TLS"); |
|
|
|
|
return GL_FALSE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return GL_TRUE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
|
// Terminate OpenGL support |
|
|
|
|
//======================================================================== |
|
|
|
|
|
|
|
|
|
void _glfwTerminateOpenGL(void) |
|
|
|
|
{ |
|
|
|
|
pthread_key_delete(_glfwCurrentTLS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//======================================================================== |
|
|
|
|
// Make the OpenGL context associated with the specified window current |
|
|
|
|
//======================================================================== |
|
|
|
@ -52,7 +80,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) |
|
|
|
|
else |
|
|
|
|
[NSOpenGLContext clearCurrentContext]; |
|
|
|
|
|
|
|
|
|
_glfwCurrentWindow = window; |
|
|
|
|
pthread_setspecific(_glfwCurrentTLS, window); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -62,7 +90,7 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window) |
|
|
|
|
|
|
|
|
|
_GLFWwindow* _glfwPlatformGetCurrentContext(void) |
|
|
|
|
{ |
|
|
|
|
return _glfwCurrentWindow; |
|
|
|
|
return (_GLFWwindow*) pthread_getspecific(_glfwCurrentTLS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -83,7 +111,7 @@ void _glfwPlatformSwapBuffers(_GLFWwindow* window) |
|
|
|
|
|
|
|
|
|
void _glfwPlatformSwapInterval(int interval) |
|
|
|
|
{ |
|
|
|
|
_GLFWwindow* window = _glfwCurrentWindow; |
|
|
|
|
_GLFWwindow* window = _glfwPlatformGetCurrentContext(); |
|
|
|
|
|
|
|
|
|
GLint sync = interval; |
|
|
|
|
[window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval]; |
|
|
|
|