Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56d4b2dd88 | ||
|
|
e0f54dde75 | ||
|
|
4b70bd9906 | ||
|
|
33fae994fc | ||
|
|
197d93ee7b | ||
|
|
81bfac20f9 | ||
|
|
27b7679bf8 | ||
|
|
fa1cd053c8 | ||
|
|
6fecc1e95e |
No files matched your search
@@ -10,4 +10,3 @@ local.properties
|
||||
Package.resolved
|
||||
*.xcodeproj
|
||||
Frameworks
|
||||
raylib-src
|
||||
@@ -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 Substitutes %VERSION% in the shared templates
|
||||
render/renderConstShader.swift RENDER_SHADER_* GLSL sources (GLSL 150)
|
||||
render/renderAux.swift renderDraw(vm), renderPixelSize(view)
|
||||
render/renderEffect.swift renderInit, renderLoadCubeModel,
|
||||
renderStartTimer, renderDeinit
|
||||
@@ -63,7 +63,7 @@ game/ver-mac/ macOS app (SPM executable target "ogs-mahjong")
|
||||
raybri/raybri.c -> symlink components/raybri/raybri.c
|
||||
raybri/raybri.h -> symlink components/raybri/raybri.h
|
||||
render/render.swift -> symlink components/render/render.swift
|
||||
render/renderAux.swift -> symlink components/render/renderAux.swift
|
||||
render/renderAux.swift -> symlink components/render/mac/renderAux.swift
|
||||
render/renderConst.swift -> symlink components/render/renderConst.swift
|
||||
render/renderConstShader.swift -> symlink .../renderConstShader.swift
|
||||
render/renderEffect.swift -> symlink components/render/renderEffect.swift
|
||||
@@ -99,7 +99,7 @@ src/other/other.swift -> ../../../../components/other/other.swift (
|
||||
src/raybri/raybri.c -> ../../../../components/raybri/raybri.c (4 up)
|
||||
src/raybri/raybri.h -> ../../../../components/raybri/raybri.h (4 up)
|
||||
src/render/render.swift -> ../../../../components/render/render.swift (4 up)
|
||||
src/render/renderAux.swift -> ../../../../components/render/renderAux.swift (4 up)
|
||||
src/render/renderAux.swift -> ../../../../components/render/mac/renderAux.swift (4 up)
|
||||
src/render/renderConst.swift-> ../../../../components/render/renderConst.swift (4 up)
|
||||
src/render/renderConstShader.swift -> ../../../../components/render/renderConstShader.swift (4 up)
|
||||
src/render/renderEffect.swift -> ../../../../components/render/renderEffect.swift (4 up)
|
||||
@@ -149,20 +149,13 @@ 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 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.
|
||||
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.
|
||||
|
||||
## Render architecture
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef OTHER_BRIDGING_HEADER_H
|
||||
#define OTHER_BRIDGING_HEADER_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef OGS_MAHJONG_RAYLIB_IOS_BRIDGING_HEADER_H
|
||||
#define OGS_MAHJONG_RAYLIB_IOS_BRIDGING_HEADER_H
|
||||
|
||||
#include "../raybri.h"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,207 @@
|
||||
// iOS counterpart of raybri.c.
|
||||
//
|
||||
// The prebuilt ghera/raylib-iOS xcframework is callback-driven: its rcore_ios.c
|
||||
// defines main(), AppDelegate, SceneDelegate and GameViewController, so linking
|
||||
// it would hand the whole app to raylib (and clash with SwiftUI's own main()).
|
||||
// Instead this bridge compiles raylib's renderer (rlgl) directly and owns only
|
||||
// the GL side. The view and the frame timer stay in ver-ios, exactly like the
|
||||
// macOS build where RenderVM drives the NSOpenGLView.
|
||||
//
|
||||
// GL runs on ANGLE (libEGL + libGLESv2, Metal backend), taken from the same
|
||||
// ghera release as raylib's headers.
|
||||
|
||||
#include "../raybri.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <libEGL/libEGL.h>
|
||||
|
||||
// rlgl's iOS branch includes <libGLESv2/GLES/glext.h> before gl2/gl3, so the
|
||||
// GL_API/GL_APIENTRY macros have to come from glplatform.h first. ghera's
|
||||
// build script does this with -include; we do it explicitly.
|
||||
#include <libGLESv2/GLES/gl.h>
|
||||
|
||||
#define RLGL_IMPLEMENTATION
|
||||
#include <rlgl.h>
|
||||
|
||||
static EGLDisplay sr_display = EGL_NO_DISPLAY;
|
||||
static EGLSurface sr_surface = EGL_NO_SURFACE;
|
||||
static EGLContext sr_context = EGL_NO_CONTEXT;
|
||||
static EGLConfig sr_config = NULL;
|
||||
static void *sr_layer = NULL;
|
||||
|
||||
static int sr_ready = 0;
|
||||
static int sr_width = 1;
|
||||
static int sr_height = 1;
|
||||
|
||||
static void sr_log(const char *text)
|
||||
{
|
||||
fprintf(stderr, "RBIOS: %s\n", text);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
// (Re)create the EGL window surface on the layer handed to us by UIKit.
|
||||
static int sr_create_surface(void)
|
||||
{
|
||||
if (sr_surface != EGL_NO_SURFACE)
|
||||
{
|
||||
eglDestroySurface(sr_display, sr_surface);
|
||||
sr_surface = EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
// ANGLE on iOS takes a CALayer as the native window.
|
||||
sr_surface = eglCreateWindowSurface(sr_display, sr_config, (EGLNativeWindowType)sr_layer, NULL);
|
||||
if (sr_surface == EGL_NO_SURFACE)
|
||||
{
|
||||
sr_log("failed to create EGL window surface");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (eglMakeCurrent(sr_display, sr_surface, sr_surface, sr_context) == EGL_FALSE)
|
||||
{
|
||||
sr_log("failed to make the EGL context current");
|
||||
return 0;
|
||||
}
|
||||
|
||||
rlViewport(0, 0, sr_width, sr_height);
|
||||
rlSetFramebufferWidth(sr_width);
|
||||
rlSetFramebufferHeight(sr_height);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int raybri_init(void *layer, int width, int height)
|
||||
{
|
||||
if (sr_ready) return 1;
|
||||
|
||||
if (layer == NULL)
|
||||
{
|
||||
sr_log("no drawable layer");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sr_layer = layer;
|
||||
sr_width = (width > 0) ? width : 1;
|
||||
sr_height = (height > 0) ? height : 1;
|
||||
|
||||
sr_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (sr_display == EGL_NO_DISPLAY)
|
||||
{
|
||||
sr_log("failed to get the EGL display");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (eglInitialize(sr_display, NULL, NULL) == EGL_FALSE)
|
||||
{
|
||||
sr_log("failed to initialize EGL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE)
|
||||
{
|
||||
sr_log("failed to bind the OpenGL ES API");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const EGLint config_attribs[] = {
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_ALPHA_SIZE, 8,
|
||||
EGL_DEPTH_SIZE, 16,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
EGLint config_count = 0;
|
||||
if (eglChooseConfig(sr_display, config_attribs, &sr_config, 1, &config_count) == EGL_FALSE || config_count < 1)
|
||||
{
|
||||
sr_log("failed to choose an EGL config");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const EGLint context_attribs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
sr_context = eglCreateContext(sr_display, sr_config, EGL_NO_CONTEXT, context_attribs);
|
||||
if (sr_context == EGL_NO_CONTEXT)
|
||||
{
|
||||
sr_log("failed to create an EGL context");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!sr_create_surface()) return 0;
|
||||
|
||||
// With GL_GLEXT_PROTOTYPES rlgl calls the ANGLE entry points directly, but
|
||||
// the call keeps parity with the platform backends and is harmless.
|
||||
rlLoadExtensions((void *)eglGetProcAddress);
|
||||
rlglInit(sr_width, sr_height);
|
||||
|
||||
sr_log("EGL/ANGLE + rlgl initialized");
|
||||
sr_ready = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void raybri_resize(int width, int height)
|
||||
{
|
||||
if (!sr_ready) return;
|
||||
|
||||
if (width <= 0 || height <= 0) return;
|
||||
if (width == sr_width && height == sr_height) return;
|
||||
|
||||
sr_width = width;
|
||||
sr_height = height;
|
||||
|
||||
if (!sr_create_surface()) return;
|
||||
|
||||
sr_log("surface recreated");
|
||||
}
|
||||
|
||||
void raybri_render(void)
|
||||
{
|
||||
if (!sr_ready) return;
|
||||
|
||||
if (eglMakeCurrent(sr_display, sr_surface, sr_surface, sr_context) == EGL_FALSE) return;
|
||||
|
||||
rlClearColor(0, 0, 255, 255);
|
||||
rlClearScreenBuffers();
|
||||
|
||||
eglSwapBuffers(sr_display, sr_surface);
|
||||
}
|
||||
|
||||
void raybri_shutdown(void)
|
||||
{
|
||||
if (!sr_ready) return;
|
||||
|
||||
eglMakeCurrent(sr_display, sr_surface, sr_surface, sr_context);
|
||||
rlglClose();
|
||||
|
||||
eglMakeCurrent(sr_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
|
||||
if (sr_surface != EGL_NO_SURFACE)
|
||||
{
|
||||
eglDestroySurface(sr_display, sr_surface);
|
||||
sr_surface = EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
if (sr_context != EGL_NO_CONTEXT)
|
||||
{
|
||||
eglDestroyContext(sr_display, sr_context);
|
||||
sr_context = EGL_NO_CONTEXT;
|
||||
}
|
||||
|
||||
if (sr_display != EGL_NO_DISPLAY)
|
||||
{
|
||||
eglTerminate(sr_display);
|
||||
sr_display = EGL_NO_DISPLAY;
|
||||
}
|
||||
|
||||
sr_layer = NULL;
|
||||
sr_ready = 0;
|
||||
|
||||
sr_log("shutdown");
|
||||
}
|
||||
@@ -4,15 +4,12 @@
|
||||
#include "rlgl.h"
|
||||
#include "raymath.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(PLATFORM_IOS)
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
static int sr_width = 1;
|
||||
static int sr_height = 1;
|
||||
|
||||
@@ -68,7 +65,6 @@ 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.
|
||||
@@ -82,7 +78,6 @@ 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.
|
||||
@@ -195,14 +190,9 @@ 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();
|
||||
@@ -226,9 +216,6 @@ 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;
|
||||
@@ -448,8 +435,6 @@ 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;
|
||||
}
|
||||
+28
-10
@@ -1,6 +1,8 @@
|
||||
#ifndef OGS_MAHJONG_RAYLIB_BRIDGE_H
|
||||
#define OGS_MAHJONG_RAYLIB_BRIDGE_H
|
||||
|
||||
#include <TargetConditionals.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -14,9 +16,32 @@ 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);
|
||||
|
||||
// Render one frame.
|
||||
void raybri_render(void);
|
||||
|
||||
// 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);
|
||||
|
||||
#else
|
||||
|
||||
// Initialise the OpenGL-backed raylib scene (no raylib window is created).
|
||||
// The four shader sources come from renderConstShader.swift (with the
|
||||
// platform #version already substituted).
|
||||
// The four shader sources come from renderConstShader.swift.
|
||||
void raybri_init(
|
||||
const char *main_vs,
|
||||
const char *main_fs,
|
||||
@@ -28,17 +53,10 @@ 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
|
||||
}
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
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<CChar>? {
|
||||
strdup(RENDER_SHADER_MAIN_VS)
|
||||
}
|
||||
|
||||
@_cdecl("rcios_shader_main_fs")
|
||||
public func rciosShaderMainFS() -> UnsafeMutablePointer<CChar>? {
|
||||
strdup(RENDER_SHADER_MAIN_FS)
|
||||
}
|
||||
|
||||
@_cdecl("rcios_shader_shadow_vs")
|
||||
public func rciosShaderShadowVS() -> UnsafeMutablePointer<CChar>? {
|
||||
strdup(RENDER_SHADER_SHADOW_VS)
|
||||
}
|
||||
|
||||
@_cdecl("rcios_shader_shadow_fs")
|
||||
public func rciosShaderShadowFS() -> UnsafeMutablePointer<CChar>? {
|
||||
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?
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
../renderVM.swift
|
||||
@@ -0,0 +1,16 @@
|
||||
import UIKit
|
||||
|
||||
// Render a single frame. The timer calls this directly: an EGL/ANGLE surface
|
||||
// presents into the view's layer, so there is no draw(_:) / needsDisplay pass
|
||||
// like in the NSOpenGLView on macOS.
|
||||
func renderDraw(_ vm: RenderVM) {
|
||||
raybri_render()
|
||||
}
|
||||
|
||||
// Backing-pixel size of the view, which is what EGL/ANGLE renders into.
|
||||
func renderPixelSize(_ view: UIView) -> [Int32] {
|
||||
let scale = view.contentScaleFactor
|
||||
let w = Int32(max(1, (view.bounds.width * scale).rounded()))
|
||||
let h = Int32(max(1, (view.bounds.height * scale).rounded()))
|
||||
return [w, h]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// iOS render constants. The macOS renderConst.swift depends on AppKit and the
|
||||
// RaylibBridge SPM module, so the two platforms keep separate files.
|
||||
let RENDER_FPS = 60.0
|
||||
@@ -0,0 +1,32 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
// Bring up EGL/ANGLE on the view's layer. Returns false when the surface could
|
||||
// not be created (the caller then leaves the timer stopped).
|
||||
func renderInit(_ vm: RenderVM) -> Bool {
|
||||
let size = renderPixelSize(vm.glView)
|
||||
let layer = Unmanaged.passUnretained(vm.glView.layer).toOpaque()
|
||||
let ok = raybri_init(layer, size[0], size[1]) != 0
|
||||
if !ok {
|
||||
otherPrintStderr("ИГР renderInit: EGL/ANGLE initialization failed")
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
// Same shape as the macOS timer: a repeating timer on the main run loop, but
|
||||
// here it calls the renderer directly instead of flagging the view for redraw.
|
||||
func renderStartTimer(_ vm: RenderVM) {
|
||||
let timer = Timer(timeInterval: 1.0 / RENDER_FPS, repeats: true) { [weak vm] _ in
|
||||
guard let vm else { return }
|
||||
renderDraw(vm)
|
||||
}
|
||||
vm.timer = timer
|
||||
// .common keeps rendering alive while the user holds a control.
|
||||
RunLoop.main.add(timer, forMode: .common)
|
||||
}
|
||||
|
||||
func renderDeinit(_ vm: RenderVM) {
|
||||
vm.timer?.invalidate()
|
||||
vm.timer = nil
|
||||
raybri_shutdown()
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#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: <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;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
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) {}
|
||||
@@ -0,0 +1,58 @@
|
||||
import UIKit
|
||||
|
||||
// UIView counterpart of the macOS RenderGLView. UIKit never draws into it: the
|
||||
// EGL/ANGLE surface renders directly into this view's layer, and the timer in
|
||||
// RenderVM presents a new frame. The view only reports when it gains a window
|
||||
// and when its backing size changes.
|
||||
final class RenderGLView: UIView {
|
||||
private weak var renderVM: RenderVM?
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
isOpaque = true
|
||||
// Touch handling is not wired to raylib yet, so keep the GL view
|
||||
// transparent to the SwiftUI hierarchy above it.
|
||||
isUserInteractionEnabled = false
|
||||
|
||||
contentScaleFactor = UIScreen.main.scale
|
||||
layer.contentsScale = contentScaleFactor
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func didMoveToWindow() {
|
||||
super.didMoveToWindow()
|
||||
|
||||
guard let window else { return }
|
||||
contentScaleFactor = window.screen.nativeScale
|
||||
layer.contentsScale = contentScaleFactor
|
||||
|
||||
guard let vm = RenderVM.shared, !vm.didPrepareGL else { return }
|
||||
guard renderInit(vm) else { return }
|
||||
|
||||
renderVM = vm
|
||||
vm.didPrepareGL = true
|
||||
vm.pixelSize = renderPixelSize(self)
|
||||
renderStartTimer(vm)
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
guard let vm = renderVM, vm.didPrepareGL else { return }
|
||||
|
||||
let size = renderPixelSize(self)
|
||||
guard size != vm.pixelSize else { return }
|
||||
|
||||
vm.pixelSize = size
|
||||
raybri_resize(size[0], size[1])
|
||||
}
|
||||
|
||||
deinit {
|
||||
guard let vm = renderVM, vm.didPrepareGL else { return }
|
||||
renderDeinit(vm)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import SwiftUI
|
||||
|
||||
struct RenderView: UIViewRepresentable {
|
||||
func makeUIView(context: Context) -> RenderGLView {
|
||||
RenderVM.shared!.glView
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: RenderGLView, context: Context) {}
|
||||
}
|
||||
File renamed without changes.
@@ -1,7 +1,6 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
/// Render view for SwiftUI
|
||||
struct RenderView: NSViewRepresentable {
|
||||
func makeNSView(context: Context) -> RenderGLView {
|
||||
RenderVM.shared!.glView
|
||||
|
||||
@@ -1,27 +1,5 @@
|
||||
// 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;
|
||||
let RENDER_SHADER_MAIN_FS = """
|
||||
#version 150
|
||||
|
||||
in vec3 vWorldPos;
|
||||
in vec3 vNormal;
|
||||
@@ -138,13 +116,8 @@ void main()
|
||||
}
|
||||
"""
|
||||
|
||||
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%
|
||||
let RENDER_SHADER_MAIN_VS = """
|
||||
#version 150
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
@@ -169,14 +142,8 @@ void main()
|
||||
}
|
||||
"""
|
||||
|
||||
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;
|
||||
let RENDER_SHADER_SHADOW_FS = """
|
||||
#version 150
|
||||
out vec4 finalColor;
|
||||
void main()
|
||||
{
|
||||
@@ -184,13 +151,8 @@ void main()
|
||||
}
|
||||
"""
|
||||
|
||||
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%
|
||||
let RENDER_SHADER_SHADOW_VS = """
|
||||
#version 150
|
||||
in vec3 vertexPosition;
|
||||
uniform mat4 mvp;
|
||||
void main()
|
||||
@@ -198,8 +160,3 @@ 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
|
||||
)
|
||||
@@ -20,48 +20,3 @@ ChkgfxContext:
|
||||
fields:
|
||||
didLaunch: Bool
|
||||
didSetup: Bool
|
||||
|
||||
RenderContext:
|
||||
type: context
|
||||
fields:
|
||||
backingPixelSize: [Int32]
|
||||
didLaunch: Bool
|
||||
didPrepareGL: Bool
|
||||
didSetup: Bool
|
||||
pixelSize: [Int32]
|
||||
reshapePixelSize: [Int32]
|
||||
willDeinit: Bool
|
||||
|
||||
RenderComponent:
|
||||
type: component
|
||||
oneliners:
|
||||
- didPrepareGL: renderInit(RenderVM.shared!)
|
||||
- didPrepareGL: RenderVM.shared!.didPrepareGL = true
|
||||
- didPrepareGL: renderStartTimer(RenderVM.shared!)
|
||||
- didPrepareGL: renderLoadCubeModel(RenderVM.shared!)
|
||||
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
|
||||
- willDeinit: renderDeinit(RenderVM.shared!)
|
||||
shoulds:
|
||||
didLaunch:
|
||||
1. Only once during the first setup:
|
||||
if:
|
||||
c.recentField == F.didSetup &&
|
||||
c.didLaunch == false
|
||||
then:
|
||||
c.didLaunch = true
|
||||
pixelSize:
|
||||
1. Upon launch:
|
||||
if:
|
||||
c.recentField == F.didLaunch
|
||||
then:
|
||||
c.pixelSize = [1, 1]
|
||||
2. Upon resize:
|
||||
if:
|
||||
c.recentField == F.reshapePixelSize
|
||||
then:
|
||||
c.pixelSize = c.reshapePixelSize
|
||||
3. Upon DPI change:
|
||||
if:
|
||||
c.recentField == F.backingPixelSize
|
||||
then:
|
||||
c.pixelSize = c.backingPixelSize
|
||||
@@ -18,23 +18,6 @@
|
||||
<string>1</string>
|
||||
<key>UILaunchScreen</key>
|
||||
<dict/>
|
||||
<key>UIApplicationSceneManifest</key>
|
||||
<dict>
|
||||
<key>UIApplicationSupportsMultipleScenes</key>
|
||||
<false/>
|
||||
<key>UISceneConfigurations</key>
|
||||
<dict>
|
||||
<key>UIWindowSceneSessionRoleApplication</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>UISceneConfigurationName</key>
|
||||
<string>Default Configuration</string>
|
||||
<key>UISceneDelegateClassName</key>
|
||||
<string>SceneDelegate</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
|
||||
@@ -10,72 +10,26 @@ targets:
|
||||
- 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
|
||||
- path: ../../components/raybri/ios
|
||||
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
|
||||
SWIFT_OBJC_BRIDGING_HEADER: ../../components/raybri/ios/RaybriIOS-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/raybri/ios"
|
||||
- "$(SRCROOT)/../../components/render/ios"
|
||||
- "$(SRCROOT)/Frameworks/include"
|
||||
- "$(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 <bundle>/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"
|
||||
@@ -0,0 +1,20 @@
|
||||
import UIKit
|
||||
|
||||
final class AppDelegate:
|
||||
NSObject,
|
||||
UIApplicationDelegate
|
||||
{
|
||||
let chkgfx = ChkgfxComponent()
|
||||
let chkgfxVM = ChkgfxVM()
|
||||
let renderVM = RenderVM()
|
||||
|
||||
func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
||||
) -> Bool {
|
||||
otherSetupConsoleLogging(chkgfx.ctrl, "Chkgfx")
|
||||
chkgfx.setup()
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct ChkgfxApp: App {
|
||||
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ZStack {
|
||||
RenderView()
|
||||
.ignoresSafeArea()
|
||||
ChkgfxView(appDelegate.chkgfxVM)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
../../../../components/chkgfx/chkgfx.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../components/chkgfx/chkgfxVM.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/chkgfx/ios/view/ChkgfxView.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../components/other/other.swift
|
||||
@@ -119,13 +119,8 @@ func registerOneliners<T>(
|
||||
|
||||
// Context field names for static type check
|
||||
public struct F {
|
||||
public static let backingPixelSize = "backingPixelSize"
|
||||
public static let didLaunch = "didLaunch"
|
||||
public static let didPrepareGL = "didPrepareGL"
|
||||
public static let didSetup = "didSetup"
|
||||
public static let pixelSize = "pixelSize"
|
||||
public static let reshapePixelSize = "reshapePixelSize"
|
||||
public static let willDeinit = "willDeinit"
|
||||
|
||||
}
|
||||
public struct ChkgfxContext: DialectContext {
|
||||
@@ -159,72 +154,6 @@ public struct ChkgfxContext: DialectContext {
|
||||
}
|
||||
}
|
||||
|
||||
public struct RenderContext: DialectContext {
|
||||
public var backingPixelSize = [Int32]()
|
||||
public var didLaunch = Bool()
|
||||
public var didPrepareGL = Bool()
|
||||
public var didSetup = Bool()
|
||||
public var pixelSize = [Int32]()
|
||||
public var reshapePixelSize = [Int32]()
|
||||
public var willDeinit = Bool()
|
||||
|
||||
public var recentField = ""
|
||||
|
||||
public func field<T>(_ name: String) -> T {
|
||||
if (name == "backingPixelSize") {
|
||||
return backingPixelSize as! T
|
||||
}
|
||||
else if (name == "didLaunch") {
|
||||
return didLaunch as! T
|
||||
}
|
||||
else if (name == "didPrepareGL") {
|
||||
return didPrepareGL as! T
|
||||
}
|
||||
else if (name == "didSetup") {
|
||||
return didSetup as! T
|
||||
}
|
||||
else if (name == "pixelSize") {
|
||||
return pixelSize as! T
|
||||
}
|
||||
else if (name == "reshapePixelSize") {
|
||||
return reshapePixelSize as! T
|
||||
}
|
||||
else if (name == "willDeinit") {
|
||||
return willDeinit as! T
|
||||
}
|
||||
|
||||
return "unknown-field-name" as! T
|
||||
}
|
||||
|
||||
public mutating func setField(
|
||||
_ name: String,
|
||||
_ value: Any
|
||||
) {
|
||||
if (name == "backingPixelSize") {
|
||||
backingPixelSize = value as! [Int32]
|
||||
}
|
||||
else if (name == "didLaunch") {
|
||||
didLaunch = value as! Bool
|
||||
}
|
||||
else if (name == "didPrepareGL") {
|
||||
didPrepareGL = value as! Bool
|
||||
}
|
||||
else if (name == "didSetup") {
|
||||
didSetup = value as! Bool
|
||||
}
|
||||
else if (name == "pixelSize") {
|
||||
pixelSize = value as! [Int32]
|
||||
}
|
||||
else if (name == "reshapePixelSize") {
|
||||
reshapePixelSize = value as! [Int32]
|
||||
}
|
||||
else if (name == "willDeinit") {
|
||||
willDeinit = value as! Bool
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public func chkgfxSet(
|
||||
_ key: String,
|
||||
_ value: Any
|
||||
@@ -232,13 +161,6 @@ public func chkgfxSet(
|
||||
ChkgfxComponent.singleton!.ctrl.set(key, value)
|
||||
}
|
||||
|
||||
public func renderSet(
|
||||
_ key: String,
|
||||
_ value: Any
|
||||
) {
|
||||
RenderComponent.singleton!.ctrl.set(key, value)
|
||||
}
|
||||
|
||||
func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext {
|
||||
var c = c
|
||||
|
||||
@@ -257,59 +179,6 @@ func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext {
|
||||
return c
|
||||
}
|
||||
|
||||
func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext {
|
||||
var c = c
|
||||
|
||||
/* 1. Only once during the first setup */
|
||||
if
|
||||
c.recentField == F.didSetup &&
|
||||
c.didLaunch == false
|
||||
{
|
||||
c.didLaunch = true
|
||||
c.recentField = F.didLaunch
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||
return c
|
||||
}
|
||||
|
||||
func renderShouldResetPixelSize(_ c: RenderContext) -> RenderContext {
|
||||
var c = c
|
||||
|
||||
/* 1. Upon launch */
|
||||
if
|
||||
c.recentField == F.didLaunch
|
||||
{
|
||||
c.pixelSize = [1, 1]
|
||||
c.recentField = F.pixelSize
|
||||
return c
|
||||
}
|
||||
|
||||
/* 2. Upon resize */
|
||||
if
|
||||
c.recentField == F.reshapePixelSize
|
||||
{
|
||||
c.pixelSize = c.reshapePixelSize
|
||||
c.recentField = F.pixelSize
|
||||
return c
|
||||
}
|
||||
|
||||
/* 3. Upon DPI change */
|
||||
if
|
||||
c.recentField == F.backingPixelSize
|
||||
{
|
||||
c.pixelSize = c.backingPixelSize
|
||||
c.recentField = F.pixelSize
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||
return c
|
||||
}
|
||||
|
||||
func chkgfxRegisterShoulds(_ ctrl: DialectController) {
|
||||
[
|
||||
chkgfxShouldResetDidLaunch,
|
||||
@@ -318,25 +187,3 @@ func chkgfxRegisterShoulds(_ ctrl: DialectController) {
|
||||
ctrl.registerFunction { c in f(c as! ChkgfxContext) }
|
||||
}
|
||||
}
|
||||
|
||||
func renderRegisterShoulds(_ ctrl: DialectController) {
|
||||
[
|
||||
renderShouldResetDidLaunch,
|
||||
renderShouldResetPixelSize,
|
||||
|
||||
].forEach { f in
|
||||
ctrl.registerFunction { c in f(c as! RenderContext) }
|
||||
}
|
||||
}
|
||||
|
||||
func renderRegisterEffects(_ ctrl: DialectController) {
|
||||
let _: RenderContext? = registerOneliners(ctrl, [
|
||||
F.didPrepareGL, { (c: RenderContext) in renderInit(RenderVM.shared!) },
|
||||
F.didPrepareGL, { (c: RenderContext) in RenderVM.shared!.didPrepareGL = true },
|
||||
F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
|
||||
F.didPrepareGL, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) },
|
||||
F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
|
||||
F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) },
|
||||
|
||||
])
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
../../../../components/render/renderAux.swift
|
||||
../../../../components/render/mac/renderAux.swift
|
||||
@@ -1 +1 @@
|
||||
../../../../components/render/renderAux.swift
|
||||
../../../../components/render/mac/renderAux.swift
|
||||
+27
-6
@@ -5,17 +5,28 @@ 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.
|
||||
# iOS rendering goes through ghera/raylib-iOS: a raylib fork that renders
|
||||
# OpenGL ES via ANGLE (Metal backend). Its stable releases ship prebuilt
|
||||
# xcframeworks (raylib + libEGL + libGLESv2, ~46 MB), so they are downloaded
|
||||
# on demand and never committed.
|
||||
#
|
||||
# Unlike the fork's own app, ver-ios does not link raylib.xcframework (its
|
||||
# rcore.o defines main() and a private view controller). We only use its
|
||||
# headers: raylib's renderer (rlgl) is compiled into components/raybri/ios,
|
||||
# and EGL/ANGLE provides the GL context.
|
||||
RAYLIB_IOS_TAG=6.0.7-iOS
|
||||
FRAMEWORKS=$SDIR/../$TARGET/ver-ios/Frameworks
|
||||
if [[ ! -d "$FRAMEWORKS/raylib.xcframework" ]]; then
|
||||
|
||||
MISSING=0
|
||||
for FRAMEWORK in raylib libEGL libGLESv2; do
|
||||
[[ -d "$FRAMEWORKS/$FRAMEWORK.xcframework" ]] || MISSING=1
|
||||
done
|
||||
|
||||
if [[ $MISSING -eq 1 ]]; then
|
||||
echo "Raylib iOS xcframeworks missing, downloading $RAYLIB_IOS_TAG..."
|
||||
mkdir -p "$FRAMEWORKS"
|
||||
TMP=$(mktemp -d)
|
||||
curl -sL -o "$TMP/raylib-ios.zip" \
|
||||
curl -sL --retry 3 -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/"
|
||||
@@ -24,5 +35,15 @@ if [[ ! -d "$FRAMEWORKS/raylib.xcframework" ]]; then
|
||||
rm -rf "$TMP"
|
||||
fi
|
||||
|
||||
# The ANGLE headers are shipped as framework Headers directories but their
|
||||
# internal includes expect the `libEGL/...` and `libGLESv2/...` layout, so
|
||||
# stage symlinks for the header search path. The headers are identical for
|
||||
# device and simulator, so one slice is enough.
|
||||
mkdir -p "$FRAMEWORKS/include"
|
||||
ln -sfn "../libEGL.xcframework/ios-arm64_x86_64-simulator/libEGL.framework/Headers" \
|
||||
"$FRAMEWORKS/include/libEGL"
|
||||
ln -sfn "../libGLESv2.xcframework/ios-arm64_x86_64-simulator/libGLESv2.framework/Headers" \
|
||||
"$FRAMEWORKS/include/libGLESv2"
|
||||
|
||||
cd $SDIR/../$TARGET/ver-ios
|
||||
xcodegen
|
||||
Reference in new issue
Block a user