Files
__mahjong/components/render/ios/renderIOS.mm
T

83 lines
2.3 KiB
Plaintext

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#include "raylib.h"
#include "raybri.h"
#include "renderConstShaderIOS.h"
// iOS entry points. The prebuilt raylib.framework (ghera/raylib-iOS) owns
// main()/AppDelegate/SceneDelegate and a full-screen EGL/ANGLE window; it
// calls these three callbacks (see src/platforms/rcore_ios.c). We therefore
// drive the same raybri_* scene as the macOS build from here, and present the
// SwiftUI UI as a transparent overlay window stacked above raylib's window.
//
// The prebuilt framework already ran rlLoadExtensions()/rlglInit() inside
// InitWindow(), so raybri_init() only compiles the shaders and builds meshes.
#if defined(__cplusplus)
extern "C" void rcios_present_overlay(void); // implemented in Swift (RenderIOS.swift)
#else
void rcios_present_overlay(void);
#endif
static double sr_start_time = 0.0;
static int sr_window_ready = 0;
double rcios_time_now(void)
{
return CACurrentMediaTime();
}
extern "C" void ios_ready(void)
{
SetTraceLogLevel(LOG_WARNING);
// Size is ignored on PLATFORM_IOS; the fork sizes the window itself.
InitWindow(0, 0, "OGS chkgfx");
// On iOS raylib's InitWindow loaded the GL functions and called rlglInit,
// so raybri_init() must not repeat it (see raybri.c, RAYBRI_PLATFORM_IOS).
raybri_init(
RENDER_SHADER_MAIN_VS,
RENDER_SHADER_MAIN_FS,
RENDER_SHADER_SHADOW_VS,
RENDER_SHADER_SHADOW_FS,
(raybri_config){ 45.0f, 0.1f, 1000.0f, 256, 40.0f }
);
// Same layout as the macOS app bundle: <bundle>/cube/cube.gltf
NSString *gltf = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"cube/cube.gltf"];
raybri_load_model([gltf UTF8String]);
sr_start_time = rcios_time_now();
sr_window_ready = 1;
// Show ChkgfxView (the SwiftUI title) above the raylib scene.
rcios_present_overlay();
}
extern "C" void ios_update(bool viewSizeChanged)
{
if (!sr_window_ready) return;
int w = GetRenderWidth();
int h = GetRenderHeight();
raybri_resize(w, h);
float t = (float)(rcios_time_now() - sr_start_time);
raybri_set_rotation(t * 6.0f, t * 18.0f, 0.0f);
BeginDrawing();
raybri_render();
EndDrawing();
}
extern "C" void ios_destroy(void)
{
if (!sr_window_ready) return;
raybri_shutdown();
CloseWindow();
sr_window_ready = 0;
}