在OpenGL ES 2.0中实现固定功能管道效率? [英] Implement the Fixed function Pipeline efficent in OpenGL ES 2.0?

查看:73
本文介绍了在OpenGL ES 2.0中实现固定功能管道效率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的openGL 2.0应用程序中使用固定函数方法,例如glTranslate(),glRotate(),glScale().我知道,我需要实现一个矩阵类-并且已经做到了.我现在的问题是关于效率.为了能够使用类似的东西:

I want to use fixed function methods like glTranslate(), glRotate(), glScale() in my openGL 2.0 App. I know, that I need to implement an matrix class - and have done this. My question now is about efficiency. To be able to use something like:

glLoadIdentity();
glRotatef(2.0f, 0.0f, 0.0f, 1.0f);
glScalef(2.0f, 2.0f, 2.0f);

我认为,我至少需要进行3次矩阵乘法(假设我们有一个投影和一个modelview矩阵,这是针对modelview的). 第一个是:Identity-Matrix * Rotation-Matrix-第二个是:ActualMatrix * ScaleMatrix,最后一个是:projectionMatrix * ActualMatrix(并且这个Im作为统一值传递到我的着色器).

I think, I need to do at least 3 matrix multiplications (assuming we have a projection and a modelview matrizes and this is for the modelview). First would be: Identity-Matrix*Rotation-Matrix - Second is: ActualMatrix*ScaleMatrix and the last would be: projectionMatrix*ActualMatrix (and this Im passing as uniform value to my shader).

glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, matrix->getProjectionModelviewMatrix());

所以我的Vertexshader看起来像:

So my Vertexshader looks like:

attribute vec4 position;
attribute vec4 color;

varying vec4 colorVarying;

uniform mat4 modelViewProjectionMatrix;

void main()
{
    gl_Position = modelViewProjectionMatrix * position;
    colorVarying = color;
}

在OpenGL ES 1.1中是否采用相同的方法?似乎,我每个都需要一个矩阵乘法:glRotate,glScale,glTranslate ...调用-对我来说,这似乎非常有用.或者,还有更好的方法? (也许矩阵乘法更少?)

Is it done the same way in OpenGL ES 1.1? It seems like, I need one matrix multiplication vor every: glRotate, glScale, glTranslate... Call - that seems very much for me. Or is there a better way? (maybe with less matrix multiplications?)

任何有关此主题的帮助将不胜感激!谢谢您阅读

Any help on this topic would be highly appreciated! Thank you for reading

推荐答案

同一性,平移,旋转和缩放矩阵不需要应用完整的矩阵乘法,因为许多术语始终为0.0或1.0.如果您写出将其他矩阵乘以这些矩阵的逐个元素的结果,您会发现许多元素可能只有几个项对其最终值有所贡献.两个简单的例子:

Identity, translation, rotation, and scaling matrices don’t require a full matrix multiplication to apply, because many of the terms are always 0.0 or 1.0. If you write out the element-by-element results of multiplying other matrices by these matrices, you’ll see that many elements may only have a few terms contributing to their final values. Two simple examples:

  • 给出单位矩阵 I 和任意矩阵 M I × M = M × I = M .
  • 缩放矩阵 S 中唯一的非零元素是沿对角线的四个,我们将其称为 S 0 S 1 S 2 S 3 . (对于glScalef之类的 S 3 始终为1.0.) S × M 缩放 M 的第n 行, S n . M × S 改为逐列工作.您也可以将单位矩阵视为特别无聊的缩放矩阵.
  • Given the identity matrix I and an arbitrary matrix M, I × M = M × I = M.
  • The only non-zero elements in a scaling matrix S are the four along the diagonal, which we’ll call S0, S1, S2, and S3. (S3 is always 1.0 for something like glScalef.) S × M scales the nth row of M by Sn. M × S works column-by-column instead. You can also think of the identity matrix as a particularly boring scaling matrix.

所生成的用于平移和旋转的逐元素表达式比这些示例要复杂一些,但仍比全矩阵乘法要简单得多. (如果旋转轴与X,Y或Z轴完全对齐,旋转也将变得非常简单.)您可能需要在询问平移,缩放或旋转时直接考虑修改矩阵,而不是考虑构造另一个矩阵并相乘.

The resulting element-by-element expressions for translations and rotations are a bit more complicated than these examples, but still greatly simpler than a full matrix multiplication. (Rotations also get a great deal simpler if the axis of rotation is exactly aligned with the X, Y, or Z axis.) You’ll probably want to look into modifying matrices directly when asked to translate, scale, or rotate, rather than constructing another matrix and multiplying.

这篇关于在OpenGL ES 2.0中实现固定功能管道效率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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