What is the fastest way to draw a 2D array of color triplets on screen?

Johannes Weiss picture Johannes Weiss · Feb 2, 2009 · Viewed 7.9k times · Source

The target language is C/C++ and the program has only to work on Linux, but platform independent solutions are preferred obviously. I run Xorg, XVideo and OpenGL are available.

How many FPS can I expect on 1024x768 on an Intel Core 2 Duo with Intel graphics? (ONLY drawing counts, consider the arrays to be ready in RAM; no precise prognosis needed)

Answer

Iraimbilanja picture Iraimbilanja · Feb 2, 2009

The fastest way to draw a 2D array of color triplets:

  1. Use float (not byte, not double) storage. Each triplet consists of 3 floats from 0.0 to 1.0 each. This is the format implemented most optimally by GPUs (but use greyscale GL_LUMINANCE storage when you don't need hue - much faster!)
  2. Upload the array to a texture with glTexImage2D
  3. Make sure that the GL_TEXTURE_MIN_FILTER texture parameter is set to GL_NEAREST
  4. Map the texture to an appropriate quad.

This method is slightly faster than glDrawPixels (which for some reason tends to be badly implemented) and a lot faster than using the platform's native blitting.

Also, it gives you the option to repeatedly do step 4 without step 2 when your pixmap hasn't changed, which of course is much faster.

Libraries that provide only slow native blitting include:

  • Windows' GDI
  • SDL on X11 (on Windows it provides a fast opengl backend when using HW_SURFACE)
  • Qt

As to the FPS you can expect, drawing a 1024x768 texture on an Intel Core 2 Duo with Intel graphics: about 60FPS if the texture changes every frame and >100FPS if it doesn't.

But just do it yourself and see ;)