Skip to content

Commit e351733

Browse files
committed
Initial commit
0 parents  commit e351733

File tree

9 files changed

+1871
-0
lines changed

9 files changed

+1871
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.zig-cache
2+
zig-out

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "OpenGL-Registry"]
2+
path = OpenGL-Registry
3+
url = https://github.com/KhronosGroup/OpenGL-Registry

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2024 MIDLIGHT STUDIOS
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

OpenGL-Registry

Submodule OpenGL-Registry added at 5466009

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Zig OpenGL Bindings
2+
A fully Zig OpenGL bindings generator, for dynamically loading or through a static interface.
3+
4+
### CURRENTLY ONLY SUPPORTS DYNAMIC LOADING ON WINDOWS
5+
6+
> Updated for Zig [0.13.0](https://ziglang.org/download).
7+
8+
> Uses [edqx/dishwasher](https://github.com/edqx/dishwasher) to parse the [OpenGL XML Spec](https://github.com/KhronosGroup/OpenGL-Registry/blob/main/xml/gl.xml).
9+
10+
## Usage: build.zig
11+
In your build.zig, you can use the `generateBindingsModule` method from the generator's build script:
12+
```zig
13+
const openglBindings = @import("zig-opengl-bindings");
14+
...
15+
const opengl = openglBindings.addBindingsModule(b, .{
16+
.api = "gles2",
17+
.version = "GL_ES_VERSION_3_0",
18+
.static = false
19+
});
20+
...
21+
executable.root_module.addImport("opengl", opengl);
22+
```
23+
24+
## Usage: Standalone
25+
### Cloning
26+
Ensure to also clone the [OpenGL-Registry](https://github.com/KhronosGroup/OpenGL-Registry/) submodule when cloning this
27+
repository. Use:
28+
```sh
29+
git clone https://github.com/MidlightStudio/zig-opengl-bindings.git --recurse-submodules
30+
```
31+
32+
### Building
33+
Building the standalone binary is as simple as:
34+
```sh
35+
zig build -Doptimize=ReleaseFast
36+
```
37+
38+
### Running
39+
You can then run the script with
40+
```sh
41+
./zig-out/bin/zig-opengl-bindings gles2 GL_ES_VERSION_3_0 out.zig
42+
```
43+
Add `--static` for a static interface

build.zig

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
7+
const dishwasher = b.dependency("dishwasher", .{});
8+
9+
const exe = b.addExecutable(.{
10+
.name = "zig-opengl-bindings",
11+
.root_source_file = b.path("src/main.zig"),
12+
.target = target,
13+
.optimize = optimize,
14+
});
15+
16+
exe.root_module.addImport("gl.xml", b.addModule("gl-xml", .{ .root_source_file = b.path("OpenGL-Registry/xml/gl.xml") }));
17+
exe.root_module.addImport("dishwasher", dishwasher.module("dishwasher"));
18+
19+
b.installArtifact(exe);
20+
21+
const run_cmd = b.addRunArtifact(exe);
22+
23+
run_cmd.step.dependOn(b.getInstallStep());
24+
25+
if (b.args) |args| {
26+
run_cmd.addArgs(args);
27+
}
28+
29+
const run_step = b.step("run", "Run the app");
30+
run_step.dependOn(&run_cmd.step);
31+
}
32+
33+
pub const BindingsOptions = struct {
34+
api: []const u8 = "gl",
35+
version: []const u8 = "GL_VERSION_4_6",
36+
static: bool = false,
37+
};
38+
39+
pub fn addBindingsModule(b: *std.Build, options: BindingsOptions) *std.Build.Module {
40+
var zigOpenGLBindings = b.dependency("zig-opengl-bindings", .{ .optimize = @as([]const u8, "ReleaseFast") });
41+
const exe = zigOpenGLBindings.artifact("zig-opengl-bindings");
42+
43+
const buildGLBindingsCmd = std.Build.Step.Run.create(b, b.fmt("generate opengl bindings", .{}));
44+
45+
buildGLBindingsCmd.addFileArg(exe.getEmittedBin());
46+
buildGLBindingsCmd.addArg(options.api);
47+
buildGLBindingsCmd.addArg(options.version);
48+
49+
const outputPath = buildGLBindingsCmd.addOutputFileArg("gl.zig");
50+
if (options.static) {
51+
buildGLBindingsCmd.addArg("--static");
52+
}
53+
54+
return b.addModule("opengl", .{ .root_source_file = outputPath });
55+
}

build.zig.zon

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.{
2+
.name = "zig-opengl-bindings",
3+
.version = "0.0.0",
4+
.dependencies = .{
5+
.@"dishwasher" = .{
6+
.url = "https://github.com/edqx/dishwasher/archive/refs/tags/1.0.4.zip",
7+
.hash = "12209f29d4963ec005990c46310ce63d883b2c02d1e79906ec60ec1b4f40466d34a0"
8+
}
9+
},
10+
.paths = .{
11+
"build.zig",
12+
"build.zig.zon",
13+
"src",
14+
"OpenGL-Registry/xml/gl.xml"
15+
},
16+
}

0 commit comments

Comments
 (0)