I am very new to OpenGL.
I am trying to draw textured quads (2 triangles). The size of texture is 900x900px. I have no problems with one quad but when I trying to draw 5-10 quads I see noticable slow down.
Maybe I'm doing something wrong...
Code:
public void onDrawFrame(GL10 gl) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
... matrix calculation ...
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
}
Vertex shaders:
uniform mat4 uMVPMatrix;
attribute vec4 vPosition;
attribute vec2 a_TexCoordinate;
varying vec2 v_TexCoordinate;
void main() {
gl_Position = uMVPMatrix*vPosition;
v_TexCoordinate = a_TexCoordinate;
}
Fragment shader:
precision mediump float;
uniform sampler2D u_PreviewTexture;
varying vec2 v_TexCoordinate;
void main() {
vec4 color = texture2D(u_PreviewTexture, v_TexCoordinate);
gl_FragColor = color;
}
Testing platform is Galaxy S3. In profiler I see that about 60ms takes eglSwapBuffers call.
How can I draw quads with big textures fast?
This could be due to the size of your textures and on the OpenGL driver implementation of the devices you are using.
Most of the modern GPUs do a quite good job with NPOT (no power of two) textures but this causes a rescaling of the texture every time it needs to be drawn to the nearest power of 2 (in your case 1024X1024).
Try to use the following 2 solutions:
1- Convert your textures to 1024x1024 and use the coordinates in your geometries to only draw what you need (900x900)
2- Try to generate mipmaps, if you have a lot of zooming this is a performance savior in many scenarios.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With