Fixed GLFW3 integration on Linux.

This commit is contained in:
Branimir Karadžić 2015-03-24 23:21:32 -07:00
Родитель 0da6c77806
Коммит 4b60ddf44d
6 изменённых файлов: 129 добавлений и 104 удалений

Просмотреть файл

@ -55,7 +55,7 @@ namespace bgfx
namespace bgfx
{
///
void x11SetDisplayWindow(void* _display, uint32_t _window);
void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx = NULL);
} // namespace bgfx
@ -155,8 +155,9 @@ namespace bgfx
{
# if BX_PLATFORM_LINUX || BX_PLATFORM_FREEBSD
::Display* display = glfwGetX11Display();
::Window window = glfwGetX11Window(_window);
x11SetDisplayWindow(display, window);
::Window window = glfwGetX11Window(_window);
void* glx = glfwGetGLXContext(_window);
x11SetDisplayWindow(display, window, glx);
# elif BX_PLATFORM_OSX
void* window = glfwGetCocoaWindow(_window);
void* nsgl = glfwGetNSGLContext(_window);

Просмотреть файл

@ -26,7 +26,7 @@ function bgfxProject(_name, _kind, _defines)
}
configuration { "linux-*" }
buildoptions {
buildoptions {
"-fPIC",
}
@ -42,6 +42,12 @@ function bgfxProject(_name, _kind, _defines)
_defines,
}
if _OPTIONS["with-glfw"] then
defines {
"BGFX_CONFIG_MULTITHREADED=0",
}
end
if _OPTIONS["with-ovr"] then
defines {
"BGFX_CONFIG_USE_OVR=1",

Просмотреть файл

@ -134,6 +134,15 @@ function exampleProject(_name)
"glfw3"
}
configuration { "linux" }
links {
"Xrandr",
"Xinerama",
"Xi",
"Xxf86vm",
"Xcursor",
}
configuration { "osx" }
linkoptions {
"-framework CoreVideo",

Просмотреть файл

@ -44,11 +44,13 @@ namespace bgfx
#elif BX_PLATFORM_LINUX
void* g_bgfxX11Display;
uint32_t g_bgfxX11Window;
void* g_bgfxGLX;
void x11SetDisplayWindow(void* _display, uint32_t _window)
void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx)
{
g_bgfxX11Display = _display;
g_bgfxX11Window = _window;
g_bgfxGLX = _glx;
}
#elif BX_PLATFORM_OSX
void* g_bgfxNSWindow = NULL;

Просмотреть файл

@ -204,6 +204,7 @@ namespace bgfx
#elif BX_PLATFORM_LINUX
extern void* g_bgfxX11Display;
extern uint32_t g_bgfxX11Window;
extern void* g_bgfxGLX;
#elif BX_PLATFORM_OSX
extern void* g_bgfxNSWindow;
extern void* g_bgfxNSGL;

Просмотреть файл

@ -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);
const char* extensions = glXQueryExtensionsString( (::Display*)g_bgfxX11Display, screen);
BX_TRACE("GLX extensions:");
dumpExtensions(extensions);
const int attrsGlx[] =
if (NULL == m_context)
{
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,
};
XLockDisplay( (::Display*)g_bgfxX11Display);
// Find suitable config
GLXFBConfig bestConfig = NULL;
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
);
int numConfigs;
GLXFBConfig* configs = glXChooseFBConfig( (::Display*)g_bgfxX11Display, screen, attrsGlx, &numConfigs);
int32_t screen = DefaultScreen( (::Display*)g_bgfxX11Display);
BX_TRACE("glX num configs %d", numConfigs);
const char* extensions = glXQueryExtensionsString( (::Display*)g_bgfxX11Display, screen);
BX_TRACE("GLX extensions:");
dumpExtensions(extensions);
for (int ii = 0; ii < numConfigs; ++ii)
{
m_visualInfo = glXGetVisualFromFBConfig( (::Display*)g_bgfxX11Display, configs[ii]);
if (NULL != m_visualInfo)
const int attrsGlx[] =
{
BX_TRACE("---");
bool valid = true;
for (uint32_t attr = 6; attr < BX_COUNTOF(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2)
{
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;
#endif // BGFX_CONFIG_DEBUG
}
}
if (valid)
{
bestConfig = configs[ii];
BX_TRACE("Best config %d.", ii);
break;
}
}
XFree(m_visualInfo);
m_visualInfo = NULL;
}
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.");
#if BGFX_CONFIG_RENDERER_OPENGL >= 31
glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB");
if (NULL != glXCreateContextAttribsARB)
{
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,
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,
};
GLXContext context = glXCreateContextAttribsARB( (::Display*)g_bgfxX11Display, bestConfig, 0, true, contextAttrs);
// Find suitable config
GLXFBConfig bestConfig = NULL;
if (NULL != context)
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)
{
glXDestroyContext( (::Display*)g_bgfxX11Display, m_context);
m_context = context;
m_visualInfo = glXGetVisualFromFBConfig( (::Display*)g_bgfxX11Display, configs[ii]);
if (NULL != m_visualInfo)
{
BX_TRACE("---");
bool valid = true;
for (uint32_t attr = 6; attr < BX_COUNTOF(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2)
{
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;
#endif // BGFX_CONFIG_DEBUG
}
}
if (valid)
{
bestConfig = configs[ii];
BX_TRACE("Best config %d.", ii);
break;
}
}
XFree(m_visualInfo);
m_visualInfo = NULL;
}
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.");
#if BGFX_CONFIG_RENDERER_OPENGL >= 31
glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB");
if (NULL != glXCreateContextAttribsARB)
{
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);
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();