From b9b7e91bcd8f7183e5ffe7ebe197d18200218fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Thu, 29 Oct 2026 17:02:28 +0300 Subject: [PATCH] introduce struct --- components/raybri/ios/raybri.c | 17 ++++++--- components/raybri/ios/raybriEGL.h | 61 ++++++++++++++----------------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/components/raybri/ios/raybri.c b/components/raybri/ios/raybri.c index 485a2a7..d1fec88 100644 --- a/components/raybri/ios/raybri.c +++ b/components/raybri/ios/raybri.c @@ -11,18 +11,23 @@ #include +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"); } diff --git a/components/raybri/ios/raybriEGL.h b/components/raybri/ios/raybriEGL.h index d2ae6d3..4a4297b 100644 --- a/components/raybri/ios/raybriEGL.h +++ b/components/raybri/ios/raybriEGL.h @@ -6,35 +6,28 @@ #include "raybriEGLConst.h" #include -// 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; }