70 lines
1.4 KiB
C++
70 lines
1.4 KiB
C++
#include <EGL/egl.h>
|
|
#include <stdbool.h>
|
|
|
|
static inline bool create_context(EGLNativeDisplayType nativeDisplay, EGLNativeWindowType nativeWindow, const EGLint * config_attribs, const EGLint * context_attribs, const EGLint * surface_attribs, EGLDisplay * outDisplay, EGLContext * outContext, EGLSurface * outSurface)
|
|
{
|
|
//
|
|
// get an EGL display connection
|
|
EGLDisplay display = eglGetDisplay(nativeDisplay);
|
|
|
|
if (EGL_NO_DISPLAY == display)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//
|
|
// initialize the EGL display connection
|
|
EGLint major, minor;
|
|
|
|
if (!eglInitialize(display, &major, &minor))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//
|
|
// bind OpenGL API
|
|
eglBindAPI(EGL_OPENGL_API);
|
|
|
|
//
|
|
// get an appropriate EGL frame buffer configuration
|
|
EGLint num_config;
|
|
EGLConfig configs[128];
|
|
|
|
if (!eglChooseConfig(display, config_attribs, configs, 128, &num_config))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
EGLConfig config = configs[0]; // FIXME
|
|
|
|
//
|
|
// create context
|
|
EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribs);
|
|
|
|
if (EGL_NO_CONTEXT == context)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//
|
|
// Create Surface
|
|
EGLSurface surface = eglCreateWindowSurface(display, config, nativeWindow, surface_attribs);
|
|
if (EGL_NO_SURFACE == surface)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//
|
|
// Set current context
|
|
if (!eglMakeCurrent(display, surface, surface, context))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
*outDisplay = display;
|
|
*outContext = context;
|
|
*outSurface = surface;
|
|
|
|
return true;
|
|
}
|