I am working on a renderer that can manage drawing a lot of instances of 3d hexagon tiles that can have a different material on each face (well just about each face anyway)
in rendering instances of each tile I use a VBO that contains 4 by 4 matrix transforms which are made up of four 4 dimensional vectors - each vector being a row of the transform matrix, and then I assign shader attributes to each vector and use glVertexAttribDivisor to make the transforms per instance rather than per vertex - so that it kind of looks like this
glBindBuffer(GL_ARRAY_BUFFER, transformBuffer); glEnableVertexAttribArray(TRANS1_ATT); glVertexAttribPointer(TRANS1_ATT, 4, GL_FLOAT, GL_FALSE, sizeof(NSMatrix4Df), 0); glVertexAttribDivisor(TRANS1_ATT, 1); glEnableVertexAttribArray(TRANS2_ATT); glVertexAttribPointer(TRANS2_ATT, 4, GL_FLOAT, GL_FALSE, sizeof(NSMatrix4Df), (const GLvoid*)(sizeof(NSVec4Df))); glVertexAttribDivisor(TRANS2_ATT, 1); glEnableVertexAttribArray(TRANS3_ATT); glVertexAttribPointer(TRANS3_ATT, 4, GL_FLOAT, GL_FALSE, sizeof(NSMatrix4Df), (const GLvoid*)(sizeof(NSVec4Df) * 2)); glVertexAttribDivisor(TRANS3_ATT, 1); glEnableVertexAttribArray(TRANS4_ATT); glVertexAttribPointer(TRANS4_ATT, 4, GL_FLOAT, GL_FALSE, sizeof(NSMatrix4Df), (const GLvoid*)(sizeof(NSVec4Df) * 3)); glVertexAttribDivisor(TRANS4_ATT, 1);
I just use the attribute divisor call to tell opengl to advance through the buffer once per instance rather than once per vertex (as each instance needs a transform not each vertex)..
So my question is this... I can potentially have a very large number of instances of one submesh - worst case scenerio 64 by 64 by 64 = 262,144 instances of a single submesh (really would never happen none the less that is the maximum).. Because I have a toolkit that lets the user place tiles in the map in real time the transformBuffer can potentially change once per frame
When creating and filling this transformBuffer, what do you think would be the best way to minimize runtime overhead? Make the buffer a certain size and use glBufferSubData and then resize the buffer only when the number of instances gets above the buffer size (kind of like how a c++ std::vector works)?