If I have a few Program3D
objects (each with it's own Vertex-Shader and Fragment-Shader responsible for it's own rendering task), do I need to instantiate a new VertexBuffer3D
and IndexBuffer3D
so that they store the data only relevant to the vertex-data format used by their corresponding Program3D
?
For example, if I was planning to define Quads in different vertex-data formats, such as:
var vertexData:Vector.<Number>;
//Vertex-Format A:
vertexData = new <Number>[
//X, Y, U, V
-.5, -.5, 0, 0,
.5, -.5, 1, 0,
.5, .5, 1, 1,
-.5, .5, 0, 1
];
//Vertex-Format B:
vertexData = new <Number>[
//X, Y, U, V, Matrix-Constant ID, Color
-.5, -.5, 0, 0, 3, 0xff0000,
.5, -.5, 1, 0 , 3, 0x00ff00,
.5, .5, 1, 1, 3, 0x0000ff,
-.5, .5, 0, 1, 3, 0xffff00
];
//Vertex-Format C:
vertexData = new <Number>[
//X, Y, Matrix-Constant ID
-.5, -.5, 3,
.5, -.5, 3,
.5, .5, 3,
-.5, .5, 3
];
Would I need to create one VertexBuffer3D
and IndexBuffer3D
to store format A, another one for format B, and yet another one for format C? Or can the various formats be mixed inside the same VertexBuffer3D
and then make some clever (or confusing!) use of a single IndexBuffer3D
to draw the triangles?
You can mix and match freely. Think of a vertex program needing all inputs hooked up to something. Where that is comming from is done with setVertexBufferAt. It can come from different buffer, it can come even from the same location. Just like connecting some wires. Index buffers just jump around in the vertex buffers. You can, and should, re-use them as much as possible.