1
\$\begingroup\$

I'm trying to draw elements from a texture atlas with OpenGL ES 2.0

Currently, I'm drawing my elements using something like this in the shader:

uniform mat4 uCamera;

uniform mat4 uModel;
attribute vec4  aPosition;
attribute vec4  aColor;
attribute vec2  aTextCoord;

uniform vec2 offset;
uniform vec2 scale;

varying lowp vec4 vColor;
varying lowp vec2 vUV;

void main() 
{   
    vUV = offset + aTextCoord * scale;
    gl_Position = (uCamera * uModel) * aPosition;
    vColor  = aColor;
}

For each element to draw I send it's offset and scale to the shader. The problem with this method is: I can't rotate the element but it's not a problem for now.

I would like to know, which is better for performance:

  • Send uniforms like that for each element on every frame
  • Update quad geometry (uvs) for each element

Thanks!

\$\endgroup\$

1 Answer 1

-1
\$\begingroup\$

The only way to go about this is to use Uniforms. You ALWAYS want to keep the Vertexs uv´s in the local space. for the reason that you don't want to have multiple vertex data containing almost the same information.

Offseting and scaling will only happen on a per mesh basis so it wont be that bad for it either. Sometimes it will be on a special case basis and thats fine to since a float4 to the gpu is not that bad of a bandwidth eater.

Compared to pulling all the data in a vertex buffer from the gpu to the cpu to just redefine a few values, and then pipe it down.

\$\endgroup\$
1
  • \$\begingroup\$ You don't have to use uniforms, so I downvoted. For example, I use a texture to store UVs and other instance data. \$\endgroup\$
    – RandyGaul
    Jul 31, 2014 at 17:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .