Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b556a4a58 | ||
|
|
37c4e6f442 |
No files matched your search
@@ -9,4 +9,3 @@ gradle-daemon-jvm.properties
|
|||||||
local.properties
|
local.properties
|
||||||
Package.resolved
|
Package.resolved
|
||||||
*.xcodeproj
|
*.xcodeproj
|
||||||
Frameworks
|
|
||||||
@@ -1,218 +1,120 @@
|
|||||||
# OGS Mahjong (`mj`)
|
# OGS applications (`mj`)
|
||||||
|
|
||||||
A macOS SwiftUI app for **OGS Mahjong**, built on the **Dialect v4** declarative
|
Native SwiftUI applications using the Dialect v4 declarative reactive engine.
|
||||||
reactive engine (see the sibling `../dialect` repo — this project is a
|
Version: `2.0.0`. Remote: `https://git.opengamestudio.org/mahjong/mahjong`.
|
||||||
downstream consumer of its code generator).
|
|
||||||
|
|
||||||
Business logic lives in `dialect.yml` (YAML). A generator turns it into
|
## Current status
|
||||||
`game/ver-mac/src/dialect.swift` (the runtime engine + `struct F` field
|
|
||||||
constants + component/should/effect registration). The Swift app shell
|
|
||||||
(`GameApp`/`AppDelegate`) and the SwiftUI views live outside the generated file
|
|
||||||
and talk to the engine through generated functions like `rootSet(...)`.
|
|
||||||
|
|
||||||
Remote: `https://git.opengamestudio.org/mahjong/mahjong` · Version: `2.0.0`
|
- `ogs-blue/` is the active minimal graphics example for macOS and iOS: a solid
|
||||||
|
blue raylib background with a SwiftUI overlay. It has no model/texture/shadow
|
||||||
|
scene; rlgl still creates its default internal GPU resources.
|
||||||
|
- `ogs-mahjong/` contains the macOS Mahjong scaffold and counter-template logic;
|
||||||
|
Mahjong gameplay has not been implemented.
|
||||||
|
- `ogs-chkgfx/` is a companion graphics scaffold with macOS/iOS project files.
|
||||||
|
Older targets can lag behind shared-component changes; verify each target
|
||||||
|
separately before claiming it builds.
|
||||||
|
- The previous `game/ver-mac` and root `dialect.yml` layout is obsolete.
|
||||||
|
|
||||||
> `dialect.yml` is still the "Root / counter" template with a `Render` context
|
## Source layout
|
||||||
> bolted on: the Mahjong game logic has not been written yet. The app shell,
|
|
||||||
> packaging, symlink wiring and the raylib renderer are in place.
|
|
||||||
|
|
||||||
## Structure
|
- `<app>/dialect.yml`: per-application logic; generates
|
||||||
|
`<app>/ver-mac/src/dialect.swift`. Blue iOS links to its macOS generated file.
|
||||||
|
- `components/`: shared source of truth. App `src/` files use relative symlinks;
|
||||||
|
edit real component files and preserve symlink parity.
|
||||||
|
- `components/render/`: shared component/model/constants, plus mirrored `ios/`
|
||||||
|
and `mac/` effects, helpers and native/SwiftUI views. macOS additionally has
|
||||||
|
`renderConstMac.swift` for native pixel-format attributes.
|
||||||
|
- `components/raybri/raybri.h`: declarations plus implementation gated by
|
||||||
|
`RAYBRI_IMPLEMENTATION`; clears blue, renders and shuts down rlgl.
|
||||||
|
- `components/raybri/raybriConst.h`: shared constants with an implementation macro.
|
||||||
|
`components/raybri/mac/raybriAux.h`: macOS OpenGL symbol loader.
|
||||||
|
- `components/egl/egl.h` and `eglConst.h`: EGL state/helpers and configuration,
|
||||||
|
using single-header implementation macros.
|
||||||
|
- `ogs-blue/ver-{mac,ios}/src/Blue.c`: platform C implementation translation units.
|
||||||
|
- `history/gitjs/`: historical JavaScript Mahjong reference, outside the build.
|
||||||
|
`ref/swiftraylib` links to the sibling renderer sample.
|
||||||
|
|
||||||
```
|
## Graphics ownership and platform differences
|
||||||
dialect.yml Single source of truth for the reactive logic.
|
|
||||||
Generates game/ver-mac/src/dialect.swift
|
|
||||||
|
|
||||||
components/ SHARED source-of-truth for all components.
|
Every GPU operation requires its context current on the calling thread.
|
||||||
other/other.swift Shared helpers (otherPrintStderr, otherWriteFile,
|
`rlLoadExtensions` also requires an existing current context; it precedes
|
||||||
otherSetupConsoleLogging, ...)
|
`rlglInit`, not native context creation.
|
||||||
raybri/raybri.h C API of the raylib bridge (raybri_config, raybri_init,
|
|
||||||
raybri_load_model, raybri_resize, raybri_set_rotation,
|
|
||||||
raybri_render, raybri_shutdown); extern "C" guards.
|
|
||||||
raybri/raybri.c Bridge implementation: rlgl scene, shadow pass, shaders.
|
|
||||||
root/root.swift RootComponent (owns DialectController, registers
|
|
||||||
effects + shoulds, sets didSetup on setup())
|
|
||||||
root/rootVM.swift RootVM (ObservableObject / @Published countText)
|
|
||||||
root/mac/view/RootView.swift SwiftUI view: RenderView in a ZStack + UI
|
|
||||||
render/render.swift RenderComponent (controller, effects + shoulds)
|
|
||||||
render/renderVM.swift RenderVM (weak shared; glView, didPrepareGL,
|
|
||||||
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/renderAux.swift renderDraw(vm), renderPixelSize(view)
|
|
||||||
render/renderEffect.swift renderInit, renderLoadCubeModel,
|
|
||||||
renderStartTimer, renderDeinit
|
|
||||||
render/mac/view/RenderGLView.swift Thin NSOpenGLView: pixel format, callbacks
|
|
||||||
-> renderSet(...), draw -> renderDraw
|
|
||||||
render/mac/view/RenderView.swift NSViewRepresentable wrapper
|
|
||||||
|
|
||||||
game/ver-mac/ macOS app (SPM executable target "ogs-mahjong")
|
macOS uses `NSOpenGLView` (OpenGL 3.2 Core). `renderInit` makes its context
|
||||||
Package.swift SPM manifest (macOS 13+, swift-tools 5.9); C target
|
current, enables VSync, loads extensions with the C loader callback and starts
|
||||||
"RaylibBridge" (path src/raybri, publicHeadersPath ".") +
|
raylib. The timer requests `needsDisplay`; `draw(_:)` forwards to `renderDraw`,
|
||||||
links Homebrew raylib; the Swift target excludes raybri
|
which activates the context, renders and presents via `flushBuffer`.
|
||||||
and gets -Xcc -DGL_SILENCE_DEPRECATION
|
|
||||||
Info.plist Bundle id org.opengamestudio.Mahjong, exec ogs-mahjong
|
|
||||||
Resources/AppIcon.icns App icon
|
|
||||||
Resources/assets/ Bundled glTF assets: cube.gltf (static),
|
|
||||||
cube_texture.png, cube_normal.png
|
|
||||||
src/
|
|
||||||
GameApp.swift @main SwiftUI App entry
|
|
||||||
AppDelegate.swift Creates Render/Root components + VMs, calls setup()
|
|
||||||
dialect.swift GENERATED — do not hand-edit (see chicken-egg below)
|
|
||||||
other/other.swift -> symlink components/other/other.swift
|
|
||||||
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/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
|
|
||||||
render/renderVM.swift -> symlink components/render/renderVM.swift
|
|
||||||
render/view/RenderGLView.swift -> symlink components/render/mac/view/...
|
|
||||||
render/view/RenderView.swift -> symlink components/render/mac/view/...
|
|
||||||
root/root.swift -> symlink components/root/root.swift
|
|
||||||
root/rootVM.swift -> symlink components/root/rootVM.swift
|
|
||||||
root/view/RootView.swift -> symlink components/root/mac/view/...
|
|
||||||
|
|
||||||
ref/swiftraylib Symlink to ../../swiftraylib — the raylib/SwiftUI
|
Blue's SPM `RaylibBridge` target compiles `src/Blue.c`, exposes headers in
|
||||||
renderer sample the game will use for 3D rendering.
|
`src/raybri`, and links Homebrew raylib. It does NOT define
|
||||||
|
`RLGL_IMPLEMENTATION`: Homebrew headers omit the `external/glad.h` needed to
|
||||||
|
compile desktop rlgl locally. Swift imports `RaylibBridge`. `RAYLIB_PREFIX`
|
||||||
|
defaults to `/opt/homebrew`; build scripts detect `brew --prefix raylib`.
|
||||||
|
The installed raylib may produce a deployment-target linker warning.
|
||||||
|
|
||||||
util/ Build/run scripts (see Build & Run)
|
On iOS, UIKit owns the view/layer and `RenderGLView.st` owns an `EGLState`.
|
||||||
paths APP_MAC = .build/OGS Mahjong.app
|
Swift effects create EGL/ANGLE state and surface, make the context current,
|
||||||
build-mac generateDialect -> buildMac -> packageMac
|
and initialize raylib. Timer ticks call rendering directly; presentation uses
|
||||||
run-mac runMac
|
`eglSwapBuffers`. Pixel sizes come from view bounds and content scale.
|
||||||
rm-mac-geom Resets saved window geometry
|
Dialect's resize event triggers `renderRecreateSurface`; the macOS helper is
|
||||||
step/ Sourced steps: generateDialect, buildMac,
|
intentionally a no-op. Teardown must stop the timer, activate the context,
|
||||||
packageMac, runMac
|
release rlgl resources, then destroy EGL surface/context/display resources.
|
||||||
|
|
||||||
history/gitjs/ GitJS "Glavred" history + the original JS source of the
|
Blue iOS uses `src/BlueBridgingHeader.h` to expose C APIs to Swift. `Blue.c`
|
||||||
web Mahjong, kept for reference — not part of the build.
|
compiles EGL helpers and rlgl using their implementation macros exactly once.
|
||||||
|
It uses the raylib-iOS XCFramework headers but does not link its full raylib
|
||||||
|
library. The app links/embeds `libEGL` and `libGLESv2` (ANGLE's Metal backend).
|
||||||
|
The XcodeGen settings define `PLATFORM_IOS`, `GRAPHICS_API_OPENGL_ES3`, and
|
||||||
|
`GL_GLEXT_PROTOTYPES`. Minimum iOS is 15.0; portrait and both landscape
|
||||||
|
orientations are enabled in Blue's Info.plist.
|
||||||
|
|
||||||
|
## Build and prerequisites
|
||||||
|
|
||||||
|
- macOS: `brew install raylib`.
|
||||||
|
- iOS project generation: `brew install xcodegen`; supply sibling
|
||||||
|
`../raylib-ios-xcframeworks` containing raylib/libEGL/libGLESv2 XCFrameworks.
|
||||||
|
`checkRaylibIOS` checks presence; it does not download them.
|
||||||
|
- Dialect: sibling `../dialect`, built with `(cd ../dialect && util/build-generator)`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
util/build-ogs-blue-mac
|
||||||
|
util/run-ogs-blue-mac
|
||||||
|
util/prepare-ogs-blue-ios
|
||||||
```
|
```
|
||||||
|
|
||||||
## Symlink parity rule
|
The corresponding macOS build/run scripts also exist for `ogs-chkgfx` and
|
||||||
|
`ogs-mahjong`; `prepare-ogs-chkgfx-ios` exists as well. Inspect their individual
|
||||||
|
configuration before assuming parity with Blue.
|
||||||
|
|
||||||
`components/` is the source of truth; `game/ver-mac/src/` contains real
|
macOS build scripts generate Dialect, run `swift build`, and package resources
|
||||||
directories whose files are **relative symlinks** back into `components/`:
|
from `ver-mac/res/` into `ver-mac/.build/<App Name>.app`. iOS preparation checks
|
||||||
|
XCFrameworks, generates Dialect, stages ANGLE include/library symlinks in
|
||||||
|
`ver-ios/.build/`, then runs XcodeGen. Build Blue for Simulator with:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
src/other/other.swift -> ../../../../components/other/other.swift (4 up)
|
xcodebuild -project 'ogs-blue/ver-ios/OGS blue.xcodeproj' -scheme ogs-blue \
|
||||||
src/raybri/raybri.c -> ../../../../components/raybri/raybri.c (4 up)
|
-sdk iphonesimulator -destination 'generic/platform=iOS Simulator' \
|
||||||
src/raybri/raybri.h -> ../../../../components/raybri/raybri.h (4 up)
|
CODE_SIGNING_ALLOWED=NO build
|
||||||
src/render/render.swift -> ../../../../components/render/render.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)
|
|
||||||
src/render/renderVM.swift -> ../../../../components/render/renderVM.swift (4 up)
|
|
||||||
src/root/root.swift -> ../../../../components/root/root.swift (4 up)
|
|
||||||
src/root/rootVM.swift -> ../../../../components/root/rootVM.swift (4 up)
|
|
||||||
src/root/view/RootView.swift-> ../../../../../components/root/mac/view/RootView.swift (5 up)
|
|
||||||
src/render/view/RenderGLView.swift -> ../../../../../components/render/mac/view/RenderGLView.swift (5 up)
|
|
||||||
src/render/view/RenderView.swift -> ../../../../../components/render/mac/view/RenderView.swift (5 up)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
SPM silently **skips** a dangling symlink (no error), so after moving
|
Audit dangling source symlinks after moves (SPM can silently skip them):
|
||||||
`components/` or a subdir, audit for broken links:
|
|
||||||
|
|
||||||
```bash
|
```sh
|
||||||
find . -type l ! -exec test -e {} \; -not -path './.build/*'
|
find components ogs-blue ogs-chkgfx ogs-mahjong -type l ! -exec test -e {} \; -not -path '*/.build/*'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Prerequisite: the generator
|
|
||||||
|
|
||||||
`util/step/generateDialect` calls the **sibling** dialect repo:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$SDIR/../../dialect/util/run-generator --file=$SDIR/../dialect.yml
|
|
||||||
```
|
|
||||||
|
|
||||||
So `/Volumes/MOE/p/dialect` must exist and its generator must be built before
|
|
||||||
`util/build-mac` can regenerate:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
(cd ../dialect && util/build-generator) # once, or after dialect core changes
|
|
||||||
```
|
|
||||||
|
|
||||||
The generator resolves the `output:` path **relative to `dialect.yml`'s
|
|
||||||
directory**, which is why `dialect.yml` says `game/ver-mac/src/dialect.swift`.
|
|
||||||
|
|
||||||
## Prerequisite: raylib
|
|
||||||
|
|
||||||
The 3D scene links against Homebrew **raylib** (`brew install raylib`). The
|
|
||||||
`RaylibBridge` C target and the link step read `RAYLIB_PREFIX` (default
|
|
||||||
`/opt/homebrew`); `util/step/buildMac` auto-detects it via `brew --prefix raylib`.
|
|
||||||
The bridge renders with raylib's rlgl layer into an `NSOpenGLView` — raylib never
|
|
||||||
creates its own window. `RootView` puts `RenderView` (backed by `RenderGLView`)
|
|
||||||
behind the SwiftUI UI in a `ZStack`. A textured cube is drawn from `Resources/assets` (`cube.gltf` +
|
|
||||||
`cube_texture.png` + `cube_normal.png`); the app rotates it each frame via `raybri_set_rotation`.
|
|
||||||
(raylib's `LoadModelAnimations` only handles *skinned* meshes, so a plain
|
|
||||||
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.
|
|
||||||
|
|
||||||
## Render architecture
|
|
||||||
|
|
||||||
The `Render` dialect context owns the GL scene. `RenderGLView` is a thin
|
|
||||||
`NSOpenGLView`; it only translates AppKit callbacks into dialect fields, and the
|
|
||||||
`render*` files do the actual work.
|
|
||||||
|
|
||||||
1. `AppDelegate` creates `RenderComponent` + `RenderVM` and calls
|
|
||||||
`render.setup()` -> `didSetup` -> `didLaunch` (should) -> `pixelSize = [1, 1]`.
|
|
||||||
2. SwiftUI builds `RenderView` -> `RenderGLView`; `prepareOpenGL()` sets
|
|
||||||
`F.didPrepareGL`. Its oneliners run `renderInit` (`raybri_init`), set
|
|
||||||
`RenderVM.didPrepareGL = true`, and `renderStartTimer`.
|
|
||||||
3. `reshape()` / `viewDidChangeBackingProperties()` compute the backing pixel
|
|
||||||
size via `renderPixelSize` and set `F.reshapePixelSize` /
|
|
||||||
`F.backingPixelSize`. The `pixelSize` shoulds fold these into `F.pixelSize`,
|
|
||||||
whose oneliner stores `RenderVM.pixelSize`.
|
|
||||||
4. The timer only sets `needsDisplay` every `1 / RENDER_FPS`. `draw(_:)` forwards
|
|
||||||
to `renderDraw` (make context current, `raybri_resize`, `raybri_set_rotation`,
|
|
||||||
`raybri_render`, `flushBuffer`).
|
|
||||||
5. A button click runs `rootSet(F.didClickIncrement)` -> RootComponent oneliner
|
|
||||||
`renderSet(F.didClickIncrement)` -> `renderLoadCubeModel` (the cube is loaded
|
|
||||||
on demand, not at startup).
|
|
||||||
6. `RenderGLView.deinit` sets `F.willDeinit` -> `renderDeinit` (stop timer,
|
|
||||||
`raybri_shutdown`).
|
|
||||||
|
|
||||||
**GL context rule**: every raylib call must run with the view's context current.
|
|
||||||
`renderInit`, `renderLoadCubeModel`, `renderDeinit` and `renderDraw` all call
|
|
||||||
`openGLContext?.makeCurrentContext()` first. Loading a model/texture without it
|
|
||||||
fails silently with `WARNING: TEXTURE: Failed to load texture`.
|
|
||||||
|
|
||||||
## Build & Run
|
|
||||||
|
|
||||||
```bash
|
|
||||||
util/build-mac # generateDialect + swift build + package OGS Mahjong.app
|
|
||||||
util/run-mac # runs .build/OGS Mahjong.app/Contents/MacOS/ogs-mahjong
|
|
||||||
util/rm-mac-geom # reset the app's saved window geometry
|
|
||||||
```
|
|
||||||
|
|
||||||
`build-mac` sources `util/paths` then the `util/step/*` scripts in order:
|
|
||||||
|
|
||||||
1. `generateDialect` — runs the sibling generator, writes `src/dialect.swift`
|
|
||||||
2. `buildMac` — `brew --prefix raylib` -> `RAYLIB_PREFIX`, `swift build`
|
|
||||||
3. `packageMac` — assembles `.build/OGS Mahjong.app` (binary `ogs-mahjong`,
|
|
||||||
`Info.plist`, `Resources/AppIcon.icns`, `Resources/assets/`)
|
|
||||||
|
|
||||||
## Editing the dialect
|
## Editing the dialect
|
||||||
|
|
||||||
- Add/modify contexts and components in `dialect.yml`, then run
|
- Add/modify contexts and components in `<app>/dialect.yml`, then run
|
||||||
`util/build-mac` to regenerate `dialect.swift`.
|
`util/build-<app>-mac` to regenerate `dialect.swift`.
|
||||||
- **Chicken-egg**: `struct F` (field-name constants) lives only in the
|
- **Chicken-egg**: `struct F` (field-name constants) lives only in the
|
||||||
generated `dialect.swift`. Adding a new field to a context in `dialect.yml`
|
generated `dialect.swift`. Adding a new field to a context in `<app>/dialect.yml`
|
||||||
requires hand-patching its `static let <field> = "<field>"` into `struct F`
|
requires hand-patching its `static let <field> = "<field>"` into `struct F`
|
||||||
in `dialect.swift` (ASCII-alphabetical order) if you cannot regenerate first,
|
in `dialect.swift` (ASCII-alphabetical order) if you cannot regenerate first,
|
||||||
otherwise the build fails on `F.<field>` being unresolved.
|
otherwise the build fails on `F.<field>` being unresolved.
|
||||||
- `dialect.swift` is generated — edits there are overwritten on the next
|
- `dialect.swift` is generated — edits there are overwritten on the next
|
||||||
`util/build-mac`. Change the source (`dialect.yml` / `components/`) instead.
|
`util/build-<app>-mac`. Change the source (`<app>/dialect.yml` / `components/`) instead.
|
||||||
- **Validate `dialect.yml` after edits** (e.g. `ruby -ryaml -e 'YAML.load_file("dialect.yml")'`).
|
- **Validate `<app>/dialect.yml` after edits** (e.g. `ruby -ryaml -e 'YAML.load_file("ogs-blue/dialect.yml")'`).
|
||||||
Every should-branch label (`1. Upon each ...`) MUST end with a colon — the
|
Every should-branch label (`1. Upon each ...`) MUST end with a colon — the
|
||||||
parser (`components/yml/ymlFun.swift`) blindly `dropLast()`s it, so a missing
|
parser (`components/yml/ymlFun.swift`) blindly `dropLast()`s it, so a missing
|
||||||
colon silently eats the label's last character in the generated `about`
|
colon silently eats the label's last character in the generated `about`
|
||||||
@@ -246,17 +148,13 @@ Do not flip it on without addressing those.
|
|||||||
- Never call raylib / `raybri_*` without making the view's GL context current first
|
- Never call raylib / `raybri_*` without making the view's GL context current first
|
||||||
(see the GL context rule above).
|
(see the GL context rule above).
|
||||||
|
|
||||||
## Skill: source-file study documents
|
## Source study documents
|
||||||
|
|
||||||
When the task is to produce a source-code study document — a self-contained,
|
|
||||||
downloadable HTML file with a line-by-line table of the file and its
|
|
||||||
explanations (and, on request, a second version highlighting changes after a
|
|
||||||
fix) — follow the skill in `docs/file-summary.md`.
|
|
||||||
|
|
||||||
- Write the result to `docs/<FileName>.html` (e.g. `docs/RaylibGLView.html`) and
|
|
||||||
name the file's Git revision in the header. The file is the source of truth —
|
|
||||||
document the exact revision requested, not the working tree.
|
|
||||||
- Existing example: `docs/RaylibGLView.html` — documents the historical
|
|
||||||
single-cube `RaylibGLView.swift`, since split into `RenderGLView.swift` plus
|
|
||||||
the `render*` files.
|
|
||||||
|
|
||||||
|
- Single-file source studies: follow [docs/file-summary.md](docs/file-summary.md).
|
||||||
|
- Mirrored platform studies: follow [docs/mirror-summary.md](docs/mirror-summary.md).
|
||||||
|
Produce one self-contained downloadable HTML with aligned function starts,
|
||||||
|
original line numbers, green/orange number fills, counts/percentages and a
|
||||||
|
non-repetitive explanation column.
|
||||||
|
- Existing mirrored example: `docs/render-platform-comparison.html`, documenting
|
||||||
|
the revision named in its header. Never silently substitute working-tree code
|
||||||
|
for a requested historical revision.
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* macOS
|
### macOS
|
||||||
|
|
||||||
`brew install raylib`
|
* `brew install raylib`
|
||||||
|
|
||||||
* iOS
|
### iOS
|
||||||
|
|
||||||
`brew install xcodegen`
|
* `brew install xcodegen`
|
||||||
|
* ghera's [raylib-ios-xcframeworks][rzip] release unpacked and placed alongside the project
|
||||||
|
|
||||||
|
[rzip]: https://github.com/ghera/raylib-iOS/releases/download/6.2.0-iOS/raylib-ios-xcframeworks-6.2.0-iOS.zip
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
class BlueComponent {
|
||||||
|
let ctrl = DialectController(BlueContext())
|
||||||
|
static private(set) weak var singleton: BlueComponent?
|
||||||
|
|
||||||
|
init() {
|
||||||
|
Self.singleton = self
|
||||||
|
//blueRegisterEffects(ctrl)
|
||||||
|
blueRegisterShoulds(ctrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setup() {
|
||||||
|
blueSet(F.didSetup, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import Combine
|
||||||
|
|
||||||
|
final class BlueVM: ObservableObject {
|
||||||
|
static private(set) weak var shared: BlueVM?
|
||||||
|
|
||||||
|
init() {
|
||||||
|
Self.shared = self
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../mac/view/BlueView.swift
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct BlueView: View {
|
||||||
|
@ObservedObject var vm: BlueVM
|
||||||
|
|
||||||
|
init(_ vm: BlueVM) {
|
||||||
|
self.vm = vm
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 16) {
|
||||||
|
ZStack {
|
||||||
|
Text("Blue")
|
||||||
|
.font(.largeTitle)
|
||||||
|
.foregroundStyle(.white)
|
||||||
|
.offset(x: 1, y: 1)
|
||||||
|
Text("Blue")
|
||||||
|
.font(.largeTitle)
|
||||||
|
.foregroundStyle(.black)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(40)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#ifndef EGL_H
|
||||||
|
#define EGL_H
|
||||||
|
|
||||||
|
#include "eglConst.h"
|
||||||
|
#include <libEGL/libEGL.h>
|
||||||
|
#include <libGLESv2/GLES/gl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef struct EGLState {
|
||||||
|
void *caLayer;
|
||||||
|
EGLConfig cfg;
|
||||||
|
EGLContext ctx;
|
||||||
|
EGLDisplay display;
|
||||||
|
EGLSurface surface;
|
||||||
|
} EGLState;
|
||||||
|
|
||||||
|
bool eglInit(EGLState *st);
|
||||||
|
bool eglMakeCurrentContext(EGLState *st);
|
||||||
|
bool eglResetSurface(EGLState *st);
|
||||||
|
|
||||||
|
// Source
|
||||||
|
|
||||||
|
#if defined(EGL_IMPLEMENTATION)
|
||||||
|
|
||||||
|
bool eglInit(EGLState *st) {
|
||||||
|
st->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
|
if (st->display == EGL_NO_DISPLAY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eglInitialize(st->display, NULL, NULL) == EGL_FALSE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EGLint cfgCount = 0;
|
||||||
|
if (
|
||||||
|
eglChooseConfig(st->display, EGL_CFG, &st->cfg, 1, &cfgCount) == EGL_FALSE ||
|
||||||
|
cfgCount < 1
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
st->ctx = eglCreateContext(st->display, st->cfg, EGL_NO_CONTEXT, EGL_CTX);
|
||||||
|
if (st->ctx == EGL_NO_CONTEXT) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool eglMakeCurrentContext(EGLState *st) {
|
||||||
|
if (eglMakeCurrent(st->display, st->surface, st->surface, st->ctx) == EGL_FALSE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool eglResetSurface(EGLState *st) {
|
||||||
|
// Destroy previous surface
|
||||||
|
if (st->surface != EGL_NO_SURFACE) {
|
||||||
|
eglDestroySurface(st->display, st->surface);
|
||||||
|
st->surface = EGL_NO_SURFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new surface
|
||||||
|
// ANGLE on iOS takes a CALayer as the native window
|
||||||
|
st->surface = eglCreateWindowSurface(
|
||||||
|
st->display,
|
||||||
|
st->cfg,
|
||||||
|
(EGLNativeWindowType)st->caLayer,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if (st->surface == EGL_NO_SURFACE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EGL_IMPLEMENTATION
|
||||||
|
|
||||||
|
#endif // EGL_H
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef EGL_CONST_H
|
||||||
|
#define EGL_CONST_H
|
||||||
|
|
||||||
|
#include <libEGL/libEGL.h>
|
||||||
|
|
||||||
|
// Header
|
||||||
|
|
||||||
|
extern const EGLint EGL_CFG[];
|
||||||
|
extern const EGLint EGL_CTX[];
|
||||||
|
|
||||||
|
// Source
|
||||||
|
|
||||||
|
#if defined(EGL_CONST_IMPLEMENTATION)
|
||||||
|
|
||||||
|
const EGLint EGL_CFG[] = {
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
const EGLint EGL_CTX[] = {
|
||||||
|
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||||
|
EGL_NONE
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EGL_CONST_IMPLEMENTATION
|
||||||
|
|
||||||
|
#endif // EGL_CONST_H
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#ifndef OGS_MAHJONG_RAYLIB_IOS_BRIDGING_HEADER_H
|
|
||||||
#define OGS_MAHJONG_RAYLIB_IOS_BRIDGING_HEADER_H
|
|
||||||
|
|
||||||
#include "../raybri.h"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,207 +0,0 @@
|
|||||||
// 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");
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#ifndef RAYBRI_AUX_H
|
||||||
|
#define RAYBRI_AUX_H
|
||||||
|
|
||||||
|
// Header
|
||||||
|
|
||||||
|
void *raybriGLLoader(const char *name);
|
||||||
|
void raybriLoadExtensions(void);
|
||||||
|
|
||||||
|
// Source
|
||||||
|
|
||||||
|
#if defined(RAYBRI_AUX_IMPLEMENTATION)
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include "raybriConst.h"
|
||||||
|
#include "rlgl.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
void *raybriGLLoader(const char *name) {
|
||||||
|
static void *handle = NULL;
|
||||||
|
|
||||||
|
if (handle == NULL) {
|
||||||
|
handle = dlopen(RAYBRI_MAC_GL, RTLD_LAZY | RTLD_LOCAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dlsym(handle, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void raybriLoadExtensions(void) {
|
||||||
|
rlLoadExtensions(raybriGLLoader);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // RAYBRI_AUX_IMPLEMENTATION
|
||||||
|
|
||||||
|
#endif // RAYBRI_AUX_H
|
||||||
@@ -1,440 +0,0 @@
|
|||||||
#include "raybri.h"
|
|
||||||
|
|
||||||
#include "raylib.h"
|
|
||||||
#include "rlgl.h"
|
|
||||||
#include "raymath.h"
|
|
||||||
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
static int sr_width = 1;
|
|
||||||
static int sr_height = 1;
|
|
||||||
|
|
||||||
// Render configuration supplied by the application (see renderConst.swift).
|
|
||||||
static raybri_config sr_cfg = { 0 };
|
|
||||||
|
|
||||||
// Cube transform (driven by the application, Euler degrees).
|
|
||||||
static float sr_rot_x = 0.0f;
|
|
||||||
static float sr_rot_y = 0.0f;
|
|
||||||
static float sr_rot_z = 0.0f;
|
|
||||||
|
|
||||||
static int sr_ready = 0;
|
|
||||||
|
|
||||||
static Model sr_model = { 0 };
|
|
||||||
static int sr_has_model = 0;
|
|
||||||
|
|
||||||
static Material sr_cube_material = { 0 };
|
|
||||||
static Material sr_cube_shadow_material = { 0 };
|
|
||||||
static Texture2D sr_cube_normal = { 0 };
|
|
||||||
|
|
||||||
static Model sr_ground_model = { 0 };
|
|
||||||
static Material sr_ground_material = { 0 };
|
|
||||||
static Material sr_ground_shadow_material = { 0 };
|
|
||||||
|
|
||||||
static Shader sr_main_shader = { 0 };
|
|
||||||
static Shader sr_shadow_shader = { 0 };
|
|
||||||
|
|
||||||
static int sr_shadow_fbo = 0;
|
|
||||||
static unsigned int sr_shadow_color = 0;
|
|
||||||
static unsigned int sr_shadow_depth = 0;
|
|
||||||
|
|
||||||
static Matrix sr_light_view = { 0 };
|
|
||||||
static Matrix sr_light_proj = { 0 };
|
|
||||||
static Vector3 sr_light_pos = { 0.0f, 0.0f, 0.0f };
|
|
||||||
|
|
||||||
// Main shader uniform locations
|
|
||||||
static int loc_light_pos = -1;
|
|
||||||
static int loc_light_color = -1;
|
|
||||||
static int loc_ambient = -1;
|
|
||||||
static int loc_light_enabled = -1;
|
|
||||||
static int loc_emissive = -1;
|
|
||||||
static int loc_albedo_color = -1;
|
|
||||||
static int loc_shadow_map = -1;
|
|
||||||
static int loc_shadow_bias = -1;
|
|
||||||
static int loc_shadow_softness = -1;
|
|
||||||
static int loc_normal_map = -1;
|
|
||||||
static int loc_normal_strength = -1;
|
|
||||||
static int loc_light_mvp = -1;
|
|
||||||
static int loc_is_ground = -1;
|
|
||||||
static int loc_grid_color = -1;
|
|
||||||
static int loc_camera_pos = -1;
|
|
||||||
static int loc_fog_color = -1;
|
|
||||||
static int loc_fog_start = -1;
|
|
||||||
static int loc_fog_end = -1;
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
static void *sr_gl_loader(const char *name)
|
|
||||||
{
|
|
||||||
static void *handle = NULL;
|
|
||||||
if (handle == NULL)
|
|
||||||
{
|
|
||||||
handle = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL);
|
|
||||||
}
|
|
||||||
if (handle == NULL) return NULL;
|
|
||||||
return dlsym(handle, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compose a model transform exactly like raylib's DrawModel() does, so the
|
|
||||||
// matrices we feed to DrawMesh() match what rlgl computes internally.
|
|
||||||
static Matrix sr_transform(Vector3 pos, float scale, float rx, float ry, float rz)
|
|
||||||
{
|
|
||||||
Matrix mat_scale = MatrixScale(scale, scale, scale);
|
|
||||||
Matrix mat_rotation = MatrixRotateXYZ((Vector3){ rx * DEG2RAD, ry * DEG2RAD, rz * DEG2RAD });
|
|
||||||
Matrix mat_translation = MatrixTranslate(pos.x, pos.y, pos.z);
|
|
||||||
return MatrixMultiply(MatrixMultiply(mat_scale, mat_rotation), mat_translation);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sr_load_shaders(const char *main_vs, const char *main_fs,
|
|
||||||
const char *shadow_vs, const char *shadow_fs)
|
|
||||||
{
|
|
||||||
sr_main_shader = LoadShaderFromMemory(main_vs, main_fs);
|
|
||||||
sr_shadow_shader = LoadShaderFromMemory(shadow_vs, shadow_fs);
|
|
||||||
|
|
||||||
loc_light_pos = GetShaderLocation(sr_main_shader, "u_lightPos");
|
|
||||||
loc_light_color = GetShaderLocation(sr_main_shader, "u_lightColor");
|
|
||||||
loc_ambient = GetShaderLocation(sr_main_shader, "u_ambient");
|
|
||||||
loc_light_enabled = GetShaderLocation(sr_main_shader, "u_lightEnabled");
|
|
||||||
loc_emissive = GetShaderLocation(sr_main_shader, "u_emissive");
|
|
||||||
loc_albedo_color = GetShaderLocation(sr_main_shader, "u_albedoColor");
|
|
||||||
loc_shadow_map = GetShaderLocation(sr_main_shader, "u_shadowMap");
|
|
||||||
loc_shadow_bias = GetShaderLocation(sr_main_shader, "u_shadowBias");
|
|
||||||
loc_shadow_softness = GetShaderLocation(sr_main_shader, "u_shadowSoftness");
|
|
||||||
loc_normal_map = GetShaderLocation(sr_main_shader, "u_normalMap");
|
|
||||||
loc_normal_strength = GetShaderLocation(sr_main_shader, "u_normalStrength");
|
|
||||||
loc_light_mvp = GetShaderLocation(sr_main_shader, "u_lightMVP");
|
|
||||||
loc_is_ground = GetShaderLocation(sr_main_shader, "u_isGround");
|
|
||||||
loc_grid_color = GetShaderLocation(sr_main_shader, "u_gridColor");
|
|
||||||
loc_camera_pos = GetShaderLocation(sr_main_shader, "u_cameraPos");
|
|
||||||
loc_fog_color = GetShaderLocation(sr_main_shader, "u_fogColor");
|
|
||||||
loc_fog_start = GetShaderLocation(sr_main_shader, "u_fogStart");
|
|
||||||
loc_fog_end = GetShaderLocation(sr_main_shader, "u_fogEnd");
|
|
||||||
|
|
||||||
// Build a framebuffer whose depth attachment is a sampleable TEXTURE (raylib's
|
|
||||||
// LoadRenderTexture() uses a non-sampleable renderbuffer, so we build it by hand).
|
|
||||||
sr_shadow_fbo = rlLoadFramebuffer();
|
|
||||||
sr_shadow_color = rlLoadTexture(NULL, sr_cfg.shadow_size, sr_cfg.shadow_size, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1);
|
|
||||||
sr_shadow_depth = rlLoadTextureDepth(sr_cfg.shadow_size, sr_cfg.shadow_size, false);
|
|
||||||
|
|
||||||
rlEnableFramebuffer(sr_shadow_fbo);
|
|
||||||
rlFramebufferAttach(sr_shadow_fbo, sr_shadow_color, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0);
|
|
||||||
rlFramebufferAttach(sr_shadow_fbo, sr_shadow_depth, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_TEXTURE2D, 0);
|
|
||||||
int shadow_ok = rlFramebufferComplete(sr_shadow_fbo);
|
|
||||||
fprintf(stderr, "SR: shadow framebuffer %s\n", shadow_ok ? "complete" : "INCOMPLETE");
|
|
||||||
rlDisableFramebuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sr_build_ground(void)
|
|
||||||
{
|
|
||||||
Mesh ground_mesh = GenMeshPlane(sr_cfg.ground_size, sr_cfg.ground_size, 1, 1);
|
|
||||||
sr_ground_model = LoadModelFromMesh(ground_mesh);
|
|
||||||
sr_ground_material = LoadMaterialDefault();
|
|
||||||
sr_ground_material.shader = sr_main_shader;
|
|
||||||
sr_ground_shadow_material = LoadMaterialDefault();
|
|
||||||
sr_ground_shadow_material.shader = sr_shadow_shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uniforms that never change between frames are uploaded once at startup.
|
|
||||||
// SetShaderValue() is a bare glUniform*(), so the program must be bound.
|
|
||||||
static void sr_config_shaders(void)
|
|
||||||
{
|
|
||||||
sr_light_pos = (Vector3){ 0.0f, 4.2f, 0.0f };
|
|
||||||
|
|
||||||
Vector3 light_color = { 1.15f, 1.08f, 0.98f };
|
|
||||||
Vector3 ambient = { 0.30f, 0.32f, 0.38f };
|
|
||||||
Vector3 grid_color = { 0.45f, 0.62f, 0.95f };
|
|
||||||
Vector3 fog_color = { 24.0f / 255.0f, 26.0f / 255.0f, 34.0f / 255.0f };
|
|
||||||
Vector3 camera_pos = { 0.0f, 2.6f, 5.6f };
|
|
||||||
float albedo[3] = { 1.0f, 1.0f, 1.0f };
|
|
||||||
float light_amount = 1.0f;
|
|
||||||
float shadow_bias = 0.0025f;
|
|
||||||
float shadow_softness = 4.0f;
|
|
||||||
float fog_start = 10.0f;
|
|
||||||
float fog_end = 34.0f;
|
|
||||||
int shadow_unit = 1;
|
|
||||||
int normal_unit = 2;
|
|
||||||
|
|
||||||
rlEnableShader(sr_main_shader.id);
|
|
||||||
|
|
||||||
SetShaderValue(sr_main_shader, loc_light_pos, &sr_light_pos, SHADER_UNIFORM_VEC3);
|
|
||||||
SetShaderValue(sr_main_shader, loc_light_color, &light_color, SHADER_UNIFORM_VEC3);
|
|
||||||
SetShaderValue(sr_main_shader, loc_ambient, &ambient, SHADER_UNIFORM_VEC3);
|
|
||||||
SetShaderValue(sr_main_shader, loc_light_enabled, &light_amount, SHADER_UNIFORM_FLOAT);
|
|
||||||
SetShaderValue(sr_main_shader, loc_shadow_bias, &shadow_bias, SHADER_UNIFORM_FLOAT);
|
|
||||||
SetShaderValue(sr_main_shader, loc_shadow_softness, &shadow_softness, SHADER_UNIFORM_FLOAT);
|
|
||||||
SetShaderValue(sr_main_shader, loc_grid_color, &grid_color, SHADER_UNIFORM_VEC3);
|
|
||||||
SetShaderValue(sr_main_shader, loc_camera_pos, &camera_pos, SHADER_UNIFORM_VEC3);
|
|
||||||
SetShaderValue(sr_main_shader, loc_fog_color, &fog_color, SHADER_UNIFORM_VEC3);
|
|
||||||
SetShaderValue(sr_main_shader, loc_fog_start, &fog_start, SHADER_UNIFORM_FLOAT);
|
|
||||||
SetShaderValue(sr_main_shader, loc_fog_end, &fog_end, SHADER_UNIFORM_FLOAT);
|
|
||||||
SetShaderValue(sr_main_shader, loc_albedo_color, albedo, SHADER_UNIFORM_VEC3);
|
|
||||||
SetShaderValue(sr_main_shader, loc_shadow_map, &shadow_unit, SHADER_UNIFORM_INT);
|
|
||||||
SetShaderValue(sr_main_shader, loc_normal_map, &normal_unit, SHADER_UNIFORM_INT);
|
|
||||||
|
|
||||||
rlDisableShader();
|
|
||||||
}
|
|
||||||
|
|
||||||
void raybri_init(
|
|
||||||
const char *main_vs,
|
|
||||||
const char *main_fs,
|
|
||||||
const char *shadow_vs,
|
|
||||||
const char *shadow_fs,
|
|
||||||
raybri_config config
|
|
||||||
) {
|
|
||||||
sr_cfg = config;
|
|
||||||
|
|
||||||
// raylib's default INFO logging is noisy; keep warnings and errors only.
|
|
||||||
SetTraceLogLevel(LOG_WARNING);
|
|
||||||
|
|
||||||
rlLoadExtensions((void *)sr_gl_loader);
|
|
||||||
// Init with default 1x1 size
|
|
||||||
rlglInit(1, 1);
|
|
||||||
|
|
||||||
sr_load_shaders(main_vs, main_fs, shadow_vs, shadow_fs);
|
|
||||||
sr_config_shaders();
|
|
||||||
sr_build_ground();
|
|
||||||
|
|
||||||
sr_ready = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void raybri_load_model(const char *gltf_path)
|
|
||||||
{
|
|
||||||
if (!sr_ready || gltf_path == NULL) return;
|
|
||||||
|
|
||||||
sr_model = LoadModel(gltf_path);
|
|
||||||
sr_has_model = (sr_model.meshCount > 0);
|
|
||||||
|
|
||||||
// The matching normal map sits next to the glTF; load it separately.
|
|
||||||
char asset_dir[1024];
|
|
||||||
const char *slash = strrchr(gltf_path, '/');
|
|
||||||
size_t dir_len = (slash != NULL) ? (size_t)(slash - gltf_path + 1) : 0;
|
|
||||||
snprintf(asset_dir, sizeof(asset_dir), "%.*s", (int)dir_len, gltf_path);
|
|
||||||
|
|
||||||
if (sr_has_model)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
Texture2D base_tex = sr_cube_material.maps[MATERIAL_MAP_DIFFUSE].texture;
|
|
||||||
SetTextureFilter(base_tex, TEXTURE_FILTER_BILINEAR);
|
|
||||||
SetTextureWrap(base_tex, TEXTURE_WRAP_CLAMP);
|
|
||||||
|
|
||||||
char normal_path[1024];
|
|
||||||
snprintf(normal_path, sizeof(normal_path), "%scube_normal.png", asset_dir);
|
|
||||||
if (FileExists(normal_path))
|
|
||||||
{
|
|
||||||
sr_cube_normal = LoadTexture(normal_path);
|
|
||||||
SetTextureFilter(sr_cube_normal, TEXTURE_FILTER_BILINEAR);
|
|
||||||
SetTextureWrap(sr_cube_normal, TEXTURE_WRAP_CLAMP);
|
|
||||||
}
|
|
||||||
|
|
||||||
sr_cube_shadow_material = sr_cube_material;
|
|
||||||
sr_cube_shadow_material.shader = sr_shadow_shader;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "SR: failed to load model: %s\n", gltf_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void raybri_resize(int width, int height)
|
|
||||||
{
|
|
||||||
if (width > 0) sr_width = width;
|
|
||||||
if (height > 0) sr_height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void raybri_set_rotation(float x_deg, float y_deg, float z_deg)
|
|
||||||
{
|
|
||||||
sr_rot_x = x_deg;
|
|
||||||
sr_rot_y = y_deg;
|
|
||||||
sr_rot_z = z_deg;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Matrix sr_cube_transform(void)
|
|
||||||
{
|
|
||||||
return sr_transform((Vector3){ 0.0f, 1.1f, 0.0f }, 1.0f, sr_rot_x, sr_rot_y, sr_rot_z);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sr_draw_object(Model model, Material material, Matrix model_mat,
|
|
||||||
Texture2D normal, float is_ground, float emissive);
|
|
||||||
|
|
||||||
static void sr_render_main_pass(void)
|
|
||||||
{
|
|
||||||
// --- Main pass: camera ---
|
|
||||||
rlViewport(0, 0, sr_width, sr_height);
|
|
||||||
rlSetFramebufferWidth(sr_width);
|
|
||||||
rlSetFramebufferHeight(sr_height);
|
|
||||||
|
|
||||||
rlClearColor(24, 26, 34, 255);
|
|
||||||
rlClearScreenBuffers();
|
|
||||||
|
|
||||||
rlMatrixMode(RL_PROJECTION);
|
|
||||||
rlPushMatrix();
|
|
||||||
rlLoadIdentity();
|
|
||||||
|
|
||||||
float aspect = (float)sr_width / (float)sr_height;
|
|
||||||
double top = (double)sr_cfg.near_plane * tan((double)sr_cfg.fov_y * 0.5 * DEG2RAD);
|
|
||||||
double right = top * (double)aspect;
|
|
||||||
rlFrustum(-right, right, -top, top, (double)sr_cfg.near_plane, (double)sr_cfg.far_plane);
|
|
||||||
|
|
||||||
rlMatrixMode(RL_MODELVIEW);
|
|
||||||
rlLoadIdentity();
|
|
||||||
|
|
||||||
Vector3 eye = { 0.0f, 2.6f, 5.6f };
|
|
||||||
Vector3 target = { 0.0f, 1.0f, 0.0f };
|
|
||||||
Vector3 up = { 0.0f, 1.0f, 0.0f };
|
|
||||||
|
|
||||||
Matrix view = MatrixLookAt(eye, target, up);
|
|
||||||
rlMultMatrixf(MatrixToFloat(view));
|
|
||||||
|
|
||||||
rlEnableDepthTest();
|
|
||||||
rlEnableBackfaceCulling();
|
|
||||||
rlSetCullFace(RL_CULL_FACE_BACK);
|
|
||||||
|
|
||||||
rlEnableShader(sr_main_shader.id);
|
|
||||||
|
|
||||||
rlActiveTextureSlot(1);
|
|
||||||
rlEnableTexture(sr_shadow_depth);
|
|
||||||
rlActiveTextureSlot(0);
|
|
||||||
|
|
||||||
// --- Ground (procedural grid floor) ---
|
|
||||||
sr_draw_object(sr_ground_model, sr_ground_material, MatrixTranslate(0.0f, 0.0f, 0.0f), (Texture2D){ 0 }, 1.0f, 0.0f);
|
|
||||||
|
|
||||||
// --- Cubes ---
|
|
||||||
if (sr_has_model)
|
|
||||||
{
|
|
||||||
sr_draw_object(sr_model, sr_cube_material, sr_cube_transform(), sr_cube_normal, 0.0f, 0.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flush while the projection/modelview matrices are still active, otherwise
|
|
||||||
// rlgl draws the pending batch with the restored (2D) projection.
|
|
||||||
rlDrawRenderBatchActive();
|
|
||||||
|
|
||||||
// --- Restore matrices (equivalent to raylib's EndMode3D) ---
|
|
||||||
rlMatrixMode(RL_PROJECTION);
|
|
||||||
rlPopMatrix();
|
|
||||||
rlMatrixMode(RL_MODELVIEW);
|
|
||||||
rlLoadIdentity();
|
|
||||||
rlDisableDepthTest();
|
|
||||||
rlDisableBackfaceCulling();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sr_render_shadow_pass(void)
|
|
||||||
{
|
|
||||||
rlViewport(0, 0, sr_cfg.shadow_size, sr_cfg.shadow_size);
|
|
||||||
rlSetFramebufferWidth(sr_cfg.shadow_size);
|
|
||||||
rlSetFramebufferHeight(sr_cfg.shadow_size);
|
|
||||||
|
|
||||||
rlEnableFramebuffer(sr_shadow_fbo);
|
|
||||||
|
|
||||||
rlClearColor(255, 255, 255, 255);
|
|
||||||
rlClearScreenBuffers();
|
|
||||||
|
|
||||||
rlEnableDepthTest();
|
|
||||||
rlEnableBackfaceCulling();
|
|
||||||
rlSetCullFace(RL_CULL_FACE_FRONT);
|
|
||||||
|
|
||||||
rlMatrixMode(RL_PROJECTION);
|
|
||||||
rlPushMatrix();
|
|
||||||
rlLoadIdentity();
|
|
||||||
rlMultMatrixf(MatrixToFloat(sr_light_proj));
|
|
||||||
|
|
||||||
rlMatrixMode(RL_MODELVIEW);
|
|
||||||
rlLoadIdentity();
|
|
||||||
rlMultMatrixf(MatrixToFloat(sr_light_view));
|
|
||||||
|
|
||||||
if (sr_has_model)
|
|
||||||
{
|
|
||||||
DrawMesh(sr_model.meshes[0], sr_cube_shadow_material, sr_cube_transform());
|
|
||||||
}
|
|
||||||
|
|
||||||
rlDrawRenderBatchActive();
|
|
||||||
|
|
||||||
rlMatrixMode(RL_PROJECTION);
|
|
||||||
rlPopMatrix();
|
|
||||||
|
|
||||||
rlSetCullFace(RL_CULL_FACE_BACK);
|
|
||||||
rlDisableFramebuffer();
|
|
||||||
|
|
||||||
rlViewport(0, 0, sr_width, sr_height);
|
|
||||||
rlSetFramebufferWidth(sr_width);
|
|
||||||
rlSetFramebufferHeight(sr_height);
|
|
||||||
rlDisableDepthTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sr_set_light_mvp(Matrix model)
|
|
||||||
{
|
|
||||||
Matrix light_mvp = MatrixMultiply(MatrixMultiply(model, sr_light_view), sr_light_proj);
|
|
||||||
SetShaderValueMatrix(sr_main_shader, loc_light_mvp, light_mvp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sr_bind_normal(Texture2D tex)
|
|
||||||
{
|
|
||||||
rlActiveTextureSlot(2);
|
|
||||||
if (tex.id > 0) rlEnableTexture(tex.id);
|
|
||||||
rlActiveTextureSlot(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void sr_draw_object(Model model, Material material, Matrix model_mat,
|
|
||||||
Texture2D normal, float is_ground, float emissive)
|
|
||||||
{
|
|
||||||
sr_set_light_mvp(model_mat);
|
|
||||||
|
|
||||||
float normal_strength = (normal.id > 0) ? 1.0f : 0.0f;
|
|
||||||
SetShaderValue(sr_main_shader, loc_emissive, &emissive, SHADER_UNIFORM_FLOAT);
|
|
||||||
SetShaderValue(sr_main_shader, loc_is_ground, &is_ground, SHADER_UNIFORM_FLOAT);
|
|
||||||
SetShaderValue(sr_main_shader, loc_normal_strength, &normal_strength, SHADER_UNIFORM_FLOAT);
|
|
||||||
|
|
||||||
sr_bind_normal(normal);
|
|
||||||
|
|
||||||
DrawMesh(model.meshes[0], material, model_mat);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raybri_render(void)
|
|
||||||
{
|
|
||||||
if (!sr_ready) return;
|
|
||||||
|
|
||||||
rlDrawRenderBatchActive();
|
|
||||||
|
|
||||||
// --- Light (point light above the scene) ---
|
|
||||||
Vector3 light_target = (Vector3){ 0.0f, -2.0f, 0.0f };
|
|
||||||
Vector3 light_up = (Vector3){ 0.0f, 0.0f, -1.0f };
|
|
||||||
sr_light_view = MatrixLookAt(sr_light_pos, light_target, light_up);
|
|
||||||
sr_light_proj = MatrixPerspective(90.0 * DEG2RAD, 1.0, 1.5, 16.0);
|
|
||||||
|
|
||||||
sr_render_shadow_pass();
|
|
||||||
sr_render_main_pass();
|
|
||||||
}
|
|
||||||
|
|
||||||
void raybri_shutdown(void)
|
|
||||||
{
|
|
||||||
if (!sr_ready) return;
|
|
||||||
|
|
||||||
if (sr_has_model)
|
|
||||||
{
|
|
||||||
UnloadModel(sr_model);
|
|
||||||
sr_has_model = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
UnloadModel(sr_ground_model);
|
|
||||||
|
|
||||||
if (sr_cube_normal.id > 0)
|
|
||||||
{
|
|
||||||
UnloadTexture(sr_cube_normal);
|
|
||||||
sr_cube_normal.id = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sr_shadow_color > 0) rlUnloadTexture(sr_shadow_color);
|
|
||||||
if (sr_shadow_depth > 0) rlUnloadTexture(sr_shadow_depth);
|
|
||||||
if (sr_shadow_fbo > 0) rlUnloadFramebuffer(sr_shadow_fbo);
|
|
||||||
if (sr_main_shader.id > 0) UnloadShader(sr_main_shader);
|
|
||||||
if (sr_shadow_shader.id > 0) UnloadShader(sr_shadow_shader);
|
|
||||||
|
|
||||||
rlglClose();
|
|
||||||
sr_ready = 0;
|
|
||||||
}
|
|
||||||
+33
-56
@@ -1,65 +1,42 @@
|
|||||||
#ifndef OGS_MAHJONG_RAYLIB_BRIDGE_H
|
#ifndef RAYBRI_H
|
||||||
#define OGS_MAHJONG_RAYLIB_BRIDGE_H
|
#define RAYBRI_H
|
||||||
|
|
||||||
#include <TargetConditionals.h>
|
// Header
|
||||||
|
|
||||||
#ifdef __cplusplus
|
void raybriInit(void);
|
||||||
extern "C" {
|
void raybriRender(int width, int height);
|
||||||
#endif
|
void raybriShutdown(void);
|
||||||
|
|
||||||
// Render configuration, sourced from renderConst.swift.
|
// Source
|
||||||
typedef struct raybri_config {
|
|
||||||
float fov_y; // vertical field of view (degrees)
|
|
||||||
float near_plane; // camera near plane
|
|
||||||
float far_plane; // camera far plane
|
|
||||||
int shadow_size; // shadow map resolution (px)
|
|
||||||
float ground_size; // ground plane extent
|
|
||||||
} raybri_config;
|
|
||||||
|
|
||||||
// The bridge always renders into a GL context owned by the app (no raylib
|
#if defined(RAYBRI_IMPLEMENTATION)
|
||||||
// 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;
|
#include "rlgl.h"
|
||||||
// on iOS it recreates the EGL window surface when it changes.
|
|
||||||
void raybri_resize(int width, int height);
|
|
||||||
|
|
||||||
// Render one frame.
|
void raybriInit(void) {
|
||||||
void raybri_render(void);
|
//SetTraceLogLevel(LOG_WARNING);
|
||||||
|
|
||||||
// Release the GL/EGL resources owned by the bridge.
|
// Initialize raylib graphics layer with a placeholder 1x1 framebuffer size
|
||||||
void raybri_shutdown(void);
|
// Graphics layer includes default texture, shader, render batch and OpenGL state
|
||||||
|
rlglInit(1, 1);
|
||||||
#if TARGET_OS_IPHONE
|
// Background is painted in blue
|
||||||
|
rlClearColor(0, 0, 255, 255);
|
||||||
// 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.
|
|
||||||
void raybri_init(
|
|
||||||
const char *main_vs,
|
|
||||||
const char *main_fs,
|
|
||||||
const char *shadow_vs,
|
|
||||||
const char *shadow_fs,
|
|
||||||
raybri_config config
|
|
||||||
);
|
|
||||||
|
|
||||||
// Load the textured cube glTF model.
|
|
||||||
void raybri_load_model(const char *gltf_path);
|
|
||||||
|
|
||||||
// Cube rotation, driven by the application (Euler angles, degrees).
|
|
||||||
void raybri_set_rotation(float x_deg, float y_deg, float z_deg);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
void raybriRender(int width, int height) {
|
||||||
|
// Set the drawing area to the current pixel size
|
||||||
|
rlViewport(0, 0, width, height);
|
||||||
|
// Clear color and depth buffers for the next frame
|
||||||
|
rlClearScreenBuffers();
|
||||||
|
// Draw any queued geometry
|
||||||
|
rlDrawRenderBatchActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
void raybriShutdown(void) {
|
||||||
|
// Release rlgl buffers, shaders and textures
|
||||||
|
rlglClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // RAYBRI_IMPLEMENTATION
|
||||||
|
|
||||||
|
#endif // RAYBRI_H
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef RAYBRI_CONST_H
|
||||||
|
#define RAYBRI_CONST_H
|
||||||
|
|
||||||
|
// Header
|
||||||
|
|
||||||
|
extern const char RAYBRI_MAC_GL[];
|
||||||
|
|
||||||
|
// Source
|
||||||
|
|
||||||
|
#if defined(RAYBRI_CONST_IMPLEMENTATION)
|
||||||
|
|
||||||
|
const char RAYBRI_MAC_GL[] = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
|
||||||
|
|
||||||
|
#endif // RAYBRI_CONST_IMPLEMENTATION
|
||||||
|
|
||||||
|
#endif // RAYBRI_CONST_H
|
||||||
@@ -1 +0,0 @@
|
|||||||
../renderVM.swift
|
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
import UIKit
|
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) {
|
func renderDraw(_ vm: RenderVM) {
|
||||||
raybri_render()
|
guard eglMakeCurrentContext(&vm.glView.st) else { return }
|
||||||
|
raybriRender(vm.pixelSize[0], vm.pixelSize[1])
|
||||||
|
eglSwapBuffers(vm.glView.st.display, vm.glView.st.surface)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backing-pixel size of the view, which is what EGL/ANGLE renders into.
|
|
||||||
func renderPixelSize(_ view: UIView) -> [Int32] {
|
func renderPixelSize(_ view: UIView) -> [Int32] {
|
||||||
let scale = view.contentScaleFactor
|
let scale = view.contentScaleFactor
|
||||||
let w = Int32(max(1, (view.bounds.width * scale).rounded()))
|
let w = Int32(max(1, (view.bounds.width * scale).rounded()))
|
||||||
let h = Int32(max(1, (view.bounds.height * scale).rounded()))
|
let h = Int32(max(1, (view.bounds.height * scale).rounded()))
|
||||||
return [w, h]
|
return [w, h]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func renderRecreateSurface(_ vm: RenderVM) {
|
||||||
|
eglResetSurface(&vm.glView.st)
|
||||||
|
eglMakeCurrentContext(&vm.glView.st)
|
||||||
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -1,32 +1,43 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
import QuartzCore
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
// Bring up EGL/ANGLE on the view's layer. Returns false when the surface could
|
func renderDeinit(_ vm: RenderVM) {
|
||||||
// not be created (the caller then leaves the timer stopped).
|
vm.timer?.invalidate()
|
||||||
func renderInit(_ vm: RenderVM) -> Bool {
|
vm.timer = nil
|
||||||
let size = renderPixelSize(vm.glView)
|
eglMakeCurrentContext(&vm.glView.st)
|
||||||
let layer = Unmanaged.passUnretained(vm.glView.layer).toOpaque()
|
raybriShutdown()
|
||||||
let ok = raybri_init(layer, size[0], size[1]) != 0
|
|
||||||
if !ok {
|
eglMakeCurrent(vm.glView.st.display, nil, nil, nil)
|
||||||
otherPrintStderr("ИГР renderInit: EGL/ANGLE initialization failed")
|
eglDestroySurface(vm.glView.st.display, vm.glView.st.surface)
|
||||||
}
|
eglDestroyContext(vm.glView.st.display, vm.glView.st.ctx)
|
||||||
return ok
|
eglTerminate(vm.glView.st.display)
|
||||||
|
}
|
||||||
|
|
||||||
|
func renderInit(_ vm: RenderVM) {
|
||||||
|
// On iOS EGL/ANGLE renders into the UIView's layer
|
||||||
|
let layer = Unmanaged.passUnretained(vm.glView.layer).toOpaque()
|
||||||
|
vm.glView.st.caLayer = layer
|
||||||
|
|
||||||
|
guard eglInit(&vm.glView.st) else { fatalError("ERROR Could not initialize EGL") }
|
||||||
|
guard eglResetSurface(&vm.glView.st) else { fatalError("ERROR Could not reset EGL surface") }
|
||||||
|
guard eglMakeCurrentContext(&vm.glView.st) else { fatalError("ERROR Could not make EGL context current") }
|
||||||
|
|
||||||
|
raybriInit()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
func renderStartTimer(_ vm: RenderVM) {
|
||||||
|
// Make a time mark for calculating time delta
|
||||||
|
vm.startTime = CACurrentMediaTime()
|
||||||
|
|
||||||
|
// The frame is presented by eglSwapBuffers into the view's layer, not by
|
||||||
|
// CoreGraphics, so the timer drives the rendering itself instead of
|
||||||
|
// invalidating the view for a draw(_:) pass the way macOS does
|
||||||
let timer = Timer(timeInterval: 1.0 / RENDER_FPS, repeats: true) { [weak vm] _ in
|
let timer = Timer(timeInterval: 1.0 / RENDER_FPS, repeats: true) { [weak vm] _ in
|
||||||
guard let vm else { return }
|
guard let vm else { return }
|
||||||
renderDraw(vm)
|
renderDraw(vm)
|
||||||
}
|
}
|
||||||
vm.timer = timer
|
vm.timer = timer
|
||||||
// .common keeps rendering alive while the user holds a control.
|
// .common means holding buttons in UI does not pause this rendering timer
|
||||||
RunLoop.main.add(timer, forMode: .common)
|
RunLoop.main.add(timer, forMode: .common)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderDeinit(_ vm: RenderVM) {
|
|
||||||
vm.timer?.invalidate()
|
|
||||||
vm.timer = nil
|
|
||||||
raybri_shutdown()
|
|
||||||
}
|
|
||||||
@@ -1,58 +1,35 @@
|
|||||||
import UIKit
|
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 {
|
final class RenderGLView: UIView {
|
||||||
private weak var renderVM: RenderVM?
|
var st = EGLState()
|
||||||
|
|
||||||
override init(frame: CGRect) {
|
override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
|
|
||||||
isOpaque = true
|
isOpaque = true
|
||||||
// Touch handling is not wired to raylib yet, so keep the GL view
|
|
||||||
// transparent to the SwiftUI hierarchy above it.
|
|
||||||
isUserInteractionEnabled = false
|
isUserInteractionEnabled = false
|
||||||
|
|
||||||
contentScaleFactor = UIScreen.main.scale
|
|
||||||
layer.contentsScale = contentScaleFactor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
renderSet(F.willDeinit, true)
|
||||||
|
}
|
||||||
|
|
||||||
override func didMoveToWindow() {
|
override func didMoveToWindow() {
|
||||||
super.didMoveToWindow()
|
super.didMoveToWindow()
|
||||||
|
|
||||||
guard let window else { return }
|
guard let window else { return }
|
||||||
contentScaleFactor = window.screen.nativeScale
|
contentScaleFactor = window.screen.nativeScale
|
||||||
layer.contentsScale = contentScaleFactor
|
layer.contentsScale = contentScaleFactor
|
||||||
|
|
||||||
guard let vm = RenderVM.shared, !vm.didPrepareGL else { return }
|
renderSet(F.didPrepareIOSGL, true);
|
||||||
guard renderInit(vm) else { return }
|
|
||||||
|
|
||||||
renderVM = vm
|
|
||||||
vm.didPrepareGL = true
|
|
||||||
vm.pixelSize = renderPixelSize(self)
|
|
||||||
renderStartTimer(vm)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func layoutSubviews() {
|
override func layoutSubviews() {
|
||||||
super.layoutSubviews()
|
super.layoutSubviews()
|
||||||
|
let ps = renderPixelSize(self)
|
||||||
guard let vm = renderVM, vm.didPrepareGL else { return }
|
renderSet(F.reshapePixelSize, ps)
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import UIKit
|
||||||
|
|
||||||
struct RenderView: UIViewRepresentable {
|
struct RenderView: UIViewRepresentable {
|
||||||
func makeUIView(context: Context) -> RenderGLView {
|
func makeUIView(context: Context) -> RenderGLView {
|
||||||
|
|||||||
@@ -3,12 +3,7 @@ import RaylibBridge
|
|||||||
|
|
||||||
func renderDraw(_ vm: RenderVM) {
|
func renderDraw(_ vm: RenderVM) {
|
||||||
vm.glView.openGLContext?.makeCurrentContext()
|
vm.glView.openGLContext?.makeCurrentContext()
|
||||||
|
raybriRender(vm.pixelSize[0], vm.pixelSize[1])
|
||||||
raybri_resize(vm.pixelSize[0], vm.pixelSize[1])
|
|
||||||
let t = Float(CACurrentMediaTime() - vm.startTime)
|
|
||||||
raybri_set_rotation(t * 6.0, t * 18.0, 0.0)
|
|
||||||
raybri_render()
|
|
||||||
|
|
||||||
vm.glView.openGLContext?.flushBuffer()
|
vm.glView.openGLContext?.flushBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,3 +13,7 @@ func renderPixelSize(_ view: NSView) -> [Int32] {
|
|||||||
let h = Int32(max(1, backing.height))
|
let h = Int32(max(1, backing.height))
|
||||||
return [w, h]
|
return [w, h]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func renderRecreateSurface(_ vm: RenderVM) {
|
||||||
|
// No-op on macOS
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import AppKit
|
||||||
|
|
||||||
|
let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [
|
||||||
|
UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core),
|
||||||
|
UInt32(NSOpenGLPFAColorSize), 24,
|
||||||
|
UInt32(NSOpenGLPFAAlphaSize), 8,
|
||||||
|
UInt32(NSOpenGLPFADepthSize), 24,
|
||||||
|
UInt32(NSOpenGLPFADoubleBuffer),
|
||||||
|
UInt32(NSOpenGLPFAAccelerated),
|
||||||
|
0
|
||||||
|
]
|
||||||
@@ -3,10 +3,10 @@ import RaylibBridge
|
|||||||
import QuartzCore
|
import QuartzCore
|
||||||
|
|
||||||
func renderDeinit(_ vm: RenderVM) {
|
func renderDeinit(_ vm: RenderVM) {
|
||||||
print("ИГР renderD")
|
|
||||||
vm.timer?.invalidate()
|
vm.timer?.invalidate()
|
||||||
|
vm.timer = nil
|
||||||
vm.glView.openGLContext?.makeCurrentContext()
|
vm.glView.openGLContext?.makeCurrentContext()
|
||||||
raybri_shutdown()
|
raybriShutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderInit(_ vm: RenderVM) {
|
func renderInit(_ vm: RenderVM) {
|
||||||
@@ -16,20 +16,8 @@ func renderInit(_ vm: RenderVM) {
|
|||||||
var swapInterval: Int32 = 1
|
var swapInterval: Int32 = 1
|
||||||
vm.glView.openGLContext?.setValues(&swapInterval, for: .swapInterval)
|
vm.glView.openGLContext?.setValues(&swapInterval, for: .swapInterval)
|
||||||
|
|
||||||
// Init Raylib
|
raybriLoadExtensions()
|
||||||
raybri_init(
|
raybriInit()
|
||||||
RENDER_SHADER_MAIN_VS,
|
|
||||||
RENDER_SHADER_MAIN_FS,
|
|
||||||
RENDER_SHADER_SHADOW_VS,
|
|
||||||
RENDER_SHADER_SHADOW_FS,
|
|
||||||
RENDER_CONFIG
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func renderLoadCubeModel(_ vm: RenderVM) {
|
|
||||||
let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE
|
|
||||||
vm.glView.openGLContext?.makeCurrentContext()
|
|
||||||
raybri_load_model(path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderStartTimer(_ vm: RenderVM) {
|
func renderStartTimer(_ vm: RenderVM) {
|
||||||
@@ -15,9 +15,20 @@ final class RenderGLView: NSOpenGLView {
|
|||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
renderSet(F.willDeinit, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func draw(_ dirtyRect: NSRect) {
|
||||||
|
let vm = RenderVM.shared!
|
||||||
|
if vm.didPrepareGL {
|
||||||
|
renderDraw(vm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override func prepareOpenGL() {
|
override func prepareOpenGL() {
|
||||||
super.prepareOpenGL()
|
super.prepareOpenGL()
|
||||||
renderSet(F.didPrepareGL, true)
|
renderSet(F.didPrepareMacGL, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func reshape() {
|
override func reshape() {
|
||||||
@@ -33,15 +44,4 @@ final class RenderGLView: NSOpenGLView {
|
|||||||
let ps = renderPixelSize(self)
|
let ps = renderPixelSize(self)
|
||||||
renderSet(F.backingPixelSize, ps)
|
renderSet(F.backingPixelSize, ps)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func draw(_ dirtyRect: NSRect) {
|
|
||||||
let vm = RenderVM.shared!
|
|
||||||
if vm.didPrepareGL {
|
|
||||||
renderDraw(vm)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deinit {
|
|
||||||
renderSet(F.willDeinit, true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,2 @@
|
|||||||
import AppKit
|
|
||||||
import RaylibBridge
|
|
||||||
|
|
||||||
let RENDER_CONFIG = raybri_config(
|
|
||||||
fov_y: 45.0,
|
|
||||||
near_plane: 0.1,
|
|
||||||
far_plane: 1000.0,
|
|
||||||
shadow_size: 256,
|
|
||||||
ground_size: 40.0
|
|
||||||
)
|
|
||||||
|
|
||||||
let RENDER_FPS = 60.0
|
let RENDER_FPS = 60.0
|
||||||
|
|
||||||
let RENDER_MODEL_CUBE = "/cube/cube.gltf"
|
let RENDER_MODEL_CUBE = "/cube/cube.gltf"
|
||||||
|
|
||||||
let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [
|
|
||||||
UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core),
|
|
||||||
UInt32(NSOpenGLPFAColorSize), 24,
|
|
||||||
UInt32(NSOpenGLPFAAlphaSize), 8,
|
|
||||||
UInt32(NSOpenGLPFADepthSize), 24,
|
|
||||||
UInt32(NSOpenGLPFADoubleBuffer),
|
|
||||||
UInt32(NSOpenGLPFAAccelerated),
|
|
||||||
0
|
|
||||||
]
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
# Mirrored source-file study documents
|
||||||
|
|
||||||
|
Use this workflow when comparing corresponding source files across platforms.
|
||||||
|
The established example is `docs/render-platform-comparison.html`.
|
||||||
|
For a single-file study, follow `docs/file-summary.md` instead.
|
||||||
|
|
||||||
|
## Source and scope
|
||||||
|
|
||||||
|
- Read sources from the exact requested Git revision with `git show REV:path`.
|
||||||
|
If no revision is specified, use HEAD and record its full commit hash.
|
||||||
|
- Discover matching relative filenames beneath the two platform directories.
|
||||||
|
State which platform-only files are excluded; never invent a counterpart.
|
||||||
|
- Produce one downloadable, self-contained HTML document in `docs/`, with
|
||||||
|
navigation links and one section per file pair. Preserve earlier documents
|
||||||
|
unless removal is requested.
|
||||||
|
- Record both source paths and the source revision. Preserve every source line,
|
||||||
|
original line number, indentation and blank line. Escape HTML characters.
|
||||||
|
|
||||||
|
## Comparison layout
|
||||||
|
|
||||||
|
- Use one table per pair with three columns: first platform's numbered source,
|
||||||
|
second platform's numbered source, and explanation. Do not create separate
|
||||||
|
line-by-line explanation tables or a Status column.
|
||||||
|
- Align corresponding function starts where possible. Insert missing-line
|
||||||
|
placeholders to keep later functions aligned; preserve source order and
|
||||||
|
original numbers. For example, macOS renderEffect line 12 aligns with iOS
|
||||||
|
line 16 at revision f0972f0d5ba796e3fa417081f43c00a9654b2aa6.
|
||||||
|
- Within each function or intervening block, align lines sequentially unless
|
||||||
|
better semantic alignment is needed. Equal line numbers need not share a row
|
||||||
|
when function alignment requires padding.
|
||||||
|
- Compare the exact source text in each aligned row, including whitespace.
|
||||||
|
Fill BOTH line-number backgrounds green when they match. Fill numbers orange
|
||||||
|
when they differ. A missing line is an orange-filled dash, not a plain dash.
|
||||||
|
Keep code backgrounds neutral and retain syntax highlighting.
|
||||||
|
- Include two filled statistics boxes beneath each section heading: green for
|
||||||
|
matching line count and percentage, orange for mismatched count and percentage.
|
||||||
|
Show the total line count as plain text alongside them.
|
||||||
|
- Count actual lines across BOTH files, including blank lines. A matching pair
|
||||||
|
contributes two matching lines; a differing pair contributes two mismatches;
|
||||||
|
a platform-only line contributes one mismatch. Missing placeholders do not
|
||||||
|
count. Percentages use the combined actual-line total. Recalculate after any
|
||||||
|
alignment change, and explain this counting convention in the document.
|
||||||
|
|
||||||
|
## Explanations
|
||||||
|
|
||||||
|
- Explain each distinct point once across the document, at its first relevant
|
||||||
|
occurrence. Leave later cells empty unless they add information.
|
||||||
|
- Eliminate semantic repetition, not just identical sentences. Do not repeat
|
||||||
|
platform/import boilerplate such as “UIKit serves iOS” for every import.
|
||||||
|
- Explain shared behavior once. Label iOS/macOS details only when needed to
|
||||||
|
distinguish behavior. Explain the reason or consequence of platform differences.
|
||||||
|
- Avoid redundant function summaries when the individual operations already
|
||||||
|
explain the same behavior. Leave blank lines and closing braces unexplained.
|
||||||
|
- When realigning rows, anchor each platform-specific explanation to its own
|
||||||
|
source line rather than to the old visual row.
|
||||||
|
|
||||||
|
## Presentation and verification
|
||||||
|
|
||||||
|
- Inline all CSS and syntax highlighting; no external fonts, scripts or requests.
|
||||||
|
- Use `<pre><code>`, `white-space: pre-wrap`, and `overflow-wrap: anywhere`.
|
||||||
|
Give the code columns equal width; ensure long lines remain readable without
|
||||||
|
horizontal scrolling. Do not use striped row shading.
|
||||||
|
- Verify every source line and number against the named Git revision, in order,
|
||||||
|
with no omissions or duplicates. Check function anchors, placeholder fills,
|
||||||
|
both matching-number fills, statistics, and explanation attachment.
|
||||||
|
- Review explanations for repeated clauses as well as repeated sentences.
|
||||||
|
- Inspect the rendered HTML for layout problems. Return a clickable file link;
|
||||||
|
tell the user to refresh an already open document after updates.
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
version: 4
|
||||||
|
|
||||||
|
output:
|
||||||
|
ver-mac/src/dialect.swift:
|
||||||
|
type: swift
|
||||||
|
|
||||||
|
BlueContext:
|
||||||
|
type: context
|
||||||
|
fields:
|
||||||
|
didLaunch: Bool
|
||||||
|
didSetup: Bool
|
||||||
|
|
||||||
|
BlueComponent:
|
||||||
|
type: component
|
||||||
|
shoulds:
|
||||||
|
didLaunch:
|
||||||
|
1. Only once during the first setup:
|
||||||
|
if:
|
||||||
|
c.recentField == F.didSetup &&
|
||||||
|
c.didLaunch == false
|
||||||
|
then:
|
||||||
|
c.didLaunch = true
|
||||||
|
|
||||||
|
RenderContext:
|
||||||
|
type: context
|
||||||
|
fields:
|
||||||
|
backingPixelSize: [Int32]
|
||||||
|
didLaunch: Bool
|
||||||
|
didPrepareGL: Bool
|
||||||
|
didPrepareIOSGL: Bool
|
||||||
|
didPrepareMacGL: Bool
|
||||||
|
didSetup: Bool
|
||||||
|
pixelSize: [Int32]
|
||||||
|
reshapePixelSize: [Int32]
|
||||||
|
willDeinit: Bool
|
||||||
|
willRecreateSurface: Bool
|
||||||
|
|
||||||
|
RenderComponent:
|
||||||
|
type: component
|
||||||
|
oneliners:
|
||||||
|
- didPrepareGL: renderInit(RenderVM.shared!)
|
||||||
|
- didPrepareGL: RenderVM.shared!.didPrepareGL = true
|
||||||
|
- didPrepareGL: renderStartTimer(RenderVM.shared!)
|
||||||
|
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
|
||||||
|
- willDeinit: renderDeinit(RenderVM.shared!)
|
||||||
|
- willRecreateSurface: renderRecreateSurface(RenderVM.shared!)
|
||||||
|
shoulds:
|
||||||
|
didLaunch:
|
||||||
|
1. Only once during the first setup:
|
||||||
|
if:
|
||||||
|
c.recentField == F.didSetup &&
|
||||||
|
c.didLaunch == false
|
||||||
|
then:
|
||||||
|
c.didLaunch = true
|
||||||
|
didPrepareGL:
|
||||||
|
1. For macOS:
|
||||||
|
if:
|
||||||
|
c.recentField == F.didPrepareMacGL
|
||||||
|
then:
|
||||||
|
c.didPrepareGL = true
|
||||||
|
2. For iOS:
|
||||||
|
if:
|
||||||
|
c.recentField == F.didPrepareIOSGL &&
|
||||||
|
!c.didPrepareGL
|
||||||
|
then:
|
||||||
|
c.didPrepareGL = 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
|
||||||
|
willRecreateSurface:
|
||||||
|
1. Upon resize:
|
||||||
|
if:
|
||||||
|
c.recentField == F.reshapePixelSize
|
||||||
|
then:
|
||||||
|
c.willRecreateSurface = true
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"filename" : "AppIcon.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"platform" : "ios",
|
||||||
|
"size" : "1024x1024"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>OGS blue</string>
|
||||||
|
<key>CFBundleDisplayName</key>
|
||||||
|
<string>OGS blue</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>org.opengamestudio.blue</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>ogs-blue</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>APPL</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1</string>
|
||||||
|
<key>UILaunchScreen</key>
|
||||||
|
<dict/>
|
||||||
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
|
<array>
|
||||||
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
name: OGS blue
|
||||||
|
options:
|
||||||
|
bundleIdPrefix: org.opengamestudio
|
||||||
|
targets:
|
||||||
|
ogs-blue:
|
||||||
|
dependencies:
|
||||||
|
- framework: .build/lib/libEGL.xcframework
|
||||||
|
embed: true
|
||||||
|
- framework: .build/lib/libGLESv2.xcframework
|
||||||
|
embed: true
|
||||||
|
deploymentTarget: "15.0"
|
||||||
|
platform: iOS
|
||||||
|
sources:
|
||||||
|
- path: Assets.xcassets
|
||||||
|
- path: src
|
||||||
|
settings:
|
||||||
|
base:
|
||||||
|
GCC_PREPROCESSOR_DEFINITIONS:
|
||||||
|
- GL_GLEXT_PROTOTYPES=1
|
||||||
|
- GRAPHICS_API_OPENGL_ES3=1
|
||||||
|
- PLATFORM_IOS=1
|
||||||
|
HEADER_SEARCH_PATHS:
|
||||||
|
- "$(SRCROOT)/.build/include"
|
||||||
|
- "$(SRCROOT)/.build/lib/raylib.xcframework/ios-arm64_x86_64-simulator/raylib.framework/Headers"
|
||||||
|
- "$(SRCROOT)/.build/lib/raylib.xcframework/ios-arm64/raylib.framework/Headers"
|
||||||
|
INFOPLIST_FILE: Info.plist
|
||||||
|
LD_RUNPATH_SEARCH_PATHS:
|
||||||
|
- "$(inherited) @executable_path/Frameworks"
|
||||||
|
PRODUCT_BUNDLE_IDENTIFIER: org.opengamestudio.blue
|
||||||
|
SWIFT_OBJC_BRIDGING_HEADER: src/BlueBridgingHeader.h
|
||||||
|
type: application
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import UIKit
|
||||||
|
|
||||||
|
final class AppDelegate:
|
||||||
|
NSObject,
|
||||||
|
UIApplicationDelegate
|
||||||
|
{
|
||||||
|
let blue = BlueComponent()
|
||||||
|
let blueVM = BlueVM()
|
||||||
|
let render = RenderComponent()
|
||||||
|
let renderVM = RenderVM()
|
||||||
|
|
||||||
|
func application(
|
||||||
|
_ application: UIApplication,
|
||||||
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
|
||||||
|
) -> Bool {
|
||||||
|
otherSetupConsoleLogging(blue.ctrl, "Blue")
|
||||||
|
blue.setup()
|
||||||
|
otherSetupConsoleLogging(render.ctrl, "Render")
|
||||||
|
render.setup()
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#define EGL_CONST_IMPLEMENTATION
|
||||||
|
#include "eglConst.h"
|
||||||
|
|
||||||
|
#define EGL_IMPLEMENTATION
|
||||||
|
#include "egl.h"
|
||||||
|
|
||||||
|
#define RAYBRI_CONST_IMPLEMENTATION
|
||||||
|
#include "raybriConst.h"
|
||||||
|
|
||||||
|
#define RAYBRI_IMPLEMENTATION
|
||||||
|
#include "raybri.h"
|
||||||
|
|
||||||
|
#define RLGL_IMPLEMENTATION
|
||||||
|
#include "rlgl.h"
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
@main
|
||||||
|
struct BlueApp: App {
|
||||||
|
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
|
||||||
|
|
||||||
|
var body: some Scene {
|
||||||
|
WindowGroup {
|
||||||
|
ZStack {
|
||||||
|
RenderView()
|
||||||
|
.ignoresSafeArea()
|
||||||
|
BlueView(appDelegate.blueVM)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef OGS_BLUE_BRIDGING_HEADER_H
|
||||||
|
#define OGS_BLUE_BRIDGING_HEADER_H
|
||||||
|
|
||||||
|
#include "egl/egl.h"
|
||||||
|
#include "raybri/raybri.h"
|
||||||
|
|
||||||
|
#endif // OGS_BLUE_BRIDGING_HEADER_H
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/blue/blue.swift
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/blue/blueVM.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../../components/blue/ios/view/BlueView.swift
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../ver-mac/src/dialect.swift
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/egl/egl.h
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/egl/eglConst.h
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/other/other.swift
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/raybri/raybri.h
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/raybri/raybriConst.h
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/render.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/ios/renderAux.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/renderConst.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/ios/renderEffect.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/renderVM.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../../components/render/ios/view/RenderGLView.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../../components/render/ios/view/RenderView.swift
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>OGS blue</string>
|
||||||
|
<key>CFBundleDisplayName</key>
|
||||||
|
<string>OGS blue</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>org.opengamestudio.blue</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>ogs-blue</string>
|
||||||
|
<key>CFBundleIconFile</key>
|
||||||
|
<string>AppIcon</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>APPL</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>2.0.0</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1</string>
|
||||||
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
<string>11.0</string>
|
||||||
|
<key>NSHighResolutionCapable</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// swift-tools-version: 5.9
|
||||||
|
import Foundation
|
||||||
|
import PackageDescription
|
||||||
|
|
||||||
|
let raylibPrefix = ProcessInfo.processInfo.environment["RAYLIB_PREFIX"] ?? "/opt/homebrew"
|
||||||
|
|
||||||
|
let package = Package(
|
||||||
|
name: "OGSBlue",
|
||||||
|
platforms: [
|
||||||
|
.macOS(.v13)
|
||||||
|
],
|
||||||
|
targets: [
|
||||||
|
.target(
|
||||||
|
name: "RaylibBridge",
|
||||||
|
path: "src",
|
||||||
|
sources: ["Blue.c"],
|
||||||
|
publicHeadersPath: "raybri",
|
||||||
|
cSettings: [
|
||||||
|
.headerSearchPath("raybri"),
|
||||||
|
.unsafeFlags(["-I", "\(raylibPrefix)/include"])
|
||||||
|
]
|
||||||
|
),
|
||||||
|
.executableTarget(
|
||||||
|
name: "ogs-blue",
|
||||||
|
dependencies: ["RaylibBridge"],
|
||||||
|
path: "src",
|
||||||
|
exclude: ["raybri", "Blue.c"],
|
||||||
|
swiftSettings: [
|
||||||
|
.unsafeFlags(["-Xcc", "-DGL_SILENCE_DEPRECATION", "-Xcc", "-I\(raylibPrefix)/include"])
|
||||||
|
],
|
||||||
|
linkerSettings: [
|
||||||
|
.unsafeFlags([
|
||||||
|
"-L", "\(raylibPrefix)/lib",
|
||||||
|
"-lraylib"
|
||||||
|
])
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../res/AppIcon.icns
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../res/cube
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import AppKit
|
||||||
|
|
||||||
|
final class AppDelegate:
|
||||||
|
NSObject,
|
||||||
|
NSApplicationDelegate
|
||||||
|
{
|
||||||
|
let blue = BlueComponent()
|
||||||
|
let blueVM = BlueVM()
|
||||||
|
let render = RenderComponent()
|
||||||
|
let renderVM = RenderVM()
|
||||||
|
|
||||||
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||||
|
// Bring the app to the foreground
|
||||||
|
NSApp.setActivationPolicy(.regular)
|
||||||
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
|
|
||||||
|
otherSetupConsoleLogging(blue.ctrl, "Blue")
|
||||||
|
blue.setup()
|
||||||
|
otherSetupConsoleLogging(render.ctrl, "Render")
|
||||||
|
render.setup()
|
||||||
|
}
|
||||||
|
|
||||||
|
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#define RAYBRI_CONST_IMPLEMENTATION
|
||||||
|
#include "raybriConst.h"
|
||||||
|
|
||||||
|
#define RAYBRI_AUX_IMPLEMENTATION
|
||||||
|
#include "raybriAux.h"
|
||||||
|
|
||||||
|
#define RAYBRI_IMPLEMENTATION
|
||||||
|
#include "raybri.h"
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
@main
|
||||||
|
struct BlueApp: App {
|
||||||
|
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
|
||||||
|
|
||||||
|
var body: some Scene {
|
||||||
|
WindowGroup {
|
||||||
|
ZStack {
|
||||||
|
RenderView()
|
||||||
|
.ignoresSafeArea()
|
||||||
|
BlueView(appDelegate.blueVM)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.defaultSize(width: 640, height: 480)
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/blue/blue.swift
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/blue/blueVM.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../../components/blue/mac/view/BlueView.swift
|
||||||
@@ -0,0 +1,412 @@
|
|||||||
|
|
||||||
|
// Reusable "none" constant
|
||||||
|
public let DIALECT_CONTEXT_RECENT_FIELD_NONE = "none"
|
||||||
|
|
||||||
|
// Base protocol for each component's state
|
||||||
|
public protocol DialectContext {
|
||||||
|
var recentField: String { get set }
|
||||||
|
|
||||||
|
func field<T>(_ name: String) -> T
|
||||||
|
func fieldAny(_ name: String) -> Any
|
||||||
|
mutating func setField(_ name: String, _ value: Any)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default implementation of `fieldAny` method for the protocol
|
||||||
|
public extension DialectContext {
|
||||||
|
func fieldAny(_ name: String) -> Any {
|
||||||
|
return field(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The engine of the dialect components
|
||||||
|
public class DialectController {
|
||||||
|
var callbacks = [(DialectContext) -> Void]()
|
||||||
|
var context: DialectContext
|
||||||
|
var functions = [(DialectContext) -> DialectContext]()
|
||||||
|
var isProcessingQueue = false
|
||||||
|
var queue = [DialectContext]()
|
||||||
|
|
||||||
|
public init(_ context: DialectContext) {
|
||||||
|
self.context = context
|
||||||
|
}
|
||||||
|
|
||||||
|
func executeFunctions() {
|
||||||
|
let c = queue.removeFirst()
|
||||||
|
// Keep SSOT: Only allow single field change per should-function
|
||||||
|
context.recentField = c.recentField
|
||||||
|
context.setField(c.recentField, c.fieldAny(c.recentField))
|
||||||
|
|
||||||
|
for f in functions {
|
||||||
|
let ctx = f(context)
|
||||||
|
if ctx.recentField != DIALECT_CONTEXT_RECENT_FIELD_NONE {
|
||||||
|
queue.append(ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reportContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
func processQueue() {
|
||||||
|
// Prevent recursion.
|
||||||
|
if isProcessingQueue {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isProcessingQueue = true
|
||||||
|
|
||||||
|
while (queue.count > 0) {
|
||||||
|
executeFunctions()
|
||||||
|
}
|
||||||
|
|
||||||
|
isProcessingQueue = false
|
||||||
|
}
|
||||||
|
|
||||||
|
public func registerCallback(_ cb: @escaping (DialectContext) -> Void) {
|
||||||
|
callbacks.append(cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func registerFieldCallback(
|
||||||
|
_ fieldName: String,
|
||||||
|
_ cb: @escaping (DialectContext) -> Void
|
||||||
|
) {
|
||||||
|
callbacks.append({ c in
|
||||||
|
if c.recentField == fieldName {
|
||||||
|
cb(c)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public func registerFunction(_ f: @escaping (DialectContext) -> DialectContext) {
|
||||||
|
functions.append(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func reportContext() {
|
||||||
|
for cb in callbacks {
|
||||||
|
cb(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func set(
|
||||||
|
_ fieldName: String,
|
||||||
|
_ value: Any
|
||||||
|
) {
|
||||||
|
var c = context
|
||||||
|
c.setField(fieldName, value)
|
||||||
|
c.recentField = fieldName
|
||||||
|
queue.append(c)
|
||||||
|
processQueue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register several oneliner callbacks to a controller
|
||||||
|
func registerOneliners<T>(
|
||||||
|
_ ctrl: DialectController,
|
||||||
|
_ items: [Any]
|
||||||
|
) -> T? {
|
||||||
|
let halfCount = items.count / 2
|
||||||
|
for i in 0..<halfCount {
|
||||||
|
let field = items[i * 2] as! String
|
||||||
|
let callback = items[i * 2 + 1] as! (T) -> Void
|
||||||
|
ctrl.registerFieldCallback(field) { cc in
|
||||||
|
let c = cc as! T
|
||||||
|
callback(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A hack for generics to operate
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 didPrepareIOSGL = "didPrepareIOSGL"
|
||||||
|
public static let didPrepareMacGL = "didPrepareMacGL"
|
||||||
|
public static let didSetup = "didSetup"
|
||||||
|
public static let pixelSize = "pixelSize"
|
||||||
|
public static let reshapePixelSize = "reshapePixelSize"
|
||||||
|
public static let willDeinit = "willDeinit"
|
||||||
|
public static let willRecreateSurface = "willRecreateSurface"
|
||||||
|
|
||||||
|
}
|
||||||
|
public struct BlueContext: DialectContext {
|
||||||
|
public var didLaunch = Bool()
|
||||||
|
public var didSetup = Bool()
|
||||||
|
|
||||||
|
public var recentField = ""
|
||||||
|
|
||||||
|
public func field<T>(_ name: String) -> T {
|
||||||
|
if (name == "didLaunch") {
|
||||||
|
return didLaunch as! T
|
||||||
|
}
|
||||||
|
else if (name == "didSetup") {
|
||||||
|
return didSetup as! T
|
||||||
|
}
|
||||||
|
|
||||||
|
return "unknown-field-name" as! T
|
||||||
|
}
|
||||||
|
|
||||||
|
public mutating func setField(
|
||||||
|
_ name: String,
|
||||||
|
_ value: Any
|
||||||
|
) {
|
||||||
|
if (name == "didLaunch") {
|
||||||
|
didLaunch = value as! Bool
|
||||||
|
}
|
||||||
|
else if (name == "didSetup") {
|
||||||
|
didSetup = value as! Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct RenderContext: DialectContext {
|
||||||
|
public var backingPixelSize = [Int32]()
|
||||||
|
public var didLaunch = Bool()
|
||||||
|
public var didPrepareGL = Bool()
|
||||||
|
public var didPrepareIOSGL = Bool()
|
||||||
|
public var didPrepareMacGL = Bool()
|
||||||
|
public var didSetup = Bool()
|
||||||
|
public var pixelSize = [Int32]()
|
||||||
|
public var reshapePixelSize = [Int32]()
|
||||||
|
public var willDeinit = Bool()
|
||||||
|
public var willRecreateSurface = 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 == "didPrepareIOSGL") {
|
||||||
|
return didPrepareIOSGL as! T
|
||||||
|
}
|
||||||
|
else if (name == "didPrepareMacGL") {
|
||||||
|
return didPrepareMacGL 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
|
||||||
|
}
|
||||||
|
else if (name == "willRecreateSurface") {
|
||||||
|
return willRecreateSurface 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 == "didPrepareIOSGL") {
|
||||||
|
didPrepareIOSGL = value as! Bool
|
||||||
|
}
|
||||||
|
else if (name == "didPrepareMacGL") {
|
||||||
|
didPrepareMacGL = 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
|
||||||
|
}
|
||||||
|
else if (name == "willRecreateSurface") {
|
||||||
|
willRecreateSurface = value as! Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func blueSet(
|
||||||
|
_ key: String,
|
||||||
|
_ value: Any
|
||||||
|
) {
|
||||||
|
BlueComponent.singleton!.ctrl.set(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func renderSet(
|
||||||
|
_ key: String,
|
||||||
|
_ value: Any
|
||||||
|
) {
|
||||||
|
RenderComponent.singleton!.ctrl.set(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func blueShouldResetDidLaunch(_ c: BlueContext) -> BlueContext {
|
||||||
|
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 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 renderShouldResetDidPrepareGL(_ c: RenderContext) -> RenderContext {
|
||||||
|
var c = c
|
||||||
|
|
||||||
|
/* 1. For macOS */
|
||||||
|
if
|
||||||
|
c.recentField == F.didPrepareMacGL
|
||||||
|
{
|
||||||
|
c.didPrepareGL = true
|
||||||
|
c.recentField = F.didPrepareGL
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 2. For iOS */
|
||||||
|
if
|
||||||
|
c.recentField == F.didPrepareIOSGL &&
|
||||||
|
!c.didPrepareGL
|
||||||
|
{
|
||||||
|
c.didPrepareGL = true
|
||||||
|
c.recentField = F.didPrepareGL
|
||||||
|
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 renderShouldResetWillRecreateSurface(_ c: RenderContext) -> RenderContext {
|
||||||
|
var c = c
|
||||||
|
|
||||||
|
/* 1. Upon resize */
|
||||||
|
if
|
||||||
|
c.recentField == F.reshapePixelSize
|
||||||
|
{
|
||||||
|
c.willRecreateSurface = true
|
||||||
|
c.recentField = F.willRecreateSurface
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func blueRegisterShoulds(_ ctrl: DialectController) {
|
||||||
|
[
|
||||||
|
blueShouldResetDidLaunch,
|
||||||
|
|
||||||
|
].forEach { f in
|
||||||
|
ctrl.registerFunction { c in f(c as! BlueContext) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func renderRegisterShoulds(_ ctrl: DialectController) {
|
||||||
|
[
|
||||||
|
renderShouldResetDidLaunch,
|
||||||
|
renderShouldResetDidPrepareGL,
|
||||||
|
renderShouldResetPixelSize,
|
||||||
|
renderShouldResetWillRecreateSurface,
|
||||||
|
|
||||||
|
].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.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
|
||||||
|
F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) },
|
||||||
|
F.willRecreateSurface, { (c: RenderContext) in renderRecreateSurface(RenderVM.shared!) },
|
||||||
|
|
||||||
|
])
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/other/other.swift
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/raybri/raybri.h
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/raybri/mac/raybriAux.h
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/raybri/raybriConst.h
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/render.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/mac/renderAux.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/renderConst.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/mac/renderConstMac.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/renderConstShader.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/mac/renderEffect.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/render/renderVM.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../../components/render/mac/view/RenderGLView.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../../components/render/mac/view/RenderView.swift
|
||||||
@@ -20,3 +20,48 @@ ChkgfxContext:
|
|||||||
fields:
|
fields:
|
||||||
didLaunch: Bool
|
didLaunch: Bool
|
||||||
didSetup: 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
|
||||||
@@ -5,31 +5,10 @@ targets:
|
|||||||
ogs-chkgfx:
|
ogs-chkgfx:
|
||||||
type: application
|
type: application
|
||||||
platform: iOS
|
platform: iOS
|
||||||
deploymentTarget: "15.6"
|
deploymentTarget: "15.0"
|
||||||
sources:
|
sources:
|
||||||
- path: Assets.xcassets
|
- path: Assets.xcassets
|
||||||
- path: src
|
- path: src
|
||||||
- path: ../../components/render/ios
|
|
||||||
- path: ../../components/raybri/ios
|
|
||||||
dependencies:
|
|
||||||
- framework: Frameworks/libEGL.xcframework
|
|
||||||
embed: true
|
|
||||||
- framework: Frameworks/libGLESv2.xcframework
|
|
||||||
embed: true
|
|
||||||
settings:
|
settings:
|
||||||
base:
|
base:
|
||||||
INFOPLIST_FILE: Info.plist
|
INFOPLIST_FILE: Info.plist
|
||||||
PRODUCT_BUNDLE_IDENTIFIER: org.opengamestudio.chkgfx
|
|
||||||
SWIFT_OBJC_BRIDGING_HEADER: ../../components/raybri/ios/RaybriIOS-Bridging-Header.h
|
|
||||||
HEADER_SEARCH_PATHS:
|
|
||||||
- "$(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
|
|
||||||
LD_RUNPATH_SEARCH_PATHS:
|
|
||||||
- "$(inherited) @executable_path/Frameworks"
|
|
||||||
@@ -6,7 +6,6 @@ final class AppDelegate:
|
|||||||
{
|
{
|
||||||
let chkgfx = ChkgfxComponent()
|
let chkgfx = ChkgfxComponent()
|
||||||
let chkgfxVM = ChkgfxVM()
|
let chkgfxVM = ChkgfxVM()
|
||||||
let renderVM = RenderVM()
|
|
||||||
|
|
||||||
func application(
|
func application(
|
||||||
_ application: UIApplication,
|
_ application: UIApplication,
|
||||||
|
|||||||
@@ -6,11 +6,7 @@ struct ChkgfxApp: App {
|
|||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
ZStack {
|
ChkgfxView(appDelegate.chkgfxVM)
|
||||||
RenderView()
|
|
||||||
.ignoresSafeArea()
|
|
||||||
ChkgfxView(appDelegate.chkgfxVM)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,8 +119,13 @@ func registerOneliners<T>(
|
|||||||
|
|
||||||
// Context field names for static type check
|
// Context field names for static type check
|
||||||
public struct F {
|
public struct F {
|
||||||
|
public static let backingPixelSize = "backingPixelSize"
|
||||||
public static let didLaunch = "didLaunch"
|
public static let didLaunch = "didLaunch"
|
||||||
|
public static let didPrepareGL = "didPrepareGL"
|
||||||
public static let didSetup = "didSetup"
|
public static let didSetup = "didSetup"
|
||||||
|
public static let pixelSize = "pixelSize"
|
||||||
|
public static let reshapePixelSize = "reshapePixelSize"
|
||||||
|
public static let willDeinit = "willDeinit"
|
||||||
|
|
||||||
}
|
}
|
||||||
public struct ChkgfxContext: DialectContext {
|
public struct ChkgfxContext: DialectContext {
|
||||||
@@ -154,6 +159,72 @@ 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(
|
public func chkgfxSet(
|
||||||
_ key: String,
|
_ key: String,
|
||||||
_ value: Any
|
_ value: Any
|
||||||
@@ -161,6 +232,13 @@ public func chkgfxSet(
|
|||||||
ChkgfxComponent.singleton!.ctrl.set(key, value)
|
ChkgfxComponent.singleton!.ctrl.set(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func renderSet(
|
||||||
|
_ key: String,
|
||||||
|
_ value: Any
|
||||||
|
) {
|
||||||
|
RenderComponent.singleton!.ctrl.set(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext {
|
func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext {
|
||||||
var c = c
|
var c = c
|
||||||
|
|
||||||
@@ -179,6 +257,59 @@ func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext {
|
|||||||
return c
|
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) {
|
func chkgfxRegisterShoulds(_ ctrl: DialectController) {
|
||||||
[
|
[
|
||||||
chkgfxShouldResetDidLaunch,
|
chkgfxShouldResetDidLaunch,
|
||||||
@@ -187,3 +318,25 @@ func chkgfxRegisterShoulds(_ ctrl: DialectController) {
|
|||||||
ctrl.registerFunction { c in f(c as! ChkgfxContext) }
|
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/raybri/raybri.c
|
../../../../components/raybri/mac/raybri.c
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/raybri/mac/raybriAux.c
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/raybri/mac/raybriAux.h
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/raybri/mac/raybriConst.c
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/raybri/mac/raybriConst.h
|
||||||
@@ -1 +1 @@
|
|||||||
../../../../components/render/mac/renderAux.swift
|
../../../../components/render/renderAux.swift
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
../../../../components/raybri/raybriConst.h
|
||||||
@@ -1 +1 @@
|
|||||||
../../../../components/render/mac/renderAux.swift
|
../../../../components/render/renderAux.swift
|
||||||
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
||||||
|
|
||||||
|
T=$SDIR/step
|
||||||
|
source $SDIR/paths
|
||||||
|
|
||||||
|
TARGET=ogs-blue
|
||||||
|
|
||||||
|
STEP=0
|
||||||
|
source $T/generateDialect $TARGET
|
||||||
|
source $T/buildMac $TARGET
|
||||||
|
source $T/packageMac $TARGET "OGS blue"
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#!/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
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
RAYLIB_IOS="raylib-ios-xcframeworks/raylib.xcframework"
|
||||||
|
RAYLIB_IOS_EGL="raylib-ios-xcframeworks/libEGL.xcframework"
|
||||||
|
RAYLIB_IOS_GLES="raylib-ios-xcframeworks/libGLESv2.xcframework"
|
||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
||||||
|
|
||||||
|
T=$SDIR/step
|
||||||
|
source $SDIR/paths
|
||||||
|
|
||||||
|
TARGET=ogs-blue
|
||||||
|
|
||||||
|
STEP=0
|
||||||
|
source $T/checkRaylibIOS $TARGET
|
||||||
|
source $T/generateDialect $TARGET
|
||||||
|
source $T/prepareANGLE $TARGET
|
||||||
|
source $T/generateIOS $TARGET
|
||||||
Executable
+8
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
SDIR=$(cd "$(dirname "$0")" ; pwd -P)
|
||||||
|
|
||||||
|
T=$SDIR/step
|
||||||
|
source $SDIR/paths
|
||||||
|
|
||||||
|
STEP=0
|
||||||
|
source $T/runMac ogs-blue "OGS blue"
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#!/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"
|
|
||||||
Executable
+16
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
DEP="raylib-ios-xcframeworks"
|
||||||
|
|
||||||
|
STEP=$((STEP+1))
|
||||||
|
echo -e "\n> > > > Step №$STEP. Check $DEP presence"
|
||||||
|
|
||||||
|
MISSING=0
|
||||||
|
[[ -e $SDIR/../../$RAYLIB_IOS ]] || MISSING=1
|
||||||
|
[[ -e $SDIR/../../$RAYLIB_IOS_EGL ]] || MISSING=1
|
||||||
|
[[ -e $SDIR/../../$RAYLIB_IOS_GLES ]] || MISSING=1
|
||||||
|
|
||||||
|
if [[ $MISSING -eq 1 ]]; then
|
||||||
|
echo "ERROR $DEP not found alongside this project"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Executable
+9
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
TARGET=$1
|
||||||
|
|
||||||
|
STEP=$((STEP+1))
|
||||||
|
echo -e "\n> > > > Step №$STEP. Generate iOS project for '$TARGET'"
|
||||||
|
|
||||||
|
cd $SDIR/../$TARGET/ver-ios
|
||||||
|
xcodegen
|
||||||
Executable
+22
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
TARGET=$1
|
||||||
|
|
||||||
|
STEP=$((STEP+1))
|
||||||
|
echo -e "\n> > > > Step №$STEP. Prepare ANGLE includes for '$TARGET'"
|
||||||
|
|
||||||
|
BUILD=$SDIR/../$TARGET/ver-ios/.build
|
||||||
|
INC=$BUILD/include
|
||||||
|
LIB=$BUILD/lib
|
||||||
|
mkdir -p $INC $LIB
|
||||||
|
|
||||||
|
# Create EGL and GLES symlinks because their internal includes refer to each other
|
||||||
|
# without knowing of XCFramework bounderies
|
||||||
|
ln -sfn "$SDIR/../../$RAYLIB_IOS_EGL/ios-arm64_x86_64-simulator/libEGL.framework/Headers" "$INC/libEGL"
|
||||||
|
ln -sfn "$SDIR/../../$RAYLIB_IOS_GLES/ios-arm64_x86_64-simulator/libGLESv2.framework/Headers" "$INC/libGLESv2"
|
||||||
|
|
||||||
|
# Symlink libraries for convenience, too
|
||||||
|
|
||||||
|
ln -sfn "$SDIR/../../$RAYLIB_IOS" "$LIB"
|
||||||
|
ln -sfn "$SDIR/../../$RAYLIB_IOS_EGL" "$LIB"
|
||||||
|
ln -sfn "$SDIR/../../$RAYLIB_IOS_GLES" "$LIB"
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
#!/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 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
|
|
||||||
|
|
||||||
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 --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/"
|
|
||||||
cp -R "$TMP/raylib-ios-xcframeworks/libEGL.xcframework" "$FRAMEWORKS/"
|
|
||||||
cp -R "$TMP/raylib-ios-xcframeworks/libGLESv2.xcframework" "$FRAMEWORKS/"
|
|
||||||
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