开发者

OpenGl: problem with MD2 animation performance

I got a problem (just bad code) with my renderMd2 function.

It just draws every vertex of the model (saved in floatarrays) with

 glBegin(GL_TRIANGLES);
 for(i = 0; i < numTriangles; i++)
 {
      CalculateNormal(vList[triIndex[i].meshIndex[0]].point,
           vList[triIndex[i].meshIndex[2]].point,
           vList[triIndex[i].meshIndex[1]].point);

    if (modelTex != NULL)
        glTexCoord2f(st[triIndex[i].stIndex[0]].s,
            st[triIndex[i].stIndex[0]].t);

      glVertex3fv(vList[triIndex[i].meshIndex[0]].point);

    if (modelTex != NULL)
        glTexCoord2f(st[triIndex[i].stIndex[2]].s ,
            st[triIndex[i].stIndex[2]].t);

      glVertex3fv(vList[triIndex[i].meshIndex[2]].point);

    if (modelTex != NULL)
        glTexCoord2f(st[triIndex[i].stIndex[1]].s,
            st[triIndex[i].stIndex[1]].t);

      glVertex3fv(vList[triIndex[i].meshIndex[1]].point);
 }
 glEnd();

The frame time increases from 1.852ms to 2.128ms with just one model...

Any tutorials or suggestions to improve the performance (I heard about display开发者_Go百科 lists, but I think they are just for static stuff)


You mean 'static' in the not-animating sense? Nope.

GL "Display Lists" are to be avoided; they are superseded by Vertex Buffer Objects, which are suited to drawing MD2 animation frames.

Place all your MD2 frames into GL_STATIC_DRAW VBOs and simply draw the appropriate VBO each frame.

Furhermore, MD2 can even interpolate in a vertex shader, making smoother animation whilst being blazingly fast.

There is code that does so here and the corresponding shader here.

A question about this on gamedev.stackoverflow.com


Display list are not just for "static stuff". Are useful and can speed up you code. Use it. It's quite improbable to achieve performance goals in rendering meshes without display list. Once you define a display list, you can always perform your transformations calling the associated matrix before calling the display list.

In addition put all possible calculation outside (before) glBegin/glEnd calls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜