proland::ParticleStorage Class Reference
[particles]

A storage to store particles. More...

#include <ParticleStorage.h>

List of all members.

Classes

class  Particle
 An abstract particle stored by a ParticleStorage. More...

Public Member Functions

 ParticleStorage (int capacity, bool pack)
 Creates a new ParticleStorage.
virtual ~ParticleStorage ()
 Deletes this ParticleStorage.
void initCpuStorage (int particleSize)
 Initializes the CPU storage for the particles.
void initGpuStorage (const string &name, TextureInternalFormat f, int components)
 Initializes a GPU storage for the particles.
int getCapacity ()
 Returns the maximum number of particles that can be stored in this storage.
ptr< TextureBuffer > getGpuStorage (const string &name)
 Returns a texture buffer containing particles data on GPU.
int getParticlesCount ()
 Returns the current number of particles stored in this storage.
vector< Particle * >::iterator getParticles ()
 Returns an iterator to the first particle currently stored in this storage.
vector< Particle * >::iterator end ()
 Returns an iterator just past the last stored particle.
int getParticleIndex (Particle *p)
 Returns the index of the given particle.
ParticlenewParticle ()
 Returns a new uninitialized particle.
void deleteParticle (Particle *p)
 Deletes the given particle.
void clear ()
 Deletes the entire list of particles.

Protected Member Functions

 ParticleStorage ()
 Creates a new uninitialized ParticleStorage.
void init (int capacity, bool pack)
 Initializes this ParticleStorage.

Private Attributes

int particleSize
 The size in bytes, on CPU, of each particle.
int capacity
 The maximum number of particles that can be stored in this storage.
int available
 The number of available slots in particles to store new particles.
void * particles
 The particles data on CPU.
map< string, ptr< TextureBuffer > > gpuTextures
 The particles data on GPU, in the form of texture buffers.
vector< Particle * > freeAndAllocatedParticles
 Pointers to the free and allocated particles in particles.
bool pack
 True to ensure that new particles are always created with the minimum available index.

Detailed Description

A storage to store particles.

This class provides both generic CPU and GPU storages for particles, and provides generic methods to keep track of the currently allocated particles in this storage, and to keep track of the free slots that can be used to allocate new particles.

Authors:
Eric Bruneton, Antoine Begault, Guillaume Piolat

Constructor & Destructor Documentation

proland::ParticleStorage::ParticleStorage ( int  capacity,
bool  pack 
)

Creates a new ParticleStorage.

Parameters:
capacity the maximum number of particles allocated and managed by this particle storage. This capacity is fixed and cannot change with time.
pack true to ensure that new particles are always created with the minimum available index. This can be useful to keep allocated particles tightly packed in memory. On the other hand the creation and destruction of particles takes logarithmic time instead of constant time.
virtual proland::ParticleStorage::~ParticleStorage (  )  [virtual]

Deletes this ParticleStorage.

This deletes the data associated with all the particles managed by this particle storage.

proland::ParticleStorage::ParticleStorage (  )  [protected]

Creates a new uninitialized ParticleStorage.


Member Function Documentation

void proland::ParticleStorage::clear (  ) 

Deletes the entire list of particles.

void proland::ParticleStorage::deleteParticle ( Particle p  ) 

Deletes the given particle.

Parameters:
p a particle created by this particle storage.
vector<Particle*>::iterator proland::ParticleStorage::end (  )  [inline]

Returns an iterator just past the last stored particle.

int proland::ParticleStorage::getCapacity (  ) 

Returns the maximum number of particles that can be stored in this storage.

ptr<TextureBuffer> proland::ParticleStorage::getGpuStorage ( const string &  name  ) 

Returns a texture buffer containing particles data on GPU.

The particles data on GPU is splitted in several textures (see initGpuStorage()) identified by names. This method returns the texture buffer whose name is given. Its associated GPU buffer can be used in a ork::MeshBuffers (via an ork::AttributeBuffer) to directly use the content of this texture as a vertex array.

Parameters:
name a gpu storage symbolic name (see initGpuStorage()).
Returns:
the GPU buffer corresponding to this GPU storage.
int proland::ParticleStorage::getParticleIndex ( Particle p  ) 

Returns the index of the given particle.

Returns:
the index of the given particle. This index is between 0 and getCapacity() (excluded).
vector<Particle*>::iterator proland::ParticleStorage::getParticles (  ) 

Returns an iterator to the first particle currently stored in this storage.

Provided the returned iterator is only used in a sequential way, particles can be added and removed while using this iterator. The iterator will only iterate through the particles that existed when this method was called, regardless of the creation and destruction of particles while iterating. This is no longer true, however, if several iterators are used at the same time and if several of them create and destroy particles while iterating.

Returns:
the list of particles currently stored in this storage.
int proland::ParticleStorage::getParticlesCount (  ) 

Returns the current number of particles stored in this storage.

void proland::ParticleStorage::init ( int  capacity,
bool  pack 
) [protected]

Initializes this ParticleStorage.

See ParticleStorage

void proland::ParticleStorage::initCpuStorage ( int  particleSize  ) 

Initializes the CPU storage for the particles.

Parameters:
particleSize the size in bytes, on CPU, of each particle.
void proland::ParticleStorage::initGpuStorage ( const string &  name,
TextureInternalFormat  f,
int  components 
)

Initializes a GPU storage for the particles.

The full GPU storage is supposed to be splitted in several textures, each texture storing one or more particle attribute (for instance one texture for positions, another for velocities, etc). All textures are texture buffers, (textures similar to 1D textures, whose pixels are accessible via a GPUBuffer) of capacity * components pixels. Each texture is associated with a name, so that ParticleLayer can access them with symbolic names.

Parameters:
name a symbolic name for this storage.
f the pixel format for this storage.
components how many components of format f must be stored per particle in this GPU storage.
Particle* proland::ParticleStorage::newParticle (  ) 

Returns a new uninitialized particle.

Returns:
a new particle, or NULL if the current number of particles stored in this storage is equal to its maximum capacity.

Member Data Documentation

The number of available slots in particles to store new particles.

The maximum number of particles that can be stored in this storage.

Pointers to the free and allocated particles in particles.

This vector is of size capacity. Its first available elements contain pointers to the free slots in particles, arranged in a heap data structure (if pack is true). The remaining elements contain pointers to the currently allocated particles.

map<string, ptr<TextureBuffer> > proland::ParticleStorage::gpuTextures [private]

The particles data on GPU, in the form of texture buffers.

See initGPUStorage().

True to ensure that new particles are always created with the minimum available index.

See ParticleStorage.

The particles data on CPU.

This memory chunk is of size capacity * particleSize bytes.

The size in bytes, on CPU, of each particle.


Generated on Sat May 12 09:41:37 2012 for proland by  doxygen 1.6.1