glopes
glopes

Reputation: 4380

Where to store VAO attributes?

I'm designing a small OpenGL abstraction layer for rapid prototyping GPU rendering. Right now I am designing the object model for separating buffer objects from the shader rendering code.

The goal is to make it really easy to change both data and shader code, so I'm trying to reduce the number of explicit couplings between the two.

One thing that is a bit of a thorn in my path right now is the VAO. For example, if my vertex data looks like this:

vbo = [1,1,1,1]

Then this data can actually work with these two shader vertex declarations:

in float x;
in float y;

or

in vec2 position;

The problem is that VAO binding needs to be different. My conclusion is that VAO information is more closely associated with the shader code than it is with the actual object data.

Furthermore, you can actually "infer" a VAO specification straight from the shader code (i.e. VAO is a kind of semantics and the semantics is specified in the shader code).

So I was thinking that rather than storing the VAO in the data object, I could actually infer it automatically and store it in the shader object. Then everytime I draw I bind the VBO from the data object and the VAO from the shader. This way I could have the same VBO work with different shaders.

Is this crazy? Are there any fundamentally obvious disadvantages to this?

Upvotes: 1

Views: 292

Answers (1)

Andon M. Coleman
Andon M. Coleman

Reputation: 43319

The general decoupling you are speaking of is already possible in recent versions of GL through the Vertex Attrib Binding and Program Interface Query extensions.

The amount of work necessary to implement this functionality yourself is noteworthy, but you certainly are not locked into rigid vertex data specification in any version of GL since the inception of generic vertex attributes (ARB VP1). Since you have tagged this GL4, you may find the two core extensions mentioned above (both of which went core in GL 4.3) useful.

Upvotes: 4

Related Questions