ziglibs / zgl

Zig OpenGL Wrapper
MIT License
425 stars 62 forks source link

Make TextureUnit non-exhaustive + add TextureUnit.unit #55

Closed sin-ack closed 2 years ago

sin-ack commented 2 years ago

TextureUnit is now non-exhaustive which allows one to specify other texture units than the ones defined. Additionally, this commit adds the TextureUnit.unit function which allows one to generate these texture units easily.

Closes #54

sin-ack commented 2 years ago

Now that I did this, I'm wondering whether there is a better way to do this by allowing TextureUnit to generate these arbitrary values itself:

const TextureUnit = enum(types.Enum) {
    texture_0,
    // ...
    _,

    pub fn unit(id: types.Enum) TextureUnit {
        return @intToEnum(TextureUnit, @enumToInt(texture_0) + id);
    }
};

This could then be used like zgl.activeTexture(zgl.TextureUnit.unit(20));, which might be nicer. What do you think?

sin-ack commented 2 years ago

Ended up switching over to this, as it is nicer.