CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
cugl::scene3::Scene3Batch Class Referenceabstract

#include <CUScene3Batch.h>

Inheritance diagram for cugl::scene3::Scene3Batch:
cugl::scene3::BillboardBatch cugl::scene3::ObjBatch cugl::scene3::ParticleBatch

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Scene3Batch()

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

Member Function Documentation

◆ append()

virtual void cugl::scene3::Scene3Batch::append ( const std::shared_ptr< SceneNode > &  node,
const Mat4 transform 
)
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.

Parameters
nodeThe node to draw
transformThe global transform

Implemented in cugl::scene3::BillboardBatch, cugl::scene3::ObjBatch, and cugl::scene3::ParticleBatch.

◆ clear()

virtual void cugl::scene3::Scene3Batch::clear ( )
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.

◆ dispose()

virtual void cugl::scene3::Scene3Batch::dispose ( )
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.

◆ flush()

virtual void cugl::scene3::Scene3Batch::flush ( const std::shared_ptr< Camera > &  camera)
pure virtual

Draws all appended nodes.

Drawing order of the nodes is implementation dependent.

Parameters
cameraThe camera to draw with

Implemented in cugl::scene3::BillboardBatch, cugl::scene3::ObjBatch, and cugl::scene3::ParticleBatch.

◆ getBatchKey()

Uint32 cugl::scene3::Scene3Batch::getBatchKey ( ) const
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.

Returns
the batch key for this batch.

◆ getPriority()

Uint32 cugl::scene3::Scene3Batch::getPriority ( ) const
inline

Returns the default priority for this batch.

The priority is used by the Scene3Pipeline to determine drawing order across multiple batches.

Returns
the default priority for this batch.

◆ init()

virtual bool cugl::scene3::Scene3Batch::init ( Uint32  key,
Uint32  priority 
)
inlinevirtual

Initializes a batch with the given key and priority.

Key value 0 is reserved and should not be used.

Parameters
keyThe batch key
priorityThe batch priority
Returns
true if initialization was successful

Reimplemented in cugl::scene3::BillboardBatch, cugl::scene3::ObjBatch, and cugl::scene3::ParticleBatch.

Member Data Documentation

◆ _batchkey

Uint32 cugl::scene3::Scene3Batch::_batchkey
protected

The batch key for identifying the batch

◆ _priority

Uint32 cugl::scene3::Scene3Batch::_priority
protected

The default priority for this batch


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