Skip to content
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

Types for offsets: usize vs ?usize vs ?*c_void #21

Closed
silversquirl opened this issue May 31, 2021 · 0 comments · Fixed by #24
Closed

Types for offsets: usize vs ?usize vs ?*c_void #21

silversquirl opened this issue May 31, 2021 · 0 comments · Fixed by #24
Labels
enhancement New feature or request

Comments

@silversquirl
Copy link
Contributor

The OpenGL API has a habit of using void pointers for offsets into buffer objects, eg. in glVertexAttribPointer, glDrawElements, etc.
The only reason I see for this being done is so pointer arithmetic can be used to remove the need to multiply things by sizeof (T), however Zig does not have pointer arithmetic, leaving this as purely confusing and difficult to handle, without any ergonomic benefit.

zgl currently uses ?usize for the offset parameter to vertexAttribPointer, and ?*const c_void for the parameter to glDrawElements and glDrawElementsInstanced. The way the former is converted into the C type will cause checked undefined behaviour if 0 is passed in, and the latter is difficult to deal with as discussed above.

I propose changing all of these functions, as well as any future functions making use of this kind of offset, to use usize, which can be converted into a *allowzero c_void for passing to C.

@ikskuh ikskuh added the enhancement New feature or request label May 31, 2021
@ikskuh ikskuh closed this as completed in #24 Jun 2, 2021
ikskuh pushed a commit that referenced this issue Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants