1

基本上,我正在使用由两个三角形和一个片段着色器组成的屏幕大小的矩形进行某种图像处理,它正在完成整个处理工作。实际效果类似于动画,因为它依赖于一个统一变量,称为current_frame.

我对用“MPix/s”来衡量性能非常感兴趣。我所做的是这样的:

/* Setup all necessary stuff, including:                 */
/* - getting the location of the `current_frame` uniform */
/* - creating an FBO, adding a color attachment          */
/*   and setting it as the current one                   */

double current_frame = 0;
double step = 1.0f / NUMBER_OF_ITERATIONS;

tic(); /* Start counting the time */

for (i = 0; i < NUMBER_OF_ITERATIONS; i++)
{
    glUniform1f(current_frame_handle, current_frame);
    current_frame += step;
    glDrawArrays(GL_TRIANGLES, 0, NUMBER_OF_INDICES);
    glFinish();
}

double elapsed_time = tac(); /* Get elapsed time in seconds */

/* Calculate achieved pixels per second */
double pps = (OUT_WIDTH * OUT_HEIGHT * NUMBER_OF_ITERATIONS) / elapsed_time;

/* Sanity check by using reading the output into a buffer */
/* using glReadPixels and saving this buffer into a file  */

就理论而言,我的概念有什么问题吗?

此外,我的印象是,glFinish()在移动硬件上不一定要等待先前的渲染调用,并且可能会进行一些优化。

当然,我总是可以在每次抽签后强制执行glReadPixels(),但这会很慢,所以这并没有真正的帮助。

你能否告诉我我的测试场景是否合理以及是否还有更多可以做的事情。

4

2 回答 2

2

关于速度,使用glDrawArrays()仍然重复共享顶点。

glDrawElements() 是减少数组中顶点数量的解决方案,因此它允许向 OpenGL 传输更少的数据。

http://www.songho.ca/opengl/gl_vertexarray.html

只是把它扔在那里以帮助加快你的结果。就您的时间概念而言,对我来说它看起来不错。你得到的结果与你所希望的相似吗?

于 2011-07-12T19:17:56.087 回答
0

我会预先计算所有可能的帧,然后使用 glEnableClientState() 和 glTexCoordPointer() 来更改在每个帧中绘制现有纹理的哪一部分。

于 2011-07-12T19:06:58.940 回答