86 lines
1.7 KiB
C
86 lines
1.7 KiB
C
#ifndef RAYBRI_EGL_H
|
|
#define RAYBRI_EGL_H
|
|
|
|
#include <libEGL/libEGL.h>
|
|
#include <libGLESv2/GLES/gl.h>
|
|
#include "raybriEGLConst.h"
|
|
#include <stdbool.h>
|
|
|
|
// Header
|
|
|
|
bool raybriEGLInit(
|
|
EGLConfig *cfg,
|
|
EGLContext *ctx,
|
|
EGLDisplay *display
|
|
);
|
|
bool raybriEGLResetSurface(
|
|
void *caLayer,
|
|
EGLConfig *cfg,
|
|
EGLDisplay *display,
|
|
EGLSurface *surface
|
|
);
|
|
|
|
// Source
|
|
|
|
#if defined(RAYBRI_EGL_IMPLEMENTATION)
|
|
|
|
bool raybriEGLInit(
|
|
EGLConfig *cfg,
|
|
EGLContext *ctx,
|
|
EGLDisplay *display
|
|
){
|
|
*display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
if (*display == EGL_NO_DISPLAY) {
|
|
return false;
|
|
}
|
|
|
|
if (eglInitialize(*display, NULL, NULL) == EGL_FALSE) {
|
|
return false;
|
|
}
|
|
|
|
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
|
|
return false;
|
|
}
|
|
|
|
EGLint cfgCount = 0;
|
|
if (
|
|
eglChooseConfig(*display, RAYBRI_EGL_CFG, cfg, 1, &cfgCount) == EGL_FALSE ||
|
|
cfgCount < 1
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
*ctx = eglCreateContext(*display, *cfg, EGL_NO_CONTEXT, RAYBRI_EGL_CTX);
|
|
if (*ctx == EGL_NO_CONTEXT) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool raybriEGLResetSurface(
|
|
void *caLayer,
|
|
EGLConfig *cfg,
|
|
EGLDisplay *display,
|
|
EGLSurface *surface
|
|
) {
|
|
// Destroy previous surface
|
|
if (*surface != EGL_NO_SURFACE) {
|
|
eglDestroySurface(*display, *surface);
|
|
*surface = EGL_NO_SURFACE;
|
|
}
|
|
|
|
// Create new surface
|
|
// ANGLE on iOS takes a CALayer as the native window
|
|
*surface = eglCreateWindowSurface(*display, *cfg, (EGLNativeWindowType)caLayer, NULL);
|
|
if (*surface == EGL_NO_SURFACE) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
#endif // RAYBRI_EGL_IMPLEMENTATION
|
|
|
|
#endif // RAYBRI_EGL_H
|