-
Notifications
You must be signed in to change notification settings - Fork 9
Description
I tried to use this package for a simple triangle example and failed to load my shader. my code looks like
const vertexShader = gl.createShader(.vertex);
const vertexSource = @embedFile("vertex.glsl");
gl.shaderSource(vertexShader, &[_] [*:0]const u8{vertexSource}, null);
I struggled to get my second argument right, but the last one seems wrong to me.
Here is the documentation of the function : https://docs.gl/gl4/glShaderSource
The sources have to either be null terminated or have their length represented in the last argument. In my case, @embedFile
makes a null terminated string.
I started zig recently, and I don't really know what should be done here, so I could do it if you can give me some input on that.
My solutions are either:
- we make the last argument optional and if null then send null pointer
- don't take a third argument (after all, it's a wrapper) as the second argument already knows its size with
src_ptrs.len
. Currently, it seems that the wrapper still uses the same function signature but "translated" so this might not be desirable - don't change anything and tell me the secret to tricking zig in sending a null pointer
- don't change anything, and I create an array of the size manually.
Lines 2759 to 2776 in 27f5f22
// pub var shaderSource: *const fn ( | |
// shader: Uint, | |
// count: Sizei, | |
// string: [*c]const [*c]const Char, | |
// length: [*c]const Int, | |
// ) callconv(.C) void = undefined; | |
pub fn shaderSource(shader: Shader, src_ptrs: []const [*:0]const u8, src_lengths: []const u32) void { | |
assert(@as(Uint, @bitCast(shader)) > 0); | |
assert(src_ptrs.len > 0); | |
assert(src_ptrs.len <= std.math.maxInt(u32)); | |
assert(src_ptrs.len == src_lengths.len); | |
bindings.shaderSource( | |
@as(Uint, @bitCast(shader)), | |
@as(Sizei, @bitCast(@as(u32, @intCast(src_ptrs.len)))), | |
@as([*c]const [*c]const Char, @ptrCast(src_ptrs)), | |
@as([*c]const Int, @ptrCast(src_lengths.ptr)), | |
); | |
} |
Metadata
Metadata
Assignees
Labels
No labels