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

GLES: Make resource IDs typesafe #4

Open
rdunnington opened this issue Nov 30, 2023 · 0 comments
Open

GLES: Make resource IDs typesafe #4

rdunnington opened this issue Nov 30, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@rdunnington
Copy link
Collaborator

Zig has non-exhaustive enums, which can let us wrap the basic GLsizei type that is used for resource identifiers such as buffers, textures, shaders, etc, and help users avoid passing the wrong ID to the appropriate function. Then the relevant resource bindings would take the enum types instead of raw integers to give better hints as to how they're supposed to be used - these would decompose into the underlying raw integer type transparently inside the binding when calling the actual GLES function. For example:

pub const Texture = enum(gles.GLsizei) { 
    _,

    fn gen(textures: []Texture) void {}
    fn bind(: Texture, target: GLenum) void {}
};

pub fn framebufferTexture2D(target: GLenum, attachment: GLenum, textarget: GLenum, texture: Texture, level: GLint) void;

This idea has a lot of value with functions like framebufferTexture2D that take a lot of integer parameters, making it easy to accidentally pass the wrong type.

Thanks to Andrew for this idea.

@rdunnington rdunnington added the enhancement New feature or request label Nov 30, 2023
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

No branches or pull requests

1 participant