@@ -484,20 +484,13 @@ int64_t DisplayServerAndroid::window_get_native_handle(HandleType p_handle_type,
484484 }
485485#ifdef GLES3_ENABLED
486486 case DISPLAY_HANDLE: {
487- if (rendering_driver == " opengl3" ) {
488- return reinterpret_cast <int64_t >(eglGetCurrentDisplay ());
489- }
490- return 0 ;
487+ return reinterpret_cast <int64_t >(egl_display);
491488 }
492489 case OPENGL_CONTEXT: {
493- if (rendering_driver == " opengl3" ) {
494- return reinterpret_cast <int64_t >(eglGetCurrentContext ());
495- }
496- return 0 ;
490+ return reinterpret_cast <int64_t >(egl_context);
497491 }
498492 case EGL_DISPLAY: {
499- // @todo Find a way to get this from the Java side.
500- return 0 ;
493+ return reinterpret_cast <int64_t >(egl_display);
501494 }
502495 case EGL_CONFIG: {
503496 // @todo Find a way to get this from the Java side.
@@ -792,6 +785,13 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis
792785#if defined(GLES3_ENABLED)
793786 if (rendering_driver == " opengl3" ) {
794787 RasterizerGLES3::make_current (false );
788+ swap_own_buffers = OS::get_singleton ()->is_separate_thread_rendering_enabled ();
789+ // These will have been set via eglMakeCurrent() on the Java side. It would be nice to explicitly pass
790+ // them from Java, but there's no way to get the native handles with javax.microedition.khronos.egl;
791+ // we'd need to switch to android.opengl.
792+ egl_display = eglGetCurrentDisplay ();
793+ egl_surface = eglGetCurrentSurface (EGL_DRAW);
794+ egl_context = eglGetCurrentContext ();
795795 }
796796#endif
797797
@@ -963,6 +963,28 @@ bool DisplayServerAndroid::should_swap_buffers() const {
963963
964964void DisplayServerAndroid::swap_buffers () {
965965 swap_buffers_flag = true ;
966+
967+ #ifdef GLES3_ENABLED
968+ if (swap_own_buffers) {
969+ eglSwapBuffers (egl_display, egl_surface);
970+ }
971+ #endif
972+ }
973+
974+ void DisplayServerAndroid::gl_window_make_current (DisplayServer::WindowID p_window_id) {
975+ #ifdef GLES3_ENABLED
976+ if (swap_own_buffers && egl_display && p_window_id == DisplayServer::MAIN_WINDOW_ID) {
977+ eglMakeCurrent (egl_display, egl_surface, egl_surface, egl_context);
978+ }
979+ #endif
980+ }
981+
982+ void DisplayServerAndroid::release_rendering_thread () {
983+ #ifdef GLES3_ENABLED
984+ if (swap_own_buffers && egl_display) {
985+ eglMakeCurrent (egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
986+ }
987+ #endif
966988}
967989
968990void DisplayServerAndroid::set_native_icon (const String &p_filename) {
0 commit comments