introduce struct
This commit is contained in:
1 parent
6c142f794c
commit
b9b7e91bcd
2 files changed
+38
-40
No files matched your search
@@ -11,18 +11,23 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static RaybriEGLState globalES = {
|
||||||
|
.caLayer = NULL,
|
||||||
|
.cfg = NULL,
|
||||||
|
.ctx = EGL_NO_CONTEXT,
|
||||||
|
.display = EGL_NO_DISPLAY,
|
||||||
|
.surface = EGL_NO_SURFACE
|
||||||
|
};
|
||||||
|
|
||||||
void raybriInit(void *layer) {
|
void raybriInit(void *layer) {
|
||||||
//SetTraceLogLevel(LOG_WARNING);
|
//SetTraceLogLevel(LOG_WARNING);
|
||||||
|
|
||||||
EGLConfig cfg = NULL;
|
globalES.caLayer = layer;
|
||||||
EGLContext ctx = EGL_NO_CONTEXT;
|
|
||||||
EGLDisplay display = EGL_NO_DISPLAY;
|
|
||||||
EGLSurface surface = EGL_NO_SURFACE;
|
|
||||||
|
|
||||||
if (!raybriEGLInit(&cfg, &ctx, &display)) {
|
if (!raybriEGLInit(&globalES)) {
|
||||||
raybriLog("ERROR Could not initialize EGL");
|
raybriLog("ERROR Could not initialize EGL");
|
||||||
}
|
}
|
||||||
if (!raybriEGLResetSurface(layer, &cfg, &display, &surface)) {
|
if (!raybriEGLResetSurface(&globalES)) {
|
||||||
raybriLog("ERROR Could not reset EGL surface");
|
raybriLog("ERROR Could not reset EGL surface");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,35 +6,28 @@
|
|||||||
#include "raybriEGLConst.h"
|
#include "raybriEGLConst.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
// Header
|
typedef struct RaybriEGLState {
|
||||||
|
void *caLayer;
|
||||||
|
EGLConfig cfg;
|
||||||
|
EGLContext ctx;
|
||||||
|
EGLDisplay display;
|
||||||
|
EGLSurface surface;
|
||||||
|
} RaybriEGLState;
|
||||||
|
|
||||||
bool raybriEGLInit(
|
bool raybriEGLInit(RaybriEGLState *st);
|
||||||
EGLConfig *cfg,
|
bool raybriEGLResetSurface(RaybriEGLState *st);
|
||||||
EGLContext *ctx,
|
|
||||||
EGLDisplay *display
|
|
||||||
);
|
|
||||||
bool raybriEGLResetSurface(
|
|
||||||
void *caLayer,
|
|
||||||
EGLConfig *cfg,
|
|
||||||
EGLDisplay *display,
|
|
||||||
EGLSurface *surface
|
|
||||||
);
|
|
||||||
|
|
||||||
// Source
|
// Source
|
||||||
|
|
||||||
#if defined(RAYBRI_EGL_IMPLEMENTATION)
|
#if defined(RAYBRI_EGL_IMPLEMENTATION)
|
||||||
|
|
||||||
bool raybriEGLInit(
|
bool raybriEGLInit(RaybriEGLState *st) {
|
||||||
EGLConfig *cfg,
|
st->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
EGLContext *ctx,
|
if (st->display == EGL_NO_DISPLAY) {
|
||||||
EGLDisplay *display
|
|
||||||
){
|
|
||||||
*display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
||||||
if (*display == EGL_NO_DISPLAY) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eglInitialize(*display, NULL, NULL) == EGL_FALSE) {
|
if (eglInitialize(st->display, NULL, NULL) == EGL_FALSE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,36 +37,36 @@ bool raybriEGLInit(
|
|||||||
|
|
||||||
EGLint cfgCount = 0;
|
EGLint cfgCount = 0;
|
||||||
if (
|
if (
|
||||||
eglChooseConfig(*display, RAYBRI_EGL_CFG, cfg, 1, &cfgCount) == EGL_FALSE ||
|
eglChooseConfig(st->display, RAYBRI_EGL_CFG, &st->cfg, 1, &cfgCount) == EGL_FALSE ||
|
||||||
cfgCount < 1
|
cfgCount < 1
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ctx = eglCreateContext(*display, *cfg, EGL_NO_CONTEXT, RAYBRI_EGL_CTX);
|
st->ctx = eglCreateContext(st->display, st->cfg, EGL_NO_CONTEXT, RAYBRI_EGL_CTX);
|
||||||
if (*ctx == EGL_NO_CONTEXT) {
|
if (st->ctx == EGL_NO_CONTEXT) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool raybriEGLResetSurface(
|
bool raybriEGLResetSurface(RaybriEGLState *st) {
|
||||||
void *caLayer,
|
|
||||||
EGLConfig *cfg,
|
|
||||||
EGLDisplay *display,
|
|
||||||
EGLSurface *surface
|
|
||||||
) {
|
|
||||||
// Destroy previous surface
|
// Destroy previous surface
|
||||||
if (*surface != EGL_NO_SURFACE) {
|
if (st->surface != EGL_NO_SURFACE) {
|
||||||
eglDestroySurface(*display, *surface);
|
eglDestroySurface(st->display, st->surface);
|
||||||
*surface = EGL_NO_SURFACE;
|
st->surface = EGL_NO_SURFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new surface
|
// Create new surface
|
||||||
// ANGLE on iOS takes a CALayer as the native window
|
// ANGLE on iOS takes a CALayer as the native window
|
||||||
*surface = eglCreateWindowSurface(*display, *cfg, (EGLNativeWindowType)caLayer, NULL);
|
st->surface = eglCreateWindowSurface(
|
||||||
if (*surface == EGL_NO_SURFACE) {
|
st->display,
|
||||||
|
st->cfg,
|
||||||
|
(EGLNativeWindowType)st->caLayer,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if (st->surface == EGL_NO_SURFACE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user