diff --git a/components/raybri/ios/RaybriIOS-Bridging-Header.h b/components/raybri/ios/RaybriIOS-Bridging-Header.h index dc8f953..0bc63c3 100644 --- a/components/raybri/ios/RaybriIOS-Bridging-Header.h +++ b/components/raybri/ios/RaybriIOS-Bridging-Header.h @@ -1,6 +1,6 @@ #ifndef OGS_MAHJONG_RAYLIB_IOS_BRIDGING_HEADER_H #define OGS_MAHJONG_RAYLIB_IOS_BRIDGING_HEADER_H -#import "raybriIOS.h" +#include "../raybri.h" #endif diff --git a/components/raybri/ios/raybriIOS.c b/components/raybri/ios/raybriIOS.c index f7cb382..36cf2a2 100644 --- a/components/raybri/ios/raybriIOS.c +++ b/components/raybri/ios/raybriIOS.c @@ -10,7 +10,7 @@ // GL runs on ANGLE (libEGL + libGLESv2, Metal backend), taken from the same // ghera release as raylib's headers. -#include "raybriIOS.h" +#include "../raybri.h" #include #include @@ -90,7 +90,7 @@ static int sr_create_surface(void) return 1; } -int raybri_ios_init(void *layer, int width, int height) +int raybri_init(void *layer, int width, int height) { if (sr_ready) return 1; @@ -166,7 +166,7 @@ int raybri_ios_init(void *layer, int width, int height) return 1; } -void raybri_ios_resize(int width, int height) +void raybri_resize(int width, int height) { if (!sr_ready) return; @@ -181,7 +181,7 @@ void raybri_ios_resize(int width, int height) sr_log("surface recreated"); } -void raybri_ios_render(double time) +void raybri_render(double time) { if (!sr_ready) return; @@ -200,7 +200,7 @@ void raybri_ios_render(double time) eglSwapBuffers(sr_display, sr_surface); } -void raybri_ios_shutdown(void) +void raybri_shutdown(void) { if (!sr_ready) return; diff --git a/components/raybri/ios/raybriIOS.h b/components/raybri/ios/raybriIOS.h deleted file mode 100644 index f5226da..0000000 --- a/components/raybri/ios/raybriIOS.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef OGS_MAHJONG_RAYLIB_IOS_BRIDGE_H -#define OGS_MAHJONG_RAYLIB_IOS_BRIDGE_H - -#ifdef __cplusplus -extern "C" { -#endif - -// Initialise EGL (ANGLE) on the given CALayer and bring up raylib's rlgl. -// Unlike the ghera/raylib-iOS backend, no raylib window, view controller or -// app delegate is involved: the caller owns the layer and the frame timer. -// Returns 1 on success, 0 on failure. -int raybri_ios_init(void *layer, int width, int height); - -// Recreate the EGL window surface for a new drawable size (backing pixels). -void raybri_ios_resize(int width, int height); - -// Render one frame: clear the drawable to a time-based background colour and -// present it. `time` is monotonically increasing seconds. -void raybri_ios_render(double time); - -// Release rlgl state and the EGL surface/context/display. -void raybri_ios_shutdown(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/raybri/raybri.h b/components/raybri/raybri.h index 5493ad3..39b3f9e 100644 --- a/components/raybri/raybri.h +++ b/components/raybri/raybri.h @@ -1,6 +1,8 @@ #ifndef OGS_MAHJONG_RAYLIB_BRIDGE_H #define OGS_MAHJONG_RAYLIB_BRIDGE_H +#include + #ifdef __cplusplus extern "C" { #endif @@ -14,6 +16,31 @@ typedef struct raybri_config { float ground_size; // ground plane extent } raybri_config; +// The bridge always renders into a GL context owned by the app (no raylib +// window), but the platform setup and the current feature set differ: +// macOS renders the textured cube through raybri.c, iOS currently only clears +// its EGL/ANGLE drawable through raybriIOS.c. The common names keep the Swift +// call sites and lifecycle symmetrical. + +// Resize the drawable (backing pixels). On macOS this only records the size; +// on iOS it recreates the EGL window surface when it changes. +void raybri_resize(int width, int height); + +// Release the GL/EGL resources owned by the bridge. +void raybri_shutdown(void); + +#if TARGET_OS_IPHONE + +// Initialise EGL (ANGLE) on the given CALayer and bring up rlgl. +// Returns 1 on success, 0 on failure. +int raybri_init(void *layer, int width, int height); + +// Render one frame: clear the drawable to a time-based background colour and +// present it. `time` is monotonically increasing seconds. +void raybri_render(double time); + +#else + // Initialise the OpenGL-backed raylib scene (no raylib window is created). // The four shader sources come from renderConstShader.swift. void raybri_init( @@ -27,17 +54,13 @@ void raybri_init( // Load the textured cube glTF model. void raybri_load_model(const char *gltf_path); -// Resize the viewport. -void raybri_resize(int width, int height); - // Cube rotation, driven by the application (Euler angles, degrees). void raybri_set_rotation(float x_deg, float y_deg, float z_deg); // Render one frame. void raybri_render(void); -// Release all GPU resources. -void raybri_shutdown(void); +#endif #ifdef __cplusplus } diff --git a/components/render/ios/renderAux.swift b/components/render/ios/renderAux.swift index 4b31e5b..349680b 100644 --- a/components/render/ios/renderAux.swift +++ b/components/render/ios/renderAux.swift @@ -6,7 +6,7 @@ import UIKit // like in the NSOpenGLView on macOS. func renderDraw(_ vm: RenderVM) { let t = CACurrentMediaTime() - vm.startTime - raybri_ios_render(t) + raybri_render(t) } // Backing-pixel size of the view, which is what EGL/ANGLE renders into. diff --git a/components/render/ios/renderEffect.swift b/components/render/ios/renderEffect.swift index 2de4e51..d129eda 100644 --- a/components/render/ios/renderEffect.swift +++ b/components/render/ios/renderEffect.swift @@ -7,7 +7,7 @@ import UIKit func renderInit(_ vm: RenderVM) -> Bool { let size = renderPixelSize(vm.glView) let layer = Unmanaged.passUnretained(vm.glView.layer).toOpaque() - let ok = raybri_ios_init(layer, size[0], size[1]) != 0 + let ok = raybri_init(layer, size[0], size[1]) != 0 if !ok { otherPrintStderr("ИГР renderInit: EGL/ANGLE initialization failed") } @@ -31,5 +31,5 @@ func renderStartTimer(_ vm: RenderVM) { func renderDeinit(_ vm: RenderVM) { vm.timer?.invalidate() vm.timer = nil - raybri_ios_shutdown() + raybri_shutdown() } diff --git a/components/render/ios/view/RenderGLView.swift b/components/render/ios/view/RenderGLView.swift index 8bcacea..4afda0d 100644 --- a/components/render/ios/view/RenderGLView.swift +++ b/components/render/ios/view/RenderGLView.swift @@ -48,7 +48,7 @@ final class RenderGLView: UIView { guard size != vm.pixelSize else { return } vm.pixelSize = size - raybri_ios_resize(size[0], size[1]) + raybri_resize(size[0], size[1]) } deinit {