0
votes

I have an android application which renders a 2D terrain. The terrain is made of many ground 'pixels' and the dimensions are 480 x 300 (terrain pixels).

The pixels are rendered as textures, and 480*300 = almost 150,000, takes 5 seconds for a new strong device to draw. The terrain is sometimes not static so using FBO's and render-to-texture methods only partially help.

In short - what's the best method to render around 150,000 extremely small textures (which are pure color and no detail) ?

Here is a small part of the terrain: http://imageshack.com/a/img822/3775/8ayq.png

1

1 Answers

0
votes

Its hard to tell without code what the real bottleneck is here, but since your question is "what is the best way to render 150,000 flat color textures on the screen, the answer is "not with textures."

The best way to do this in my opinion is to create a new vertex attrib array of color vectors, and use it like so

//vertex shader
attribute vec4 vertexCoords;
attribute vec4 vertexColor;
varying   vec4 fragmentColor;
void main()
{
   fragmentColor = vertexColor;
   gl_Position = vertexCoords; 
}

//fragment shader
varying lowp vec4 fragmentColor;
    void main()
{

   gl_FragColor = fragmentColor; 
}

This way you can draw your whole background in one draw call, and changing what the background looks like is just a glBufferSubData call away.