mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-29 02:55:36 -05:00
Add GLSurfaceView / external EGLContext support on Android by skipping the creation of BGFX's eglContext if g_bgfxAndroidWindow is set to NULL
This commit is contained in:
parent
62d2d744f9
commit
9e7e143f21
1 changed files with 34 additions and 13 deletions
|
@ -178,6 +178,15 @@ EGL_IMPORT
|
||||||
|
|
||||||
m_eglLibrary = eglOpen();
|
m_eglLibrary = eglOpen();
|
||||||
|
|
||||||
|
|
||||||
|
# if BX_PLATFORM_ANDROID
|
||||||
|
if (!g_bgfxAndroidWindow)
|
||||||
|
{
|
||||||
|
BX_TRACE("androidSetWindow() was not called, assuming EGLContext and buffer-swapping are managed outside bgfx.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
# endif
|
||||||
BX_UNUSED(_width, _height);
|
BX_UNUSED(_width, _height);
|
||||||
EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY;
|
EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY;
|
||||||
EGLNativeWindowType nwh = (EGLNativeWindowType)NULL;
|
EGLNativeWindowType nwh = (EGLNativeWindowType)NULL;
|
||||||
|
@ -257,7 +266,9 @@ EGL_IMPORT
|
||||||
m_current = NULL;
|
m_current = NULL;
|
||||||
|
|
||||||
eglSwapInterval(m_display, 0);
|
eglSwapInterval(m_display, 0);
|
||||||
|
# if BX_PLATFORM_ANDROID
|
||||||
|
}
|
||||||
|
# endif
|
||||||
# if BX_PLATFORM_EMSCRIPTEN
|
# if BX_PLATFORM_EMSCRIPTEN
|
||||||
emscripten_set_canvas_size(_width, _height);
|
emscripten_set_canvas_size(_width, _height);
|
||||||
# endif // BX_PLATFORM_EMSCRIPTEN
|
# endif // BX_PLATFORM_EMSCRIPTEN
|
||||||
|
@ -266,12 +277,15 @@ EGL_IMPORT
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlContext::destroy()
|
void GlContext::destroy()
|
||||||
|
{
|
||||||
|
if (m_display)
|
||||||
{
|
{
|
||||||
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
eglDestroyContext(m_display, m_context);
|
eglDestroyContext(m_display, m_context);
|
||||||
eglDestroySurface(m_display, m_surface);
|
eglDestroySurface(m_display, m_surface);
|
||||||
eglTerminate(m_display);
|
eglTerminate(m_display);
|
||||||
m_context = NULL;
|
m_context = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
eglClose(m_eglLibrary);
|
eglClose(m_eglLibrary);
|
||||||
|
|
||||||
|
@ -283,13 +297,18 @@ EGL_IMPORT
|
||||||
void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags)
|
void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags)
|
||||||
{
|
{
|
||||||
BX_UNUSED(_width, _height);
|
BX_UNUSED(_width, _height);
|
||||||
|
|
||||||
# if BX_PLATFORM_ANDROID
|
# if BX_PLATFORM_ANDROID
|
||||||
|
if (m_display)
|
||||||
|
{
|
||||||
EGLint format;
|
EGLint format;
|
||||||
eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
|
eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
|
||||||
ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format);
|
ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format);
|
||||||
|
}
|
||||||
# endif // BX_PLATFORM_ANDROID
|
# endif // BX_PLATFORM_ANDROID
|
||||||
|
|
||||||
bool vsync = !!(_flags&BGFX_RESET_VSYNC);
|
bool vsync = !!(_flags&BGFX_RESET_VSYNC);
|
||||||
|
if (m_display)
|
||||||
eglSwapInterval(m_display, vsync ? 1 : 0);
|
eglSwapInterval(m_display, vsync ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,6 +336,7 @@ EGL_IMPORT
|
||||||
|
|
||||||
if (NULL == _swapChain)
|
if (NULL == _swapChain)
|
||||||
{
|
{
|
||||||
|
if (m_display)
|
||||||
eglSwapBuffers(m_display, m_surface);
|
eglSwapBuffers(m_display, m_surface);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -333,6 +353,7 @@ EGL_IMPORT
|
||||||
|
|
||||||
if (NULL == _swapChain)
|
if (NULL == _swapChain)
|
||||||
{
|
{
|
||||||
|
if (m_display)
|
||||||
eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
eglMakeCurrent(m_display, m_surface, m_surface, m_context);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue