I've developed (yet another) GUI library that I use for my own game projects. Most of the time, the GUI I make are quite complex : they uses many different textures and render targets.
Up until now, I've always relied on the render system of the graphics library I use to draw the game world (Ogre3D, SFML, ...) to draw my GUI on the screen. So the rendering is done in hardware.
Doing it in real time is a real performance hit, that I've minimized using cache render targets, that are only updated when their content is modified.
Yet I feel it's not enough. Plus, using screen wide render targets for caching has its own cost (both in memory and render time, for large resolutions).
So I had another idea. Seeing how powerful CPUs can get nowadays, and seeing how badly they are used in game programming, I was wondering if I could use that spare computing power to release the strain on the GPU and render the whole GUI in software, maybe in another thread.
Several other considerations tend to make this choice a credible alternative :
- most of the time, GUI rendering consists of 1 to 1 texture drawing, which can be implemented as a simple copy (or blending) of pixel
- proper 2D alpha blending is not feasible in one pass using todays hardware (afaik)
- current GPUs are optimized for 3D rendering, and little effort is made to improve 2D performances
- GUIs are most of the time made of plenty of small textures, which tends to create a large number of batches (even though this problem can partially be solved with texture packing algorithms, this system has its limitations)
- hardware render targets can be tricky (poor support on old GPUs or with bad drivers, see Intel integrated chips)
I'm currently running some tests with my own software renderer (using SDL for texture loading and window management) and performances seem quite acceptable.
My test case, which consists of 9 sprites using 9 different 32x32 textures, with alpha blending, rendered into a 256x256 render target, which is then rendered into a 1024x768 render target takes approximately 1ms. Transferring the result to the screen then takes 4ms, but that depends highly on the underlying render system (here SDL), and is here a quasi constant cost (proportional to the final render area).
There is still room for optimization : I could use SSE instructions to blend colors for example.
My questions are :
Has anybody considered this alternative ?
Does it seem viable to you ?
What is the fastest, portable, software 2D renderer out there ?
Do I have a chance to do something better if I develop my own renderer, suited especially for my GUI system ?