A storage to store particles. More...
#include <ParticleStorage.h>
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. | |
Particle * | newParticle () |
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. |
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.
proland::ParticleStorage::ParticleStorage | ( | int | capacity, | |
bool | pack | |||
) |
Creates a new ParticleStorage.
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.
void proland::ParticleStorage::clear | ( | ) |
Deletes the entire list of particles.
void proland::ParticleStorage::deleteParticle | ( | Particle * | p | ) |
Deletes the given particle.
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.
name | a gpu storage symbolic name (see initGpuStorage()). |
int proland::ParticleStorage::getParticleIndex | ( | Particle * | p | ) |
Returns the index of the given particle.
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.
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.
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.
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.
int proland::ParticleStorage::available [private] |
The number of available slots in particles to store new particles.
int proland::ParticleStorage::capacity [private] |
The maximum number of particles that can be stored in this storage.
vector<Particle*> proland::ParticleStorage::freeAndAllocatedParticles [private] |
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().
bool proland::ParticleStorage::pack [private] |
True to ensure that new particles are always created with the minimum available index.
See ParticleStorage.
void* proland::ParticleStorage::particles [private] |
The particles data on CPU.
This memory chunk is of size capacity * particleSize bytes.
int proland::ParticleStorage::particleSize [private] |
The size in bytes, on CPU, of each particle.