Skip to content

Commit ece6db9

Browse files
committed
WIP: Upgrade BGFX
1 parent 8711923 commit ece6db9

1,331 files changed

Lines changed: 300468 additions & 70514 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
project.xcworkspace/
2828
xcuserdata/
2929

30+
# Kevelop
31+
*.kdev4
32+
3033
kcov-output/
3134

3235
imgui.ini
@@ -36,6 +39,7 @@ _static.zig
3639
# VSCode
3740
.vscode/launch.json
3841
.vscode/settings.json
42+
.vscode/tasks.json
3943

4044
# Idea
4145
.idea/
@@ -51,4 +55,4 @@ result.xml
5155
*.tracy
5256
NodeEditor.json
5357

54-
*.zst
58+
*.zst

.ide.zon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
.{
2+
.tasks = .{
3+
.{ .name = "Build", .type = "shell", .command = "zig", .args = .{"build"} },
4+
},
5+
26
.launchers = .{
37
.{ .name = "Unit tests", .program = .{ .path = "zig-out/bin/cetech1_test" }, .args = .{} },
48
.{ .name = "No asset root", .args = .{} },

build.zig

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const std = @import("std");
22
const builtin = @import("builtin");
33

44
pub const generate_ide = @import("src/tools/generate_ide.zig");
5+
const zbgfx = @import("zbgfx");
56

67
const min_zig_version = std.SemanticVersion.parse("0.15.1") catch @panic("Where is .zigversion?");
78
const cetech1_version = std.SemanticVersion.parse(@embedFile(".version")) catch @panic("Where is .version?");
@@ -131,6 +132,8 @@ pub fn createKernelExe(
131132
ignored_modules: ?[]const []const u8,
132133
ignored_modules_prefix: ?[]const []const u8,
133134
) !*std.Build.Step.Compile {
135+
const use_lld = !target.result.os.tag.isDarwin();
136+
134137
const exe = b.addExecutable(.{
135138
.name = bin_name,
136139
.version = versionn,
@@ -140,6 +143,7 @@ pub fn createKernelExe(
140143
.optimize = optimize,
141144
}),
142145
.use_llvm = true,
146+
.use_lld = use_lld,
143147
});
144148
exe.root_module.link_libc = true;
145149
exe.root_module.addImport("kernel", cetech1_kernel);
@@ -172,7 +176,7 @@ pub fn createStudioExe(
172176
return try createKernelExe(
173177
b,
174178
base_bin_name ++ "_studio",
175-
"studio",
179+
"run-studio",
176180
"Run studio",
177181
root_source,
178182
cetech1_kernel,
@@ -246,7 +250,7 @@ pub fn build(b: *std.Build) !void {
246250
.nfd_portal = b.option(bool, "nfd_portal", "build NFD with xdg-desktop-portal instead of GTK. ( Linux, nice for steamdeck;) )") orelse true,
247251

248252
// ZGUI
249-
.with_freetype = b.option(bool, "with_freetype", "build coreui with freetype support") orelse false,
253+
.with_freetype = b.option(bool, "with_freetype", "build coreui with freetype support") orelse true,
250254

251255
// BGFX
252256
.with_shaderc = b.option(bool, "with_shaderc", "build with shaderc support") orelse true,
@@ -264,6 +268,8 @@ pub fn build(b: *std.Build) !void {
264268
}
265269
const options_module = options_step.createModule();
266270

271+
const use_lld = !target.result.os.tag.isDarwin();
272+
267273
//
268274
// Extrnals
269275
//
@@ -343,7 +349,8 @@ pub fn build(b: *std.Build) !void {
343349
);
344350

345351
// ZBGFX
346-
const zbgfx = b.dependency(
352+
// TODO: Remove
353+
const zbgfx_dep = b.dependency(
347354
"zbgfx",
348355
.{
349356
.target = target,
@@ -475,7 +482,6 @@ pub fn build(b: *std.Build) !void {
475482
const gen_ide_step = b.step("gen-ide", "init/update IDE configs");
476483
{
477484
const ide = b.option(generate_ide.EditorType, "ide", "IDE for gen-ide command") orelse .VSCode;
478-
const no_zls = b.option(bool, "no_zls", "Dont write zls path with gen-ide command") orelse false;
479485

480486
const gen_ide = b.addRunArtifact(generate_ide_tool);
481487

@@ -493,10 +499,6 @@ pub fn build(b: *std.Build) !void {
493499
gen_ide.addArg("--config");
494500
gen_ide.addDirectoryArg(b.path(".ide.zon"));
495501

496-
if (no_zls) {
497-
gen_ide.addArg("--no-zls");
498-
}
499-
500502
gen_ide_step.dependOn(&gen_ide.step);
501503
}
502504

@@ -520,7 +522,8 @@ pub fn build(b: *std.Build) !void {
520522
});
521523

522524
if (options.with_shaderc) {
523-
b.installArtifact(zbgfx.artifact("shaderc"));
525+
const shaderc_install = try zbgfx.build_step.installShaderc(b, zbgfx_dep);
526+
b.getInstallStep().dependOn(shaderc_install);
524527
}
525528

526529
//
@@ -655,6 +658,7 @@ pub fn build(b: *std.Build) !void {
655658
.imports = &imports,
656659
}),
657660
.use_llvm = true,
661+
.use_lld = use_lld,
658662
});
659663
useSystemSDK(b, target, tests);
660664
b.installArtifact(tests);

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@
106106

107107
// zig-gamedev
108108
.system_sdk = .{
109-
.url = "https://github.com/zig-gamedev/system_sdk/archive/c0dbf11cdc17da5904ea8a17eadc54dee26567ec.tar.gz",
110-
.hash = "system_sdk-0.3.0-dev-alwUNnYaaAJAtIdE2fg4NQfDqEKs7QCXy_qYukAOBfmF",
109+
.url = "https://github.com/zig-gamedev/system_sdk/archive/777e76828f05d5d223df47a4c0de95ae4efde884.tar.gz",
110+
.hash = "system_sdk-0.3.0-dev-alwUNqAaaALJ5VoZImZo3n6prezBnQnrpziun3ZeZwcp",
111111
.lazy = true,
112112
},
113113
.zglfw = .{ .path = "externals/shared/lib/zglfw" },

docs/topics/getting-started.md

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,18 @@ Get ZIG `0.15.1`.
4646
</tab>
4747
</tabs>
4848

49-
## VSCode
50-
51-
> Repository contain recommended extension.
49+
## NVim
5250

53-
> add `-Dno_zls` to disable zls path change (For example if you are install zls via vscode plugin).
54-
> {style="note"}
51+
> This generate `vscode/{launch.json,tasks.json,settings.json}`
52+
> that can read pluggins in NVim (ex.: overseer, nvim-dap, ..)
5553
5654
1. Create vscode configs.
5755
<code-block lang="bash">
5856
# This generate vscode launch.json with predefined cases
5957
# create or update settings.json
6058
# and set zls path to locally builded
6159
zig build gen-ide -Dide=VSCode
62-
</code-block>
63-
2. Install extension `ziglang.vscode-zig` (or install all recommended)
60+
</code-block>
6461

6562
## Idea
6663

@@ -73,6 +70,19 @@ Need [zigbrains](https://plugins.jetbrains.com/plugin/22456-zigbrains)
7370
zig build gen-ide -Dide=IDEA
7471
</code-block>
7572

73+
## VSCode
74+
75+
> Repository contain recommended extension.
76+
77+
1. Create vscode configs.
78+
<code-block lang="bash">
79+
# This generate vscode launch.json with predefined cases
80+
# create or update settings.json
81+
# and set zls path to locally builded
82+
zig build gen-ide -Dide=VSCode
83+
</code-block>
84+
2. Install extension `ziglang.vscode-zig` (or install all recommended)
85+
7686
## Build
7787

7888
<tabs>
@@ -132,27 +142,6 @@ Need [zigbrains](https://plugins.jetbrains.com/plugin/22456-zigbrains)
132142
| `--test-ui-speed` | `fast`, `normal`, `cinematic` | `fast` | UI test speed. |
133143
| `--test-ui-junit` | `str` | `null` | UI test JUnit result filename. |
134144

135-
## ZLS
136-
137-
CETech provide ZLS as submodule, but you must build it.
138-
139-
<tabs>
140-
<tab title="MacOS/Linux">
141-
<code-block lang="bash">
142-
git submodule update --init externals/shared/repo/zls
143-
cd externals/shared/repo/zls
144-
zig build -Doptimize=ReleaseFast
145-
</code-block>
146-
</tab>
147-
<tab title="Windows">
148-
<code-block lang="bash">
149-
git submodule update --init externals/shared/repo/zls
150-
cd externals/shared/repo/zls
151-
zig.exe build -Doptimize=ReleaseFast
152-
</code-block>
153-
</tab>
154-
</tabs>
155-
156145
## Tracy profiler
157146

158147
CETech1 has builtin support for tracy profiler and provide Tracy as submodule, but you must build it first.

externals/shared/lib/zbgfx/README.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,22 @@ When [zig](https://codeberg.org/ziglang/zig) meets [bgfx](https://github.com/bka
99
- [x] Zig api.
1010
- [x] Compile as standard zig library.
1111
- [x] `shaderc` as build artifact.
12-
- [x] Shader compile in `build.zig` to `*.bin.h`.
13-
- [x] Shader compile in `build.zig` and embed as zig module. (this is zig equivalent of `*.bin.h`)
1412
- [x] Shader compile from runtime via `shaderc` as child process.
13+
- [x] Shader compile in `build.zig` and embed as zig module.
1514
- [x] Binding for [DebugDraw API](https://github.com/bkaradzic/bgfx/tree/master/examples/common/debugdraw)
1615
- [x] `imgui` render backend. Use build option `imgui_include` to enable. ex. for
1716
zgui: `.imgui_include = zgui.path("libs").getPath(b),`
1817
- [ ] Zig based allocator.
1918

20-
> [!IMPORTANT]
19+
> [!IMPORTANT]
20+
>
2121
> - This is only zig binding. For BGFX stuff goto [bgfx](https://github.com/bkaradzic/bgfx).
2222
> - Github repository is only mirror. Development continues [here](https://codeberg.org/cyberegoorg/zbgfx)
2323
2424
> [!WARNING]
25+
>
2526
> - `shaderc` need some time to compile.
2627
27-
> [!NOTE]
28-
> - If you build shaders/app and see something like `run shaderc (shader.bin.h) stderr`.
29-
This is not "true" error (build success), but only in debug build shader print some stuff to stderr and zig
30-
build catch it.
31-
3228
## License
3329

3430
Folders `libs`, `shaders` is copy&paste from [bgfx](https://github.com/bkaradzic/bgfx) for more sell-contained
@@ -42,9 +38,9 @@ Minimal is `0.15.1`. But you know try your version and believe.
4238

4339
## Bgfx version
4440

45-
- [BX](https://github.com/bkaradzic/bx//compare/ce31b1445475ecd4b090471144c4c30a1cbdd871...master)
46-
- [BImg](https://github.com/bkaradzic/bimg/compare/bf10ffbb3df1f9f12ad7a9105e5e96e11a9c5a0c...master)
47-
- [BGFX](https://github.com/bkaradzic/bgfx/compare/56eb016280731451c3b7f18433dc114df035d52a...master)
41+
- [BX](https://github.com/bkaradzic/bx/compare/cac72f6cfa0893393ea12692ebfacb4495f8c826...master)
42+
- [BImg](https://github.com/bkaradzic/bimg/compare/9114b47f532ce59cd0c6c9f8932df2c48888d4c1...master)
43+
- [BGFX](https://github.com/bkaradzic/bgfx/compare/a7016487e5970c5299bb837f1af42dcb24909a67...master)
4844

4945
## Getting started
5046

@@ -93,39 +89,39 @@ cd examples
9389
zig build
9490
```
9591

96-
### [00-Minimal](examples/00-minimal/)
92+
### [Minimal GLFW](examples/minimal-glfw/)
9793

9894
Minimal setup with GLFW for window and input.
9995

10096
```sh
101-
examples/zig-out/bin/00-minimal
97+
examples/zig-out/bin/minimal-glfw
10298
```
10399

104100
| Key | Description |
105101
|-----|--------------|
106102
| `v` | Vsync on/off |
107103
| `d` | Debug on/off |
108104

109-
### [01-ZGui](examples/01-zgui/)
105+
### [Shader embed](examples/shader-embed/)
110106

111-
Minimal setup for zgui/ImGui.
107+
Basic usage of shaders compiled in build and embed to zig module.
112108

113109
```sh
114-
examples/zig-out/bin/01-zgui
110+
examples/zig-out/bin/shader-embed
115111
```
116112

117113
| Key | Description |
118114
|-----|--------------|
119115
| `v` | Vsync on/off |
120116
| `d` | Debug on/off |
121117

122-
### [02-Runtime shaderc](examples/02-runtime-shaderc/)
118+
### [Shader runtime](examples/shader-runtime/)
123119

124120
Basic usage of shader compile in runtime.
125121
Try edit shaders in `zig-out/bin/shaders` and hit `r` to recompile.
126122

127123
```sh
128-
examples/zig-out/bin/02-runtime-shaderc
124+
examples/zig-out/bin/shader-runtime
129125
```
130126

131127
| Key | Description |
@@ -134,12 +130,25 @@ examples/zig-out/bin/02-runtime-shaderc
134130
| `d` | Debug on/off |
135131
| `r` | Recompile shaders form file |
136132

137-
### [03-debugdraw](examples/03-debugdraw/)
133+
### [ZGui](examples/zgui/)
134+
135+
Minimal setup for zgui/ImGui.
136+
137+
```sh
138+
examples/zig-out/bin/zgui
139+
```
140+
141+
| Key | Description |
142+
|-----|--------------|
143+
| `v` | Vsync on/off |
144+
| `d` | Debug on/off |
145+
146+
### [debugdraw](examples/debugdraw/)
138147

139148
DebugDraw api usage example.
140149

141150
```sh
142-
examples/zig-out/bin/03-debugdraw
151+
examples/zig-out/bin/debugdraw
143152
```
144153

145154
| Key | Description |

0 commit comments

Comments
 (0)