I have an iPad app with UI written in OpenGL ES 2.0, some UI elements are hidden by default and when I need to show them there is pretty big delay before they actually shown (about 300-500 ms on a control which contains about 20 other controls inside), using Instruments.app I determined that when I render every unique object, it takes much longer to render it first time then after it was rendered at least once and the difference in rendering time is huge. Here is the code I have for rendering and this code is shown by Instruments taking all this delay:
- (void)render:(id <ESRenderer>)renderer
{
[shader useShader];
glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, _squareVertices);
glEnableVertexAttribArray(ATTRIB_TEXTCOORD);
glVertexAttribPointer(ATTRIB_TEXTCOORD, 2, GL_SHORT, 0, 0, coords);
float x1 = self.position.x;
float y1 = self.position.y;
glUniform1f(shader.ext_uniforms[UNIFORM_TRANSLATE_X], -x1+_squareVertices[0]);
glUniform1f(shader.ext_uniforms[UNIFORM_TRANSLATE_Y], -y1+_squareVertices[1]);
glUniform1f(shader.ext_uniforms[UNIFORM_ROTATE], self.rotation);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(ATTRIB_VERTEX);
glDisableVertexAttribArray(ATTRIB_TEXTCOORD);
}
When it is called at least once it works perfectly fast.
My shader is very simple too:
vec4 col = texture2D(texture, coordVarying);
gl_FragColor = col;
Thanks!
I would guess it’s the actual transfer of data to the GPU that occurs only once. You should be able to force the loading/compilation at some point before your first rendering to remove that performance hit. Either the vertex data transfer if it’s huge, or the shader transfer/compilation.
EDIT: as noted in other answer, there is also the texture data that could be transferred.