2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
2015-06-01 20:55:06 +00:00
|
|
|
// GLFW 3.2 GLX - www.glfw.org
|
2010-09-07 15:34:51 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
// 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>
|
2015-05-26 23:06:36 +00:00
|
|
|
#include <dlfcn.h>
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-12-30 17:13:04 +00:00
|
|
|
#ifndef GLXBadProfileARB
|
|
|
|
#define GLXBadProfileARB 13
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-05-13 13:49:59 +00:00
|
|
|
// Returns the specified attribute of the specified GLXFBConfig
|
|
|
|
//
|
|
|
|
static int getFBConfigAttrib(GLXFBConfig fbconfig, int attrib)
|
|
|
|
{
|
|
|
|
int value;
|
2015-08-12 22:21:33 +00:00
|
|
|
_glfw_glXGetFBConfigAttrib(_glfw.x11.display, fbconfig, attrib, &value);
|
2013-05-13 13:49:59 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of available and usable framebuffer configs
|
|
|
|
//
|
2015-08-23 17:30:04 +00:00
|
|
|
static GLFWbool chooseFBConfig(const _GLFWfbconfig* desired, GLXFBConfig* result)
|
2013-05-13 13:49:59 +00:00
|
|
|
{
|
|
|
|
GLXFBConfig* nativeConfigs;
|
|
|
|
_GLFWfbconfig* usableConfigs;
|
|
|
|
const _GLFWfbconfig* closest;
|
|
|
|
int i, nativeCount, usableCount;
|
|
|
|
const char* vendor;
|
2015-08-23 17:30:04 +00:00
|
|
|
GLFWbool trustWindowBit = GLFW_TRUE;
|
2013-05-13 13:49:59 +00:00
|
|
|
|
2015-04-07 00:51:45 +00:00
|
|
|
// HACK: This is a (hopefully temporary) workaround for Chromium
|
|
|
|
// (VirtualBox GL) not setting the window bit on any GLXFBConfigs
|
2015-08-12 22:21:33 +00:00
|
|
|
vendor = _glfw_glXGetClientString(_glfw.x11.display, GLX_VENDOR);
|
2013-05-13 13:49:59 +00:00
|
|
|
if (strcmp(vendor, "Chromium") == 0)
|
2015-08-23 17:30:04 +00:00
|
|
|
trustWindowBit = GLFW_FALSE;
|
2013-05-13 13:49:59 +00:00
|
|
|
|
2015-08-12 22:21:33 +00:00
|
|
|
nativeConfigs = _glfw_glXGetFBConfigs(_glfw.x11.display, _glfw.x11.screen,
|
|
|
|
&nativeCount);
|
2013-05-13 13:49:59 +00:00
|
|
|
if (!nativeCount)
|
|
|
|
{
|
2014-03-06 15:45:40 +00:00
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE, "GLX: No GLXFBConfigs returned");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2013-05-13 13:49:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-04 12:54:07 +00:00
|
|
|
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
|
2013-05-13 13:49:59 +00:00
|
|
|
usableCount = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < nativeCount; i++)
|
|
|
|
{
|
|
|
|
const GLXFBConfig n = nativeConfigs[i];
|
|
|
|
_GLFWfbconfig* u = usableConfigs + usableCount;
|
|
|
|
|
2015-04-07 00:51:45 +00:00
|
|
|
// Only consider RGBA GLXFBConfigs
|
2013-05-13 13:49:59 +00:00
|
|
|
if (!(getFBConfigAttrib(n, GLX_RENDER_TYPE) & GLX_RGBA_BIT))
|
|
|
|
continue;
|
|
|
|
|
2015-04-07 00:51:45 +00:00
|
|
|
// Only consider window GLXFBConfigs
|
2013-05-13 13:49:59 +00:00
|
|
|
if (!(getFBConfigAttrib(n, GLX_DRAWABLE_TYPE) & GLX_WINDOW_BIT))
|
|
|
|
{
|
|
|
|
if (trustWindowBit)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
u->redBits = getFBConfigAttrib(n, GLX_RED_SIZE);
|
|
|
|
u->greenBits = getFBConfigAttrib(n, GLX_GREEN_SIZE);
|
|
|
|
u->blueBits = getFBConfigAttrib(n, GLX_BLUE_SIZE);
|
|
|
|
|
|
|
|
u->alphaBits = getFBConfigAttrib(n, GLX_ALPHA_SIZE);
|
|
|
|
u->depthBits = getFBConfigAttrib(n, GLX_DEPTH_SIZE);
|
|
|
|
u->stencilBits = getFBConfigAttrib(n, GLX_STENCIL_SIZE);
|
|
|
|
|
|
|
|
u->accumRedBits = getFBConfigAttrib(n, GLX_ACCUM_RED_SIZE);
|
|
|
|
u->accumGreenBits = getFBConfigAttrib(n, GLX_ACCUM_GREEN_SIZE);
|
|
|
|
u->accumBlueBits = getFBConfigAttrib(n, GLX_ACCUM_BLUE_SIZE);
|
|
|
|
u->accumAlphaBits = getFBConfigAttrib(n, GLX_ACCUM_ALPHA_SIZE);
|
|
|
|
|
|
|
|
u->auxBuffers = getFBConfigAttrib(n, GLX_AUX_BUFFERS);
|
2014-04-24 17:21:10 +00:00
|
|
|
|
|
|
|
if (getFBConfigAttrib(n, GLX_STEREO))
|
2015-08-23 17:30:04 +00:00
|
|
|
u->stereo = GLFW_TRUE;
|
2014-04-24 17:21:10 +00:00
|
|
|
if (getFBConfigAttrib(n, GLX_DOUBLEBUFFER))
|
2015-08-23 17:30:04 +00:00
|
|
|
u->doublebuffer = GLFW_TRUE;
|
2013-05-13 13:49:59 +00:00
|
|
|
|
|
|
|
if (_glfw.glx.ARB_multisample)
|
|
|
|
u->samples = getFBConfigAttrib(n, GLX_SAMPLES);
|
|
|
|
|
2015-07-14 13:44:13 +00:00
|
|
|
if (_glfw.glx.ARB_framebuffer_sRGB || _glfw.glx.EXT_framebuffer_sRGB)
|
2013-05-13 13:49:59 +00:00
|
|
|
u->sRGB = getFBConfigAttrib(n, GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB);
|
|
|
|
|
|
|
|
u->glx = n;
|
|
|
|
usableCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
closest = _glfwChooseFBConfig(desired, usableConfigs, usableCount);
|
|
|
|
if (closest)
|
|
|
|
*result = closest->glx;
|
|
|
|
|
|
|
|
XFree(nativeConfigs);
|
|
|
|
free(usableConfigs);
|
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
return closest ? GLFW_TRUE : GLFW_FALSE;
|
2013-05-13 13:49:59 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
// 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)
|
|
|
|
{
|
2015-08-12 22:21:33 +00:00
|
|
|
return _glfw_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
|
|
|
{
|
2015-08-18 14:56:19 +00:00
|
|
|
#if defined(__CYGWIN__)
|
|
|
|
const char* soname = "libGL-1.so";
|
|
|
|
#else
|
|
|
|
const char* soname = "libGL.so.1";
|
|
|
|
#endif
|
|
|
|
|
2015-05-05 01:31:20 +00:00
|
|
|
if (!_glfwCreateContextTLS())
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2014-03-30 12:37:20 +00:00
|
|
|
|
2015-08-18 14:56:19 +00:00
|
|
|
_glfw.glx.handle = dlopen(soname, RTLD_LAZY | RTLD_GLOBAL);
|
2015-05-26 23:06:36 +00:00
|
|
|
if (!_glfw.glx.handle)
|
2013-01-15 19:00:27 +00:00
|
|
|
{
|
2015-05-26 23:06:36 +00:00
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE, "GLX: %s", dlerror());
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2013-01-15 19:00:27 +00:00
|
|
|
}
|
2015-05-26 23:06:36 +00:00
|
|
|
|
2015-08-12 22:21:33 +00:00
|
|
|
_glfw.glx.GetFBConfigs =
|
|
|
|
dlsym(_glfw.glx.handle, "glXGetFBConfigs");
|
|
|
|
_glfw.glx.GetFBConfigAttrib =
|
|
|
|
dlsym(_glfw.glx.handle, "glXGetFBConfigAttrib");
|
|
|
|
_glfw.glx.GetClientString =
|
|
|
|
dlsym(_glfw.glx.handle, "glXGetClientString");
|
|
|
|
_glfw.glx.QueryExtension =
|
|
|
|
dlsym(_glfw.glx.handle, "glXQueryExtension");
|
|
|
|
_glfw.glx.QueryVersion =
|
|
|
|
dlsym(_glfw.glx.handle, "glXQueryVersion");
|
|
|
|
_glfw.glx.DestroyContext =
|
|
|
|
dlsym(_glfw.glx.handle, "glXDestroyContext");
|
|
|
|
_glfw.glx.MakeCurrent =
|
|
|
|
dlsym(_glfw.glx.handle, "glXMakeCurrent");
|
|
|
|
_glfw.glx.SwapBuffers =
|
|
|
|
dlsym(_glfw.glx.handle, "glXSwapBuffers");
|
|
|
|
_glfw.glx.QueryExtensionsString =
|
|
|
|
dlsym(_glfw.glx.handle, "glXQueryExtensionsString");
|
|
|
|
_glfw.glx.CreateNewContext =
|
|
|
|
dlsym(_glfw.glx.handle, "glXCreateNewContext");
|
2015-10-15 18:10:24 +00:00
|
|
|
_glfw.glx.CreateWindow =
|
|
|
|
dlsym(_glfw.glx.handle, "glXCreateWindow");
|
|
|
|
_glfw.glx.DestroyWindow =
|
|
|
|
dlsym(_glfw.glx.handle, "glXDestroyWindow");
|
2015-05-26 23:06:36 +00:00
|
|
|
_glfw.glx.GetProcAddress =
|
|
|
|
dlsym(_glfw.glx.handle, "glXGetProcAddress");
|
|
|
|
_glfw.glx.GetProcAddressARB =
|
|
|
|
dlsym(_glfw.glx.handle, "glXGetProcAddressARB");
|
2015-06-18 12:03:02 +00:00
|
|
|
_glfw.glx.GetVisualFromFBConfig =
|
|
|
|
dlsym(_glfw.glx.handle, "glXGetVisualFromFBConfig");
|
2012-06-03 14:31:56 +00:00
|
|
|
|
2015-08-12 22:21:33 +00:00
|
|
|
if (!_glfw_glXQueryExtension(_glfw.x11.display,
|
|
|
|
&_glfw.glx.errorBase,
|
|
|
|
&_glfw.glx.eventBase))
|
2012-06-03 14:31:56 +00:00
|
|
|
{
|
2014-03-30 08:45:33 +00:00
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE, "GLX: GLX extension not found");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2012-06-03 14:31:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 22:21:33 +00:00
|
|
|
if (!_glfw_glXQueryVersion(_glfw.x11.display,
|
|
|
|
&_glfw.glx.major,
|
|
|
|
&_glfw.glx.minor))
|
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");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
2013-01-15 19:00:27 +00:00
|
|
|
|
2015-05-27 12:35:31 +00:00
|
|
|
if (_glfw.glx.major == 1 && _glfw.glx.minor < 3)
|
2014-03-30 08:45:33 +00:00
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
|
|
|
"GLX: GLX version 1.3 is required");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2014-03-30 08:45:33 +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)
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.EXT_swap_control = GLFW_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)
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.SGI_swap_control = GLFW_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)
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.MESA_swap_control = GLFW_TRUE;
|
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"))
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.ARB_multisample = GLFW_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_ARB_framebuffer_sRGB"))
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.ARB_framebuffer_sRGB = GLFW_TRUE;
|
2012-12-02 15:10:00 +00:00
|
|
|
|
2015-07-14 13:44:13 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_EXT_framebuffer_sRGB"))
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.EXT_framebuffer_sRGB = GLFW_TRUE;
|
2015-07-14 13:44:13 +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)
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.ARB_create_context = GLFW_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness"))
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.ARB_create_context_robustness = GLFW_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-01-15 19:00:27 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile"))
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.ARB_create_context_profile = GLFW_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"))
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.EXT_create_context_es2_profile = GLFW_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2014-08-21 17:21:45 +00:00
|
|
|
if (_glfwPlatformExtensionSupported("GLX_ARB_context_flush_control"))
|
2015-08-23 17:30:04 +00:00
|
|
|
_glfw.glx.ARB_context_flush_control = GLFW_TRUE;
|
2014-08-21 17:21:45 +00:00
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_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
|
|
|
{
|
2015-08-12 22:21:33 +00:00
|
|
|
// NOTE: This function may not call any X11 functions, as it is called after
|
|
|
|
// XCloseDisplay (see _glfwPlatformTerminate for details)
|
|
|
|
|
2015-05-26 23:06:36 +00:00
|
|
|
if (_glfw.glx.handle)
|
2012-12-30 17:13:04 +00:00
|
|
|
{
|
2015-05-26 23:06:36 +00:00
|
|
|
dlclose(_glfw.glx.handle);
|
|
|
|
_glfw.glx.handle = NULL;
|
2012-12-30 17:13:04 +00:00
|
|
|
}
|
2013-05-02 14:48:11 +00:00
|
|
|
|
2015-05-05 01:31:20 +00:00
|
|
|
_glfwDestroyContextTLS();
|
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; \
|
2013-07-15 16:37:02 +00:00
|
|
|
assert((size_t) index < sizeof(attribs) / sizeof(attribs[0])); \
|
2013-01-15 19:00:27 +00:00
|
|
|
}
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2014-08-20 18:12:59 +00:00
|
|
|
// Create the OpenGL or OpenGL ES context
|
2013-02-04 12:22:10 +00:00
|
|
|
//
|
2013-01-15 19:00:27 +00:00
|
|
|
int _glfwCreateContext(_GLFWwindow* window,
|
2014-03-06 19:05:32 +00:00
|
|
|
const _GLFWctxconfig* ctxconfig,
|
2013-01-15 19:00:27 +00:00
|
|
|
const _GLFWfbconfig* fbconfig)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
|
|
|
int attribs[40];
|
2015-08-12 16:02:02 +00:00
|
|
|
GLXFBConfig native = NULL;
|
2012-04-23 10:48:57 +00:00
|
|
|
GLXContext share = NULL;
|
|
|
|
|
2014-03-06 19:05:32 +00:00
|
|
|
if (ctxconfig->share)
|
|
|
|
share = ctxconfig->share->glx.context;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-05-13 13:49:59 +00:00
|
|
|
if (!chooseFBConfig(fbconfig, &native))
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2015-09-16 14:24:21 +00:00
|
|
|
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
2013-05-13 13:49:59 +00:00
|
|
|
"GLX: Failed to find a suitable GLXFBConfig");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2014-03-06 19:05:32 +00:00
|
|
|
if (ctxconfig->api == 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-08-21 09:56:48 +00:00
|
|
|
_glfwInputError(GLFW_API_UNAVAILABLE,
|
2015-03-10 18:51:14 +00:00
|
|
|
"GLX: OpenGL ES requested but GLX_EXT_create_context_es2_profile is unavailable");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_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
|
|
|
|
2014-03-06 19:05:32 +00:00
|
|
|
if (ctxconfig->forward)
|
2012-12-13 19:43:15 +00:00
|
|
|
{
|
2013-01-02 00:40:42 +00:00
|
|
|
if (!_glfw.glx.ARB_create_context)
|
2012-07-21 23:10:59 +00:00
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
2015-03-10 18:51:14 +00:00
|
|
|
"GLX: Forward compatibility requested but GLX_ARB_create_context_profile is unavailable");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_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
|
|
|
|
2014-03-06 19:05:32 +00:00
|
|
|
if (ctxconfig->profile)
|
2012-12-13 19:43:15 +00:00
|
|
|
{
|
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
|
|
|
{
|
2012-12-31 20:05:28 +00:00
|
|
|
_glfwInputError(GLFW_VERSION_UNAVAILABLE,
|
2015-03-10 18:51:14 +00:00
|
|
|
"GLX: An OpenGL profile requested but GLX_ARB_create_context_profile is unavailable");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2012-12-13 19:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 16:38:21 +00:00
|
|
|
_glfwGrabXErrorHandler();
|
2013-01-21 19:19:20 +00:00
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
if (_glfw.glx.ARB_create_context)
|
2012-12-13 19:43:15 +00:00
|
|
|
{
|
2015-04-10 11:18:26 +00:00
|
|
|
int index = 0, mask = 0, flags = 0;
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2014-03-06 19:05:32 +00:00
|
|
|
if (ctxconfig->api == GLFW_OPENGL_API)
|
2012-12-13 19:43:15 +00:00
|
|
|
{
|
2014-03-06 19:05:32 +00:00
|
|
|
if (ctxconfig->forward)
|
2012-04-23 10:48:57 +00:00
|
|
|
flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
|
|
|
|
2015-04-10 11:18:26 +00:00
|
|
|
if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE)
|
|
|
|
mask |= GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
|
|
|
|
else if (ctxconfig->profile == 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
|
|
|
|
2015-02-27 01:53:21 +00:00
|
|
|
if (ctxconfig->debug)
|
|
|
|
flags |= GLX_CONTEXT_DEBUG_BIT_ARB;
|
2015-08-10 10:46:14 +00:00
|
|
|
if (ctxconfig->noerror)
|
|
|
|
flags |= GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR;
|
2015-02-27 01:53:21 +00:00
|
|
|
|
2014-08-20 18:12:59 +00:00
|
|
|
if (ctxconfig->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
|
|
|
{
|
2014-03-06 19:05:32 +00:00
|
|
|
if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION)
|
2015-04-10 11:18:26 +00:00
|
|
|
{
|
|
|
|
setGLXattrib(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
|
|
|
|
GLX_NO_RESET_NOTIFICATION_ARB);
|
|
|
|
}
|
2014-03-06 19:05:32 +00:00
|
|
|
else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET)
|
2015-04-10 11:18:26 +00:00
|
|
|
{
|
|
|
|
setGLXattrib(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-08-21 17:21:45 +00:00
|
|
|
if (ctxconfig->release)
|
|
|
|
{
|
|
|
|
if (_glfw.glx.ARB_context_flush_control)
|
|
|
|
{
|
|
|
|
if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE)
|
|
|
|
{
|
|
|
|
setGLXattrib(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB,
|
|
|
|
GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB);
|
|
|
|
}
|
|
|
|
else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH)
|
|
|
|
{
|
|
|
|
setGLXattrib(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB,
|
|
|
|
GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 00:51:45 +00:00
|
|
|
// NOTE: Only request an explicitly versioned context when necessary, as
|
|
|
|
// explicitly requesting version 1.0 does not always return the
|
|
|
|
// highest version supported by the driver
|
2014-03-06 19:05:32 +00:00
|
|
|
if (ctxconfig->major != 1 || ctxconfig->minor != 0)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2014-03-06 19:05:32 +00:00
|
|
|
setGLXattrib(GLX_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major);
|
|
|
|
setGLXattrib(GLX_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor);
|
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 (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);
|
|
|
|
|
|
|
|
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-05-13 13:49:59 +00:00
|
|
|
native,
|
2013-01-02 00:40:42 +00:00
|
|
|
share,
|
|
|
|
True,
|
|
|
|
attribs);
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2015-04-07 00:51:45 +00:00
|
|
|
// HACK: This is a fallback for broken versions of the Mesa
|
|
|
|
// implementation of GLX_ARB_create_context_profile that fail
|
|
|
|
// default 1.0 context creation with a GLXBadProfileARB error in
|
|
|
|
// violation of the extension spec
|
2014-08-20 18:12:59 +00:00
|
|
|
if (!window->glx.context)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2013-07-10 23:23:26 +00:00
|
|
|
if (_glfw.x11.errorCode == _glfw.glx.errorBase + GLXBadProfileARB &&
|
2014-03-06 19:05:32 +00:00
|
|
|
ctxconfig->api == GLFW_OPENGL_API &&
|
|
|
|
ctxconfig->profile == GLFW_OPENGL_ANY_PROFILE &&
|
2015-08-23 17:30:04 +00:00
|
|
|
ctxconfig->forward == GLFW_FALSE)
|
2012-12-30 17:13:04 +00:00
|
|
|
{
|
2013-05-13 13:49:59 +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-05-13 13:49:59 +00:00
|
|
|
window->glx.context = createLegacyContext(window, native, share);
|
2012-04-23 10:48:57 +00:00
|
|
|
|
2013-07-09 16:38:21 +00:00
|
|
|
_glfwReleaseXErrorHandler();
|
2013-01-21 19:19:20 +00:00
|
|
|
|
2014-08-20 18:12:59 +00:00
|
|
|
if (!window->glx.context)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2015-03-10 18:51:14 +00:00
|
|
|
_glfwInputXError(GLFW_VERSION_UNAVAILABLE, "GLX: Failed to create context");
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-15 18:10:24 +00:00
|
|
|
window->glx.window = _glfw_glXCreateWindow(_glfw.x11.display, native,
|
|
|
|
window->x11.handle, NULL);
|
|
|
|
if (!window->glx.window)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to create window");
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_TRUE;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2015-10-15 18:10:24 +00:00
|
|
|
if (window->glx.window)
|
|
|
|
{
|
|
|
|
_glfw_glXDestroyWindow(_glfw.x11.display, window->glx.window);
|
|
|
|
window->glx.window = None;
|
|
|
|
}
|
|
|
|
|
2013-01-02 00:40:42 +00:00
|
|
|
if (window->glx.context)
|
2012-04-23 10:48:57 +00:00
|
|
|
{
|
2015-08-12 22:21:33 +00:00
|
|
|
_glfw_glXDestroyContext(_glfw.x11.display, window->glx.context);
|
2013-01-02 00:40:42 +00:00
|
|
|
window->glx.context = NULL;
|
2012-04-23 10:48:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-18 12:03:02 +00:00
|
|
|
// Returns the Visual and depth of the chosen GLXFBConfig
|
|
|
|
//
|
|
|
|
GLFWbool _glfwChooseVisual(const _GLFWctxconfig* ctxconfig,
|
|
|
|
const _GLFWfbconfig* fbconfig,
|
|
|
|
Visual** visual, int* depth)
|
|
|
|
{
|
|
|
|
GLXFBConfig native;
|
|
|
|
XVisualInfo* result;
|
|
|
|
|
|
|
|
if (!chooseFBConfig(fbconfig, &native))
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_FORMAT_UNAVAILABLE,
|
|
|
|
"GLX: Failed to find a suitable GLXFBConfig");
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = _glfw_glXGetVisualFromFBConfig(_glfw.x11.display, native);
|
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
|
|
"GLX: Failed to retrieve Visual for GLXFBConfig");
|
|
|
|
return GLFW_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*visual = result->visual;
|
|
|
|
*depth = result->depth;
|
|
|
|
|
|
|
|
XFree(result);
|
|
|
|
return GLFW_TRUE;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2015-08-12 22:21:33 +00:00
|
|
|
_glfw_glXMakeCurrent(_glfw.x11.display,
|
2015-10-15 18:10:24 +00:00
|
|
|
window->glx.window,
|
2015-08-12 22:21:33 +00:00
|
|
|
window->glx.context);
|
2011-07-27 14:01:27 +00:00
|
|
|
}
|
|
|
|
else
|
2015-08-12 22:21:33 +00:00
|
|
|
_glfw_glXMakeCurrent(_glfw.x11.display, None, NULL);
|
2012-08-12 12:13:18 +00:00
|
|
|
|
2015-05-05 01:31:20 +00:00
|
|
|
_glfwSetContextTLS(window);
|
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
|
|
|
{
|
2015-10-15 18:10:24 +00:00
|
|
|
_glfw_glXSwapBuffers(_glfw.x11.display, window->glx.window);
|
2011-03-04 13:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformSwapInterval(int interval)
|
|
|
|
{
|
2013-05-02 14:48:11 +00:00
|
|
|
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
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,
|
2015-10-15 18:10:24 +00:00
|
|
|
window->glx.window,
|
2013-01-02 00:40:42 +00:00
|
|
|
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
|
|
|
{
|
2015-08-12 22:21:33 +00:00
|
|
|
const char* extensions =
|
|
|
|
_glfw_glXQueryExtensionsString(_glfw.x11.display, _glfw.x11.screen);
|
2015-04-07 00:51:45 +00:00
|
|
|
if (extensions)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-08 13:51:25 +00:00
|
|
|
if (_glfwStringInExtensionString(extension, extensions))
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_TRUE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 17:30:04 +00:00
|
|
|
return GLFW_FALSE;
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 22:16:40 +00:00
|
|
|
GLFWglproc _glfwPlatformGetProcAddress(const char* procname)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2015-05-26 23:06:36 +00:00
|
|
|
if (_glfw.glx.GetProcAddress)
|
|
|
|
return _glfw.glx.GetProcAddress((const GLubyte*) procname);
|
|
|
|
else if (_glfw.glx.GetProcAddressARB)
|
|
|
|
return _glfw.glx.GetProcAddressARB((const GLubyte*) procname);
|
|
|
|
else
|
|
|
|
return dlsym(_glfw.glx.handle, 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);
|
2015-06-18 12:03:02 +00:00
|
|
|
|
|
|
|
if (window->context.api == GLFW_NO_API)
|
|
|
|
{
|
|
|
|
_glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-15 21:38:14 +00:00
|
|
|
return window->glx.context;
|
|
|
|
}
|
|
|
|
|