Support Forum       G3D Web Page     
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
G3D::ParticleMaterial Class Reference

For efficiency, individual Particles use materials that have been pre-registered with the ParticleSystem that are addressed with these handles. More...

Inherits G3D::ReferenceCountedObject.

Public Member Functions

 ~ParticleMaterial ()
 No garbage collection of now-unused materials is performed during the destructor because that would slow scene loading. More...
 

Static Public Member Functions

static shared_ptr< ParticleMaterialcreate (const UniversalMaterial::Specification &material)
 Allocates a material handle for use with particles. More...
 
static shared_ptr< ParticleMaterialcreate (const shared_ptr< UniversalMaterial > &material)
 Allocates a material handle for use with particles. More...
 
static void freeAllUnusedMaterials ()
 

Protected Member Functions

 ParticleMaterial (int index, int texelWidth)
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 
static int insertMaterial (const shared_ptr< UniversalMaterial > &newMaterial)
 Adds in newMaterial to the s_material array, and returns the layer it resides on. More...
 

Protected Attributes

int m_texelWidth
 Width in texels of the part of the layer that is used by this ParticleMaterial. More...
 
int m_textureIndex
 Index into the s_material 2D_ARRAY texture layer. More...
 

Static Protected Attributes

static shared_ptr< UniversalMaterials_material
 A single material for all particle systems, using a 2D_ARRAY texture. More...
 
static Array< weak_ptr< ParticleMaterial > > s_materialArray
 Back-pointers used for reallocating slots in s_material when it is garbage collected. More...
 

Friends

class ParticleSurface
 
class ParticleSystem
 

Detailed Description

For efficiency, individual Particles use materials that have been pre-registered with the ParticleSystem that are addressed with these handles.

Particle Materials are not collected until the Entity that registered them is no longer in memory, even if no individual Particle uses that Material. Particle materials are packed into a single large texture array, so the memory requirements are that of the largest material times the number of materials.

See also
ParticleSystem

Constructor & Destructor Documentation

◆ ParticleMaterial()

G3D::ParticleMaterial::ParticleMaterial ( int  index,
int  texelWidth 
)
inlineprotected

◆ ~ParticleMaterial()

G3D::ParticleMaterial::~ParticleMaterial ( )

No garbage collection of now-unused materials is performed during the destructor because that would slow scene loading.

Instead, unused materials are repurposed during creation of new materials. You can force reallocation to clear memory by invoking ParticleMaterial::freeAllUnusedMaterials

Member Function Documentation

◆ create() [1/2]

static shared_ptr<ParticleMaterial> G3D::ParticleMaterial::create ( const UniversalMaterial::Specification material)
static

Allocates a material handle for use with particles.

This call is very slow and should not be made per frame.

◆ create() [2/2]

static shared_ptr<ParticleMaterial> G3D::ParticleMaterial::create ( const shared_ptr< UniversalMaterial > &  material)
static

Allocates a material handle for use with particles.

This call is very slow and should not be made per frame.

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ freeAllUnusedMaterials()

static void G3D::ParticleMaterial::freeAllUnusedMaterials ( )
static

◆ insertMaterial()

static int G3D::ParticleMaterial::insertMaterial ( const shared_ptr< UniversalMaterial > &  newMaterial)
staticprotected

Adds in newMaterial to the s_material array, and returns the layer it resides on.

Friends And Related Function Documentation

◆ ParticleSurface

friend class ParticleSurface
friend

◆ ParticleSystem

friend class ParticleSystem
friend

Member Data Documentation

◆ m_texelWidth

int G3D::ParticleMaterial::m_texelWidth
protected

Width in texels of the part of the layer that is used by this ParticleMaterial.

◆ m_textureIndex

int G3D::ParticleMaterial::m_textureIndex
protected

Index into the s_material 2D_ARRAY texture layer.

◆ s_material

shared_ptr<UniversalMaterial> G3D::ParticleMaterial::s_material
staticprotected

A single material for all particle systems, using a 2D_ARRAY texture.

◆ s_materialArray

Array<weak_ptr<ParticleMaterial> > G3D::ParticleMaterial::s_materialArray
staticprotected

Back-pointers used for reallocating slots in s_material when it is garbage collected.


documentation generated on Wed Nov 24 2021 08:01:58 using doxygen 1.8.15