diff --git a/.gitignore b/.gitignore index 162f817..fed5d95 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ gradle-daemon-jvm.properties local.properties Package.resolved *.xcodeproj +Frameworks +raylib-src diff --git a/AGENTS.md b/AGENTS.md index 9026946..a43020d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,7 +38,7 @@ components/ SHARED source-of-truth for all components. pixelSize, startTime, timer) render/renderConst.swift RENDER_CONFIG (raybri_config), RENDER_FPS, RENDER_MODEL_CUBE, RENDER_OPENGL_ATTRS - render/renderConstShader.swift RENDER_SHADER_* GLSL sources (GLSL 150) + render/renderConstShader.swift Substitutes %VERSION% in the shared templates render/renderAux.swift renderDraw(vm), renderPixelSize(view) render/renderEffect.swift renderInit, renderLoadCubeModel, renderStartTimer, renderDeinit @@ -149,13 +149,20 @@ behind the SwiftUI UI in a `ZStack`. A textured cube is drawn from `Resources/as node-rotation glTF animation cannot be played by the renderer — hence the cube is app-driven.) `packageMac` bundles `Resources/assets/` into the app. -Shaders and render constants live in **Swift**, not in C: GLSL sources are -`RENDER_SHADER_*` in `components/render/renderConstShader.swift`, and -`RENDER_CONFIG` / `raybri_config` tunables are in `renderConst.swift`. `raybri_init` -compiles the shaders in place (no storage/`strdup`). `cube_normal.png` drives -tangentless normal mapping via the derivative-based `cotangentFrame`. The -context is OpenGL 3.2 Core (`RENDER_OPENGL_ATTRS`); on Apple Silicon the driver -still reports 4.1/GLSL 4.10. +Shaders live in **Swift** and are shared by both builds: the GLSL bodies are +the `RENDER_SHADER_*_T` templates in +`components/render/renderConstShader.swift`, each starting with the `%VERSION%` +placeholder. The `RENDER_SHADER_*` sources passed to `raybri_init` are produced +by `replacingOccurrences`, choosing `RENDER_SHADER_VERSION_GL` (`#version 150`) +or `RENDER_SHADER_VERSION_ES` (`#version 300 es`) via `#if os(iOS)`. The +directive must be the first shader token, so it cannot be picked by an `#ifdef` +inside the GLSL. Fragment templates also carry `precision highp float;` — +required by GLSL ES, accepted and ignored by desktop GLSL. The iOS ObjC++ bridge +reaches the strings through `@_cdecl` accessors in `RenderIOS.swift`. `RENDER_CONFIG` / `raybri_config` tunables stay in `renderConst.swift`. +`raybri_init` compiles the shaders in place (no storage/`strdup`). +`cube_normal.png` drives tangentless normal mapping via the derivative-based +`cotangentFrame`. The context is OpenGL 3.2 Core (`RENDER_OPENGL_ATTRS`); on +Apple Silicon the driver still reports 4.1/GLSL 4.10. ## Render architecture diff --git a/README.md b/README.md index e528e84..6db0e2d 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,7 @@ * macOS `brew install raylib` + +* iOS + + `brew install xcodegen` diff --git a/components/chkgfx/ios/view/ChkgfxView.swift b/components/chkgfx/ios/view/ChkgfxView.swift new file mode 120000 index 0000000..3a1e13d --- /dev/null +++ b/components/chkgfx/ios/view/ChkgfxView.swift @@ -0,0 +1 @@ +../../mac/view/ChkgfxView.swift \ No newline at end of file diff --git a/components/other/other-Bridging-Header.h b/components/other/other-Bridging-Header.h new file mode 100644 index 0000000..279c54f --- /dev/null +++ b/components/other/other-Bridging-Header.h @@ -0,0 +1,8 @@ +#ifndef OTHER_BRIDGING_HEADER_H +#define OTHER_BRIDGING_HEADER_H + +#import +#import +#import + +#endif diff --git a/components/raybri/raybri.c b/components/raybri/raybri.c index 1151cd8..7f61066 100644 --- a/components/raybri/raybri.c +++ b/components/raybri/raybri.c @@ -4,12 +4,15 @@ #include "rlgl.h" #include "raymath.h" -#include #include #include #include #include +#if !defined(PLATFORM_IOS) +#include +#endif + static int sr_width = 1; static int sr_height = 1; @@ -65,6 +68,7 @@ static int loc_fog_color = -1; static int loc_fog_start = -1; static int loc_fog_end = -1; +#if !defined(PLATFORM_IOS) // raylib is built as a static/dynamic library with GLFW baked in, but we never // call InitWindow(). Instead we render into an OpenGL context owned by the // macOS app, so we must supply the OpenGL entry point loader ourselves. @@ -78,6 +82,7 @@ static void *sr_gl_loader(const char *name) if (handle == NULL) return NULL; return dlsym(handle, name); } +#endif // Compose a model transform exactly like raylib's DrawModel() does, so the // matrices we feed to DrawMesh() match what rlgl computes internally. @@ -190,9 +195,14 @@ void raybri_init( // raylib's default INFO logging is noisy; keep warnings and errors only. SetTraceLogLevel(LOG_WARNING); +#if !defined(PLATFORM_IOS) rlLoadExtensions((void *)sr_gl_loader); // Init with default 1x1 size rlglInit(1, 1); +#else + // On iOS the prebuilt raylib (ghera/raylib-iOS) already calls + // rlLoadExtensions() and rlglInit() inside InitWindow(); skip here. +#endif sr_load_shaders(main_vs, main_fs, shadow_vs, shadow_fs); sr_config_shaders(); @@ -216,6 +226,9 @@ void raybri_load_model(const char *gltf_path) if (sr_has_model) { + fprintf(stderr, "SR: model loaded: %s (%d meshes, %d materials)\n", + gltf_path, sr_model.meshCount, sr_model.materialCount); + int cube_mat_index = (sr_model.materialCount > 0) ? sr_model.meshMaterial[0] : 0; sr_cube_material = sr_model.materials[cube_mat_index]; sr_cube_material.shader = sr_main_shader; @@ -435,6 +448,8 @@ void raybri_shutdown(void) if (sr_main_shader.id > 0) UnloadShader(sr_main_shader); if (sr_shadow_shader.id > 0) UnloadShader(sr_shadow_shader); +#if !defined(PLATFORM_IOS) rlglClose(); +#endif sr_ready = 0; } diff --git a/components/raybri/raybri.h b/components/raybri/raybri.h index 5493ad3..237a574 100644 --- a/components/raybri/raybri.h +++ b/components/raybri/raybri.h @@ -15,7 +15,8 @@ typedef struct raybri_config { } raybri_config; // Initialise the OpenGL-backed raylib scene (no raylib window is created). -// The four shader sources come from renderConstShader.swift. +// The four shader sources come from renderConstShader.swift (with the +// platform #version already substituted). void raybri_init( const char *main_vs, const char *main_fs, diff --git a/components/render/ios/RenderIOS.swift b/components/render/ios/RenderIOS.swift new file mode 100644 index 0000000..be44367 --- /dev/null +++ b/components/render/ios/RenderIOS.swift @@ -0,0 +1,98 @@ +import SwiftUI +import UIKit + +// The prebuilt raylib iOS framework owns the app entry point (main()/ +// AppDelegate/SceneDelegate in rcore_ios.c). Its SceneDelegate creates the +// window, installs GameViewController as the root and only then calls +// ios_ready(), so by the time rcios_present_overlay() runs there is already a +// key window with a GL-backed root view. +// +// We deliberately do NOT create a second UIWindow: that would sit at a fixed +// windowLevel and break alerts/buttons later. Instead we add the SwiftUI +// content as a child UIViewController of raylib's root view controller, so: +// - buttons receive touches through the normal responder chain; +// - .alert / sheets present correctly in the same window; +// - rotation and geometry changes apply to both layers at once. +// +// ChkgfxComponent/ChkgfxVM live here because the component lifecycle is +// otherwise driven by the (iOS-unavailable) SwiftUI app shell. + +enum RenderIOS { + static let chkgfx = ChkgfxComponent() + static let chkgfxVM = ChkgfxVM() + // Inert on iOS (the raylib framework drives the scene), but the generated + // dialect refers to them, so keep them alive. + static let render = RenderComponent() + static let renderVM = RenderVM() +} + +// The GLSL sources live in renderConstShader.swift (shared with the macOS +// build, with the platform #version already substituted). Expose them to the +// ObjC++ bridge as C strings; each call returns a malloc'd copy the caller +// must free(). +@_cdecl("rcios_shader_main_vs") +public func rciosShaderMainVS() -> UnsafeMutablePointer? { + strdup(RENDER_SHADER_MAIN_VS) +} + +@_cdecl("rcios_shader_main_fs") +public func rciosShaderMainFS() -> UnsafeMutablePointer? { + strdup(RENDER_SHADER_MAIN_FS) +} + +@_cdecl("rcios_shader_shadow_vs") +public func rciosShaderShadowVS() -> UnsafeMutablePointer? { + strdup(RENDER_SHADER_SHADOW_VS) +} + +@_cdecl("rcios_shader_shadow_fs") +public func rciosShaderShadowFS() -> UnsafeMutablePointer? { + strdup(RENDER_SHADER_SHADOW_FS) +} + +@_cdecl("rcios_present_overlay") +public func rciosPresentOverlay() { + otherSetupConsoleLogging(RenderIOS.chkgfx.ctrl, "Chkgfx") + RenderIOS.chkgfx.setup() + + DispatchQueue.main.async { + guard let scene = UIApplication.shared.connectedScenes + .compactMap({ $0 as? UIWindowScene }) + .first(where: { $0.activationState == .foregroundActive }) + ?? UIApplication.shared.connectedScenes + .compactMap({ $0 as? UIWindowScene }).first + else { return } + + // raylib's SceneDelegate made its window key before calling ios_ready(). + guard let window = scene.windows.first(where: { $0.isKeyWindow }) + ?? scene.windows.first, + let host = window.rootViewController + else { return } + + let root = ChkgfxView(RenderIOS.chkgfxVM) + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top) + + let hosting = UIHostingController(rootView: root) + hosting.view.backgroundColor = .clear + // The UI is a passive title for now. Once it gains buttons, drop this + // line; touches will then stay in the SwiftUI layer over the whole + // screen instead of reaching raylib's GameViewController. + hosting.view.isUserInteractionEnabled = false + + host.addChild(hosting) + hosting.view.frame = host.view.bounds + hosting.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] + host.view.addSubview(hosting.view) + hosting.didMove(toParent: host) + + // addChild retains the hosting controller for as long as it stays + // attached, so no extra strong reference is needed here. + OverlayHost.retained = hosting + } +} + +// Optional handle for later use (e.g. presenting an alert from the hosting +// controller). The parent view controller keeps it alive while attached. +private enum OverlayHost { + static weak var retained: UIViewController? +} diff --git a/components/render/ios/renderIOS.mm b/components/render/ios/renderIOS.mm new file mode 100644 index 0000000..4bfc58f --- /dev/null +++ b/components/render/ios/renderIOS.mm @@ -0,0 +1,110 @@ +#import +#import + +#include +#include + +#include "raylib.h" +#include "raybri.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 inside raylib's own window (see RenderIOS.swift). +// +// 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 + +// The GLSL sources live in renderConstShader.swift (shared with the macOS +// build, with the platform #version already substituted there). These Swift +// accessors return malloc'd copies that sr_shader() releases. +#if defined(__cplusplus) +extern "C" { +#endif +char *rcios_shader_main_vs(void); +char *rcios_shader_main_fs(void); +char *rcios_shader_shadow_vs(void); +char *rcios_shader_shadow_fs(void); +#if defined(__cplusplus) +} +#endif + +static std::string sr_shader(char *(*accessor)(void)) +{ + char *source = accessor(); + std::string shader = source ? source : ""; + free(source); + return shader; +} + +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). + std::string main_vs = sr_shader(rcios_shader_main_vs); + std::string main_fs = sr_shader(rcios_shader_main_fs); + std::string shadow_vs = sr_shader(rcios_shader_shadow_vs); + std::string shadow_fs = sr_shader(rcios_shader_shadow_fs); + raybri_init( + main_vs.c_str(), + main_fs.c_str(), + shadow_vs.c_str(), + shadow_fs.c_str(), + (raybri_config){ 45.0f, 0.1f, 1000.0f, 256, 40.0f } + ); + + // Same layout as the macOS app 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; +} diff --git a/components/render/ios/renderIOSComponent.swift b/components/render/ios/renderIOSComponent.swift new file mode 100644 index 0000000..f9b30e4 --- /dev/null +++ b/components/render/ios/renderIOSComponent.swift @@ -0,0 +1,46 @@ +import Combine +import Foundation + +// On iOS the renderer is the prebuilt raylib framework's own full-screen +// window (see components/render/ios/renderIOS.mm: ios_ready/ios_update/ +// ios_destroy). The macOS render component is not used there, but the +// generated dialect.swift still refers to RenderComponent/RenderVM and to the +// renderInit/renderStartTimer/renderLoadCubeModel/renderDeinit oneliners, so +// we provide inert counterparts to keep the dialect compiling. +// +// The real work happens in renderIOS.mm, which talks to the very same +// raybri_* bridge functions these stubs would call on macOS. + +final class RenderVM: ObservableObject { + var didPrepareGL = false + var pixelSize = [Int32]() + var startTime: CFTimeInterval = 0 + + static private(set) weak var shared: RenderVM? + + init() { + Self.shared = self + } +} + +class RenderComponent { + let ctrl = DialectController(RenderContext()) + static private(set) weak var singleton: RenderComponent? + + init() { + Self.singleton = self + renderRegisterShoulds(ctrl) + } + + func setup() { + renderSet(F.didSetup, true) + } +} + +func renderInit(_ vm: RenderVM) {} + +func renderStartTimer(_ vm: RenderVM) {} + +func renderLoadCubeModel(_ vm: RenderVM) {} + +func renderDeinit(_ vm: RenderVM) {} diff --git a/components/render/renderConstShader.swift b/components/render/renderConstShader.swift index 665feb9..d75120d 100644 --- a/components/render/renderConstShader.swift +++ b/components/render/renderConstShader.swift @@ -1,5 +1,27 @@ -let RENDER_SHADER_MAIN_FS = """ -#version 150 +// GLSL sources shared by the macOS (GLSL 150) and iOS (GLSL ES 300) +// builds. A shader's #version directive must precede everything else (even +// "precision"), so it cannot be chosen with an #ifdef inside the GLSL; the +// templates below start with RENDER_SHADER_VERSION_TOKEN and the platform +// version is substituted with replacingOccurrences. +// +// The fragment templates carry "precision highp float;" because GLSL ES has +// no default float precision in the fragment stage; desktop GLSL 1.30+ +// accepts and ignores it. GLSL ES vertex shaders default to highp, so the +// vertex templates need no precision statement. + +let RENDER_SHADER_VERSION_TOKEN = "%VERSION%" +let RENDER_SHADER_VERSION_GL = "#version 150" +let RENDER_SHADER_VERSION_ES = "#version 300 es" + +#if os(iOS) +let RENDER_SHADER_VERSION = RENDER_SHADER_VERSION_ES +#else +let RENDER_SHADER_VERSION = RENDER_SHADER_VERSION_GL +#endif + +let RENDER_SHADER_MAIN_FS_T = """ +%VERSION% +precision highp float; in vec3 vWorldPos; in vec3 vNormal; @@ -116,8 +138,13 @@ void main() } """ -let RENDER_SHADER_MAIN_VS = """ -#version 150 +let RENDER_SHADER_MAIN_FS = RENDER_SHADER_MAIN_FS_T.replacingOccurrences( + of: RENDER_SHADER_VERSION_TOKEN, + with: RENDER_SHADER_VERSION +) + +let RENDER_SHADER_MAIN_VS_T = """ +%VERSION% in vec3 vertexPosition; in vec2 vertexTexCoord; in vec3 vertexNormal; @@ -142,8 +169,14 @@ void main() } """ -let RENDER_SHADER_SHADOW_FS = """ -#version 150 +let RENDER_SHADER_MAIN_VS = RENDER_SHADER_MAIN_VS_T.replacingOccurrences( + of: RENDER_SHADER_VERSION_TOKEN, + with: RENDER_SHADER_VERSION +) + +let RENDER_SHADER_SHADOW_FS_T = """ +%VERSION% +precision highp float; out vec4 finalColor; void main() { @@ -151,8 +184,13 @@ void main() } """ -let RENDER_SHADER_SHADOW_VS = """ -#version 150 +let RENDER_SHADER_SHADOW_FS = RENDER_SHADER_SHADOW_FS_T.replacingOccurrences( + of: RENDER_SHADER_VERSION_TOKEN, + with: RENDER_SHADER_VERSION +) + +let RENDER_SHADER_SHADOW_VS_T = """ +%VERSION% in vec3 vertexPosition; uniform mat4 mvp; void main() @@ -160,3 +198,8 @@ void main() gl_Position = mvp * vec4(vertexPosition, 1.0); } """ + +let RENDER_SHADER_SHADOW_VS = RENDER_SHADER_SHADOW_VS_T.replacingOccurrences( + of: RENDER_SHADER_VERSION_TOKEN, + with: RENDER_SHADER_VERSION +) diff --git a/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png b/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png new file mode 100644 index 0000000..f2520ea Binary files /dev/null and b/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png differ diff --git a/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/Contents.json b/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..ca34fdb --- /dev/null +++ b/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,14 @@ +{ + "images" : [ + { + "filename" : "AppIcon.png", + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} \ No newline at end of file diff --git a/ogs-chkgfx/ver-ios/Info.plist b/ogs-chkgfx/ver-ios/Info.plist new file mode 100644 index 0000000..3829ca4 --- /dev/null +++ b/ogs-chkgfx/ver-ios/Info.plist @@ -0,0 +1,43 @@ + + + + + CFBundleName + OGS chkgfx + CFBundleDisplayName + OGS chkgfx + CFBundleIdentifier + org.opengamestudio.chkgfx + CFBundleExecutable + ogs-chkgfx + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + UILaunchScreen + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + SceneDelegate + + + + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + + diff --git a/ogs-chkgfx/ver-ios/project.yml b/ogs-chkgfx/ver-ios/project.yml new file mode 100644 index 0000000..768c025 --- /dev/null +++ b/ogs-chkgfx/ver-ios/project.yml @@ -0,0 +1,81 @@ +name: OGS chkgfx +options: + bundleIdPrefix: org.opengamestudio +targets: + ogs-chkgfx: + type: application + platform: iOS + deploymentTarget: "15.6" + sources: + - path: Assets.xcassets + - path: src + - path: ../../components/render/ios + - path: ../../components/render/renderConstShader.swift + - path: ../../components/raybri + - path: ../../components/other + - path: ../../components/chkgfx/chkgfx.swift + - path: ../../components/chkgfx/chkgfxVM.swift + - path: ../../components/chkgfx/ios/view/ChkgfxView.swift + dependencies: + - framework: Frameworks/raylib.xcframework + embed: true + - framework: Frameworks/libEGL.xcframework + embed: true + - framework: Frameworks/libGLESv2.xcframework + embed: true + - sdk: UIKit.framework + - sdk: SwiftUI.framework + - sdk: QuartzCore.framework + - sdk: CoreGraphics.framework + - sdk: Foundation.framework + settings: + base: + INFOPLIST_FILE: Info.plist + PRODUCT_BUNDLE_IDENTIFIER: org.opengamestudio.chkgfx + SWIFT_OBJC_BRIDGING_HEADER: ../../components/other/other-Bridging-Header.h + HEADER_SEARCH_PATHS: + - "$(SRCROOT)/../../components" + - "$(SRCROOT)/../../components/raybri" + - "$(SRCROOT)/../../components/render" + - "$(SRCROOT)/../../components/render/ios" + - "$(SRCROOT)/../../components/other" + - "$(SRCROOT)/Frameworks/raylib.xcframework/ios-arm64_x86_64-simulator/raylib.framework/Headers" + - "$(SRCROOT)/Frameworks/raylib.xcframework/ios-arm64/raylib.framework/Headers" + - "$(SRCROOT)/Frameworks/libEGL.xcframework/ios-arm64_x86_64-simulator/Headers" + - "$(SRCROOT)/Frameworks/libEGL.xcframework/ios-arm64/Headers" + - "$(SRCROOT)/Frameworks/libGLESv2.xcframework/ios-arm64_x86_64-simulator/Headers" + - "$(SRCROOT)/Frameworks/libGLESv2.xcframework/ios-arm64/Headers" + USER_HEADER_SEARCH_PATHS: + - "$(SRCROOT)/../../components/raybri" + - "$(SRCROOT)/../../components/render/ios" + - "$(SRCROOT)/Frameworks/raylib.xcframework/ios-arm64_x86_64-simulator/raylib.framework/Headers" + - "$(SRCROOT)/Frameworks/raylib.xcframework/ios-arm64/raylib.framework/Headers" + GCC_PREPROCESSOR_DEFINITIONS: + - PLATFORM_IOS=1 + - GRAPHICS_API_OPENGL_ES3=1 + - GL_GLEXT_PROTOTYPES=1 + OTHER_LDFLAGS: + - "-ObjC" + FRAMEWORK_SEARCH_PATHS: + - "$(SRCROOT)/Frameworks" + - "$(SRCROOT)/Frameworks/raylib.xcframework/ios-arm64_x86_64-simulator" + - "$(SRCROOT)/Frameworks/raylib.xcframework/ios-arm64" + - "$(SRCROOT)/Frameworks/libEGL.xcframework/ios-arm64_x86_64-simulator" + - "$(SRCROOT)/Frameworks/libEGL.xcframework/ios-arm64" + - "$(SRCROOT)/Frameworks/libGLESv2.xcframework/ios-arm64_x86_64-simulator" + - "$(SRCROOT)/Frameworks/libGLESv2.xcframework/ios-arm64" + LD_RUNPATH_SEARCH_PATHS: + - "$(inherited) @executable_path/Frameworks" + postBuildScripts: + - name: Copy res + script: | + # Mirror the macOS packaging: the shared res/ tree (symlinks + # dereferenced) lands in the app bundle root, so the model is + # at /cube/cube.gltf + RES="${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + mkdir -p "$RES" + cp -R -L "${SRCROOT}/../../res/." "$RES/" + inputFiles: + - "$(SRCROOT)/../../res" + outputFiles: + - "$(TARGET_BUILD_DIR)/$(UNLOCALIZED_RESOURCES_FOLDER_PATH)/cube/cube.gltf" diff --git a/ogs-chkgfx/ver-ios/src/dialect.swift b/ogs-chkgfx/ver-ios/src/dialect.swift new file mode 120000 index 0000000..a931c95 --- /dev/null +++ b/ogs-chkgfx/ver-ios/src/dialect.swift @@ -0,0 +1 @@ +../../ver-mac/src/dialect.swift \ No newline at end of file diff --git a/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift b/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift index 105f2dc..090c94b 100644 --- a/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift +++ b/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift @@ -1,4 +1,3 @@ -import AppKit import SwiftUI @main diff --git a/ogs-mahjong/ver-mac/src/GameApp.swift b/ogs-mahjong/ver-mac/src/MahjongApp.swift similarity index 90% rename from ogs-mahjong/ver-mac/src/GameApp.swift rename to ogs-mahjong/ver-mac/src/MahjongApp.swift index 449a921..3d71dfe 100644 --- a/ogs-mahjong/ver-mac/src/GameApp.swift +++ b/ogs-mahjong/ver-mac/src/MahjongApp.swift @@ -1,8 +1,7 @@ -import AppKit import SwiftUI @main -struct GameApp: App { +struct MahjongApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate var body: some Scene { diff --git a/util/build-ogs-chkgfx-ios b/util/build-ogs-chkgfx-ios new file mode 100755 index 0000000..e8f26c1 --- /dev/null +++ b/util/build-ogs-chkgfx-ios @@ -0,0 +1,14 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" ; pwd -P) + +T=$SDIR/step +source $SDIR/paths + +TARGET=ogs-chkgfx + +STEP=0 +source $T/generateDialect $TARGET +source $T/prepareIOS $TARGET + +cd $SDIR/../$TARGET/ver-ios +xcodebuild -scheme "ogs-chkgfx" -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' -derivedDataPath .build build diff --git a/util/prepare-ogs-chkgfx-ios b/util/prepare-ogs-chkgfx-ios new file mode 100755 index 0000000..80c6be5 --- /dev/null +++ b/util/prepare-ogs-chkgfx-ios @@ -0,0 +1,11 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" ; pwd -P) + +T=$SDIR/step +source $SDIR/paths + +TARGET=ogs-chkgfx + +STEP=0 +source $T/generateDialect $TARGET +source $T/prepareIOS $TARGET diff --git a/util/run-ogs-chkgfx-ios b/util/run-ogs-chkgfx-ios new file mode 100755 index 0000000..d0ba3fd --- /dev/null +++ b/util/run-ogs-chkgfx-ios @@ -0,0 +1,26 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" ; pwd -P) + +T=$SDIR/step +source $SDIR/paths + +TARGET=ogs-chkgfx +BUNDLE_ID=org.opengamestudio.chkgfx +APP="$SDIR/../$TARGET/ver-ios/.build/Build/Products/Debug-iphonesimulator/ogs-chkgfx.app" + +if [[ ! -d "$APP" ]]; then + echo "iOS app not built yet, run util/build-ogs-chkgfx-ios" + exit 1 +fi + +DEVICE=${DEVICE:-"iPhone 15 Pro"} +UDID=$(xcrun simctl list devices available | grep -m1 "$DEVICE (" | sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/') +if [[ -z "$UDID" ]]; then + echo "Simulator '$DEVICE' not found" + exit 1 +fi + +xcrun simctl boot "$UDID" 2>/dev/null || true +sleep 2 +xcrun simctl install "$UDID" "$APP" +xcrun simctl launch "$UDID" "$BUNDLE_ID" diff --git a/util/step/prepareIOS b/util/step/prepareIOS new file mode 100755 index 0000000..e8519b9 --- /dev/null +++ b/util/step/prepareIOS @@ -0,0 +1,28 @@ +#!/bin/bash -e + +TARGET=$1 + +STEP=$((STEP+1)) +echo -e "\n> > > > Step №$STEP. Generate iOS project for '$TARGET'" + +# iOS rendering goes through ghera/raylib-iOS: a raylib fork that adds an +# iOS platform (rcore_ios.c) rendering OpenGL ES via ANGLE. Its stable +# releases ship prebuilt xcframeworks (raylib + libEGL + libGLESv2). They are +# ~46 MB, so they are downloaded on demand and never committed. +RAYLIB_IOS_TAG=6.0.7-iOS +FRAMEWORKS=$SDIR/../$TARGET/ver-ios/Frameworks +if [[ ! -d "$FRAMEWORKS/raylib.xcframework" ]]; then + echo "Raylib iOS xcframeworks missing, downloading $RAYLIB_IOS_TAG..." + mkdir -p "$FRAMEWORKS" + TMP=$(mktemp -d) + curl -sL -o "$TMP/raylib-ios.zip" \ + "https://github.com/ghera/raylib-iOS/releases/download/$RAYLIB_IOS_TAG/raylib-ios-xcframeworks-$RAYLIB_IOS_TAG.zip" + unzip -q "$TMP/raylib-ios.zip" -d "$TMP" + cp -R "$TMP/raylib-ios-xcframeworks/raylib.xcframework" "$FRAMEWORKS/" + cp -R "$TMP/raylib-ios-xcframeworks/libEGL.xcframework" "$FRAMEWORKS/" + cp -R "$TMP/raylib-ios-xcframeworks/libGLESv2.xcframework" "$FRAMEWORKS/" + rm -rf "$TMP" +fi + +cd $SDIR/../$TARGET/ver-ios +xcodegen