CUGL 3.0
Cornell University Game Library
|
#include <CUScene3Pipeline.h>
Public Member Functions | |
Scene3Pipeline () | |
~Scene3Pipeline () | |
void | dispose () |
bool | init () |
bool | initWithStandard () |
bool | attach (const std::shared_ptr< Scene3Batch > &batch) |
bool | attach (const std::shared_ptr< Scene3Batch > &batch, Uint32 priority) |
void | setPriority (CUEnum key, Uint32 priority) |
Sint32 | getPriority (CUEnum key) const |
void | append (const std::shared_ptr< SceneNode > &node, const Mat4 &transform) |
void | flush (const std::shared_ptr< Camera > &camera) |
void | clear () |
Static Public Member Functions | |
static std::shared_ptr< Scene3Pipeline > | alloc () |
static std::shared_ptr< Scene3Pipeline > | allocWithStandard () |
This class manages the batches used to process a 3d scene graph.
Unlike 2d scene graphs, each node type in a 3d scene graph is likely to have its own batch/shader. While occasional shader switching is okay, switching for each object is too expensive. The solution is split the scene graph into multiple passes, one for each batch/shader type. As 3d scene graphs leverage depth testing, this is generally okay.
A render queue does not use the standard begin()/end() pattern that we have in graphics::SpriteBatch
and other general purpose shaders. That is because a pipeline is a collection of batches, each with their own queue. To draw with the pipeline, we populate the individual queues with the method append
. We then render these queue contents with flush
.
The piplein has predefined shaders for the built-in 3d scene graph types like ObjNode
and ParticleNode
. However, it is extensible enough to include extra shaders as well. You should create a fresh CUEnum (unsigned int) for your new shader before adding it via attach
. Make sure that this enum does not conflict with existing values.
All shaders (including the built-in ones) have a priority. Shaders are applied in order of priority from lowest value to highest. Priorities can be reassigned at any time with setPriority
. As a general rule, particles and shaders with transparency effects should be processed last.
|
inline |
Creates a new degenerate pipeline on the stack.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.
|
inline |
Deletes this pipeline, disposing all resources
|
inlinestatic |
Returns a newly allocated empty pipeline.
The initialized pipeline starts with no batches. They must be attached via attach
.
|
inlinestatic |
Returns a newly allocated default pipeline.
The pipeline starts with the all the default batches: ObjBatch
, BillboardBatch
, and ParticleBatch
. Additional batches may be added via attach
.
void cugl::scene3::Scene3Pipeline::append | ( | const std::shared_ptr< SceneNode > & | node, |
const Mat4 & | transform | ||
) |
Adds the node and transform to this pipeline for drawing.
No drawing will occur until flush
is called. Drawing will be processed by batch, according to priority. Drawing order for each batch depends upon the specification for that batch type.
node | The node to draw |
transform | The global transform for the node |
bool cugl::scene3::Scene3Pipeline::attach | ( | const std::shared_ptr< Scene3Batch > & | batch | ) |
Attaches the batch to this pipeline.
The batch will use the values Scene3Batch#getBatchKey
and Scene3Batch#getPriority
to set the batch key and priority, respectively. This method will fail if the pipeline already has a batch with the specified key.
batch | The batch to attach to this pipeline. |
bool cugl::scene3::Scene3Pipeline::attach | ( | const std::shared_ptr< Scene3Batch > & | batch, |
Uint32 | priority | ||
) |
Attaches the batch to this pipeline with the given priority.
The batch will use the value Scene3Batch#getBatchKey
to set batch key. This method will fail if the pipeline already has a batch with the specified key.
batch | The batch to attach to this pipeline. |
priority | The batch priority. |
void cugl::scene3::Scene3Pipeline::clear | ( | ) |
Removes all appended nodes without drawing them.
Calling flush
after this method will draw nothing.
void cugl::scene3::Scene3Pipeline::dispose | ( | ) |
Disposes all of the resources used by this pipeline.
A disposed pipeline can be safely reinitialized. Any batches owned by this pipeline will be released. They will be deleted if no other object owns them.
void cugl::scene3::Scene3Pipeline::flush | ( | const std::shared_ptr< Camera > & | camera | ) |
Draws all appended nodes.
Drawing will be processed by batch, according to priority. Drawing order for each batch depends upon the specification for that batch type.
camera | The camera to draw with |
Sint32 cugl::scene3::Scene3Pipeline::getPriority | ( | CUEnum | key | ) | const |
Returns the priority for the given batch key.
This method will return -1 if key does not reference an attached batch.
key | The batch key |
bool cugl::scene3::Scene3Pipeline::init | ( | ) |
Initializes a new empty pipeline.
The initialized pipeline starts with no batches. They must be attached via attach
.
bool cugl::scene3::Scene3Pipeline::initWithStandard | ( | ) |
Initializes a new default pipeline.
The pipeline starts with the all the default batches: ObjBatch
, BillboardBatch
, and ParticleBatch
. Additional batches may be added via attach
.
void cugl::scene3::Scene3Pipeline::setPriority | ( | CUEnum | key, |
Uint32 | priority | ||
) |
Sets the priority for the given batch key.
This method will do nothing if key does not reference an attached batch.
key | The batch key |
priority | The batch priority. |