Implement the Fixed function Pipeline efficent in OpenGL ES 2.0?

我与影子孤独终老i 提交于 2019-12-08 03:45:12

问题


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


回答1:


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:

  • 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.

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.




回答2:


Check out this: http://glm.g-truc.net/about.html



来源:https://stackoverflow.com/questions/4875258/implement-the-fixed-function-pipeline-efficent-in-opengl-es-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!