Out of interest, what do you mean that this is type safe? As opposed to what which wasn't?
glBindBuffer(int target, int handle)
accepts an int value as the target. You could pass in 6382 which would result in an OpenGL error, as it only accepts a selection of OpenGL values, e.g GL_ARRAY_BUFFER
. If you encapsulated that function in a method which only accepts those values (which is what the enum is for), then it's effectively (though not truely) making it type-safe. You cannot pass in a value such as 6382 as it would result in a compile time error.
You don't need to have an anon class per enum entry in this case...just pass in the target value to a constructor.
I thought of doing that but this approach allows you to name the entries whatever you like which is what I wanted to do. EDIT:
That would also eliminate the type-safety as you could similarly pass in 343278 to the constructor which would result in a runtime error.