mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
GLX: Added swap chain support.
This commit is contained in:
parent
2850924e95
commit
9ba0956812
2 changed files with 63 additions and 20 deletions
|
@ -25,6 +25,34 @@ namespace bgfx
|
||||||
static ::Display* s_display;
|
static ::Display* s_display;
|
||||||
static ::Window s_window;
|
static ::Window s_window;
|
||||||
|
|
||||||
|
struct SwapChainGL
|
||||||
|
{
|
||||||
|
SwapChainGL(::Window _window, XVisualInfo* _visualInfo, GLXContext _context)
|
||||||
|
: m_window(_window)
|
||||||
|
{
|
||||||
|
m_context = glXCreateContext(s_display, _visualInfo, _context, GL_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
~SwapChainGL()
|
||||||
|
{
|
||||||
|
glXMakeCurrent(s_display, 0, 0);
|
||||||
|
glXDestroyContext(s_display, m_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void makeCurrent()
|
||||||
|
{
|
||||||
|
glXMakeCurrent(s_display, m_window, m_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
void swapBuffers()
|
||||||
|
{
|
||||||
|
glXSwapBuffers(s_display, m_window);
|
||||||
|
}
|
||||||
|
|
||||||
|
Window m_window;
|
||||||
|
GLXContext m_context;
|
||||||
|
};
|
||||||
|
|
||||||
void x11SetDisplayWindow(::Display* _display, ::Window _window)
|
void x11SetDisplayWindow(::Display* _display, ::Window _window)
|
||||||
{
|
{
|
||||||
s_display = _display;
|
s_display = _display;
|
||||||
|
@ -74,11 +102,10 @@ namespace bgfx
|
||||||
|
|
||||||
BX_TRACE("glX num configs %d", numConfigs);
|
BX_TRACE("glX num configs %d", numConfigs);
|
||||||
|
|
||||||
XVisualInfo* visualInfo = NULL;
|
|
||||||
for (int ii = 0; ii < numConfigs; ++ii)
|
for (int ii = 0; ii < numConfigs; ++ii)
|
||||||
{
|
{
|
||||||
visualInfo = glXGetVisualFromFBConfig(s_display, configs[ii]);
|
m_visualInfo = glXGetVisualFromFBConfig(s_display, configs[ii]);
|
||||||
if (NULL != visualInfo)
|
if (NULL != m_visualInfo)
|
||||||
{
|
{
|
||||||
BX_TRACE("---");
|
BX_TRACE("---");
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
|
@ -113,19 +140,17 @@ namespace bgfx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XFree(visualInfo);
|
XFree(m_visualInfo);
|
||||||
visualInfo = NULL;
|
m_visualInfo = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
XFree(configs);
|
XFree(configs);
|
||||||
BGFX_FATAL(visualInfo, Fatal::UnableToInitialize, "Failed to find a suitable X11 display configuration.");
|
BGFX_FATAL(m_visualInfo, Fatal::UnableToInitialize, "Failed to find a suitable X11 display configuration.");
|
||||||
|
|
||||||
BX_TRACE("Create GL 2.1 context.");
|
BX_TRACE("Create GL 2.1 context.");
|
||||||
m_context = glXCreateContext(s_display, visualInfo, 0, GL_TRUE);
|
m_context = glXCreateContext(s_display, m_visualInfo, 0, GL_TRUE);
|
||||||
BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create GL 2.1 context.");
|
BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create GL 2.1 context.");
|
||||||
|
|
||||||
XFree(visualInfo);
|
|
||||||
|
|
||||||
#if BGFX_CONFIG_RENDERER_OPENGL >= 31
|
#if BGFX_CONFIG_RENDERER_OPENGL >= 31
|
||||||
glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB");
|
glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB");
|
||||||
|
|
||||||
|
@ -192,6 +217,7 @@ namespace bgfx
|
||||||
{
|
{
|
||||||
glXMakeCurrent(s_display, 0, 0);
|
glXMakeCurrent(s_display, 0, 0);
|
||||||
glXDestroyContext(s_display, m_context);
|
glXDestroyContext(s_display, m_context);
|
||||||
|
XFree(m_visualInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, bool _vsync)
|
void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, bool _vsync)
|
||||||
|
@ -214,28 +240,43 @@ namespace bgfx
|
||||||
|
|
||||||
bool GlContext::isSwapChainSupported()
|
bool GlContext::isSwapChainSupported()
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwapChainGL* GlContext::createSwapChain(void* /*_nwh*/)
|
SwapChainGL* GlContext::createSwapChain(void* _nwh)
|
||||||
{
|
{
|
||||||
BX_CHECK(false, "Shouldn't be called!");
|
return BX_NEW(g_allocator, SwapChainGL)( (::Window)_nwh, m_visualInfo, m_context);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlContext::destorySwapChain(SwapChainGL* /*_swapChain*/)
|
void GlContext::destorySwapChain(SwapChainGL* _swapChain)
|
||||||
{
|
{
|
||||||
BX_CHECK(false, "Shouldn't be called!");
|
BX_DELETE(g_allocator, _swapChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlContext::swap(SwapChainGL* _swapChain)
|
void GlContext::swap(SwapChainGL* _swapChain)
|
||||||
{
|
{
|
||||||
BX_CHECK(NULL == _swapChain, "Shouldn't be called!"); BX_UNUSED(_swapChain);
|
if (NULL == _swapChain)
|
||||||
|
{
|
||||||
|
glXMakeCurrent(s_display, s_window, m_context);
|
||||||
glXSwapBuffers(s_display, s_window);
|
glXSwapBuffers(s_display, s_window);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
void GlContext::makeCurrent(SwapChainGL* /*_swapChain*/)
|
|
||||||
{
|
{
|
||||||
|
_swapChain->makeCurrent();
|
||||||
|
_swapChain->swapBuffers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlContext::makeCurrent(SwapChainGL* _swapChain)
|
||||||
|
{
|
||||||
|
if (NULL == _swapChain)
|
||||||
|
{
|
||||||
|
glXMakeCurrent(s_display, s_window, m_context);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_swapChain->makeCurrent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlContext::import()
|
void GlContext::import()
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace bgfx
|
||||||
{
|
{
|
||||||
GlContext()
|
GlContext()
|
||||||
: m_context(0)
|
: m_context(0)
|
||||||
|
, m_visualInfo(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ namespace bgfx
|
||||||
}
|
}
|
||||||
|
|
||||||
GLXContext m_context;
|
GLXContext m_context;
|
||||||
|
XVisualInfo* m_visualInfo;
|
||||||
};
|
};
|
||||||
} // namespace bgfx
|
} // namespace bgfx
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue