Core S2 Software Solutions

Immediate and Retained Mode Graphics Programming

Older article from Voxel Entertainment; originally written by Jeremy Bridon.

Most students new to programming computer graphics start with a well known graphics library. Either it is with a low-level rendering system, such as OpenGL or DirectX, or they do direct canvas manipulation, such as software rendering (directly editing the per-pixel colors of a window by the processor). Though there are plenty of topics to be learned though direct-window drawing, such as learning the complexity of drawing graphics primitives, most students end up working in low-level graphics libraries such as OpenGL.

What is unknown to new programmers of computer graphics is the fundamental differences in approach within all graphics libraries! This topic is sometimes never discussed in a university-level course, but is fundamental to good performance: Immediate and retained rendering modes. Immediate mode is the direct access of the rendering system in which only explicitly defined objects are rendered during each render-cycle. That’s computer-graphics-jargon for “Only render what the program says during each loop of the render code”. On the other hand, retained mode allows programmers to save specific objects onto specialized hardware (graphics cards) to release some of the data transfer overhead costs. Why is this subtle difference important? As computer scientists, the topic of performance is near and dear to our hearts, and immediate mode is the worst approach possible!

Immediate mode allows us to have a great deal of control over our render-cycles. No mater what happens, we always know what is and isn’t sent, since it is up to our explicit instructions and rendering data. Any particle, any model, or even any GUI component must be sent to the rendering system for each cycle of the render loop! On the other hand, immediate mode has a great drawback: the overheads in time needed to transfer drawing instructions and model data for each cycle is huge. Imagine a simple scene with 1000 cubes (A 10 by 10 by 10 cube of sub-cubes). Each cube has eight vertices, which are three floats each, with other data such as the edge connections. If we do the math, 1000 cubes * 8 vertices per cube * 3 floats per vertex * 4 bytes per float = 96000 bytes per render-cycle. This isn’t at all much (only ~0.1MB) data to transfer to a graphics card, but consider we want to push through as many render-cycles per second: we want to eliminate as much communication over-head between the processor/main-memory and the dedicated rendering hardware/graphics-card. If we render at 60 frames a second, the standard refresh rate of a TV screen, that’s 60 * 0.1 = 6 MB of data transfer per second. Yes, most modern day computers are fast at transferring data of this size, but the given example is of a very simple world. Imagine playing any modern game with tens of millions of polygons being sent per render cycle! The time needed to transfer data would almost halt the game to a mere one frame-per-second!

The reason why graphics cards exist is that it can not only work in parallel to the main processor, but eliminates the need to transfer data. How? All graphics cards have their own dedicated memory; each game can save commonly rendered objects onto the card and never send it again! This is why load-screens exist, as there are usually no pre-calculations needed, mostly it is just transfer of game data to the dedicated hardware. If there is no need to send data between the main processor to the graphics card at run-time, then the graphics card can go as fast as it can, rather then be throttled by the processor. Even better is the fact that graphic cards are extremely good at massive parallel computations. Simply, let the graphics card do what it does best, and leave the main processor alone for simple single-threaded game logic.

Retained mode is the opposite of immediate: most rendering data is pre-loaded onto the graphics card and thus when a render cycle takes place, only render instructions, and not data, are sent. Both immediate and retained mode can be used at the same time on all graphics cards, though the moral of the story is that if possible, use retained mode to improve performance. The difference is big enough such that the graphics card industry isn’t going to disappear any time soon.

This entry was posted in News & Updates. Bookmark the permalink.

3 Responses to Immediate and Retained Mode Graphics Programming

Leave a Reply to Sybil Cancel reply

Your email address will not be published. Required fields are marked *


*

Sites map