So I am iterating through a couple of meshes each stored in its own GL_ARRAY_BUFFER, but both sharing the same glVertexAttribPointer structure. I iterate through each render/draw pass in a for loop:
if (sConfig.mRendering.isRenderTypeActive(RENDER_TYPE_SINGLE_MESH) ||
sConfig.mRendering.isRenderTypeActive(RENDER_TYPE_TWO_MESH)) {
const int mesh_count = sConfig.mRendering.isRenderTypeActive(RENDER_TYPE_TWO_MESH) ? 2 : 1;
for (int i = 0; i < mesh_count; i++) {
std::lock_guard<std::mutex> lock(mModelDataMutex[i]);
mUniV_VertexTransform->setValue(mModelTransform[i]);
glBindBuffer(GL_ARRAY_BUFFER, mVBOs[i]); CHECK_GL_ERR;
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)mVertexCount[i]); CHECK_GL_ERR;
}
}
And set the data for each VBO using a couple of calls to the following function:
bool ::updateModelData(const RenderCloud& data, VERTEX_BUFFER_ID id /*= VBID_MESH_0*/)
{
if (id < VBID_COUNT)
{
std::lock_guard<std::mutex> lock(mModelDataMutex[id]);
// Bind Point VBO
glBindBuffer(GL_ARRAY_BUFFER, mVBOs[id]); CHECK_GL_ERR_RET;
// Set coordinate attribute
glVertexAttribPointer(BTID_COORDS, 3, GL_FLOAT, GL_FALSE, RenderCloud::elemSize(), (GLvoid*)BT_COORDS_OFFSET); CHECK_GL_ERR_RET;
glEnableVertexAttribArray(BTID_COORDS); CHECK_GL_ERR_RET;
// Set the normals attribute
glVertexAttribPointer(BTID_NORMALS, 3, GL_FLOAT, GL_FALSE, RenderCloud::elemSize(), (GLvoid*)(BT_NORMALS_OFFSET)); CHECK_GL_ERR_RET;
glEnableVertexAttribArray(BTID_NORMALS); CHECK_GL_ERR_RET;
// Set the colors attribute
glVertexAttribPointer(BTID_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, RenderCloud::elemSize(), (GLvoid*)(BT_COLOR_OFFSET)); CHECK_GL_ERR_RET;
glEnableVertexAttribArray(BTID_COLOR); CHECK_GL_ERR_RET;
// Copy Data
glBufferData(GL_ARRAY_BUFFER, data.pts.size() * data.elemSize(), data.pts.data(), GL_STATIC_DRAW); CHECK_GL_ERR_RET;
mVertexCount[id] = data.pts.size();
// Unbind buffer
glBindBuffer(GL_ARRAY_BUFFER, 0); CHECK_GL_ERR_RET;
return true;
}
return false;
}
I can verify the data is there for both VBOs, but only the first VBO in the for loop is rendered using glDrawArrays()
They share the shame geometry shader, which is then used by a deferred rendering stack to apply effects.
Does each glDrawArrays() call need its own instance of the geometry shader, so long as they all share the same draw buffers?
It is not the bound vertex buffer object, which define an array of generic vertex attribute data, but it is the state which is stored in the default vertex array object.
When you call glVertexAttribPointer the the array of generic vertex attribute data is defined. If at this point, an array buffer is bound, then the array definition refers to the buffer object.
This means you have to switch the array definition, before you draw the object:
glBindBuffer(GL_ARRAY_BUFFER, mVBOs[id]);
glVertexAttribPointer(BTID_COORDS, 3, GL_FLOAT, GL_FALSE, RenderCloud::elemSize(), (GLvoid*)BT_COORDS_OFFSET);
glEnableVertexAttribArray(BTID_COORDS);
glVertexAttribPointer(BTID_NORMALS, 3, GL_FLOAT, GL_FALSE, RenderCloud::elemSize(), (GLvoid*)(BT_NORMALS_OFFSET));
glEnableVertexAttribArray(BTID_NORMALS);
glVertexAttribPointer(BTID_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, RenderCloud::elemSize(), (GLvoid*)(BT_COLOR_OFFSET));
glEnableVertexAttribArray(BTID_COLOR);
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)mVertexCount[i]);
glBindBuffer(GL_ARRAY_BUFFER, 0);
But I recommend to use a Vertex Array Object. A vertex array object stores the state of the generic vertex array definition:
GLuint vao[VBID_COUNT];
....
glGenVertexArrays( 1, vao[i] );
glBindVertexArray( vao[i] );
glBindBuffer(GL_ARRAY_BUFFER, mVBOs[id]);
glVertexAttribPointer(BTID_COORDS, 3, GL_FLOAT, GL_FALSE, RenderCloud::elemSize(), (GLvoid*)BT_COORDS_OFFSET);
glEnableVertexAttribArray(BTID_COORDS);
glVertexAttribPointer(BTID_NORMALS, 3, GL_FLOAT, GL_FALSE, RenderCloud::elemSize(), (GLvoid*)(BT_NORMALS_OFFSET));
glEnableVertexAttribArray(BTID_NORMALS);
glVertexAttribPointer(BTID_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, RenderCloud::elemSize(), (GLvoid*)(BT_COLOR_OFFSET));
glEnableVertexAttribArray(BTID_COLOR);
glBufferData(GL_ARRAY_BUFFER, data.pts.size() * data.elemSize(), data.pts.data(), GL_STATIC_DRAW);
mVertexCount[id] = data.pts.size();
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray( 0 );
glBindVertexArray( vao[i] );
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)mVertexCount[i]);
glBindVertexArray( 0 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With