A ork::Uniform to access texture tiles stored on GPU. More...
#include <TileSampler.h>
Classes | |
class | TileFilter |
A filter to decide whether a texture tile must be produced or not for a given quad. More... | |
class | Tree |
An internal quadtree to store the texture tile associated with each terrain quad. More... | |
Public Member Functions | |
TileSampler (const string &name, ptr< TileProducer > producer=NULL) | |
Creates a new TileSampler. | |
virtual | ~TileSampler () |
Deletes this TileSampler. | |
ptr< TileProducer > | get () |
Returns the producer to create new tiles in update. | |
ptr< TerrainNode > | getTerrain (int i) |
Returns a terrain associated with this uniform. | |
bool | getStoreLeaf () |
Returns true if texture tiles must be created for leaf quads. | |
bool | getAsync () |
Returns true if new tiles must be produced asychronously. | |
bool | getMipMap () |
Returns true if a (part of) parent tile can be used instead of the tile itself for rendering (this may happen if tiles are produced asynchronously, and if a tile is not ready but a parent tile is). | |
void | set (ptr< TileProducer > producer) |
Sets the producer to create new tiles in update. | |
void | addTerrain (ptr< TerrainNode > terrain) |
Adds a terrain associated with this uniform. | |
void | setStoreLeaf (bool storeLeaf) |
Sets the option to create new tiles for leaf quads or not. | |
void | setStoreParent (bool storeParent) |
Sets the option to create new tiles for non leaf quads or not. | |
void | setStoreInvisible (bool storeInvisible) |
Sets the option to create new tiles for invisible quads or not. | |
void | setStoreFilter (TileFilter *filter) |
Sets the options to create new tiles for arbitrary quads or not. | |
void | setAsynchronous (bool async) |
Sets the option to create new tiles for new quads in synchronous or asychronous way. | |
void | setMipMap (bool mipmap) |
Sets the option to allow using a (part of) parent tile instead of the tile itself for rendering. | |
void | setTile (int level, int tx, int ty) |
Sets the GLSL uniforms necessary to access the texture tile for the given quad. | |
void | setTileMap () |
Sets the GLSL uniforms necessary to access the texture tiles for arbitrary quads on GPU. | |
virtual ptr< Task > | update (ptr< SceneManager > scene, ptr< TerrainQuad > root) |
Returns the task graph necessary to create new texture tiles for newly created quads in the given terrain quadtree (and to release tiles for destroyed quads). | |
Protected Member Functions | |
TileSampler () | |
Creates an uninitialized TileSampler. | |
virtual void | init (const string &name, ptr< TileProducer > producer=NULL) |
Initializes this TileSampler. | |
virtual bool | needTile (ptr< TerrainQuad > q) |
Returns true if a tile is needed for the given terrain quad. | |
virtual void | putTiles (Tree **t, ptr< TerrainQuad > q) |
Updates the internal quadtree to make it identical to the given terrain quadtree. | |
virtual void | getTiles (Tree *parent, Tree **t, ptr< TerrainQuad > q, ptr< TaskGraph > result) |
Updates the internal quadtree to make it identical to the given terrain quadtree. | |
void | prefetch (Tree *t, ptr< TerrainQuad > q, int &prefetchCount) |
Creates prefetch tasks for the sub quads of quads marked as new in Tree::newTree, in the limit of the prefetch count. | |
void | checkUniforms () |
Checks if the last checked Program is the same as the current one, and updates the Uniforms if necessary. | |
Protected Attributes | |
Tree * | root |
An internal quadtree to store the texture tiles associated with each quad. | |
Private Attributes | |
ptr< TileProducer > | producer |
The producer to be used to create texture tiles for newly created quads. | |
vector< ptr< TerrainNode > > | terrains |
The terrains associated with this uniform. | |
ptr< Program > | lastProgram |
Last used GLSL program. | |
ptr< UniformSampler > | samplerU |
The texture sampler to access the proland::GPUTileStorage. | |
ptr< Uniform3f > | coordsU |
The coordinates of a tile in the proland::GPUTileStorage. | |
ptr< Uniform3f > | sizeU |
The relative size of a tile in the proland::GPUTileStorage. | |
ptr< UniformSampler > | tileMapU |
The texture sampler to access the proland::GPUTileStorage tile map (an indirection structure to get the storage coordinate of a tile from its logical coordinates). | |
ptr< Uniform4f > | quadInfoU |
rootTileSize, splitDistance, k=ceil(splitDistance), 4*k+2. | |
ptr< Uniform4f > | poolInfoU |
Tile size in pixels including borders, border in pixels, tilePool 1/w, 1/h. | |
vector< ptr< Uniform4f > > | cameraU |
The current camera position in local space for each terrain associated with this uniform (only used with setTileMap). | |
bool | storeLeaf |
True to store texture tiles for leaf quads. | |
bool | storeParent |
True to store texture tiles for non leaf quads. | |
bool | storeInvisible |
True to store texture tiles for invisible quads. | |
vector< TileFilter * > | storeFilters |
A set of filters to decide whether a texture tile must be stored for a given quad. | |
bool | async |
True if tiles must be loaded in an asynchronous way, using prefetching. | |
bool | mipmap |
True if a parent tile can be used instead of the tile itself for rendering. |
A ork::Uniform to access texture tiles stored on GPU.
This class can set the GLSL uniforms necessary to access a given texture tile on GPU, stored in a proland::GPUTileStorage. This class also manages the creation of new texture tiles when a terrain quadtree is updated, via a proland::TileProducer.
proland::TileSampler::TileSampler | ( | const string & | name, | |
ptr< TileProducer > | producer = NULL | |||
) |
Creates a new TileSampler.
name | the GLSL name of this uniform. | |
producer | the producer to be used to create new tiles in update. Maybe NULL if this producer is used to update a tileMap (see setTileMap). If not NULL, must have a proland::GPUTileStorage. |
virtual proland::TileSampler::~TileSampler | ( | ) | [virtual] |
Deletes this TileSampler.
proland::TileSampler::TileSampler | ( | ) | [protected] |
Creates an uninitialized TileSampler.
void proland::TileSampler::addTerrain | ( | ptr< TerrainNode > | terrain | ) |
Adds a terrain associated with this uniform.
Only used with setTileMap.
terrain | a terrain to be associated with this uniform. |
void proland::TileSampler::checkUniforms | ( | ) | [protected] |
Checks if the last checked Program is the same as the current one, and updates the Uniforms if necessary.
ptr<TileProducer> proland::TileSampler::get | ( | ) |
Returns the producer to create new tiles in update.
bool proland::TileSampler::getAsync | ( | ) |
Returns true if new tiles must be produced asychronously.
bool proland::TileSampler::getMipMap | ( | ) |
Returns true if a (part of) parent tile can be used instead of the tile itself for rendering (this may happen if tiles are produced asynchronously, and if a tile is not ready but a parent tile is).
bool proland::TileSampler::getStoreLeaf | ( | ) |
Returns true if texture tiles must be created for leaf quads.
ptr<TerrainNode> proland::TileSampler::getTerrain | ( | int | i | ) |
Returns a terrain associated with this uniform.
Only used with setTileMap.
a | terrain index. |
virtual void proland::TileSampler::getTiles | ( | Tree * | parent, | |
Tree ** | t, | |||
ptr< TerrainQuad > | q, | |||
ptr< TaskGraph > | result | |||
) | [protected, virtual] |
Updates the internal quadtree to make it identical to the given terrain quadtree.
Collects the tasks necessary to create the missing texture tiles, corresponding to newly created quads, in the given task graph.
t | the internal quadtree node corresponding to q. | |
q | a quadtree node. | |
result | the task graph to collect the tile producer tasks. |
Reimplemented in proland::TileSamplerZ.
virtual void proland::TileSampler::init | ( | const string & | name, | |
ptr< TileProducer > | producer = NULL | |||
) | [protected, virtual] |
Initializes this TileSampler.
name | the GLSL name of this uniform. | |
producer | the producer to be used to create new tiles in update. Maybe NULL if this producer is used to update a tileMap (see setTileMap). If not NULL, must have a proland::GPUTileStorage. |
Reimplemented in proland::TileSamplerZ.
virtual bool proland::TileSampler::needTile | ( | ptr< TerrainQuad > | q | ) | [protected, virtual] |
Returns true if a tile is needed for the given terrain quad.
q | a quadtree node. |
Reimplemented in proland::TileSamplerZ.
void proland::TileSampler::prefetch | ( | Tree * | t, | |
ptr< TerrainQuad > | q, | |||
int & | prefetchCount | |||
) | [protected] |
Creates prefetch tasks for the sub quads of quads marked as new in Tree::newTree, in the limit of the prefetch count.
t | the internal quadtree node corresponding to q. | |
q | a quadtree node. | |
[in,out] | prefetchCount | the maximum number of prefetch tasks that can be created by this method. |
virtual void proland::TileSampler::putTiles | ( | Tree ** | t, | |
ptr< TerrainQuad > | q | |||
) | [protected, virtual] |
Updates the internal quadtree to make it identical to the given terrain quadtree.
This method releases the texture tiles corresponding to deleted quads.
t | the internal quadtree node corresponding to q. | |
q | a quadtree node. |
void proland::TileSampler::set | ( | ptr< TileProducer > | producer | ) |
Sets the producer to create new tiles in update.
This producer must have a proland::GPUTileStorage.
producer | the producer to create new tiles in update. |
void proland::TileSampler::setAsynchronous | ( | bool | async | ) |
Sets the option to create new tiles for new quads in synchronous or asychronous way.
In synchronous mode, a frame is not displayed until all the tasks to create the tile data have been executed, which can lead to perceptible pauses. In asynchronous mode, the frame is displayed even if all tile data are not yet ready. In this case the first tile ancestor whose data is ready is used instead (the asynchronous mode is only possible is setStoreParent is true). This mode can lead to visible popping when more precise data suddenly replaces coarse data. NOTE: the asynchronous mode requires a scheduler that supports prefetching of any kind of task (both cpu and gpu). NOTE: you can mix TileSampler in synchronous mode with others using asynchronous mode. Hence some tile data can be produced synchronously while other data is produced asynchronously.
async | true to create tiles asynchrously. |
void proland::TileSampler::setMipMap | ( | bool | mipmap | ) |
Sets the option to allow using a (part of) parent tile instead of the tile itself for rendering.
This option is only useful when the asynchronous mode is set.
void proland::TileSampler::setStoreFilter | ( | TileFilter * | filter | ) |
Sets the options to create new tiles for arbitrary quads or not.
filter | a filter to decide whether a new texture tile must be created for a given quad. This filter is added to previously added filters with this method. A texture tile is created for a quad if at least one filter returns true for this quad. |
void proland::TileSampler::setStoreInvisible | ( | bool | storeInvisible | ) |
Sets the option to create new tiles for invisible quads or not.
storeInvisible | true to create new tiles for invisible quads. |
void proland::TileSampler::setStoreLeaf | ( | bool | storeLeaf | ) |
Sets the option to create new tiles for leaf quads or not.
storeLeaf | true to create new tiles for leaf quads. |
void proland::TileSampler::setStoreParent | ( | bool | storeParent | ) |
Sets the option to create new tiles for non leaf quads or not.
storeParent | true to create new tiles for non leaf quads. |
void proland::TileSampler::setTile | ( | int | level, | |
int | tx, | |||
int | ty | |||
) |
Sets the GLSL uniforms necessary to access the texture tile for the given quad.
This methods does nothing if terrains are associated with this uniform (uniform intended to be used with setTileMap).
level | a quad level. | |
tx | a quad logical x coordinate. | |
ty | a quad logical y coordinate. |
void proland::TileSampler::setTileMap | ( | ) |
Sets the GLSL uniforms necessary to access the texture tiles for arbitrary quads on GPU.
This method does nothing if terrains have not been associated with this uniform. These terrains must be all the terrains for which the tile map may be used on GPU.
virtual ptr<Task> proland::TileSampler::update | ( | ptr< SceneManager > | scene, | |
ptr< TerrainQuad > | root | |||
) | [virtual] |
Returns the task graph necessary to create new texture tiles for newly created quads in the given terrain quadtree (and to release tiles for destroyed quads).
This method returns an empty task graph if terrains have been associated with this uniform (uniform intended to be used with setTileMap).
scene | the scene manager. | |
root | the root of a terrain quadtree. |
Reimplemented in proland::TileSamplerZ.
bool proland::TileSampler::async [private] |
True if tiles must be loaded in an asynchronous way, using prefetching.
vector< ptr<Uniform4f> > proland::TileSampler::cameraU [private] |
The current camera position in local space for each terrain associated with this uniform (only used with setTileMap).
ptr<Uniform3f> proland::TileSampler::coordsU [private] |
The coordinates of a tile in the proland::GPUTileStorage.
ptr<Program> proland::TileSampler::lastProgram [private] |
Last used GLSL program.
Updated each time setTile or setTileMap is called with a different Program. Helps to retrieve the correct Uniforms and store them.
bool proland::TileSampler::mipmap [private] |
True if a parent tile can be used instead of the tile itself for rendering.
ptr<Uniform4f> proland::TileSampler::poolInfoU [private] |
Tile size in pixels including borders, border in pixels, tilePool 1/w, 1/h.
ptr<TileProducer> proland::TileSampler::producer [private] |
The producer to be used to create texture tiles for newly created quads.
ptr<Uniform4f> proland::TileSampler::quadInfoU [private] |
rootTileSize, splitDistance, k=ceil(splitDistance), 4*k+2.
Tree* proland::TileSampler::root [protected] |
An internal quadtree to store the texture tiles associated with each quad.
ptr<UniformSampler> proland::TileSampler::samplerU [private] |
The texture sampler to access the proland::GPUTileStorage.
ptr<Uniform3f> proland::TileSampler::sizeU [private] |
The relative size of a tile in the proland::GPUTileStorage.
vector<TileFilter*> proland::TileSampler::storeFilters [private] |
A set of filters to decide whether a texture tile must be stored for a given quad.
A texture is stored if at least one filter returns true.
bool proland::TileSampler::storeInvisible [private] |
True to store texture tiles for invisible quads.
bool proland::TileSampler::storeLeaf [private] |
True to store texture tiles for leaf quads.
bool proland::TileSampler::storeParent [private] |
True to store texture tiles for non leaf quads.
vector< ptr<TerrainNode> > proland::TileSampler::terrains [private] |
The terrains associated with this uniform.
Only used with setTileMap.
ptr<UniformSampler> proland::TileSampler::tileMapU [private] |
The texture sampler to access the proland::GPUTileStorage tile map (an indirection structure to get the storage coordinate of a tile from its logical coordinates).