SDL_GL_SwapWindow bad performance

徘徊边缘 提交于 2019-12-11 11:45:38

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/34650517/sdl-gl-swapwindow-bad-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!