139 lines
4.4 KiB
C
139 lines
4.4 KiB
C
#include "egl_context.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
void printEGLError(){
|
|
EGLint errorCode = eglGetError();
|
|
switch (errorCode){
|
|
case EGL_SUCCESS:
|
|
printf("EGL_SUCCESS : The last function succeeded without error.\n");
|
|
break;
|
|
case EGL_NOT_INITIALIZED:
|
|
printf("EGL_NOT_INITIALIZED : EGL is not initialized, or could not be initialized, for the specified EGL display connection.\n");
|
|
break;
|
|
case EGL_BAD_ACCESS:
|
|
printf("EGL_BAD_ACCESS : EGL cannot access a requested resource (for example a context is bound in another thread).\n");
|
|
break;
|
|
case EGL_BAD_ALLOC:
|
|
printf("EGL_BAD_ALLOC : EGL failed to allocate resources for the requested operation.\n");
|
|
break;
|
|
case EGL_BAD_ATTRIBUTE:
|
|
printf("EGL_BAD_ATTRIBUTE : An unrecognized attribute or attribute value was passed in the attribute list.\n");
|
|
break;
|
|
case EGL_BAD_CONTEXT:
|
|
printf("EGL_BAD_CONTEXT : An EGLContext argument does not name a valid EGL rendering context.\n");
|
|
break;
|
|
case EGL_BAD_CONFIG:
|
|
printf("EGL_BAD_CONFIG : An EGLConfig argument does not name a valid EGL frame buffer configuration.\n");
|
|
break;
|
|
case EGL_BAD_CURRENT_SURFACE:
|
|
printf("EGL_BAD_CURRENT_SURFACE : The current surface of the calling thread is a window, pixel buffer or pixmap that is no longer valid.\n");
|
|
break;
|
|
case EGL_BAD_DISPLAY:
|
|
printf("EGL_BAD_DISPLAY : An EGLDisplay argument does not name a valid EGL display connection.\n");
|
|
break;
|
|
case EGL_BAD_SURFACE:
|
|
printf("EGL_BAD_SURFACE : An EGLSurface argument does not name a valid surface (window, pixel buffer or pixmap) configured for GL rendering.\n");
|
|
break;
|
|
case EGL_BAD_MATCH:
|
|
printf("EGL_BAD_MATCH : Arguments are inconsistent (for example, a valid context requires buffers not supplied by a valid surface).\n");
|
|
break;
|
|
case EGL_BAD_PARAMETER:
|
|
printf("EGL_BAD_PARAMETER : One or more argument values are invalid.\n");
|
|
break;
|
|
case EGL_BAD_NATIVE_PIXMAP:
|
|
printf("EGL_BAD_NATIVE_PIXMAP : A NativePixmapType argument does not refer to a valid native pixmap.\n");
|
|
break;
|
|
case EGL_BAD_NATIVE_WINDOW:
|
|
printf("EGL_BAD_NATIVE_WINDOW : A NativeWindowType argument does not refer to a valid native window.\n");
|
|
break;
|
|
case EGL_CONTEXT_LOST:
|
|
printf("EGL_CONTEXT_LOST : A power management event has occurred. The application must destroy all contexts and reinitialise OpenGL ES state and objects to continue rendering.\n");
|
|
break;
|
|
default:
|
|
printf("UNKNOWN : wtf dude\n");
|
|
}
|
|
}
|
|
|
|
egl_context *egl_context_malloc() {
|
|
return malloc( sizeof( egl_context));
|
|
}
|
|
|
|
/*
|
|
wl_display, wl_surface, w, h
|
|
egl_window CREATE
|
|
egl_display CREATE
|
|
egl_config FIND
|
|
|
|
egl_surface CREATE
|
|
|
|
egl_context CREATE
|
|
*/
|
|
egl_context *egl_context_new( struct wl_display *display) {
|
|
EGLint major;
|
|
EGLint minor;
|
|
EGLint num_configs;
|
|
|
|
EGLint lastEGLOp;
|
|
/*
|
|
replaced EGL_OPENGL_BIT with EGL_OPENGL_ES2_BIT
|
|
*/
|
|
EGLint attribs[] = {
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
EGL_NONE
|
|
};
|
|
|
|
egl_context *e = egl_context_malloc();
|
|
|
|
e->display = eglGetDisplay((EGLNativeDisplayType) display);
|
|
|
|
if(EGL_NO_DISPLAY == e->display) {
|
|
fprintf(stderr, "Couldn't get EGL display\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
if( EGL_TRUE != eglInitialize(e->display, &major, &minor)) {
|
|
fprintf(stderr, "Couldnt initialize EGL\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
|
|
/* null buffer for querying the count*/
|
|
lastEGLOp = eglChooseConfig( e->display, attribs, NULL, 1, &num_configs);
|
|
if( EGL_TRUE != lastEGLOp) {
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
fprintf(stderr, "found %d matching EGL configurations\n", num_configs);
|
|
|
|
EGLConfig *all_the_configs = malloc( num_configs * sizeof( EGLConfig));
|
|
|
|
/* was &e->config but broken */
|
|
lastEGLOp = eglChooseConfig( e->display, attribs, all_the_configs, num_configs, &num_configs);
|
|
if( EGL_TRUE != lastEGLOp) {
|
|
fprintf(stderr, "CouldnÄt find matching EGL config\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
e->config = all_the_configs[0];
|
|
|
|
/* added from
|
|
https://stackoverflow.com/questions/25843368/glgetstringgl-version-returns-opengl-es-cm-1-1-but-my-phone-supports-opengl
|
|
*/
|
|
const EGLint context_attrib_list[] = {
|
|
// request a context using Open GL ES 2.0
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
EGL_NONE
|
|
};
|
|
|
|
/*thanks to the dudes of stackoverflow for explaining how the attrib_list works*/
|
|
e->context = eglCreateContext(e->display, e->config, EGL_NO_CONTEXT, context_attrib_list);
|
|
if( EGL_NO_CONTEXT == e->context) {
|
|
fprintf(stderr, "Couldn't create EGL context\n");
|
|
printEGLError();
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
return e;
|
|
}
|