Skip to content

Commit

Permalink
Initial DebugDraw API support
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraVoves committed Apr 14, 2024
1 parent e07bc02 commit c5386af
Show file tree
Hide file tree
Showing 41 changed files with 7,289 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ jobs:
- name: Build example 02
shell: bash
run: cd examples/02-runtime-shaderc && zig build
- name: Build example 03
shell: bash
run: cd examples/03-debugdraw && zig build
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ REMEMBER: This is only zig binding. For BGFX stuff goto [bgfx](https://github.co

- [x] Zig api.
- [x] Compile as standard zig library.
- [x] `shaderc` as build artifact.
- [x] Shader compile in `build.zig` to `*.bin.h`.
- [x] Shader compile in `build.zig` and embed as zig module. (this is zig equivalent of `*.bin.h`)
- [x] Shader compile from code (in memory solution, no tmp files).
- [x] `shaderc` as build artifact.
- [x] Binding for [DebugDraw API](https://github.com/bkaradzic/bgfx/tree/master/examples/common/debugdraw)
- [x] `imgui` render backend. Use build option `imgui_include` to enable. ex. for
zgui: `.imgui_include = zgui.path("libs").getPath(b),`


- [ ] WIP: [DebugDraw API](https://github.com/bkaradzic/bgfx/tree/master/examples/common/debugdraw)

## Warnings

- Shader compile/shaderc api is first draft and need cleanup.
- Binding for DebugDraw is first draft and need cleanup.
- `shaderc` and `shaderc-static` need some time to compile.

## Know problems

Expand Down Expand Up @@ -72,13 +72,6 @@ See examples for binding usage and [bgfx](https://github.com/bkaradzic/bgfx) for
| `with_shaderc` | `true` | Compile with shaderc executable |
| `with_static_shaderc` | `true` | Compile with shaderc as static lib |

## License

Folders `libs`, `shaders`, `src/imgui_impl_bgfx` is copy&paste from [bgfx](https://github.com/bkaradzic/bgfx) for more
sell-contained experience and is licensed [by](https://github.com/bkaradzic/bgfx/blob/master/LICENSE)

Zig binding is licensed by [WTFPL](LICENSE)

## Examples

Examples use [zig-gamedev](https://github.com/zig-gamedev/zig-gamedev) as submodule.
Expand Down Expand Up @@ -134,3 +127,26 @@ zig-out/bin/runtime-shaderc
| `v` | Vsync on/off |
| `d` | Debug on/off |
| `r` | Recompile shaders form file |

### [03-debugdraw](examples/03-debugdraw/)

DebugDraw api usage example.

```sh
cd examples/03-debugdraw
zig build
zig-out/bin/runtime-shaderc
```

| Key | Description |
|-----|-----------------------------|
| `v` | Vsync on/off |
| `d` | Debug on/off |
| `r` | Recompile shaders form file |

## License

Folders `libs`, `shaders`, `src/imgui_impl_bgfx` is copy&paste from [bgfx](https://github.com/bkaradzic/bgfx) for more
sell-contained experience and is licensed [by](https://github.com/bkaradzic/bgfx/blob/master/LICENSE)

Zig binding is licensed by [WTFPL](LICENSE)
8 changes: 8 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ pub fn build(b: *std.Build) !void {
},
});

// debugdraw
bgfx.addCSourceFiles(.{
.flags = &cxx_options,
.files = &[_][]const u8{
"libs/bgfx/examples/common/debugdraw/debugdraw.cpp",
},
});

//
// Bgfx imgui backend
// TODO: zig based
Expand Down
2 changes: 1 addition & 1 deletion examples/00-minimal/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub fn main() anyerror!u8 {
// Create view and proj matrices
//
const viewMtx = zm.lookAtRh(zm.f32x4(0.0, 0.0, -50.0, 1.0), zm.f32x4(0.0, 0.0, 0.0, 1.0), zm.f32x4(0.0, 1.0, 0.0, 0.0));
var projMtx = zm.perspectiveFovRhGl(0.25 * math.pi, @as(f32, @floatFromInt(old_size[0])) / @as(f32, @floatFromInt(old_size[1])), 0.1, 100.0);
var projMtx: zm.Mat = undefined;

//
// Default state
Expand Down
2 changes: 1 addition & 1 deletion examples/02-runtime-shaderc/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ pub fn main() anyerror!u8 {
// Create view and proj matrices
//
const viewMtx = zm.lookAtRh(zm.f32x4(0.0, 0.0, -50.0, 1.0), zm.f32x4(0.0, 0.0, 0.0, 1.0), zm.f32x4(0.0, 1.0, 0.0, 0.0));
var projMtx = zm.perspectiveFovRhGl(0.25 * math.pi, @as(f32, @floatFromInt(old_size[0])) / @as(f32, @floatFromInt(old_size[1])), 0.1, 100.0);
var projMtx: zm.Mat = undefined;

//
// Default state
Expand Down
53 changes: 53 additions & 0 deletions examples/03-debugdraw/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const std = @import("std");

const zbgfx = @import("zbgfx");

pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

//
// OPTIONS
//

//
// Dependencies
//
const zbgfx_dep = b.dependency(
"zbgfx",
.{
.target = target,
.optimize = optimize,
},
);

const zglfw = b.dependency(
"zglfw",
.{
.target = target,
.optimize = optimize,
},
);

const zmath = b.dependency(
"zmath",
.{
.target = target,
.optimize = optimize,
},
);

const exe = b.addExecutable(.{
.name = "debugdraw",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
});
b.installArtifact(exe);
exe.linkLibrary(zbgfx_dep.artifact("bgfx"));

exe.root_module.addImport("zbgfx", zbgfx_dep.module("zbgfx"));

exe.root_module.addImport("zmath", zmath.module("root"));
exe.root_module.addImport("zglfw", zglfw.module("root"));
exe.linkLibrary(zglfw.artifact("glfw"));
}
14 changes: 14 additions & 0 deletions examples/03-debugdraw/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.{
.name = "zbgfx-minimal",
.version = "0.1.0",
.paths = .{
"build.zig",
"build.zig.zon",
},

.dependencies = .{
.zbgfx = .{ .path = "../../" },
.zglfw = .{ .path = "../libs/zig-gamedev/libs/zglfw" },
.zmath = .{ .path = "../libs/zig-gamedev/libs/zmath" },
},
}
Loading

0 comments on commit c5386af

Please sign in to comment.