在 OpenGL ES 2.0 中实现固定功能流水线高效吗?
我想在我的 openGL 2.0 应用程序中使用固定函数方法,例如 glTranslate()、glRotate()、glScale()。我知道,我需要实现一个矩阵类 - 并且已经做到了。我现在的问题是关于效率。为了能够使用类似的东西:
glLoadIdentity();
glRotatef(2.0f, 0.0f, 0.0f, 1.0f);
glScalef(2.0f, 2.0f, 2.0f);
我认为,我需要至少进行 3 次矩阵乘法(假设我们有一个投影和一个模型视图矩阵,这是针对模型视图的)。 第一个是:Identity-Matrix*Rotation-Matrix - 第二个是:ActualMatrix*ScaleMatrix,最后一个是:projectionMatrix*ActualMatrix(我将其作为统一值传递给我的着色器)。
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEW_PROJECTION_MATRIX], 1, GL_FALSE, matrix->getProjectionModelviewMatrix());
所以我的 Vertexshader 看起来像:
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...调用 - 这对我来说似乎非常重要。或者有更好的方法吗? (也许矩阵乘法更少?)
有关此主题的任何帮助将不胜感激!感谢您的阅读
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);
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());
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;
}
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恒等、平移、旋转和缩放矩阵不需要应用完整的矩阵乘法,因为许多项始终为 0.0 或 1.0。如果您逐个写出其他矩阵与这些矩阵相乘的结果,您会发现许多元素可能只有少数项影响其最终值。两个简单的例子:
glScalef
这样的东西,S3 始终是 1.0。)S × M将 M 的第 nth 行缩放 Sn。 M × S 而是逐列工作。您还可以将单位矩阵视为特别无聊的缩放矩阵。生成的平移和旋转的逐元素表达式比这些示例稍微复杂一些,但仍然比完整的矩阵乘法简单得多。 (如果旋转轴与 X、Y 或 Z 轴完全对齐,旋转也会变得更加简单。)当要求平移、缩放或旋转时,您可能希望直接修改矩阵,而不是构造另一个矩阵并相乘。
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:
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.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.
看看这个:http://glm.g-truc.net/about.html
Check out this: http://glm.g-truc.net/about.html