How to draw a screen composed of rectangular colored pixels ?

Hello,

In an emulator project, I would like to draw a “screen” composed of rectangular colored pixels (around 300x200 or perhaps more).

I see two options:

Option1:
Draw a set of colored quads.

Option 2:
Draw one textured quad and modify the texture pixels when needed.

Which one is the best ?

I have implemented option 1 and it works well.
But with this option, each pixel (quad) has:

  • 4 * vec4 for the position;
  • 4 times the same color.
    Which is a lot for this simple object.

From the application side, the API should be something like:
setPixel(int x, int y, color).

Do you think it is possible for the vertex shader, to generate the quad, based only on x, y and color, supposing it has the “screen layout info” ?

What do you think ?

Thanks,

Olivier

The Option 2 is simpler to implement and is faster AFAIK. Updating a small portion of a texture with glTexSubImage2D() is immensely fast. You could just call it in setPixel() defining offsets with x and y, and content with color.

You could also generate quads (or better triangle strips) using gl_VertexID, without need to send attributes for each one. But, there is no need for that. The previous solution is much simpler.

Thanks for your reply. I will test option 2 ! By the way, is option 2 can run efficiently on recent Android devices ?
Thanks.

I have no experience with Android platforms, but on desktops it works fine.
And, of course, I hope you will not call 6000 times glTexSubImage2D() in each draw-call. Just when some “pixel” has changed its color.
Also, try to group multiple “pixels” and substitute it with a single glTexSubImage2D() per draw-call.