mid smth
This commit is contained in:
1 parent
7a0a09c2a1
commit
0af2d75754
18 files changed
+509
-37
No files matched your search
@@ -9,3 +9,5 @@ gradle-daemon-jvm.properties
|
|||||||
local.properties
|
local.properties
|
||||||
Package.resolved
|
Package.resolved
|
||||||
*.xcodeproj
|
*.xcodeproj
|
||||||
|
Frameworks
|
||||||
|
raylib-src
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef OTHER_BRIDGING_HEADER_H
|
||||||
|
#define OTHER_BRIDGING_HEADER_H
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <QuartzCore/QuartzCore.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -4,12 +4,15 @@
|
|||||||
#include "rlgl.h"
|
#include "rlgl.h"
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#if !defined(PLATFORM_IOS)
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static int sr_width = 1;
|
static int sr_width = 1;
|
||||||
static int sr_height = 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_start = -1;
|
||||||
static int loc_fog_end = -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
|
// 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
|
// call InitWindow(). Instead we render into an OpenGL context owned by the
|
||||||
// macOS app, so we must supply the OpenGL entry point loader ourselves.
|
// 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;
|
if (handle == NULL) return NULL;
|
||||||
return dlsym(handle, name);
|
return dlsym(handle, name);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Compose a model transform exactly like raylib's DrawModel() does, so the
|
// Compose a model transform exactly like raylib's DrawModel() does, so the
|
||||||
// matrices we feed to DrawMesh() match what rlgl computes internally.
|
// 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.
|
// raylib's default INFO logging is noisy; keep warnings and errors only.
|
||||||
SetTraceLogLevel(LOG_WARNING);
|
SetTraceLogLevel(LOG_WARNING);
|
||||||
|
|
||||||
|
#if !defined(PLATFORM_IOS)
|
||||||
rlLoadExtensions((void *)sr_gl_loader);
|
rlLoadExtensions((void *)sr_gl_loader);
|
||||||
// Init with default 1x1 size
|
// Init with default 1x1 size
|
||||||
rlglInit(1, 1);
|
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_load_shaders(main_vs, main_fs, shadow_vs, shadow_fs);
|
||||||
sr_config_shaders();
|
sr_config_shaders();
|
||||||
@@ -216,6 +226,9 @@ void raybri_load_model(const char *gltf_path)
|
|||||||
|
|
||||||
if (sr_has_model)
|
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;
|
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 = sr_model.materials[cube_mat_index];
|
||||||
sr_cube_material.shader = sr_main_shader;
|
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_main_shader.id > 0) UnloadShader(sr_main_shader);
|
||||||
if (sr_shadow_shader.id > 0) UnloadShader(sr_shadow_shader);
|
if (sr_shadow_shader.id > 0) UnloadShader(sr_shadow_shader);
|
||||||
|
|
||||||
|
#if !defined(PLATFORM_IOS)
|
||||||
rlglClose();
|
rlglClose();
|
||||||
|
#endif
|
||||||
sr_ready = 0;
|
sr_ready = 0;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
// The prebuilt raylib iOS framework owns the app entry point (main()/
|
||||||
|
// AppDelegate/SceneDelegate in rcore_ios.c), so our SwiftUI @main shell is
|
||||||
|
// not used on iOS. Instead the C bridge calls rcios_present_overlay() from
|
||||||
|
// ios_ready(), and we stack a transparent window hosting ChkgfxView above
|
||||||
|
// raylib's window.
|
||||||
|
//
|
||||||
|
// 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()
|
||||||
|
}
|
||||||
|
|
||||||
|
@_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 }
|
||||||
|
|
||||||
|
let root = ChkgfxView(RenderIOS.chkgfxVM)
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
|
||||||
|
|
||||||
|
let hosting = UIHostingController(rootView: root)
|
||||||
|
hosting.view.backgroundColor = .clear
|
||||||
|
|
||||||
|
let overlay = UIWindow(windowScene: scene)
|
||||||
|
overlay.rootViewController = hosting
|
||||||
|
overlay.backgroundColor = .clear
|
||||||
|
overlay.windowLevel = .alert + 1
|
||||||
|
overlay.isUserInteractionEnabled = false
|
||||||
|
overlay.isHidden = false
|
||||||
|
|
||||||
|
OverlayWindow.retained = overlay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UIWindow is not retained by UIKit once we drop our reference, so hold it.
|
||||||
|
private enum OverlayWindow {
|
||||||
|
static var retained: UIWindow?
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
#ifndef OGS_CHKGFX_RENDER_CONST_SHADER_IOS_H
|
||||||
|
#define OGS_CHKGFX_RENDER_CONST_SHADER_IOS_H
|
||||||
|
|
||||||
|
// OpenGL ES 3.0 (GLSL ES 3.00) shaders for the iOS build. They mirror the
|
||||||
|
// macOS GLSL 150 sources in renderConstShader.swift, with the desktop-only
|
||||||
|
// bits replaced:
|
||||||
|
// - "#version 150" -> "#version 300 es"
|
||||||
|
// - fragment shaders need an explicit float precision qualifier
|
||||||
|
// raylib's LoadShaderFromMemory() passes the code straight to
|
||||||
|
// glShaderSource(), so the version/precision lines must live here.
|
||||||
|
//
|
||||||
|
// They live in C (not Swift) because the iOS bridge
|
||||||
|
// (components/render/ios/renderIOS.mm) feeds them to raybri_init() directly.
|
||||||
|
|
||||||
|
static const char RENDER_SHADER_MAIN_FS[] =
|
||||||
|
"#version 300 es\n"
|
||||||
|
"precision highp float;\n"
|
||||||
|
"in vec3 vWorldPos;\n"
|
||||||
|
"in vec3 vNormal;\n"
|
||||||
|
"in vec2 vTexCoord;\n"
|
||||||
|
"in vec4 vLightClip;\n"
|
||||||
|
"uniform sampler2D texture0;\n"
|
||||||
|
"uniform sampler2D u_normalMap;\n"
|
||||||
|
"uniform float u_normalStrength;\n"
|
||||||
|
"uniform sampler2D u_shadowMap;\n"
|
||||||
|
"uniform vec3 u_lightPos;\n"
|
||||||
|
"uniform vec3 u_lightColor;\n"
|
||||||
|
"uniform vec3 u_ambient;\n"
|
||||||
|
"uniform vec3 u_albedoColor;\n"
|
||||||
|
"uniform float u_lightEnabled;\n"
|
||||||
|
"uniform float u_emissive;\n"
|
||||||
|
"uniform float u_shadowBias;\n"
|
||||||
|
"uniform float u_shadowSoftness;\n"
|
||||||
|
"uniform float u_isGround;\n"
|
||||||
|
"uniform vec3 u_gridColor;\n"
|
||||||
|
"uniform vec3 u_cameraPos;\n"
|
||||||
|
"uniform vec3 u_fogColor;\n"
|
||||||
|
"uniform float u_fogStart;\n"
|
||||||
|
"uniform float u_fogEnd;\n"
|
||||||
|
"out vec4 finalColor;\n"
|
||||||
|
"bool isPixelInShadowMap(vec3 proj)\n"
|
||||||
|
"{\n"
|
||||||
|
" return proj.x >= 0.0 && proj.x <= 1.0 &&\n"
|
||||||
|
" proj.y >= 0.0 && proj.y <= 1.0 &&\n"
|
||||||
|
" proj.z >= 0.0 && proj.z <= 1.0;\n"
|
||||||
|
"}\n"
|
||||||
|
"float shadowFactor()\n"
|
||||||
|
"{\n"
|
||||||
|
" vec3 proj = vLightClip.xyz / vLightClip.w;\n"
|
||||||
|
" proj = proj * 0.5 + 0.5;\n"
|
||||||
|
" if (!isPixelInShadowMap(proj)) return 0.0;\n"
|
||||||
|
" int radius = int(u_shadowSoftness);\n"
|
||||||
|
" vec2 texel = 1.0 / vec2(textureSize(u_shadowMap, 0));\n"
|
||||||
|
" float sum = 0.0;\n"
|
||||||
|
" float count = 0.0;\n"
|
||||||
|
" for (int x = -radius; x <= radius; x++)\n"
|
||||||
|
" {\n"
|
||||||
|
" for (int y = -radius; y <= radius; y++)\n"
|
||||||
|
" {\n"
|
||||||
|
" float d = texture(u_shadowMap, proj.xy + vec2(float(x), float(y)) * texel).r;\n"
|
||||||
|
" sum += (proj.z - u_shadowBias > d) ? 1.0 : 0.0;\n"
|
||||||
|
" count += 1.0;\n"
|
||||||
|
" }\n"
|
||||||
|
" }\n"
|
||||||
|
" return sum / count;\n"
|
||||||
|
"}\n"
|
||||||
|
"mat3 cotangentFrame(vec3 N, vec3 p, vec2 uv)\n"
|
||||||
|
"{\n"
|
||||||
|
" vec3 dp1 = dFdx(p);\n"
|
||||||
|
" vec3 dp2 = dFdy(p);\n"
|
||||||
|
" vec2 duv1 = dFdx(uv);\n"
|
||||||
|
" vec2 duv2 = dFdy(uv);\n"
|
||||||
|
" vec3 dp2perp = cross(dp2, N);\n"
|
||||||
|
" vec3 dp1perp = cross(N, dp1);\n"
|
||||||
|
" vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n"
|
||||||
|
" vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n"
|
||||||
|
" float invmax = inversesqrt(max(dot(T, T), dot(B, B)));\n"
|
||||||
|
" return mat3(T * invmax, B * invmax, N);\n"
|
||||||
|
"}\n"
|
||||||
|
"void main()\n"
|
||||||
|
"{\n"
|
||||||
|
" vec4 texel = texture(texture0, vTexCoord);\n"
|
||||||
|
" vec3 albedo = texel.rgb * u_albedoColor;\n"
|
||||||
|
" vec3 N = normalize(vNormal);\n"
|
||||||
|
" if (u_normalStrength > 0.0)\n"
|
||||||
|
" {\n"
|
||||||
|
" vec3 nm = texture(u_normalMap, vTexCoord).rgb * 2.0 - 1.0;\n"
|
||||||
|
" nm.xy *= u_normalStrength;\n"
|
||||||
|
" N = normalize(cotangentFrame(N, vWorldPos, vTexCoord) * nm);\n"
|
||||||
|
" }\n"
|
||||||
|
" if (u_isGround > 0.5)\n"
|
||||||
|
" {\n"
|
||||||
|
" vec2 uv = vWorldPos.xz;\n"
|
||||||
|
" vec2 gg = abs(fract(uv - 0.5) - 0.5) / fwidth(uv);\n"
|
||||||
|
" float line = min(gg.x, gg.y);\n"
|
||||||
|
" float grid = 1.0 - min(line, 1.0);\n"
|
||||||
|
" albedo = mix(albedo, u_gridColor, grid * 0.7);\n"
|
||||||
|
" }\n"
|
||||||
|
" vec3 color = albedo * u_ambient;\n"
|
||||||
|
" if (u_lightEnabled > 0.5)\n"
|
||||||
|
" {\n"
|
||||||
|
" vec3 toLight = u_lightPos - vWorldPos;\n"
|
||||||
|
" float dist = length(toLight);\n"
|
||||||
|
" vec3 L = toLight / max(dist, 0.0001);\n"
|
||||||
|
" float diff = max(dot(N, L), 0.0);\n"
|
||||||
|
" float attenuation = 1.0 / (1.0 + 0.14 * dist + 0.07 * dist * dist);\n"
|
||||||
|
" float shadow = shadowFactor();\n"
|
||||||
|
" color += albedo * u_lightColor * diff * attenuation * (1.0 - shadow);\n"
|
||||||
|
" }\n"
|
||||||
|
" color += albedo * u_emissive;\n"
|
||||||
|
" float fogDist = length(u_cameraPos - vWorldPos);\n"
|
||||||
|
" float fog = clamp((fogDist - u_fogStart) / (u_fogEnd - u_fogStart), 0.0, 1.0);\n"
|
||||||
|
" color = mix(color, u_fogColor, fog);\n"
|
||||||
|
" finalColor = vec4(color, 1.0);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
static const char RENDER_SHADER_MAIN_VS[] =
|
||||||
|
"#version 300 es\n"
|
||||||
|
"in vec3 vertexPosition;\n"
|
||||||
|
"in vec2 vertexTexCoord;\n"
|
||||||
|
"in vec3 vertexNormal;\n"
|
||||||
|
"uniform mat4 mvp;\n"
|
||||||
|
"uniform mat4 matModel;\n"
|
||||||
|
"uniform mat4 u_lightMVP;\n"
|
||||||
|
"out vec3 vWorldPos;\n"
|
||||||
|
"out vec3 vNormal;\n"
|
||||||
|
"out vec2 vTexCoord;\n"
|
||||||
|
"out vec4 vLightClip;\n"
|
||||||
|
"void main()\n"
|
||||||
|
"{\n"
|
||||||
|
" vec4 worldPos = matModel * vec4(vertexPosition, 1.0);\n"
|
||||||
|
" vWorldPos = worldPos.xyz;\n"
|
||||||
|
" vNormal = normalize(mat3(matModel) * vertexNormal);\n"
|
||||||
|
" vTexCoord = vertexTexCoord;\n"
|
||||||
|
" vLightClip = u_lightMVP * vec4(vertexPosition, 1.0);\n"
|
||||||
|
" gl_Position = mvp * vec4(vertexPosition, 1.0);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
static const char RENDER_SHADER_SHADOW_FS[] =
|
||||||
|
"#version 300 es\n"
|
||||||
|
"precision highp float;\n"
|
||||||
|
"out vec4 finalColor;\n"
|
||||||
|
"void main()\n"
|
||||||
|
"{\n"
|
||||||
|
" finalColor = vec4(1.0);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
static const char RENDER_SHADER_SHADOW_VS[] =
|
||||||
|
"#version 300 es\n"
|
||||||
|
"in vec3 vertexPosition;\n"
|
||||||
|
"uniform mat4 mvp;\n"
|
||||||
|
"void main()\n"
|
||||||
|
"{\n"
|
||||||
|
" gl_Position = mvp * vec4(vertexPosition, 1.0);\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
@@ -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) {}
|
||||||
@@ -18,6 +18,23 @@
|
|||||||
<string>1</string>
|
<string>1</string>
|
||||||
<key>UILaunchScreen</key>
|
<key>UILaunchScreen</key>
|
||||||
<dict/>
|
<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>
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
<array>
|
<array>
|
||||||
<string>UIInterfaceOrientationPortrait</string>
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
|
|||||||
@@ -5,10 +5,76 @@ targets:
|
|||||||
ogs-chkgfx:
|
ogs-chkgfx:
|
||||||
type: application
|
type: application
|
||||||
platform: iOS
|
platform: iOS
|
||||||
deploymentTarget: "15.0"
|
deploymentTarget: "15.6"
|
||||||
sources:
|
sources:
|
||||||
- path: Assets.xcassets
|
- path: Assets.xcassets
|
||||||
- path: src
|
- path: src
|
||||||
|
- path: ../../components/render/ios
|
||||||
|
- 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:
|
settings:
|
||||||
base:
|
base:
|
||||||
INFOPLIST_FILE: Info.plist
|
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 <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"
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import UIKit
|
|
||||||
|
|
||||||
final class AppDelegate:
|
|
||||||
NSObject,
|
|
||||||
UIApplicationDelegate
|
|
||||||
{
|
|
||||||
let chkgfx = ChkgfxComponent()
|
|
||||||
let chkgfxVM = ChkgfxVM()
|
|
||||||
|
|
||||||
func application(
|
|
||||||
_ application: UIApplication,
|
|
||||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
|
||||||
) -> Bool {
|
|
||||||
otherSetupConsoleLogging(chkgfx.ctrl, "Chkgfx")
|
|
||||||
chkgfx.setup()
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
|
|
||||||
@main
|
|
||||||
struct ChkgfxApp: App {
|
|
||||||
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
|
|
||||||
|
|
||||||
var body: some Scene {
|
|
||||||
WindowGroup {
|
|
||||||
ChkgfxView(appDelegate.chkgfxVM)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../components/chkgfx/chkgfx.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../components/chkgfx/chkgfxVM.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../../components/chkgfx/ios/view/ChkgfxView.swift
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../../../components/other/other.swift
|
|
||||||
Executable
+14
@@ -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
|
||||||
Executable
+26
@@ -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"
|
||||||
@@ -5,5 +5,24 @@ TARGET=$1
|
|||||||
STEP=$((STEP+1))
|
STEP=$((STEP+1))
|
||||||
echo -e "\n> > > > Step №$STEP. Generate iOS project for '$TARGET'"
|
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
|
cd $SDIR/../$TARGET/ver-ios
|
||||||
xcodegen
|
xcodegen
|
||||||
Reference in new issue
Block a user