Prepare hello-raylib for Windows (#8)
Co-authored-by: Михаил Капелько <kornerr@gmail.com>
This commit was merged in pull request #8.
This commit is contained in:
1 parent
b111ab6323
commit
c0be6b1d8d
41 files changed
+214
-46
No files matched your search
@@ -11,6 +11,9 @@ Remote: `https://git.opengamestudio.org/mahjong/mahjong`.
|
||||
a GTK GLArea, system raylib and shared packaging scripts; Linux runtime
|
||||
verification remains required. See the source study and reuse map in section 12 of
|
||||
[docs/components-over-platforms.md](docs/components-over-platforms.md).
|
||||
Its Windows target currently displays only the shared HRB title, with shared
|
||||
build/run scripts and icon; Render symbols are placeholders for the common
|
||||
generated engine, and native Windows verification remains required.
|
||||
- `hello/hello-platform/` — macOS + iOS + Android + Linux + Windows platform-support sample (Hello counter). Its
|
||||
structure, startup flow and dialect rules are in
|
||||
[docs/hello-platform.md](docs/hello-platform.md); read that file whenever anything
|
||||
|
||||
@@ -91,14 +91,20 @@
|
||||
Build config: +assertions
|
||||
```
|
||||
|
||||
* Install Raylib
|
||||
|
||||
Unpack [source code zip][raylib-zip] (and rename to `raylib` dir) alongside the project dir
|
||||
|
||||
## Components
|
||||
|
||||
| Component | Android | iOS | Linux | macOS | Windows | Description | Image |
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| craylib | X | X | √ | √ | ? | **craylib** exposes installed raylib headers and library linkage to Swift | N/A |
|
||||
| craylib | X | X | √ | √ | √ | **craylib** exposes installed Raylib headers and library linkage to Swift | N/A |
|
||||
| glbri| X | √ | X | X | √ | Open**GL** **bri**dge manages graphics context and surface through EGL for select platforms | N/A |
|
||||
| hp | √ | √ | √ | √ | √ | **h**ello-**p**latform is a simple UI to validate platform support | |
|
||||
| hrb | √ | √ | √ | √ | ? | **h**ello-**r**ayli**b** is a simple raylib rendering to validate platform support | |
|
||||
| hrb | √ | √ | √ | √ | ? | **h**ello-**r**ayli**b** is a simple Raylib rendering to validate platform support | |
|
||||
|
||||
[raylib-zip]: https://github.com/raysan5/raylib/archive/refs/tags/6.2.zip
|
||||
[rzip]: https://github.com/ghera/raylib-iOS/releases/download/6.2.0-iOS/raylib-ios-xcframeworks-6.2.0-iOS.zip
|
||||
[swiftly]: https://www.swift.org/install/linux/
|
||||
[vs]: https://www.swift.org/install/windows/
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
module CRaylib [system] {
|
||||
header "shim.h"
|
||||
export *
|
||||
}
|
||||
@@ -1,29 +1,29 @@
|
||||
#ifndef EGL_H
|
||||
#define EGL_H
|
||||
#ifndef GLBRI_H
|
||||
#define GLBRI_H
|
||||
|
||||
#include "eglConst.h"
|
||||
#include "glbriConst.h"
|
||||
#include <libEGL/libEGL.h>
|
||||
#include <libGLESv2/GLES/gl.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct EGLState {
|
||||
typedef struct GLBriState {
|
||||
void *caLayer;
|
||||
EGLConfig cfg;
|
||||
EGLContext ctx;
|
||||
EGLDisplay display;
|
||||
EGLSurface surface;
|
||||
} EGLState;
|
||||
} GLBriState;
|
||||
|
||||
bool eglInit(EGLState *st);
|
||||
bool eglMakeCurrentContext(EGLState *st);
|
||||
bool eglResetSurface(EGLState *st);
|
||||
void eglShutdown(EGLState *st);
|
||||
bool glbriInit(GLBriState *st);
|
||||
bool glbriMakeCurrentContext(GLBriState *st);
|
||||
bool glbriResetSurface(GLBriState *st);
|
||||
void glbriShutdown(GLBriState *st);
|
||||
|
||||
// Source
|
||||
|
||||
#if defined(EGL_IMPLEMENTATION)
|
||||
#if defined(GLBRI_IMPLEMENTATION)
|
||||
|
||||
bool eglInit(EGLState *st) {
|
||||
bool glbriInit(GLBriState *st) {
|
||||
st->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (st->display == EGL_NO_DISPLAY) {
|
||||
return false;
|
||||
@@ -39,13 +39,13 @@ bool eglInit(EGLState *st) {
|
||||
|
||||
EGLint cfgCount = 0;
|
||||
if (
|
||||
eglChooseConfig(st->display, EGL_CFG, &st->cfg, 1, &cfgCount) == EGL_FALSE ||
|
||||
eglChooseConfig(st->display, GLBRI_CFG, &st->cfg, 1, &cfgCount) == EGL_FALSE ||
|
||||
cfgCount < 1
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
st->ctx = eglCreateContext(st->display, st->cfg, EGL_NO_CONTEXT, EGL_CTX);
|
||||
st->ctx = eglCreateContext(st->display, st->cfg, EGL_NO_CONTEXT, GLBRI_CTX);
|
||||
if (st->ctx == EGL_NO_CONTEXT) {
|
||||
return false;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ bool eglInit(EGLState *st) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool eglMakeCurrentContext(EGLState *st) {
|
||||
bool glbriMakeCurrentContext(GLBriState *st) {
|
||||
if (eglMakeCurrent(st->display, st->surface, st->surface, st->ctx) == EGL_FALSE) {
|
||||
return false;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ bool eglMakeCurrentContext(EGLState *st) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool eglResetSurface(EGLState *st) {
|
||||
bool glbriResetSurface(GLBriState *st) {
|
||||
// Destroy previous surface
|
||||
if (st->surface != EGL_NO_SURFACE) {
|
||||
eglDestroySurface(st->display, st->surface);
|
||||
@@ -83,13 +83,13 @@ bool eglResetSurface(EGLState *st) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void eglShutdown(EGLState *st) {
|
||||
void glbriShutdown(GLBriState *st) {
|
||||
eglMakeCurrent(st->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
eglDestroySurface(st->display, st->surface);
|
||||
eglDestroyContext(st->display, st->ctx);
|
||||
eglTerminate(st->display);
|
||||
}
|
||||
|
||||
#endif // EGL_IMPLEMENTATION
|
||||
#endif // GLBRI_IMPLEMENTATION
|
||||
|
||||
#endif // EGL_H
|
||||
#endif // GLBRI_H
|
||||
@@ -1,18 +1,18 @@
|
||||
#ifndef EGL_CONST_H
|
||||
#define EGL_CONST_H
|
||||
#ifndef GLBRI_CONST_H
|
||||
#define GLBRI_CONST_H
|
||||
|
||||
#include <libEGL/libEGL.h>
|
||||
|
||||
// Header
|
||||
|
||||
extern const EGLint EGL_CFG[];
|
||||
extern const EGLint EGL_CTX[];
|
||||
extern const EGLint GLBRI_CFG[];
|
||||
extern const EGLint GLBRI_CTX[];
|
||||
|
||||
// Source
|
||||
|
||||
#if defined(EGL_CONST_IMPLEMENTATION)
|
||||
#if defined(GLBRI_CONST_IMPLEMENTATION)
|
||||
|
||||
const EGLint EGL_CFG[] = {
|
||||
const EGLint GLBRI_CFG[] = {
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_RED_SIZE, 8,
|
||||
@@ -23,11 +23,11 @@ const EGLint EGL_CFG[] = {
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
const EGLint EGL_CTX[] = {
|
||||
const EGLint GLBRI_CTX[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
#endif // EGL_CONST_IMPLEMENTATION
|
||||
#endif // GLBRI_CONST_IMPLEMENTATION
|
||||
|
||||
#endif // EGL_CONST_H
|
||||
#endif // GLBRI_CONST_H
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#define TRACELOG(level, ...) do { fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while (0)
|
||||
|
||||
#define EGL_CONST_IMPLEMENTATION
|
||||
#include "egl/eglConst.h"
|
||||
#define GLBRI_CONST_IMPLEMENTATION
|
||||
#include "glbri/glbriConst.h"
|
||||
|
||||
#define EGL_IMPLEMENTATION
|
||||
#include "egl/egl.h"
|
||||
#define GLBRI_IMPLEMENTATION
|
||||
#include "glbri/glbri.h"
|
||||
|
||||
#define RAYBRI_IMPLEMENTATION
|
||||
#include "raybri/raybri.h"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import UIKit
|
||||
|
||||
func renderDraw(_ vm: RenderVM) {
|
||||
guard eglMakeCurrentContext(&vm.glView.st) else { return }
|
||||
guard glbriMakeCurrentContext(&vm.glView.st) else { return }
|
||||
raybriRender(Int32(vm.pixelSize[0]), Int32(vm.pixelSize[1]))
|
||||
eglSwapBuffers(vm.glView.st.display, vm.glView.st.surface)
|
||||
}
|
||||
@@ -14,6 +14,6 @@ func renderPixelSize(_ view: UIView) -> [Int] {
|
||||
}
|
||||
|
||||
func renderRecreateSurface(_ vm: RenderVM) {
|
||||
eglResetSurface(&vm.glView.st)
|
||||
eglMakeCurrentContext(&vm.glView.st)
|
||||
glbriResetSurface(&vm.glView.st)
|
||||
glbriMakeCurrentContext(&vm.glView.st)
|
||||
}
|
||||
@@ -5,10 +5,10 @@ import UIKit
|
||||
func renderDeinit(_ vm: RenderVM) {
|
||||
vm.timer?.invalidate()
|
||||
vm.timer = nil
|
||||
eglMakeCurrentContext(&vm.glView.st)
|
||||
glbriMakeCurrentContext(&vm.glView.st)
|
||||
raybriShutdown()
|
||||
|
||||
eglShutdown(&vm.glView.st)
|
||||
glbriShutdown(&vm.glView.st)
|
||||
}
|
||||
|
||||
func renderInit(_ vm: RenderVM) {
|
||||
@@ -16,9 +16,9 @@ func renderInit(_ vm: RenderVM) {
|
||||
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") }
|
||||
guard glbriInit(&vm.glView.st) else { fatalError("ERROR Could not initialize EGL") }
|
||||
guard glbriResetSurface(&vm.glView.st) else { fatalError("ERROR Could not reset EGL surface") }
|
||||
guard glbriMakeCurrentContext(&vm.glView.st) else { fatalError("ERROR Could not make EGL context current") }
|
||||
|
||||
raybriInit()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import UIKit
|
||||
|
||||
final class RenderGLView: UIView {
|
||||
var st = EGLState()
|
||||
var st = GLBriState()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
../mac/render.swift
|
||||
@@ -0,0 +1,2 @@
|
||||
// Placeholder required by the shared generated Dialect engine
|
||||
func renderRecreateSurface(_ vm: RenderVM) {}
|
||||
@@ -0,0 +1 @@
|
||||
../mac/renderConst.swift
|
||||
@@ -0,0 +1,6 @@
|
||||
// Placeholders required by the shared generated Dialect engine
|
||||
func renderDeinit(_ vm: RenderVM) {}
|
||||
|
||||
func renderInit(_ vm: RenderVM) {}
|
||||
|
||||
func renderStartTimer(_ vm: RenderVM) {}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Placeholder required by the shared generated Dialect engine
|
||||
final class RenderVM {
|
||||
var didPrepareGL = false
|
||||
var pixelSize = [Int]()
|
||||
|
||||
static private(set) weak var shared: RenderVM?
|
||||
|
||||
init() {
|
||||
Self.shared = self
|
||||
}
|
||||
}
|
||||
@@ -599,7 +599,7 @@ their component/controller may survive. queueEvent guarantees Android's renderin
|
||||
thread but does not create, restore or guarantee a current EGL context.
|
||||
|
||||
iOS cleanup stops its timer, makes the context current, calls raybriShutdown and
|
||||
then eglShutdown. The latter lives in components/egl/egl.h and owns unbinding,
|
||||
then glbriShutdown. The latter lives in components/glbri/ios/glbri.h and owns unbinding,
|
||||
surface/context destruction and display termination. Preserve that order so
|
||||
graphics resources are released before their context disappears.
|
||||
|
||||
@@ -721,3 +721,42 @@ Reference APIs checked against the implementation:
|
||||
[GTK unrealize](https://docs.gtk.org/gtk4/signal.Widget.unrealize.html),
|
||||
[GTK framebuffer/scale implementation](https://github.com/GNOME/gtk/blob/4.14.5/gtk/gtkglarea.c),
|
||||
[rlgl extension initialization](https://github.com/raysan5/raylib/blob/6.2/src/rlgl.h).
|
||||
|
||||
### GL bridge naming
|
||||
|
||||
The iOS EGL helper component is named glbri to avoid collisions with external
|
||||
EGL/egl.h headers on case-insensitive filesystems. Its source owners are
|
||||
components/glbri/ios/glbri.h and glbriConst.h; ver-ios/src/glbri links directly
|
||||
to those files. Helper functions use the glbri prefix, state is GLBriState and
|
||||
bridge constants/macros use GLBRI_. Native EGL API names and framework includes
|
||||
remain unchanged.
|
||||
|
||||
### Windows UI-only stage
|
||||
|
||||
hello-raylib/ver-windows currently mirrors hello-platform/ver-windows's SwiftCrossUI
|
||||
and WinUIBackend skeleton. HRBApp presents HRBView and calls delegate setup from
|
||||
onAppear. The delegate retains HRBComponent and HRBVM, registers logging once in
|
||||
init, initializes the title through Dialect and applies otherSetupWindowIcon(101).
|
||||
|
||||
The app links hrb.swift directly from components/hrb and the SwiftCrossUI model/view
|
||||
directly from components/hrb/linux. It shares the generated ver-mac/src/dialect.swift
|
||||
without changing dialect.yml. Because that engine also references Render symbols,
|
||||
components/render/windows contains a placeholder VM and no-op effect/auxiliary
|
||||
functions; render.swift and renderConst.swift link to the macOS owners. The delegate
|
||||
does not create or start Render, and there is no native graphics view or bridge yet.
|
||||
|
||||
run-windows differs from hello-platform's entry script only by TARGET;
|
||||
build-windows also exports RAYLIB_DIR. Their step scripts symlink directly to
|
||||
hello-platform's implementations.
|
||||
res/AppIcon.res links to the repository resource; the shared build step exports
|
||||
APP_RES_DIR for resource linkage. No ANGLE dependency, DLL packaging or icon
|
||||
generation is part of this stage. Host manifest/syntax and symlink checks do not
|
||||
replace a native Windows build/run.
|
||||
|
||||
The Windows executable now depends on a CRaylib system-library target under
|
||||
src/craylib, with direct symlinks to the shared shim.h and Windows module map.
|
||||
It exposes rlgl.h without linking a raylib library or making graphics calls.
|
||||
build-windows exports RAYLIB_DIR, defaulting to a raylib checkout alongside mj;
|
||||
override it to select another checkout. Package.swift force-unwraps that variable
|
||||
and adds its src directory to the Swift Clang importer's search path. Direct
|
||||
manifest commands also need RAYLIB_DIR. No pkg-config installation is required.
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash -e
|
||||
SDIR=$(cd "$(dirname "$0")" && pwd -P)
|
||||
|
||||
T=$SDIR/step
|
||||
TARGET=hello-raylib
|
||||
|
||||
export RAYLIB_DIR="${RAYLIB_DIR:-$SDIR/../../../../raylib}"
|
||||
|
||||
STEP=0
|
||||
source "$T/buildWindows" "$TARGET"
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash -e
|
||||
SDIR=$(cd "$(dirname "$0")" && pwd -P)
|
||||
|
||||
T=$SDIR/step
|
||||
TARGET=hello-raylib
|
||||
|
||||
STEP=0
|
||||
source "$T/runWindows" "$TARGET"
|
||||
@@ -0,0 +1 @@
|
||||
../../../hello-platform/util/step/buildWindows
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../hello-platform/util/step/runWindows
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef HRB_BRIDGING_HEADER_H
|
||||
#define HRB_BRIDGING_HEADER_H
|
||||
|
||||
#include "egl/egl.h"
|
||||
#include "glbri/glbri.h"
|
||||
#include "raybri/raybri.h"
|
||||
|
||||
#endif // HRB_BRIDGING_HEADER_H
|
||||
@@ -1 +0,0 @@
|
||||
../../../../../components/egl/egl.h
|
||||
@@ -1 +0,0 @@
|
||||
../../../../../components/egl/eglConst.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/glbri/ios/glbri.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/glbri/ios/glbriConst.h
|
||||
@@ -0,0 +1,32 @@
|
||||
// swift-tools-version: 5.10
|
||||
import Foundation
|
||||
import PackageDescription
|
||||
|
||||
let raylibDir = ProcessInfo.processInfo.environment["RAYLIB_DIR"]!
|
||||
let resDir = ProcessInfo.processInfo.environment["APP_RES_DIR"]!
|
||||
|
||||
let package = Package(
|
||||
name: "hello-raylib",
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/moreSwift/swift-cross-ui", branch: "v0.10.0")
|
||||
],
|
||||
targets: [
|
||||
.systemLibrary(name: "CRaylib", path: "src/craylib"),
|
||||
.executableTarget(
|
||||
name: "hello-raylib",
|
||||
dependencies: [
|
||||
"CRaylib",
|
||||
.product(name: "SwiftCrossUI", package: "swift-cross-ui"),
|
||||
.product(name: "WinUIBackend", package: "swift-cross-ui")
|
||||
],
|
||||
path: "src",
|
||||
exclude: ["craylib"],
|
||||
swiftSettings: [
|
||||
.unsafeFlags(["-Xcc", "-I\(raylibDir)/src"])
|
||||
],
|
||||
linkerSettings: [
|
||||
.unsafeFlags(["-Xlinker", "\(resDir)/AppIcon.res"])
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
../../../../res/AppIcon.res
|
||||
@@ -0,0 +1,16 @@
|
||||
import SwiftCrossUI
|
||||
import WinUIBackend
|
||||
|
||||
@main
|
||||
struct HRBApp: App {
|
||||
let delegate = HRBAppDelegate()
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup("hello-raylib") {
|
||||
HRBView(delegate.hrbVM)
|
||||
.onAppear {
|
||||
delegate.setup()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
final class HRBAppDelegate {
|
||||
let hrb = HRBComponent()
|
||||
let hrbVM = HRBVM()
|
||||
|
||||
init() {
|
||||
otherSetupConsoleLogging(hrb.ctrl, "HRB")
|
||||
}
|
||||
|
||||
func setup() {
|
||||
hrb.setup()
|
||||
otherSetupWindowIcon(101)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/craylib/windows/module.modulemap
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/craylib/shim.h
|
||||
@@ -0,0 +1 @@
|
||||
../../ver-mac/src/dialect.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/hrb/hrb.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/hrb/linux/hrbVM.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../components/hrb/linux/view/HRBView.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/other/other.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/other/windows/otherWindows.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/windows/render.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/windows/renderAux.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/windows/renderConst.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/windows/renderEffect.swift
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../components/render/windows/renderVM.swift
|
||||
Reference in new issue
Block a user