CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cugl::scene3::Scene3Pipeline Class Reference

#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< Scene3Pipelinealloc ()
 
static std::shared_ptr< Scene3PipelineallocWithStandard ()
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Scene3Pipeline()

cugl::scene3::Scene3Pipeline::Scene3Pipeline ( )
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.

◆ ~Scene3Pipeline()

cugl::scene3::Scene3Pipeline::~Scene3Pipeline ( )
inline

Deletes this pipeline, disposing all resources

Member Function Documentation

◆ alloc()

static std::shared_ptr< Scene3Pipeline > cugl::scene3::Scene3Pipeline::alloc ( )
inlinestatic

Returns a newly allocated empty pipeline.

The initialized pipeline starts with no batches. They must be attached via attach.

Returns
a newly allocated empty pipeline.

◆ allocWithStandard()

static std::shared_ptr< Scene3Pipeline > cugl::scene3::Scene3Pipeline::allocWithStandard ( )
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.

Returns
a newly allocated default pipeline.

◆ append()

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.

Parameters
nodeThe node to draw
transformThe global transform for the node

◆ attach() [1/2]

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.

Parameters
batchThe batch to attach to this pipeline.

◆ attach() [2/2]

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.

Parameters
batchThe batch to attach to this pipeline.
priorityThe batch priority.

◆ clear()

void cugl::scene3::Scene3Pipeline::clear ( )

Removes all appended nodes without drawing them.

Calling flush after this method will draw nothing.

◆ dispose()

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.

◆ flush()

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.

Parameters
cameraThe camera to draw with

◆ getPriority()

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.

Parameters
keyThe batch key
Returns
the priority for the given batch key.

◆ init()

bool cugl::scene3::Scene3Pipeline::init ( )

Initializes a new empty pipeline.

The initialized pipeline starts with no batches. They must be attached via attach.

Returns
true if initialization was successful.

◆ initWithStandard()

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.

Returns
true if initialization was successful.

◆ setPriority()

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.

Parameters
keyThe batch key
priorityThe batch priority.

The documentation for this class was generated from the following file: