-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
OpenGL/ES defines a large number of values that have virtually no type safety - you can often pass completely unrelated values such as:
GL_BUFFER_USAGEGL_DEPTH_FUNCGL_VIEWPORT
to parameters that take an unsigned integer, and get no type checking to help you fail faster. A straightforward example would be:
const ShaderType = enum(GLenum) {
Vertex = 0x8B31,
Fragment = 0x8B30,
Compute = 0x91B9,
};
pub fn glCreateShader(shader_type: ShaderType) GLuint {}Note that in the native API, you could pass any integer, where with this system you could only pass valid parameters. This gets a lot of value when dealing with more complicated functions:
// Raw openGL binding:
extern fn glFramebufferTexture2D(target: GLenum, attachment: GLenum, textarget: GLenum, texture: GLuint, level: GLint) void;
// Zig binding:
const FramebufferTarget = enum (GLenum) { ... };
const FramebufferAttachment = enum (GLenum) { ... };
const TextureTarget = enum (GLenum) { ... };
pub fn framebufferTexture2D(target: FramebufferTarget, attachment: FramebufferAttachment, textarget: TextureTarget, texture: Texture, level: GLint) void {}For variable-sized values such as fn glActiveTexture(texture: GLenum) void, which takes GL_TEXTUREi to GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1 values, these can still be generated for the user at comptime into a bounded typesafe enum.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request