Renderer Interface - yvt/openspades GitHub Wiki
Rendering is done through an interface called spades::client::IRenderer
. This abstracts the actual rendering APIs.
How to render scene
- Setup a struct
SceneDefinition
and give it toBeginScene
- Add objects to the scene by renderer commands (this must be done for every frame since the renderer doesn't remember them over a frame):
- Models
- Dynamic Light
- Sprites
- Debug Line
- Call
EndScene
to tell the renderer that we have nothing to add to the scene anymore - Draw 2D images
- Call
FrameDone
. - Call
Flip
. The renderer will transfer the rendered image to the screen.
Renderer Commands
Init
Initializes all subsystems of the renderer.
Shutdown
Destroys every objects needed by the renderer and releases memory used by them.
RegisterImage
Returns an image object with the specified file name. Loaded images are cached during the lifetime of the renderer (that is, the renderer keeps a reference to the image).
RegisterModel
Returns a model object with the specified file name. Loaded models are cached during the lifetime of the renderer (that is, the renderer keeps a reference to the model).
CreateImage
Creates a temporary image object from the given bitmap.
CreateModel
Creates a temporary model object from the given voxel bitmap.
SetGameMap
Tells the renderer to render the given game map instead of the currently set one.
SetFogColor
Specifies the fog color.
StartScene
Tells the renderer to get ready for the 3D renderer commands.
EndScene
Tells the renderer that there are no more 3D renderers commands for the current frame.
AddLight [3D]
Adds a point light or spotlight to the scene. This should not be called outside of BeginScene ... EndScene.
RenderModel [3D]
Adds a model to the scene. This should not be called outside of BeginScene ... EndScene.
AddDebugLine [3D]
Adds a 3D line segment to the scene. (Actually this should be used for debugging)
This should not be called outside of BeginScene ... EndScene.
AddSprite [3D]
Adds a sprite particle. This should not be called outside of BeginScene ... EndScene.
AddLongSprite [3D]
Adds a long sprite. This is mainly used for long bright objects without an exact shape, such as bullet tracers. This should not be called outside of BeginScene ... EndScene.
SetColor
Specifies the color used by AddSprite
, AddLongSprite
, and DrawImage
.
DrawImage
treats this color value as "non-alpha premultiplied." So when A = 0, the renderer image becomes completely invisible.AddSprite
andAddLongSprite
treat this color value as "alpha premultiplied." Therefore when A = 0, additive blending occurs.
DrawImage [2D]
Draws an image in the screen coordinate system. This should not be called between BeginScene and EndScene.
DrawFlatGameMap [2D]
Draws a 2D view of the current game map in the specified rectangle. This should not be called between BeginScene and EndScene.
FrameDone
Tells the renderer that there are no more things to render in the current frame. This should not be called between BeginScene and EndScene.
Flip
Displays the rendered image to the screen. This should not be called between BeginScene and EndScene.
ReadBitmap
Returns the current renderer image as a bitmap. Note that usually this operation is extremely slow.
This should not be called between BeginScene and EndScene.
GLRenderer
Implementation
GLRenderer
is an OpenGL 2.0/3.0 implementation of IRenderer
and supports all required function. GLRenderer
is currently the only implementation of IRenderer
.
BeginScene
just initializes the renderingEndScene
renders the scene in multiple passes:- Preparation
- Shadow Maps Generation
- Ocean Reflection Pass
- Sun-light Pass
- Dynamic Light Pass
- Post-process
FrameDone
flushes 2D rendering command buffer.Flip
callsSwap
of the OpenGL device.
SWRenderer
Implementation
SWRenderer
is a multi-threaded software implementation (similar to VOXLAP) of IRenderer
and supports the following fundamental features.
- Map
- Models
- 2D Images
- Sprites
Fast mode (r_swUndersampling
) can be used to boost the performance up by reducing the ray tracing density (effectively lowering the screen resolution).
Performance
- Intel Core i5 1.7GHz (Dual Core, HTT enabled, Clang 3.3?, OS X)
- 30FPS @ 1280x720
- 55FPS @ 800x600
- Intel Core 2 Duo 1.4GHz (Dual Core, Microsoft Visual C++ 2013, Windows 8)
- 20FPS @ 800x600
- AMD E-450 (Dual Core, Microsoft Visual C++ 2013, Windows 7)
- 15FPS @ 800x600
SMP Renderer (obsolete)
Obsolete feature: This was removed in 0.2.0.
When cg_smp
is set to 1, multi-threaded rendering architecture is enabled. Client
issues commands to AsyncRenderer
, and AsyncRenderer
sends the commands to IRenderer
in a separate thread.
This architecture is similar to cg_smp
of id Software's Quake 3.
Note that SMP renderer is unstable, difficult to trace errors, and there is some lag because of thread scheduling. Logging facility might not work expectedly.