Hey!
Im wondering if it’s a good idea to modify a buffer like this with glBufferSubData, or is it better maybe using uniforms?
Right now i update the rectVBO with the rectMODS array everytime a press the left mouse button.
My goal is to render quads from some kind of game, maybe and RTS.
So there might be quite a lot of quads including many units, map/terrain objects etc…
CJE_Rectangle rect1 =
{
-150.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
-150.0f, 150.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
- 50.0f, 150.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
- 50.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f
};
CJE_Rectangle rect2 =
{
50.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
50.0f, 450.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
800.0f, 450.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
800.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f
};
CJE_Rectangle rectVertices[] =
{
rect1,
rect2
}
// HERE IM CREATING VBO's and VAO's
//....
//...
//...
float rectMODS[8] =
{
-150.0f, 0.0f,
-150.0f, 150.0f,
- 50.0f, 150.0f,
- 50.0f, 0.0f,
};
while(!glfwWindowShouldClose(window) && running)
{
checkInput(window);
glClearColor(0.0f, 0.2f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
if(keyPressed[LEFT_MOUSE_BUTTON])
{
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
for(int i = 0; i < sizeof(float) * 8; i++)
{
rectMODS[i] += 1.0f;
}
for(int i = 0; i < 4; i++)
{
glBufferSubData(GL_ARRAY_BUFFER, (sizeof(float) * 7 * i), sizeof(float) * 2, &rectMODS[i * 2]);
}
}