I am working on a project which needs very clean geometry management. I decided to take this as a good chance to develop an API to wrap around some geometry-related OpenGL functionalities. This is definetly necessary to make project development easier.
Now, since the very beginning, I was very determined to pass per-vertex data using the interface defined by ARB_vertex_program. As I stated in a recent post in beginner’s forum, this allows more functionalities and also looks easier to implement. Having to call VertexAttribPointerARB(index, …) and EnableVertexAttribArrayARB(n) makes the code way better than having to choose what I am working and using a bunch of ifs to decide what function to use between ColorPointer, VertexPointer and stuff like that.
Now, ARB_vertex_program defines all the calls to VertexAttribPointerARB(0, …) to be equivalent to Vertex*(…). They both produce a vertex, no matter if vertex programs are enabled or not. Fine.
There are some references in the specification which says that aliasing between standard vertex attributes and generic vertex attributes can alias.
Building on the two things above, I was also thinking that EnableVertexAttribArrayARB(n) should be equivalent to EnableClientState, but looks like it is not.
glVertexPointer(vertexComponents, vertexFormat, vertexStride, vertexPointer);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(colorComponents, colorFormat, colorStride, colorPointer);
glEnableClientState(GL_COLOR_ARRAY);
After that, calling DrawElements produces the expected results - something is gettin rendered.
glVertexAttribPointerARB(0, vertexComponents, vertexFormat, vertexNormalize, vertexStride, vertexPointer);
glEnableVertexAttribArrayARB(0);
glVertexAttribPointerARB(3, colorComponents, colorFormat, colorNormalize, colorStride, colorPointer);
glEnableVertexAttribArrayARB(3);
Does not render at all.
I figured out there are two ways to make it work:
1- Enable vertex program mode and bind a decent VP. This is a quick and dirty solution.
2- Use standard attributes when possible - in the case VPs are enabled, they will override generic attributes and everything will go fine anyway.
I think using ifs to do (2) would be the better way however, I am not sure - this would require a lot of ifs in a performance path.
In other terms this means I can define a standard vertex attribute (example: color) to define a generic attribute (3), however, I cannot define a generic attribute (3) to define a standard attribute (color).
Since I am quite sure someone already figured out the best way wrap around that, I would like to get some advices on the topic.
Thanks.