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: X11/GLX
|
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-06-03 14:33:48 +00:00
|
|
|
#include <string.h>
|
2012-04-23 10:48:57 +00:00
|
|
|
#include <stdlib.h>
|
2013-01-15 19:00:27 +00:00
|
|
|
#include <assert.h>
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-02-01 21:00:07 +00:00
|
|
|
// This is the only glXGetProcAddress variant not declared by glxext.h
|
2010-09-08 13:58:43 +00:00
|
|
|
void (*glXGetProcAddressEXT(const GLubyte* procName))();
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
|
2012-12-30 17:13:04 +00:00
|
|
|
#ifndef GLXBadProfileARB
|
|
|
|
#define GLXBadProfileARB 13
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-08-13 14:03:44 +00:00
|
|
|
// Thread local storage attribute macro
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2012-08-13 14:03:44 +00:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
#define _GLFW_TLS __thread
|
|
|
|
#else
|
|
|
|
#define _GLFW_TLS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-08-12 12:13:18 +00:00
|
|
|
// The per-thread current context/window pointer
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2012-08-13 14:03:44 +00:00
|
|
|
static _GLFW_TLS _GLFWwindow* _glfwCurrentWindow = NULL;
|
2012-08-12 12:13:18 +00:00
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2013-01-21 19:19:20 +00:00
|
|
|
// Error handler used when creating a context
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2013-01-15 19:00:27 +00:00
|
|
|
static int errorHandler(Display *display, XErrorEvent* event)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-05-02 14:37:55 +00:00
|
|
|
_glfw.glx.errorCode = event->error_code;
|
2013-01-15 19:00:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the OpenGL context using legacy API
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2013-01-15 19:00:27 +00:00
|
|
|
static GLXContext createLegacyContext(_GLFWwindow* window,
|
|
|
|
GLXFBConfig fbconfig,
|
|
|
|
GLXContext share)
|
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
if (_glfw.glx.SGIX_fbconfig)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
return _glfw.glx.CreateContextWithConfigSGIX(_glfw.x11.display,
|
|
|
|
fbconfig,
|
|
|
|
GLX_RGBA_TYPE,
|
|
|
|
share,
|
|
|
|
True);
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
else
|
2013-01-15 19:00:27 +00:00
|
|
|
{
|
|
|
|
return glXCreateNewContext(_glfw.x11.display,
|
|
|
|
fbconfig,
|
|
|
|
GLX_RGBA_TYPE,
|
|
|
|
share,
|
|
|
|
True);
|
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW internal API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Initialize GLX
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2013-01-15 19:49:29 +00:00
|
|
|
int _glfwInitContextAPI(void)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
#ifdef _GLFW_DLOPEN_LIBGL
|
|
|
|
int i;
|
|
|
|
char* libGL_names[ ] =
|
|
|
|
{
|
|
|
|
"libGL.so",
|
|
|
|
"libGL.so.1",
|
|
|
|
"/usr/lib/libGL.so",
|
|
|
|
"/usr/lib/libGL.so.1",
|
|
|
|
NULL
|
|
|
|
};
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
for (i = 0; libGL_names[i] != NULL; i++)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
_glfw.glx.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL);
|
|
|
|
if (_glfw.glx.libGL)
|
|
|
|
break;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (!_glfw.glx.libGL)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to find libGL");
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
2012-06-03 14:31:56 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
// Check if GLX is supported on this display
|
|
|
|
if (!glXQueryExtension(_glfw.x11.display,
|
|
|
|
&_glfw.glx.errorBase,
|
|
|
|
&_glfw.glx.eventBase))
|
2012-06-03 14:31:56 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE, "GLX: GLX support not found");
|
|
|
|
return GL_FALSE;
|
2012-06-03 14:31:56 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (!glXQueryVersion(_glfw.x11.display,
|
|
|
|
&_glfw.glx.versionMajor,
|
|
|
|
&_glfw.glx.versionMinor))
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
|
|
"GLX: Failed to query GLX version");
|
|
|
|
return GL_FALSE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
2013-01-15 19:00:27 +00:00
|
|
|
|
|
|
|
if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control"))
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
_glfw.glx.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)
|
|
|
|
_glfwPlatformGetProcAddress("glXSwapIntervalEXT");
|
|
|
|
|
|
|
|
if (_glfw.glx.SwapIntervalEXT)
|
|
|
|
_glfw.glx.EXT_swap_control = GL_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control"))
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
_glfw.glx.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
|
|
|
|
_glfwPlatformGetProcAddress("glXSwapIntervalSGI");
|
|
|
|
|
|
|
|
if (_glfw.glx.SwapIntervalSGI)
|
|
|
|
_glfw.glx.SGI_swap_control = GL_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_MESA_swap_control"))
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
_glfw.glx.SwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC)
|
|
|
|
_glfwPlatformGetProcAddress("glXSwapIntervalMESA");
|
2012-06-03 14:40:54 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfw.glx.SwapIntervalMESA)
|
|
|
|
_glfw.glx.MESA_swap_control = GL_TRUE;
|
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig"))
|
|
|
|
{
|
|
|
|
_glfw.glx.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC)
|
|
|
|
_glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX");
|
|
|
|
_glfw.glx.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC)
|
|
|
|
_glfwPlatformGetProcAddress("glXChooseFBConfigSGIX");
|
|
|
|
_glfw.glx.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC)
|
|
|
|
_glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX");
|
|
|
|
_glfw.glx.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC)
|
|
|
|
_glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX");
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfw.glx.GetFBConfigAttribSGIX &&
|
|
|
|
_glfw.glx.ChooseFBConfigSGIX &&
|
|
|
|
_glfw.glx.CreateContextWithConfigSGIX &&
|
|
|
|
_glfw.glx.GetVisualFromFBConfigSGIX)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
_glfw.glx.SGIX_fbconfig = GL_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
2013-01-15 19:00:27 +00:00
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_ARB_multisample"))
|
|
|
|
_glfw.glx.ARB_multisample = GL_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_ARB_framebuffer_sRGB"))
|
|
|
|
_glfw.glx.ARB_framebuffer_sRGB = GL_TRUE;
|
2012-12-02 15:10:00 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context"))
|
|
|
|
{
|
|
|
|
_glfw.glx.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
|
|
|
|
_glfwPlatformGetProcAddress("glXCreateContextAttribsARB");
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfw.glx.CreateContextAttribsARB)
|
|
|
|
_glfw.glx.ARB_create_context = GL_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness"))
|
|
|
|
_glfw.glx.ARB_create_context_robustness = GL_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile"))
|
|
|
|
_glfw.glx.ARB_create_context_profile = GL_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile"))
|
|
|
|
_glfw.glx.EXT_create_context_es2_profile = GL_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
return GL_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
// Terminate GLX
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2013-01-15 19:49:29 +00:00
|
|
|
void _glfwTerminateContextAPI(void)
|
2012-12-30 17:13:04 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
// Unload libGL.so if necessary
|
|
|
|
#ifdef _GLFW_DLOPEN_LIBGL
|
|
|
|
if (_glfw.glx.libGL != NULL)
|
2012-12-30 17:13:04 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
dlclose(_glfw.glx.libGL);
|
|
|
|
_glfw.glx.libGL = NULL;
|
2012-12-30 17:13:04 +00:00
|
|
|
}
|
2013-01-15 19:00:27 +00:00
|
|
|
#endif
|
2012-12-30 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
#define setGLXattrib(attribName, attribValue) \
|
2013-01-15 19:00:27 +00:00
|
|
|
{ \
|
2012-04-23 10:48:57 +00:00
|
|
|
attribs[index++] = attribName; \
|
2013-01-15 19:00:27 +00:00
|
|
|
attribs[index++] = attribValue; \
|
|
|
|
assert(index < sizeof(attribs) / sizeof(attribs[0])); \
|
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-02-04 12:22:10 +00:00
|
|
|
// Prepare for creation of the OpenGL context
|
|
|
|
//
|
2013-01-15 19:00:27 +00:00
|
|
|
int _glfwCreateContext(_GLFWwindow* window,
|
|
|
|
const _GLFWwndconfig* wndconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
|
|
|
int attribs[40];
|
2013-01-15 19:00:27 +00:00
|
|
|
GLXFBConfig* native;
|
2012-04-23 10:48:57 +00:00
|
|
|
GLXContext share = NULL;
|
|
|
|
|
|
|
|
if (wndconfig->share)
|
2013-01-02 00:40:42 +00:00
|
|
|
share = wndconfig->share->glx.context;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
// Find a suitable GLXFBConfig
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
int count, index = 0;
|
|
|
|
|
|
|
|
setGLXattrib(GLX_DOUBLEBUFFER, True);
|
|
|
|
setGLXattrib(GLX_X_RENDERABLE, True);
|
|
|
|
|
|
|
|
if (fbconfig->redBits)
|
|
|
|
setGLXattrib(GLX_RED_SIZE, fbconfig->redBits);
|
|
|
|
if (fbconfig->greenBits)
|
|
|
|
setGLXattrib(GLX_GREEN_SIZE, fbconfig->greenBits);
|
|
|
|
if (fbconfig->blueBits)
|
|
|
|
setGLXattrib(GLX_BLUE_SIZE, fbconfig->blueBits);
|
|
|
|
if (fbconfig->alphaBits)
|
2013-01-16 18:49:15 +00:00
|
|
|
setGLXattrib(GLX_ALPHA_SIZE, fbconfig->alphaBits);
|
2013-01-15 19:00:27 +00:00
|
|
|
|
|
|
|
if (fbconfig->depthBits)
|
|
|
|
setGLXattrib(GLX_DEPTH_SIZE, fbconfig->depthBits);
|
|
|
|
if (fbconfig->stencilBits)
|
|
|
|
setGLXattrib(GLX_STENCIL_SIZE, fbconfig->stencilBits);
|
|
|
|
|
|
|
|
if (fbconfig->auxBuffers)
|
|
|
|
setGLXattrib(GLX_AUX_BUFFERS, fbconfig->auxBuffers);
|
|
|
|
|
|
|
|
if (fbconfig->accumRedBits)
|
|
|
|
setGLXattrib(GLX_ACCUM_RED_SIZE, fbconfig->accumRedBits);
|
|
|
|
if (fbconfig->accumGreenBits)
|
|
|
|
setGLXattrib(GLX_ACCUM_GREEN_SIZE, fbconfig->accumGreenBits);
|
|
|
|
if (fbconfig->accumBlueBits)
|
|
|
|
setGLXattrib(GLX_ACCUM_BLUE_SIZE, fbconfig->accumBlueBits);
|
|
|
|
if (fbconfig->accumAlphaBits)
|
|
|
|
setGLXattrib(GLX_ACCUM_BLUE_SIZE, fbconfig->accumAlphaBits);
|
|
|
|
|
|
|
|
if (fbconfig->stereo)
|
|
|
|
setGLXattrib(GLX_STEREO, True);
|
|
|
|
|
|
|
|
if (_glfw.glx.ARB_multisample)
|
|
|
|
{
|
|
|
|
if (fbconfig->samples)
|
|
|
|
{
|
|
|
|
setGLXattrib(GLX_SAMPLE_BUFFERS_ARB, 1);
|
|
|
|
setGLXattrib(GLX_SAMPLES_ARB, fbconfig->samples);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_glfw.glx.ARB_framebuffer_sRGB)
|
|
|
|
{
|
|
|
|
if (fbconfig->sRGB)
|
|
|
|
setGLXattrib(GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, True);
|
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
setGLXattrib(None, None);
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
if (_glfw.glx.SGIX_fbconfig)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
native = _glfw.glx.ChooseFBConfigSGIX(_glfw.x11.display,
|
|
|
|
_glfw.x11.screen,
|
|
|
|
attribs,
|
|
|
|
&count);
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
native = glXChooseFBConfig(_glfw.x11.display,
|
|
|
|
_glfw.x11.screen,
|
|
|
|
attribs,
|
|
|
|
&count);
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (native == NULL)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
2013-01-15 19:00:27 +00:00
|
|
|
"GLX: Failed to find a suitable GLXFBConfig");
|
2012-04-23 10:48:57 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the corresponding visual
|
2013-01-02 00:40:42 +00:00
|
|
|
if (_glfw.glx.SGIX_fbconfig)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
window->glx.visual =
|
2013-01-15 19:00:27 +00:00
|
|
|
_glfw.glx.GetVisualFromFBConfigSGIX(_glfw.x11.display, *native);
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
window->glx.visual = glXGetVisualFromFBConfig(_glfw.x11.display,
|
2013-01-15 19:00:27 +00:00
|
|
|
*native);
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
if (window->glx.visual == NULL)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
XFree(native);
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"GLX: Failed to retrieve visual for GLXFBConfig");
|
2012-04-23 10:48:57 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
if (wndconfig->clientAPI == GLFW_OPENGL_ES_API)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
if (!_glfw.glx.ARB_create_context ||
|
|
|
|
!_glfw.glx.ARB_create_context_profile ||
|
|
|
|
!_glfw.glx.EXT_create_context_es2_profile)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
XFree(native);
|
|
|
|
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"GLX: OpenGL ES requested but "
|
|
|
|
"GLX_EXT_create_context_es2_profile is unavailable");
|
2012-12-13 19:43:15 +00:00
|
|
|
return GL_FALSE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
2012-12-13 19:43:15 +00:00
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
if (wndconfig->glForward)
|
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
if (!_glfw.glx.ARB_create_context)
|
2012-07-21 23:10:59 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
XFree(native);
|
|
|
|
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"GLX: Forward compatibility requested but "
|
|
|
|
"GLX_ARB_create_context_profile is unavailable");
|
2012-12-13 19:43:15 +00:00
|
|
|
return GL_FALSE;
|
2012-07-21 23:10:59 +00:00
|
|
|
}
|
2012-12-13 19:43:15 +00:00
|
|
|
}
|
2012-07-21 23:10:59 +00:00
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
if (wndconfig->glProfile)
|
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
if (!_glfw.glx.ARB_create_context ||
|
|
|
|
!_glfw.glx.ARB_create_context_profile)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
XFree(native);
|
|
|
|
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
|
|
|
"GLX: An OpenGL profile requested but "
|
|
|
|
"GLX_ARB_create_context_profile is unavailable");
|
2012-12-13 19:43:15 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 14:37:55 +00:00
|
|
|
_glfw.glx.errorCode = Success;
|
2013-01-21 19:19:20 +00:00
|
|
|
XSetErrorHandler(errorHandler);
|
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
if (_glfw.glx.ARB_create_context)
|
2012-12-13 19:43:15 +00:00
|
|
|
{
|
|
|
|
int index = 0, mask = 0, flags = 0, strategy = 0;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
if (wndconfig->clientAPI == GLFW_OPENGL_API)
|
|
|
|
{
|
2012-04-23 10:48:57 +00:00
|
|
|
if (wndconfig->glForward)
|
|
|
|
flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
|
|
|
|
|
|
|
if (wndconfig->glDebug)
|
|
|
|
flags |= GLX_CONTEXT_DEBUG_BIT_ARB;
|
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
2012-12-13 19:43:15 +00:00
|
|
|
else
|
|
|
|
mask |= GLX_CONTEXT_ES2_PROFILE_BIT_EXT;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
if (wndconfig->glRobustness != GLFW_NO_ROBUSTNESS)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
if (_glfw.glx.ARB_create_context_robustness)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2012-12-13 19:43:15 +00:00
|
|
|
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;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
flags |= GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB;
|
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2012-12-13 19:43:15 +00:00
|
|
|
// NOTE: Only request an explicitly versioned context when
|
|
|
|
// necessary, as explicitly requesting version 1.0 does not always
|
|
|
|
// return the highest available version
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
setGLXattrib(GLX_CONTEXT_MAJOR_VERSION_ARB, wndconfig->glMajor);
|
|
|
|
setGLXattrib(GLX_CONTEXT_MINOR_VERSION_ARB, wndconfig->glMinor);
|
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
if (mask)
|
|
|
|
setGLXattrib(GLX_CONTEXT_PROFILE_MASK_ARB, mask);
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
if (flags)
|
|
|
|
setGLXattrib(GLX_CONTEXT_FLAGS_ARB, flags);
|
|
|
|
|
|
|
|
if (strategy)
|
|
|
|
setGLXattrib(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, strategy);
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2012-12-13 19:43:15 +00:00
|
|
|
setGLXattrib(None, None);
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
window->glx.context =
|
|
|
|
_glfw.glx.CreateContextAttribsARB(_glfw.x11.display,
|
2013-01-15 19:00:27 +00:00
|
|
|
*native,
|
2013-01-02 00:40:42 +00:00
|
|
|
share,
|
|
|
|
True,
|
|
|
|
attribs);
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
if (window->glx.context == NULL)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2012-12-30 17:13:04 +00:00
|
|
|
// HACK: This is a fallback for the broken Mesa implementation of
|
|
|
|
// GLX_ARB_create_context_profile, which fails default 1.0 context
|
|
|
|
// creation with a GLXBadProfileARB error in violation of the spec
|
2013-05-02 14:37:55 +00:00
|
|
|
if (_glfw.glx.errorCode == _glfw.glx.errorBase + GLXBadProfileARB &&
|
2012-12-30 17:13:04 +00:00
|
|
|
wndconfig->clientAPI == GLFW_OPENGL_API &&
|
|
|
|
wndconfig->glProfile == GLFW_OPENGL_NO_PROFILE &&
|
|
|
|
wndconfig->glForward == GL_FALSE)
|
|
|
|
{
|
2013-01-15 19:00:27 +00:00
|
|
|
window->glx.context = createLegacyContext(window, *native, share);
|
2012-12-30 17:13:04 +00:00
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-30 17:13:04 +00:00
|
|
|
else
|
2013-01-15 19:00:27 +00:00
|
|
|
window->glx.context = createLegacyContext(window, *native, share);
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-21 19:19:20 +00:00
|
|
|
XSetErrorHandler(NULL);
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
XFree(native);
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
if (window->glx.context == NULL)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-21 19:19:20 +00:00
|
|
|
char buffer[8192];
|
|
|
|
XGetErrorText(_glfw.x11.display,
|
2013-05-02 14:37:55 +00:00
|
|
|
_glfw.glx.errorCode,
|
2013-01-21 19:19:20 +00:00
|
|
|
buffer, sizeof(buffer));
|
|
|
|
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"GLX: Failed to create context: %s",
|
|
|
|
buffer);
|
|
|
|
|
2012-04-23 10:48:57 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef setGLXattrib
|
|
|
|
|
|
|
|
// Destroy the OpenGL context
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2012-04-23 10:48:57 +00:00
|
|
|
void _glfwDestroyContext(_GLFWwindow* window)
|
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
if (window->glx.visual)
|
2012-04-23 20:31:55 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
XFree(window->glx.visual);
|
|
|
|
window->glx.visual = NULL;
|
2012-04-23 20:31:55 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
if (window->glx.context)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
glXDestroyContext(_glfw.x11.display, window->glx.context);
|
|
|
|
window->glx.context = NULL;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-12 12:13:18 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW platform API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-07-27 14:01:27 +00:00
|
|
|
void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
|
|
|
{
|
|
|
|
if (window)
|
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
glXMakeCurrent(_glfw.x11.display,
|
|
|
|
window->x11.handle,
|
|
|
|
window->glx.context);
|
2011-07-27 14:01:27 +00:00
|
|
|
}
|
|
|
|
else
|
2013-01-02 00:40:42 +00:00
|
|
|
glXMakeCurrent(_glfw.x11.display, None, NULL);
|
2012-08-12 12:13:18 +00:00
|
|
|
|
|
|
|
_glfwCurrentWindow = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
_GLFWwindow* _glfwPlatformGetCurrentContext(void)
|
|
|
|
{
|
|
|
|
return _glfwCurrentWindow;
|
2011-07-27 14:01:27 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 16:13:37 +00:00
|
|
|
void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
2011-03-04 13:25:12 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
glXSwapBuffers(_glfw.x11.display, window->x11.handle);
|
2011-03-04 13:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSwapInterval(int interval)
|
|
|
|
{
|
2012-08-12 12:13:18 +00:00
|
|
|
_GLFWwindow* window = _glfwCurrentWindow;
|
2011-03-04 13:25:12 +00:00
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
if (_glfw.glx.EXT_swap_control)
|
2011-03-04 13:25:12 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
_glfw.glx.SwapIntervalEXT(_glfw.x11.display,
|
|
|
|
window->x11.handle,
|
|
|
|
interval);
|
2011-03-04 13:25:12 +00:00
|
|
|
}
|
2013-01-02 00:40:42 +00:00
|
|
|
else if (_glfw.glx.MESA_swap_control)
|
|
|
|
_glfw.glx.SwapIntervalMESA(interval);
|
|
|
|
else if (_glfw.glx.SGI_swap_control)
|
2012-07-15 14:48:39 +00:00
|
|
|
{
|
|
|
|
if (interval > 0)
|
2013-01-02 00:40:42 +00:00
|
|
|
_glfw.glx.SwapIntervalSGI(interval);
|
2012-07-15 14:48:39 +00:00
|
|
|
}
|
2011-03-04 13:25:12 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 13:58:43 +00:00
|
|
|
int _glfwPlatformExtensionSupported(const char* extension)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 13:58:43 +00:00
|
|
|
const GLubyte* extensions;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
// Get list of GLX extensions
|
2013-01-02 00:40:42 +00:00
|
|
|
extensions = (const GLubyte*) glXQueryExtensionsString(_glfw.x11.display,
|
|
|
|
_glfw.x11.screen);
|
2010-09-08 13:51:25 +00:00
|
|
|
if (extensions != NULL)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 13:51:25 +00:00
|
|
|
if (_glfwStringInExtensionString(extension, extensions))
|
2010-09-07 15:34:51 +00:00
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-04 22:16:40 +00:00
|
|
|
GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-06-04 22:16:40 +00:00
|
|
|
return _glfw_glXGetProcAddress((const GLubyte*) procname);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 21:38:14 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
////// GLFW native API //////
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* handle)
|
|
|
|
{
|
|
|
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
2013-02-19 23:28:08 +00:00
|
|
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
2013-01-15 21:38:14 +00:00
|
|
|
return window->glx.context;
|
|
|
|
}
|
|
|
|
|