Android support, attempt-1 #8

Open
kornerr wants to merge 62 commits from and1 into master
pull from: and1
2 changed files with 38 additions and 40 deletions
Showing only changes of commit b9b7e91bcd - Show all commits

No files matched your search

+11 -6
View File
@@ -11,18 +11,23 @@
#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) {
//SetTraceLogLevel(LOG_WARNING);
EGLConfig cfg = NULL;
EGLContext ctx = EGL_NO_CONTEXT;
EGLDisplay display = EGL_NO_DISPLAY;
EGLSurface surface = EGL_NO_SURFACE;
globalES.caLayer = layer;
if (!raybriEGLInit(&cfg, &ctx, &display)) {
if (!raybriEGLInit(&globalES)) {
raybriLog("ERROR Could not initialize EGL");
}
if (!raybriEGLResetSurface(layer, &cfg, &display, &surface)) {
if (!raybriEGLResetSurface(&globalES)) {
raybriLog("ERROR Could not reset EGL surface");
}
+27 -34
View File
@@ -6,35 +6,28 @@
#include "raybriEGLConst.h"
#include <stdbool.h>
// Header
typedef struct RaybriEGLState {
void *caLayer;
EGLConfig cfg;
EGLContext ctx;
EGLDisplay display;
EGLSurface surface;
} RaybriEGLState;
bool raybriEGLInit(
EGLConfig *cfg,
EGLContext *ctx,
EGLDisplay *display
);
bool raybriEGLResetSurface(
void *caLayer,
EGLConfig *cfg,
EGLDisplay *display,
EGLSurface *surface
);
bool raybriEGLInit(RaybriEGLState *st);
bool raybriEGLResetSurface(RaybriEGLState *st);
// Source
#if defined(RAYBRI_EGL_IMPLEMENTATION)
bool raybriEGLInit(
EGLConfig *cfg,
EGLContext *ctx,
EGLDisplay *display
){
*display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (*display == EGL_NO_DISPLAY) {
bool raybriEGLInit(RaybriEGLState *st) {
st->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (st->display == EGL_NO_DISPLAY) {
return false;
}
if (eglInitialize(*display, NULL, NULL) == EGL_FALSE) {
if (eglInitialize(st->display, NULL, NULL) == EGL_FALSE) {
return false;
}
@@ -44,36 +37,36 @@ bool raybriEGLInit(
EGLint cfgCount = 0;
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
) {
return false;
}
*ctx = eglCreateContext(*display, *cfg, EGL_NO_CONTEXT, RAYBRI_EGL_CTX);
if (*ctx == EGL_NO_CONTEXT) {
st->ctx = eglCreateContext(st->display, st->cfg, EGL_NO_CONTEXT, RAYBRI_EGL_CTX);
if (st->ctx == EGL_NO_CONTEXT) {
return false;
}
return true;
}
bool raybriEGLResetSurface(
void *caLayer,
EGLConfig *cfg,
EGLDisplay *display,
EGLSurface *surface
) {
bool raybriEGLResetSurface(RaybriEGLState *st) {
// Destroy previous surface
if (*surface != EGL_NO_SURFACE) {
eglDestroySurface(*display, *surface);
*surface = EGL_NO_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
*surface = eglCreateWindowSurface(*display, *cfg, (EGLNativeWindowType)caLayer, NULL);
if (*surface == EGL_NO_SURFACE) {
st->surface = eglCreateWindowSurface(
st->display,
st->cfg,
(EGLNativeWindowType)st->caLayer,
NULL
);
if (st->surface == EGL_NO_SURFACE) {
return false;
}