我正在编写一个 OpenGL3 2D 引擎。目前,我正在尝试解决瓶颈。因此请提供 AMD Profiler 的以下输出:http: //h7.abload.de/img/profilerausa.png
数据是使用数千个精灵制作的。
但是,在 50.000 个精灵时,testapp 在 5 fps 时已经无法使用。
这表明,我的瓶颈是我使用的变换函数。那就是对应的函数: http ://code.google.com/p/nightlight2d/source/browse/NightLightDLL/NLBoundingBox.cpp#130
void NLBoundingBox::applyTransform(NLVertexData* vertices)
{
if ( needsTransform() )
{
// Apply Matrix
for ( int i=0; i<6; i++ )
{
glm::vec4 transformed = m_rotation * m_translation * glm::vec4(vertices[i].x, vertices[i].y, 0, 1.0f);
vertices[i].x = transformed.x;
vertices[i].y = transformed.y;
}
m_translation = glm::mat4(1);
m_rotation = glm::mat4(1);
m_needsTransform = false;
}
}
我不能在着色器中这样做,因为我一次批处理所有精灵。这意味着,我必须使用 CPU 来计算转换。
我的问题是:解决这个瓶颈的最佳方法是什么?
我不使用任何线程 atm,所以当我使用 vsync 时,我也会受到额外的性能影响,因为它会等待屏幕完成。这告诉我我应该使用线程。
另一种方法是使用 OpenCL 也许?我想避免使用 CUDA,因为据我所知它只能在 NVIDIA 卡上运行。那正确吗?
后文:
如果您愿意,可以在此处下载演示:
http://www63.zippyshare.com/v/45025690/file.html
请注意,这需要安装 VC++2008,因为它是用于运行分析器的调试版本。