现在的位置: 首页 > 综合 > 正文

优化Klimt三维图形程序

2013年11月01日 ⁄ 综合 ⁄ 共 5146字 ⁄ 字号 评论关闭
文章目录
1. 使用顶点数组
从Klimt 0.6.3开始,顶点数组是会被缓存的。使用顶点数组可以减少在变换和光照阶段(Transform and Lighting, TnL stage)中所花费的时间,从而增加三角面的产生率。这对于需要绘制大量多边形的场景是非常重要的。这种方法可以全面将三维图像的表现能力提升50%(具体请参照 teapot 的演示)。从版本0.6.3开始,Klimt就实现了顶点缓冲,它实现了可以通过顶点数组传递顶点信息数据,理论上也可以传递定点格式(fixed point format)的顶点数据。
2. 使用带状连续模式绘制三角形(Triangle Strip)
这是一种在顶点数组中可选的方法,带状的图形编排(使用有一定长度的带状)与使用顶点数组有同样的效果。要注意的是在Klimt中,默认带状长度的最大限制是128,如果需要绘制更长的带状,可以修改MAX_PRIMITIVE_LENGTH 这个宏定义的值。这种方法也可以全面将三维图像的表现能力提升50%。从版本0.6.3开始,Klimt就实现了顶点缓冲,它实现了可以通过顶点数组(即使顶点不是带状格式的)传递顶点信息数据。
3. 关闭纹理矩阵的使用
使用Klimt函数klTweak(KL_TEXTUREMATRIX, GL_FALSE); 把你暂时不需要使用的纹理矩阵设置成不活动状态。这样可以提高三角面的产生率。
4. 关闭透视纹理映射
使用glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); 关闭透视纹理映射。许多模块譬如字符透视纹理映射是不需要的。Klimt有许多对使用正方形纹理图像的非透视纹理映射的优化。
5. 关闭正规法线
使用函数klTweak(KL_ENABLE_NORMALIZATION, GL_FALSE); ,在你以正规化格式传递法线参数的时候,把正规法线设置成不活动的。这样可以提高三角面的产生率。
6. 使用表面剔除
使用表面剔除可以大概较少一半的绘制的基元(取决于场景的设置)。Klimt保证可以在屏幕的空间里实现表面的剔除,这就是说,在每个三角面被剔除之前,每个三角面已经被变换,省略和投影。因此表面剔除主要是提高像素填充率和减少三角面的设置时间花费,特别是在使用纹理的时候。
7. 使用小尺寸纹理图像
纹理图像的尺寸对缓冲区的使用有直接的影响。大尺寸的纹理图像会减少像素填充率。
8. 使用 MipMaps 纹理
使用MipMaps 纹理可以提高缓存的使用——特别是纹理映射在绘制的多边形比纹理图像的尺寸小的时候。创建MipMaps 纹理最简单的方法是调用klCreateMipMaps();函数,它可以自动为当前活动的纹理创建MipMap。这种方法可以提高像素填充率。
9. 使用全白绘制纹理的多边形,不在绘制顶点前绘制其他颜色
当不使用光照效果绘制多边形时,调用glColor3f(1.0f, 1.0f, 1.0f); 设置顶点颜色为白色。在这种情况下,纹理的变换没有使用顶点的颜色。这样可以提高像素填充率。
10. 使用定点类型(fixed point)API 函数比与之对应的浮点类型的要好
使用在OpenGL|ES中说明的定点(fixed point)函数可以节省数据从浮点型到内部定点类型的转换过程。
11. 使用平值的明暗处理
每次创建场景的时候,使用glShadeModel(GL_FLAT);激活平直明暗。这样可以提高像素填充率。
12. 关闭光照效果
光照效果是一个花费高昂的操作,特别是在多于一个光源被使用的时候。关闭光照效果可以提高三角面的产生率。
13. 关闭z-testing
使用深度缓冲方法glDisable(GL_DEPTH_TEST); 使得场景不依赖于z-testing。这样可以提高像素填充率。
14. 关闭z-writing
无论什么时候,关闭z-writing是一种明智的做法。这样可以提高像素填充率。
15. 当使用基础场景图像API绘制时,激活播放列表(display lists)
加入你使用基础场景图像API,使用播放列表(display lists) 可以获得图形的加速。虽然播放列表只提供自身镜像加速(主要是节省了数据从浮点型到内部定点类型的转换过程),但他们可以通过移除图像部分旋转的需求来加速场景图像基础库。
 

原文:

Use vertex arrays

Vertex arrays are cached since Klimt 0.6.3. Using vertex arrays will reduce time spent in the TnL stage which will increase triangle throughput. This is most important for scene with a high polygon count. This method can increase the overall performance by up to 50%. (See teapot demo). From version 0.6.3 on Klimt does vertex caching which makes the usage of vertex arrays the prevered way to pass vertex data. Ideally pass vertex data in fixed point format.

Use triange strips

This is an alternative method to using vertex arrays. Stripified meshes (with long strips) have the same effect as using vertex arrays. Please note that Klimt has a maximum primitive length of 128 (as of version 0.6.3). If longer strips are needed modify the value of MAX_PRIMITIVE_LENGTH. This method can increase overall performance by up to 50%. (See teapot demo). From version 0.6.3 on Klimt does vertex caching which makes the usage of vertex arrays (even not stripified) the prevered way to pass vertex data.

Turn off texture matrix usage

Use klTweak(KL_TEXTUREMATRIX, GL_FALSE); to deactivate the usage of texture matrix if you don't need it. This will increase triangle throughput.

 

Turn off perspective texture mapping

Use glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); to turn of perspective texture mapping. For many models such as characters perspective texture mapping is not necessary. Klimt has specially optimized code for affine (non-perspective) texture mapping with square textures images (from 16x16 to 256-256).

Turn off normals normalization

Use klTweak(KL_ENABLE_NORMALIZATION, GL_FALSE); to deactivate normals normalization if you pass normals in a normalized format. This will increase triangle throughput.

Turn on culling

Using culling roughly halves the number of primitives to be rendered (depending of the scene setup). Klimt does culling in screen-space. This means that each triangle has been transformed, clipped and projected before it is culled. Therefore culling primarily increases pixel fill-rate and reduces time spent for triangle setup, which is especially costly when using texturing.

Use small textures

Texture image size has a direct influence on cache usage. Large textures will therefore reduce pixel fill-rate.

Use mipmaps for texturing

Using mipmaps improves cache usage - especially if the texture mapped onto a polygon is rendered a lot smaller than the texture's real image size. The easiest way to create mipmaps is to call klCreateMipMaps();, which automatically creates all mipmap levels for the currently active texture. This will increase pixel fill-rate.

Use full white for rendering textured polygons without per-vertex color

When rendering polygons without light, use glColor3f(1.0f, 1.0f, 1.0f); to set the vertex color to full white. In this case texturing is performed without using vertex colors. This will increase pixel fill-rate.

Prefer fixed point API functions over their floating point counterparts

The usage of fixed point functions introduced with OpenGL|ES removes the need to convert data from floating-point to the internal fixed point format.

Use flat shading

Whenever it makes sense, activate flat shading via glShadeModel(GL_FLAT);. This will increase pixel fill-rate.

Turn off lighting

Lighting is an expensive operation - especially if more than one light is used. Turning off lighting will increase triangle throughput.

Turn off z-testing

Use depth buffering methods that do not rely on z-testing (e.g. BSP tree). This will increase pixel fill-rate.

Turn off z-writing

Whenever possible it is wise to turn of z-writing. This will increase pixel fill-rate.

Activate display lists when using a scene graph based API

If you use a scene graph based API speedups can be gained by activating display lists. Although display lists give only minor speedups on their own (primarily removing the need for floating point to fixed point conversion), they can speed up scene graph based libraries by removing the need to traverse part of the graph.

抱歉!评论已关闭.