|
|
@@ -55,122 +55,128 @@ namespace bgfx { namespace gl
|
|
|
void GlContext::create(uint32_t _width, uint32_t _height)
|
|
|
{
|
|
|
BX_UNUSED(_width, _height);
|
|
|
- XLockDisplay( (::Display*)g_bgfxX11Display);
|
|
|
|
|
|
- int major, minor;
|
|
|
- bool version = glXQueryVersion( (::Display*)g_bgfxX11Display, &major, &minor);
|
|
|
- BGFX_FATAL(version, Fatal::UnableToInitialize, "Failed to query GLX version");
|
|
|
- BGFX_FATAL( (major == 1 && minor >= 2) || major > 1
|
|
|
- , Fatal::UnableToInitialize
|
|
|
- , "GLX version is not >=1.2 (%d.%d)."
|
|
|
- , major
|
|
|
- , minor
|
|
|
- );
|
|
|
+ m_context = (GLXContext)g_bgfxGLX;
|
|
|
|
|
|
- int32_t screen = DefaultScreen( (::Display*)g_bgfxX11Display);
|
|
|
+ if (NULL == m_context)
|
|
|
+ {
|
|
|
+ XLockDisplay( (::Display*)g_bgfxX11Display);
|
|
|
|
|
|
- const char* extensions = glXQueryExtensionsString( (::Display*)g_bgfxX11Display, screen);
|
|
|
- BX_TRACE("GLX extensions:");
|
|
|
- dumpExtensions(extensions);
|
|
|
+ int major, minor;
|
|
|
+ bool version = glXQueryVersion( (::Display*)g_bgfxX11Display, &major, &minor);
|
|
|
+ BGFX_FATAL(version, Fatal::UnableToInitialize, "Failed to query GLX version");
|
|
|
+ BGFX_FATAL( (major == 1 && minor >= 2) || major > 1
|
|
|
+ , Fatal::UnableToInitialize
|
|
|
+ , "GLX version is not >=1.2 (%d.%d)."
|
|
|
+ , major
|
|
|
+ , minor
|
|
|
+ );
|
|
|
|
|
|
- const int attrsGlx[] =
|
|
|
- {
|
|
|
- GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
|
|
- GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
|
|
- GLX_DOUBLEBUFFER, true,
|
|
|
- GLX_RED_SIZE, 8,
|
|
|
- GLX_BLUE_SIZE, 8,
|
|
|
- GLX_GREEN_SIZE, 8,
|
|
|
-// GLX_ALPHA_SIZE, 8,
|
|
|
- GLX_DEPTH_SIZE, 24,
|
|
|
- GLX_STENCIL_SIZE, 8,
|
|
|
- 0,
|
|
|
- };
|
|
|
-
|
|
|
- // Find suitable config
|
|
|
- GLXFBConfig bestConfig = NULL;
|
|
|
-
|
|
|
- int numConfigs;
|
|
|
- GLXFBConfig* configs = glXChooseFBConfig( (::Display*)g_bgfxX11Display, screen, attrsGlx, &numConfigs);
|
|
|
-
|
|
|
- BX_TRACE("glX num configs %d", numConfigs);
|
|
|
-
|
|
|
- for (int ii = 0; ii < numConfigs; ++ii)
|
|
|
- {
|
|
|
- m_visualInfo = glXGetVisualFromFBConfig( (::Display*)g_bgfxX11Display, configs[ii]);
|
|
|
- if (NULL != m_visualInfo)
|
|
|
+ int32_t screen = DefaultScreen( (::Display*)g_bgfxX11Display);
|
|
|
+
|
|
|
+ const char* extensions = glXQueryExtensionsString( (::Display*)g_bgfxX11Display, screen);
|
|
|
+ BX_TRACE("GLX extensions:");
|
|
|
+ dumpExtensions(extensions);
|
|
|
+
|
|
|
+ const int attrsGlx[] =
|
|
|
{
|
|
|
- BX_TRACE("---");
|
|
|
- bool valid = true;
|
|
|
- for (uint32_t attr = 6; attr < BX_COUNTOF(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2)
|
|
|
+ GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
|
|
+ GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
|
|
|
+ GLX_DOUBLEBUFFER, true,
|
|
|
+ GLX_RED_SIZE, 8,
|
|
|
+ GLX_BLUE_SIZE, 8,
|
|
|
+ GLX_GREEN_SIZE, 8,
|
|
|
+ // GLX_ALPHA_SIZE, 8,
|
|
|
+ GLX_DEPTH_SIZE, 24,
|
|
|
+ GLX_STENCIL_SIZE, 8,
|
|
|
+ 0,
|
|
|
+ };
|
|
|
+
|
|
|
+ // Find suitable config
|
|
|
+ GLXFBConfig bestConfig = NULL;
|
|
|
+
|
|
|
+ int numConfigs;
|
|
|
+ GLXFBConfig* configs = glXChooseFBConfig( (::Display*)g_bgfxX11Display, screen, attrsGlx, &numConfigs);
|
|
|
+
|
|
|
+ BX_TRACE("glX num configs %d", numConfigs);
|
|
|
+
|
|
|
+ for (int ii = 0; ii < numConfigs; ++ii)
|
|
|
+ {
|
|
|
+ m_visualInfo = glXGetVisualFromFBConfig( (::Display*)g_bgfxX11Display, configs[ii]);
|
|
|
+ if (NULL != m_visualInfo)
|
|
|
{
|
|
|
- int value;
|
|
|
- glXGetFBConfigAttrib( (::Display*)g_bgfxX11Display, configs[ii], attrsGlx[attr], &value);
|
|
|
- BX_TRACE("glX %d/%d %2d: %4x, %8x (%8x%s)"
|
|
|
- , ii
|
|
|
- , numConfigs
|
|
|
- , attr/2
|
|
|
- , attrsGlx[attr]
|
|
|
- , value
|
|
|
- , attrsGlx[attr + 1]
|
|
|
- , value < attrsGlx[attr + 1] ? " *" : ""
|
|
|
- );
|
|
|
-
|
|
|
- if (value < attrsGlx[attr + 1])
|
|
|
+ BX_TRACE("---");
|
|
|
+ bool valid = true;
|
|
|
+ for (uint32_t attr = 6; attr < BX_COUNTOF(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2)
|
|
|
{
|
|
|
- valid = false;
|
|
|
+ int value;
|
|
|
+ glXGetFBConfigAttrib( (::Display*)g_bgfxX11Display, configs[ii], attrsGlx[attr], &value);
|
|
|
+ BX_TRACE("glX %d/%d %2d: %4x, %8x (%8x%s)"
|
|
|
+ , ii
|
|
|
+ , numConfigs
|
|
|
+ , attr/2
|
|
|
+ , attrsGlx[attr]
|
|
|
+ , value
|
|
|
+ , attrsGlx[attr + 1]
|
|
|
+ , value < attrsGlx[attr + 1] ? " *" : ""
|
|
|
+ );
|
|
|
+
|
|
|
+ if (value < attrsGlx[attr + 1])
|
|
|
+ {
|
|
|
+ valid = false;
|
|
|
#if !BGFX_CONFIG_DEBUG
|
|
|
- break;
|
|
|
+ break;
|
|
|
#endif // BGFX_CONFIG_DEBUG
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (valid)
|
|
|
- {
|
|
|
- bestConfig = configs[ii];
|
|
|
- BX_TRACE("Best config %d.", ii);
|
|
|
- break;
|
|
|
+ if (valid)
|
|
|
+ {
|
|
|
+ bestConfig = configs[ii];
|
|
|
+ BX_TRACE("Best config %d.", ii);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- XFree(m_visualInfo);
|
|
|
- m_visualInfo = NULL;
|
|
|
- }
|
|
|
+ XFree(m_visualInfo);
|
|
|
+ m_visualInfo = NULL;
|
|
|
+ }
|
|
|
|
|
|
- XFree(configs);
|
|
|
- BGFX_FATAL(m_visualInfo, Fatal::UnableToInitialize, "Failed to find a suitable X11 display configuration.");
|
|
|
+ XFree(configs);
|
|
|
+ BGFX_FATAL(m_visualInfo, Fatal::UnableToInitialize, "Failed to find a suitable X11 display configuration.");
|
|
|
|
|
|
- BX_TRACE("Create GL 2.1 context.");
|
|
|
- m_context = glXCreateContext( (::Display*)g_bgfxX11Display, m_visualInfo, 0, GL_TRUE);
|
|
|
- BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create GL 2.1 context.");
|
|
|
+ BX_TRACE("Create GL 2.1 context.");
|
|
|
+ m_context = glXCreateContext( (::Display*)g_bgfxX11Display, m_visualInfo, 0, GL_TRUE);
|
|
|
+ BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create GL 2.1 context.");
|
|
|
|
|
|
#if BGFX_CONFIG_RENDERER_OPENGL >= 31
|
|
|
- glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB");
|
|
|
+ glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB");
|
|
|
|
|
|
- if (NULL != glXCreateContextAttribsARB)
|
|
|
- {
|
|
|
- BX_TRACE("Create GL 3.1 context.");
|
|
|
- const int contextAttrs[] =
|
|
|
+ if (NULL != glXCreateContextAttribsARB)
|
|
|
{
|
|
|
- GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
|
|
- GLX_CONTEXT_MINOR_VERSION_ARB, 1,
|
|
|
- GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
|
|
|
- 0,
|
|
|
- };
|
|
|
+ BX_TRACE("Create GL 3.1 context.");
|
|
|
+ const int contextAttrs[] =
|
|
|
+ {
|
|
|
+ GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
|
|
|
+ GLX_CONTEXT_MINOR_VERSION_ARB, 1,
|
|
|
+ GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
|
|
|
+ 0,
|
|
|
+ };
|
|
|
|
|
|
- GLXContext context = glXCreateContextAttribsARB( (::Display*)g_bgfxX11Display, bestConfig, 0, true, contextAttrs);
|
|
|
+ GLXContext context = glXCreateContextAttribsARB( (::Display*)g_bgfxX11Display, bestConfig, 0, true, contextAttrs);
|
|
|
|
|
|
- if (NULL != context)
|
|
|
- {
|
|
|
- glXDestroyContext( (::Display*)g_bgfxX11Display, m_context);
|
|
|
- m_context = context;
|
|
|
+ if (NULL != context)
|
|
|
+ {
|
|
|
+ glXDestroyContext( (::Display*)g_bgfxX11Display, m_context);
|
|
|
+ m_context = context;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
#else
|
|
|
- BX_UNUSED(bestConfig);
|
|
|
+ BX_UNUSED(bestConfig);
|
|
|
#endif // BGFX_CONFIG_RENDERER_OPENGL >= 31
|
|
|
|
|
|
- XUnlockDisplay( (::Display*)g_bgfxX11Display);
|
|
|
+ XUnlockDisplay( (::Display*)g_bgfxX11Display);
|
|
|
+ }
|
|
|
|
|
|
import();
|
|
|
|