Play-/Source/ui_android/GSH_OpenGLAndroid.cpp

99 lines
2.1 KiB
C++
Raw Normal View History

2015-03-09 23:35:45 -04:00
#include <cassert>
#include "opengl/OpenGlDef.h"
#include "GSH_OpenGLAndroid.h"
#include "../Log.h"
CGSH_OpenGLAndroid::CGSH_OpenGLAndroid(NativeWindowType window)
: 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
{
2015-04-11 01:37:46 -04:00
static const EGLint configAttribs[] =
2015-03-09 23:35:45 -04:00
{
2015-04-11 01:37:46 -04:00
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
};
static const EGLint contextAttribs[] =
{
EGL_CONTEXT_CLIENT_VERSION, 3,
2015-03-09 23:35:45 -04:00
EGL_NONE
};
2015-03-09 23:35:45 -04:00
m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(m_display, 0, 0);
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);
2015-03-09 23:35:45 -04: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();
2015-03-09 23:35:45 -04:00
CGSH_OpenGL::InitializeImpl();
}
void CGSH_OpenGLAndroid::PresentBackbuffer()
{
eglSwapBuffers(m_display, m_surface);
}
void CGSH_OpenGLAndroid::SetWindow(NativeWindowType window)
{
m_window = window;
m_mailBox.SendCall(
[this] ()
{
SetupContext();
},
true
);
}
void CGSH_OpenGLAndroid::SetupContext()
{
if(m_surface != EGL_NO_SURFACE)
{
eglDestroySurface(m_display, m_surface);
m_surface = EGL_NO_SURFACE;
}
2015-03-09 23:35:45 -04:00
m_surface = eglCreateWindowSurface(m_display, m_config, m_window, NULL);
assert(m_surface != EGL_NO_SURFACE);
auto makeCurrentResult = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
2015-03-09 23:35:45 -04:00
assert(makeCurrentResult != EGL_FALSE);
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);
PRESENTATION_PARAMS presentationParams;
presentationParams.mode = PRESENTATION_MODE_FIT;
presentationParams.windowWidth = w;
presentationParams.windowHeight = h;
SetPresentationParams(presentationParams);
}
2015-03-09 23:35:45 -04:00
}