![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUScene3Batch.h>
Public Member Functions | |
Scene3Batch () | |
virtual void | dispose () |
virtual bool | init (Uint32 key, Uint32 priority) |
Uint32 | getBatchKey () const |
Uint32 | getPriority () const |
virtual void | append (const std::shared_ptr< SceneNode > &node, const Mat4 &transform)=0 |
virtual void | flush (const std::shared_ptr< Camera > &camera)=0 |
virtual void | clear ()=0 |
Protected Attributes | |
Uint32 | _batchkey |
Uint32 | _priority |
This class is used to batch together SceneNode
objects for drawing.
Scene3
is different from scene2::Scene2
in that there is no single pipeline for drawing all node types. Each node type has its own shader with its own uniforms. To minimize shader switching (which is expensive), we use batches to gather together all nodes of a single type before drawing.
This batching allows us to do any necessary pre-drawing computation such as sorting nodes by their z-depth. This is important for transparency affects, as depth buffers are incompatible with alpha blending. However, not all batches sort. This optimization is handled on a type-by-type basis.
This is an abstract class, and should not be instantiated by itself. Implementing subclasses must define append
, flush
and clear
.
|
inline |
Creates a new degenerate batch on the stack.
The batch has no shader, and therefore cannot draw anything.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.
|
pure virtual |
Appends the given node and transform for drawing.
Drawing order within a batch depends on the implementation. Some batches draw nodes in the order that they are appended. Some sort the nodes before drawing, in order to manage transparency or color blending.
node | The node to draw |
transform | The global transform |
Implemented in cugl::scene3::BillboardBatch, cugl::scene3::ObjBatch, and cugl::scene3::ParticleBatch.
|
pure virtual |
Removes all appended nodes without drawing them.
Calling flush
after this method will draw nothing.
Implemented in cugl::scene3::BillboardBatch, cugl::scene3::ObjBatch, and cugl::scene3::ParticleBatch.
|
inlinevirtual |
Disposes all of the resources used by this batch.
A disposed batch can be safely reinitialized. Any shader owned by this batch will be released. It will be deleted if no other object owns it.
Reimplemented in cugl::scene3::BillboardBatch, cugl::scene3::ObjBatch, and cugl::scene3::ParticleBatch.
|
pure virtual |
Draws all appended nodes.
Drawing order of the nodes is implementation dependent.
camera | The camera to draw with |
Implemented in cugl::scene3::BillboardBatch, cugl::scene3::ObjBatch, and cugl::scene3::ParticleBatch.
|
inline |
Returns the batch key for this batch.
The batch key is used by the Scene3Pipeline
to distinguish individual batches from each other. These keys may not be reassigned once the batch is instantiated.
Key value 0 is reserved and should not be used.
|
inline |
Returns the default priority for this batch.
The priority is used by the Scene3Pipeline
to determine drawing order across multiple batches.
|
inlinevirtual |
Initializes a batch with the given key and priority.
Key value 0 is reserved and should not be used.
key | The batch key |
priority | The batch priority |
Reimplemented in cugl::scene3::BillboardBatch, cugl::scene3::ObjBatch, and cugl::scene3::ParticleBatch.
|
protected |
The batch key for identifying the batch
|
protected |
The default priority for this batch