Play-/Source/androidui/GSH_OpenGLAndroid.cpp

63 lines
1.5 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
{
static const EGLint attribs[] =
{
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,
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
EGLConfig config = 0;
EGLint numConfigs = 0;
eglChooseConfig(m_display, attribs, &config, 1, &numConfigs);
2015-03-09 23:35:45 -04:00
m_surface = eglCreateWindowSurface(m_display, config, m_window, NULL);
assert(m_surface != EGL_NO_SURFACE);
2015-03-09 23:35:45 -04:00
auto context = eglCreateContext(m_display, config, NULL, NULL);
2015-03-09 23:35:45 -04:00
assert(context != EGL_NO_CONTEXT);
auto makeCurrentResult = eglMakeCurrent(m_display, m_surface, m_surface, context);
2015-03-09 23:35:45 -04:00
assert(makeCurrentResult != EGL_FALSE);
GLint w = 0, h = 0;
eglQuerySurface(m_display, m_surface, EGL_WIDTH, &w);
eglQuerySurface(m_display, m_surface, EGL_HEIGHT, &h);
2015-03-09 23:35:45 -04:00
CLog::GetInstance().Print("gles", "w: %d, h: %d\r\n", w, h);
CGSH_OpenGL::InitializeImpl();
2015-03-09 23:35:45 -04:00
}
void CGSH_OpenGLAndroid::PresentBackbuffer()
{
eglSwapBuffers(m_display, m_surface);
2015-03-09 23:35:45 -04:00
}