Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to draw element from a texture atlas with OpenGL ES 2.

Currently, I'm drawing my elements using something like that 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 elements to draw I send his offset and scale to the shader. The problem with this method: I can't rotate the element but it's not a problem for now.

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

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

Thanks!

share|improve this question
add comment

1 Answer 1

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.