Merge pull request #351 from ming4883/pull-request

Add GLSurfaceView / external EGLContext support on Android
This commit is contained in:
Branimir Karadžić 2015-04-18 00:34:36 -07:00
commit 8dc0603c80

View file

@ -178,6 +178,15 @@ EGL_IMPORT
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);
EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY;
EGLNativeWindowType nwh = (EGLNativeWindowType)NULL;
@ -257,7 +266,9 @@ EGL_IMPORT
m_current = NULL;
eglSwapInterval(m_display, 0);
# if BX_PLATFORM_ANDROID
}
# endif
# if BX_PLATFORM_EMSCRIPTEN
emscripten_set_canvas_size(_width, _height);
# endif // BX_PLATFORM_EMSCRIPTEN
@ -267,12 +278,15 @@ EGL_IMPORT
void GlContext::destroy()
{
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(m_display, m_context);
eglDestroySurface(m_display, m_surface);
eglTerminate(m_display);
m_context = NULL;
if (m_display)
{
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(m_display, m_context);
eglDestroySurface(m_display, m_surface);
eglTerminate(m_display);
m_context = NULL;
}
eglClose(m_eglLibrary);
# if BX_PLATFORM_RPI
@ -283,14 +297,19 @@ EGL_IMPORT
void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags)
{
BX_UNUSED(_width, _height);
# if BX_PLATFORM_ANDROID
EGLint format;
eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format);
if (m_display)
{
EGLint format;
eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format);
}
# endif // BX_PLATFORM_ANDROID
bool vsync = !!(_flags&BGFX_RESET_VSYNC);
eglSwapInterval(m_display, vsync ? 1 : 0);
if (m_display)
eglSwapInterval(m_display, vsync ? 1 : 0);
}
bool GlContext::isSwapChainSupported()
@ -317,7 +336,8 @@ EGL_IMPORT
if (NULL == _swapChain)
{
eglSwapBuffers(m_display, m_surface);
if (m_display)
eglSwapBuffers(m_display, m_surface);
}
else
{
@ -333,7 +353,8 @@ EGL_IMPORT
if (NULL == _swapChain)
{
eglMakeCurrent(m_display, m_surface, m_surface, m_context);
if (m_display)
eglMakeCurrent(m_display, m_surface, m_surface, m_context);
}
else
{