SDL_GL_SwapWindow性能不佳 [英] SDL_GL_SwapWindow bad performance

查看:536
本文介绍了SDL_GL_SwapWindow性能不佳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些性能测试,结果如下:

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); (U32 i = 0; i< objectList.length(); ++ i)
{
PC b(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次调用0.000085s和0.000043s每个

}

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

调用 SDL_GL_SwapWindow(mainWindow); 比平局要长200倍!据我的理解,我认为所有的功能应该做的是交换缓冲区。这意味着交换所花费的时间将根据屏幕大小进行缩放?不,它基于几何的数量进行缩放......我在网上做了一些搜索,我有双缓冲启用和vsync关闭。我很难过。

解决方案

您的OpenGL驱动程序可能会执行延迟渲染。

这意味着对 glDrawArrays 和朋友的调用不会绘制任何内容。实际的渲染发生在SDL_GL_SwapWindow中。



实际渲染发生在SDL_GL_SwapWindow中。



现在这种行为很典型,因为您希望尽可能避免在CPU和GPU之间进行同步。

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.

解决方案

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.

这篇关于SDL_GL_SwapWindow性能不佳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆