pkg/glslang: complete the API

This commit is contained in:
Mitchell Hashimoto
2023-11-15 22:05:45 -08:00
parent 4afaea19d6
commit 54ee8c1e3d
3 changed files with 62 additions and 1 deletions

View File

@ -23,7 +23,7 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(&tests_run.step); test_step.dependOn(&tests_run.step);
// Uncomment this if we're debugging tests // Uncomment this if we're debugging tests
b.installArtifact(test_exe); // b.installArtifact(test_exe);
} }
} }

View File

@ -1,5 +1,6 @@
pub const c = @import("c.zig"); pub const c = @import("c.zig");
pub usingnamespace @import("init.zig"); pub usingnamespace @import("init.zig");
pub usingnamespace @import("program.zig");
pub usingnamespace @import("shader.zig"); pub usingnamespace @import("shader.zig");
test { test {

60
pkg/glslang/program.zig Normal file
View File

@ -0,0 +1,60 @@
const std = @import("std");
const c = @import("c.zig");
const testlib = @import("test.zig");
const Shader = @import("shader.zig").Shader;
pub const Program = opaque {
pub fn create() !*Program {
if (c.glslang_program_create()) |ptr| return @ptrCast(ptr);
return error.OutOfMemory;
}
pub fn delete(self: *Program) void {
c.glslang_program_delete(@ptrCast(self));
}
pub fn addShader(self: *Program, shader: *Shader) void {
c.glslang_program_add_shader(@ptrCast(self), @ptrCast(shader));
}
pub fn link(self: *Program, messages: c_int) !void {
if (c.glslang_program_link(@ptrCast(self), messages) != 0) return;
return error.GlslangFailed;
}
pub fn spirvGenerate(self: *Program, stage: c.glslang_stage_t) void {
c.glslang_program_spirv_generate(@ptrCast(self), stage);
}
pub fn spirvGetSize(self: *Program) usize {
return @intCast(c.glslang_program_spirv_get_size(@ptrCast(self)));
}
pub fn spirvGet(self: *Program, buf: []u8) void {
c.glslang_program_spirv_get(@ptrCast(self), buf.ptr);
}
pub fn spirvGetPtr(self: *Program) ![*]u8 {
return c.glslang_program_SPIRV_get_ptr(@ptrCast(self));
}
pub fn sprivGetMessages(self: *Program) ![:0]const u8 {
const ptr = c.glslang_program_spirv_get_messages(@ptrCast(self));
return std.mem.sliceTo(ptr, 0);
}
pub fn getInfoLog(self: *Program) ![:0]const u8 {
const ptr = c.glslang_program_get_info_log(@ptrCast(self));
return std.mem.sliceTo(ptr, 0);
}
pub fn getDebugInfoLog(self: *Program) ![:0]const u8 {
const ptr = c.glslang_program_get_info_debug_log(@ptrCast(self));
return std.mem.sliceTo(ptr, 0);
}
};
test {
var program = try Program.create();
defer program.delete();
}