I want to draw two layers in my scene (let us say main layer and debug info layer). Now I draw my layers in this way:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
layer1->draw();
layer2->draw();
I want do something like this:
static int frameCount = 0;
layer1->draw();
if (frameCount % 2) {
layer2->draw();
}
frameCount++;
But I don't want draw my second layer each second frame. I want draw this layer each frame, but redraw each second. For example, I'm drawing my layer in this way:
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glDrawArrays(GL_POINTS, 0, vertexNumber);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
How can I redraw this layer only each second frame?
you have to use backbuffering technique so:
There are two options
Choose what is better for you. I usually have bool _redraw
for each redraw and rerender the texture only if something changed in the layer. But visualize the content of texture each frame ...