Play-/Source/ui_android/GSH_OpenGLAndroid.cpp

96 lines
2.3 KiB
C++
Raw Permalink Normal View History

2015-03-09 23:35:45 -04:00
#include <cassert>
#include "opengl/OpenGlDef.h"
#include "GSH_OpenGLAndroid.h"
#include "AppConfig.h"
2015-03-09 23:35:45 -04:00
CGSH_OpenGLAndroid::CGSH_OpenGLAndroid(NativeWindowType window)
2018-04-30 21:01:23 +01:00
: m_window(window)
{
//We'll probably need to keep 'window' as a Global JNI object
}
CGSH_OpenGLAndroid::~CGSH_OpenGLAndroid()
{
}
CGSHandler::FactoryFunction CGSH_OpenGLAndroid::GetFactoryFunction(NativeWindowType window)
{
return [window]() { return new CGSH_OpenGLAndroid(window); };
}
void CGSH_OpenGLAndroid::InitializeImpl()
2015-03-09 23:35:45 -04:00
{
2018-04-30 21:01:23 +01:00
static const EGLint configAttribs[] =
{
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_NONE};
2015-04-11 01:37:46 -04:00
static const EGLint contextAttribs[] =
2018-04-30 21:01:23 +01:00
{
EGL_CONTEXT_CLIENT_VERSION, 3,
EGL_NONE};
m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(m_display, 0, 0);
2018-04-30 21:01:23 +01:00
2015-03-09 23:35:45 -04:00
EGLint numConfigs = 0;
2015-04-11 01:37:46 -04:00
eglChooseConfig(m_display, configAttribs, &m_config, 1, &numConfigs);
assert(numConfigs > 0);
2018-04-30 21:01:23 +01:00
2015-04-11 01:37:46 -04:00
m_context = eglCreateContext(m_display, m_config, NULL, contextAttribs);
assert(m_context != EGL_NO_CONTEXT);
SetupContext();
2018-04-30 21:01:23 +01:00
CGSH_OpenGL::InitializeImpl();
}
void CGSH_OpenGLAndroid::PresentBackbuffer()
{
eglSwapBuffers(m_display, m_surface);
}
void CGSH_OpenGLAndroid::SetWindow(NativeWindowType window)
{
m_window = window;
SendGSCall(
2018-04-30 21:01:23 +01:00
[this]() {
SetupContext();
},
true);
}
void CGSH_OpenGLAndroid::SetupContext()
{
if(m_surface != EGL_NO_SURFACE)
{
eglDestroySurface(m_display, m_surface);
m_surface = EGL_NO_SURFACE;
}
2018-04-30 21:01:23 +01:00
m_surface = eglCreateWindowSurface(m_display, m_config, m_window, NULL);
assert(m_surface != EGL_NO_SURFACE);
2018-04-30 21:01:23 +01:00
auto makeCurrentResult = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
2015-03-09 23:35:45 -04:00
assert(makeCurrentResult != EGL_FALSE);
2018-04-30 21:01:23 +01:00
2015-03-14 01:36:48 -04:00
{
GLint w = 0, h = 0;
eglQuerySurface(m_display, m_surface, EGL_WIDTH, &w);
eglQuerySurface(m_display, m_surface, EGL_HEIGHT, &h);
2018-04-30 21:01:23 +01:00
2015-03-14 01:36:48 -04:00
PRESENTATION_PARAMS presentationParams;
presentationParams.mode = static_cast<CGSHandler::PRESENTATION_MODE>(CAppConfig::GetInstance().GetPreferenceInteger(PREF_CGSHANDLER_PRESENTATION_MODE));
2018-04-30 21:01:23 +01:00
presentationParams.windowWidth = w;
presentationParams.windowHeight = h;
2015-03-14 01:36:48 -04:00
SetPresentationParams(presentationParams);
}
2023-07-28 13:36:20 -04:00
eglSwapInterval(m_display, 0);
2015-03-09 23:35:45 -04:00
}