96 lines
2.1 KiB
C
96 lines
2.1 KiB
C
#ifndef GLBRI_H
|
|
#define GLBRI_H
|
|
|
|
#include "glbriConst.h"
|
|
#include <libEGL/libEGL.h>
|
|
#include <libGLESv2/GLES/gl.h>
|
|
#include <stdbool.h>
|
|
|
|
typedef struct GLBriState {
|
|
void *caLayer;
|
|
EGLConfig cfg;
|
|
EGLContext ctx;
|
|
EGLDisplay display;
|
|
EGLSurface surface;
|
|
} GLBriState;
|
|
|
|
bool glbriInit(GLBriState *st);
|
|
bool glbriMakeCurrentContext(GLBriState *st);
|
|
bool glbriResetSurface(GLBriState *st);
|
|
void glbriShutdown(GLBriState *st);
|
|
|
|
// Source
|
|
|
|
#if defined(GLBRI_IMPLEMENTATION)
|
|
|
|
bool glbriInit(GLBriState *st) {
|
|
st->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
if (st->display == EGL_NO_DISPLAY) {
|
|
return false;
|
|
}
|
|
|
|
if (eglInitialize(st->display, NULL, NULL) == EGL_FALSE) {
|
|
return false;
|
|
}
|
|
|
|
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
|
|
return false;
|
|
}
|
|
|
|
EGLint cfgCount = 0;
|
|
if (
|
|
eglChooseConfig(st->display, GLBRI_CFG, &st->cfg, 1, &cfgCount) == EGL_FALSE ||
|
|
cfgCount < 1
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
st->ctx = eglCreateContext(st->display, st->cfg, EGL_NO_CONTEXT, GLBRI_CTX);
|
|
if (st->ctx == EGL_NO_CONTEXT) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool glbriMakeCurrentContext(GLBriState *st) {
|
|
if (eglMakeCurrent(st->display, st->surface, st->surface, st->ctx) == EGL_FALSE) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool glbriResetSurface(GLBriState *st) {
|
|
// Destroy previous surface
|
|
if (st->surface != EGL_NO_SURFACE) {
|
|
eglDestroySurface(st->display, st->surface);
|
|
st->surface = EGL_NO_SURFACE;
|
|
}
|
|
|
|
// Create new surface
|
|
// ANGLE on iOS takes a CALayer as the native window
|
|
st->surface = eglCreateWindowSurface(
|
|
st->display,
|
|
st->cfg,
|
|
(EGLNativeWindowType)st->caLayer,
|
|
NULL
|
|
);
|
|
if (st->surface == EGL_NO_SURFACE) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void glbriShutdown(GLBriState *st) {
|
|
eglMakeCurrent(st->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
eglDestroySurface(st->display, st->surface);
|
|
eglDestroyContext(st->display, st->ctx);
|
|
eglTerminate(st->display);
|
|
}
|
|
|
|
#endif // GLBRI_IMPLEMENTATION
|
|
|
|
#endif // GLBRI_H
|