# Drawing more that one quad with only one glDrawArray call…?

Edit

After initially thinking that my sprite batch test was faster than calling each sprite individually, it appears that is not the case!! :-(

With a single set of GL calls for a each sprite, I can get about 90 quads to move with no performance degradation.

With my batching test I can get about 12 (all in one call).

The problem is that I can't find any examples (code) anywhere for how this can be achieved using Android (Java) and OpenGL ES 2.0.

My method involved passing in an array of coordinate sets instead of a single set of coordinates, and then the method would build an array to store these coordinates in and then render the relevant amount of vertices. Like I say, it works but the performance is awful!! Is this the right approach?

Could anyone help? Thanks!

I'm using Android with openGLES 2.0 and I can't work out how to draw 2 (or more, but for the sake of simplicity, lets say 2 for the time being) textured quads using only 1 call to glDrawArrays.

My shaders are fairly standard and take into account sprite opacity as follows:

//vertex shader
"uniform mat4 uMVPMatrix;" +
"attribute vec4 a_position;\n"+
"attribute vec2 a_texCoords;" +
"varying vec2 v_texCoords;" +
"void main()\n" +
"{\n" +
"gl_Position = uMVPMatrix * a_position;\n"+
"v_texCoords = a_texCoords;" +
"}";

"precision mediump float;" +
"uniform float opValue;"+
"varying vec2 v_texCoords;" +
"uniform sampler2D u_baseMap;" +
"void main()" +
"{" +
"gl_FragColor = texture2D(u_baseMap, v_texCoords);" +
"gl_FragColor *= opValue;"+
"}";


Then my rendering method takes in vertices that set the position and size of the quad, set the texture, apply rotation (if any) etc...

And then draws with the following line:

GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);


I've been looking for a couple of days now for examples of how this can be achieved, but nothing seems to explain how it is actually done.

Can anyone give me any clues?

Note: To keep the question short, I have omitted my actual draw method. If this is required to give a fuller answer, please just ask and I will post.

Also please note that I need to do this as I'm trying to work out how to batch my sprites to increase performance.

• Are you working in a 2D or 3D environment? – Mokosha Apr 13 '13 at 13:45
• Sorry @Mokosha, it's a 2d game I'm writing, so my quads are basically being used as sprites. – BungleBonce Apr 13 '13 at 14:33