From 3b7a595138c8cb4291c85b5770e625c1c62bc365 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 9 May 2020 16:02:47 -0700 Subject: Enabled swap interval control on Android/GLES --- Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp | 3 +++ Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp index d50c7e51..ed4e94b2 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp @@ -69,6 +69,9 @@ private: int32_t screen_width_ = 0; int32_t screen_height_ = 0; + EGLint min_swap_interval_ = 0; + EGLint max_swap_interval_ = 1; + //Flags bool gles_initialized_ = false; bool egl_context_initialized_ = false; diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp index 233cc487..3a7e9003 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp @@ -127,6 +127,9 @@ bool GLContext::InitEGLSurface() eglGetConfigAttrib(display_, config_, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(window_, 0, 0, format); + eglGetConfigAttrib(display_, config_, EGL_MIN_SWAP_INTERVAL, &min_swap_interval_); + eglGetConfigAttrib(display_, config_, EGL_MAX_SWAP_INTERVAL, &max_swap_interval_); + return true; } @@ -248,7 +251,7 @@ GLContext::~GLContext() Terminate(); } -void GLContext::SwapBuffers(int /*SwapInterval*/) +void GLContext::SwapBuffers(int SwapInterval) { if (surface_ == EGL_NO_SURFACE) { @@ -256,6 +259,10 @@ void GLContext::SwapBuffers(int /*SwapInterval*/) return; } + SwapInterval = std::max(SwapInterval, min_swap_interval_); + SwapInterval = std::min(SwapInterval, max_swap_interval_); + eglSwapInterval(display_, SwapInterval); + bool b = eglSwapBuffers(display_, surface_); if (!b) { -- cgit v1.2.3