2

I did some performance testing and came up with this:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

for(U32 i=0;i<objectList.length();++i)
{
    PC d("draw");
    VoxelObject& obj = *objectList[i];
    glBindVertexArray(obj.vao);
    tmpM = usedView->projection * usedView->transform * obj.transform;
    glUniformMatrix4fv(shader.modelViewMatrixLoc, 1, GL_FALSE, tmpM.data());
    //glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, typesheet.tbo);
    glUniform1i(shader.typesheetLoc, 0);
    glDrawArrays(GL_TRIANGLES, 0, VoxelObject::VERTICES_PER_BOX*obj.getNumBoxes());
    d.out(); // 2 calls 0.000085s and 0.000043s each

}

PC swap("swap");
SDL_GL_SwapWindow(mainWindow); // 1 call 0.007823s
swap.out();

The call to SDL_GL_SwapWindow(mainWindow); is taking 200 times longer than the draw calls! To my understanding i thought all that function was supposed to do was swap buffers. That would mean that the time it takes to swap would scale depending on the screen size right? No it scales based on the amount of geometry... I did some searching online, I have double buffering enable and vsync is turned off. I am stumped.

Evan Baad
  • 91
  • 5
  • Maybe your are not using a hardware accelerated OpenGL implementation. Fetch the OpenGL vendor with glGetString to find out. – Cecilio Pardo Jan 07 '16 at 08:40

1 Answers1

7

Your OpenGL driver is likely doing deferred rendering.

That means the calls to the glDrawArrays and friends don't draw anything. Instead they buffer all required information to perform the operation later on.

The actual rendering happens inside SDL_GL_SwapWindow.

This behavior is typical these days because you want to avoid having to synchronize between the CPU and the GPU as much as possible.

Nils Pipenbrinck
  • 83,631
  • 31
  • 151
  • 221