mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
GL: Cache current GL context. Issue #262.
This commit is contained in:
parent
a57634cd09
commit
7279a31768
6 changed files with 60 additions and 36 deletions
|
@ -254,6 +254,7 @@ EGL_IMPORT
|
|||
|
||||
success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
||||
BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");
|
||||
m_current = NULL;
|
||||
|
||||
eglSwapInterval(m_display, 0);
|
||||
|
||||
|
@ -311,27 +312,32 @@ EGL_IMPORT
|
|||
|
||||
void GlContext::swap(SwapChainGL* _swapChain)
|
||||
{
|
||||
makeCurrent(_swapChain);
|
||||
|
||||
if (NULL == _swapChain)
|
||||
{
|
||||
eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
||||
eglSwapBuffers(m_display, m_surface);
|
||||
}
|
||||
else
|
||||
{
|
||||
_swapChain->makeCurrent();
|
||||
_swapChain->swapBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
void GlContext::makeCurrent(SwapChainGL* _swapChain)
|
||||
{
|
||||
if (NULL == _swapChain)
|
||||
if (m_current != _swapChain)
|
||||
{
|
||||
eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
||||
}
|
||||
else
|
||||
{
|
||||
_swapChain->makeCurrent();
|
||||
m_current = _swapChain;
|
||||
|
||||
if (NULL == _swapChain)
|
||||
{
|
||||
eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
||||
}
|
||||
else
|
||||
{
|
||||
_swapChain->makeCurrent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@ namespace bgfx
|
|||
struct GlContext
|
||||
{
|
||||
GlContext()
|
||||
: m_context(NULL)
|
||||
: m_current(NULL)
|
||||
, m_context(NULL)
|
||||
, m_display(NULL)
|
||||
, m_surface(NULL)
|
||||
{
|
||||
|
@ -41,6 +42,7 @@ namespace bgfx
|
|||
}
|
||||
|
||||
void* m_eglLibrary;
|
||||
SwapChainGL* m_current;
|
||||
EGLConfig m_config;
|
||||
EGLContext m_context;
|
||||
EGLDisplay m_display;
|
||||
|
|
|
@ -175,6 +175,7 @@ namespace bgfx
|
|||
import();
|
||||
|
||||
glXMakeCurrent( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window, m_context);
|
||||
m_current = NULL;
|
||||
|
||||
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT");
|
||||
if (NULL != glXSwapIntervalEXT)
|
||||
|
@ -248,27 +249,32 @@ namespace bgfx
|
|||
|
||||
void GlContext::swap(SwapChainGL* _swapChain)
|
||||
{
|
||||
makeCurrent(_swapChain);
|
||||
|
||||
if (NULL == _swapChain)
|
||||
{
|
||||
glXMakeCurrent( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window, m_context);
|
||||
glXSwapBuffers( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window);
|
||||
}
|
||||
else
|
||||
{
|
||||
_swapChain->makeCurrent();
|
||||
_swapChain->swapBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
void GlContext::makeCurrent(SwapChainGL* _swapChain)
|
||||
{
|
||||
if (NULL == _swapChain)
|
||||
if (m_current != _swapChain)
|
||||
{
|
||||
glXMakeCurrent( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window, m_context);
|
||||
}
|
||||
else
|
||||
{
|
||||
_swapChain->makeCurrent();
|
||||
m_current = _swapChain;
|
||||
|
||||
if (NULL == _swapChain)
|
||||
{
|
||||
glXMakeCurrent( (::Display*)g_bgfxX11Display, (::Window)g_bgfxX11Window, m_context);
|
||||
}
|
||||
else
|
||||
{
|
||||
_swapChain->makeCurrent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ namespace bgfx
|
|||
struct GlContext
|
||||
{
|
||||
GlContext()
|
||||
: m_context(0)
|
||||
: m_current(NULL)
|
||||
, m_context(0)
|
||||
, m_visualInfo(NULL)
|
||||
{
|
||||
}
|
||||
|
@ -40,6 +41,7 @@ namespace bgfx
|
|||
return 0 != m_context;
|
||||
}
|
||||
|
||||
SwapChainGL* m_current;
|
||||
GLXContext m_context;
|
||||
XVisualInfo* m_visualInfo;
|
||||
};
|
||||
|
|
|
@ -184,7 +184,7 @@ namespace bgfx
|
|||
|
||||
int result;
|
||||
uint32_t numFormats = 0;
|
||||
do
|
||||
do
|
||||
{
|
||||
result = wglChoosePixelFormatARB(m_hdc, attrs, NULL, 1, &m_pixelFormat, &numFormats);
|
||||
if (0 == result
|
||||
|
@ -259,6 +259,7 @@ namespace bgfx
|
|||
|
||||
int result = wglMakeCurrent(m_hdc, m_context);
|
||||
BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!");
|
||||
m_current = NULL;
|
||||
|
||||
if (NULL != wglSwapIntervalEXT)
|
||||
{
|
||||
|
@ -316,37 +317,42 @@ namespace bgfx
|
|||
BX_DELETE(g_allocator, _swapChain);
|
||||
}
|
||||
|
||||
void GlContext::makeCurrent(SwapChainGL* _swapChain)
|
||||
{
|
||||
if (NULL == _swapChain)
|
||||
{
|
||||
wglMakeCurrent(m_hdc, m_context);
|
||||
GLenum err = glGetError();
|
||||
BX_WARN(0 == err, "wglMakeCurrent failed with GL error: 0x%04x.", err); BX_UNUSED(err);
|
||||
}
|
||||
else
|
||||
{
|
||||
_swapChain->makeCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
void GlContext::swap(SwapChainGL* _swapChain)
|
||||
{
|
||||
makeCurrent(_swapChain);
|
||||
|
||||
if (NULL == _swapChain)
|
||||
{
|
||||
if (NULL != g_bgfxHwnd)
|
||||
{
|
||||
wglMakeCurrent(m_hdc, m_context);
|
||||
SwapBuffers(m_hdc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_swapChain->makeCurrent();
|
||||
_swapChain->swapBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
void GlContext::makeCurrent(SwapChainGL* _swapChain)
|
||||
{
|
||||
if (m_current != _swapChain)
|
||||
{
|
||||
m_current = _swapChain;
|
||||
|
||||
if (NULL == _swapChain)
|
||||
{
|
||||
wglMakeCurrent(m_hdc, m_context);
|
||||
GLenum err = glGetError();
|
||||
BX_WARN(0 == err, "wglMakeCurrent failed with GL error: 0x%04x.", err); BX_UNUSED(err);
|
||||
}
|
||||
else
|
||||
{
|
||||
_swapChain->makeCurrent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GlContext::import()
|
||||
{
|
||||
BX_TRACE("Import:");
|
||||
|
|
|
@ -61,7 +61,8 @@ typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum z
|
|||
struct GlContext
|
||||
{
|
||||
GlContext()
|
||||
: m_opengl32dll(NULL)
|
||||
: m_current(NULL)
|
||||
, m_opengl32dll(NULL)
|
||||
, m_context(NULL)
|
||||
, m_hdc(NULL)
|
||||
{
|
||||
|
@ -87,6 +88,7 @@ typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum z
|
|||
int32_t m_contextAttrs[9];
|
||||
int m_pixelFormat;
|
||||
PIXELFORMATDESCRIPTOR m_pfd;
|
||||
SwapChainGL* m_current;
|
||||
void* m_opengl32dll;
|
||||
HGLRC m_context;
|
||||
HDC m_hdc;
|
||||
|
|
Loading…
Reference in a new issue