Skip to content

[Wrapper] Can't pass null to ShaderSource() #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tonitch opened this issue May 10, 2025 · 0 comments
Open

[Wrapper] Can't pass null to ShaderSource() #13

tonitch opened this issue May 10, 2025 · 0 comments

Comments

@tonitch
Copy link

tonitch commented May 10, 2025

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:

  1. we make the last argument optional and if null then send null pointer
  2. 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
  3. don't change anything and tell me the secret to tricking zig in sending a null pointer
  4. don't change anything, and I create an array of the size manually.

zopengl/src/wrapper.zig

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)),
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant