June 30, 2012

Quake 3 Source Code Review: Renderer (Part 2 of 5) >>

The Quake III renderer is an evolution of the Quake II hardware accelerated renderer: The classic part is that it is built on a "Binary Partition"/"Potential Visible Set" architecture but two new key aspects are noticeable:



Architecture

The renderer is entirely contained in renderer.lib and statically linked against quake3.exe:


The renderer overall architecure is the Quake Classic: It relies on the famous BSP/PVS/Lightmap combo:

The multitexturing and lightmap step is clearly visible when the engine is modified to display only one or the other:

The texture drawn by the level designer/artists:


The lightmap generated by q3light.exe :


The final result when combined at runtime via multi-texturing :


The rendering architecture was discussed by Brian Hook at the 1999 Game Developer Conference. Unfortunately the GDC Vault video is currently down :( !

Shaders

The shader system is build on top of OpenGL 1.X fixed pipeline and is hence very costy. Developers can program vertex modifications but also add texture passes. This is detailled in the Quake 3 Shader bible:

Multicore Renderer and SMP (Symmetric multiprocessing)

Unknown to a lot of people: Quake III Arena shipped with SMP support via r_smp cvariable. The frontend and the backend communicate via a standard Producer/Consumer design. When r_smp is set to 1 drawing surfaces are alternatively stored in a double buffer located in RAM. The frontend (that is called Main thread in this example) alternatively write to one of the buffer while the other is read by the backend (called Renderer thread in this example).

An example to illustrate how things are working:

From t0 to t1 :






From t1 to t2 : Things start to move all over the place:


Note that at t2:

This case (where the Renderer thread is locking the Main thread is actually the most common while playing Quake III: It illustrate the blocking limitation of some of the method in the OpenGL API.




After t2 :




Note : The synchronization is performed via Windows Event Objects in winglimp.c (SMP acceleration section at bottom).

Next part

The Network Model

Comments

 

Fabien Sanglard @2012