osgEarth 2.1.1
|
Public Types | |
typedef std::vector< UID > | TextureSlotVector |
typedef std::vector< int > | RenderOrderVector |
Public Member Functions | |
TextureLayout () | |
int | getSlot (UID layerUID, unsigned which=0, unsigned maxSlotsToSearch=~0) const |
int | getOrder (UID layerUID) const |
int | getMaxUsedSlot () const |
bool | isSlotAvailable (int slot) const |
const TextureSlotVector & | getTextureSlots () const |
const RenderOrderVector & | getRenderOrder () const |
bool | containsSecondarySlots (unsigned maxSlotsToSearch=~0) const |
bool | isBlendingEnabled (UID layerUID) const |
Protected Member Functions | |
void | applyMapModelChange (const MapModelChange &change, bool reserveSeconarySlotIfNecessary) |
void | setReservedSlots (const std::set< int > &reservedSlots) |
void | assignPrimarySlot (ImageLayer *layer, int index) |
void | assignSecondarySlot (ImageLayer *layer) |
Protected Attributes | |
TextureSlotVector | _slots |
RenderOrderVector | _order |
bool | _textureImageUnitPerSlot |
std::set< int > | _reservedSlots |
std::map< UID, bool > | _lodBlending |
Friends | |
class | TextureCompositor |
Tracks the usage of texture slots and their rendering order for a map.
A "slot" is a home for a texture layer. For example, in a multitexturing setup, a slot corresponds to a texture image unit in the hardware. In a texture_array setup, a slot is one "slice" of the texture array.
A single layer can occupy more than one slot. (Specifically, this is the case when LOD Blending is enabled on that layer -- the layer will require 2 slots in order to blend the images together in the shader.) In this case, we refer to the first slot as the "primary" slot, and any additional slots belonging to the same layer as "secondary" slots.
Definition at line 45 of file TextureCompositor.
typedef std::vector<int> osgEarth::TextureLayout::RenderOrderVector |
Definition at line 53 of file TextureCompositor.
typedef std::vector<UID> osgEarth::TextureLayout::TextureSlotVector |
Definition at line 50 of file TextureCompositor.
TextureLayout::TextureLayout | ( | ) |
Definition at line 38 of file TextureCompositor.cpp.
{
//nop
}
void TextureLayout::applyMapModelChange | ( | const MapModelChange & | change, |
bool | reserveSeconarySlotIfNecessary | ||
) | [protected] |
Definition at line 161 of file TextureCompositor.cpp.
{ if ( change.getAction() == MapModelChange::ADD_IMAGE_LAYER ) { assignPrimarySlot( change.getImageLayer(), change.getFirstIndex() ); bool blendingOn = change.getImageLayer()->getImageLayerOptions().lodBlending() == true; _lodBlending[ change.getImageLayer()->getUID() ] = blendingOn; if ( blendingOn && reserveSeconarySlotIfNecessary ) { assignSecondarySlot( change.getImageLayer() ); } } else if ( change.getAction() == MapModelChange::REMOVE_IMAGE_LAYER ) { for( int which = 0; which <= 1; ++which ) { int slot = getSlot( change.getLayer()->getUID(), which ); if ( slot < 0 ) break; _slots[slot] = -1; if ( which == 0 ) // primary slot; remove from render order: { for( RenderOrderVector::iterator j = _order.begin(); j != _order.end(); ) { if ( *j == slot ) j = _order.erase( j ); else ++j; } } } } else if ( change.getAction() == MapModelChange::MOVE_IMAGE_LAYER ) { int fromIndex = getOrder( change.getLayer()->getUID() ); int toIndex = change.getSecondIndex(); if ( fromIndex != toIndex ) { int slot = _order[fromIndex]; _order.erase( _order.begin() + fromIndex ); _order.insert( _order.begin() + toIndex, slot ); } } //OE_INFO << LC << "Layout Slots: " << std::endl; //for( int i=0; i<_slots.size(); ++i ) // OE_INFO << LC << " Slot " << i << ": uid=" << _slots[i] << ", order=" << getOrder(_slots[i]) << std::endl; //OE_INFO << LC << "Layout Order: " << std::endl; //for( int i=0; i<_order.size(); ++i ) // OE_INFO << LC << " Ordr " << i << ": slot=" << _order[i] << std::endl; }
void TextureLayout::assignPrimarySlot | ( | ImageLayer * | layer, |
int | index | ||
) | [protected] |
Definition at line 77 of file TextureCompositor.cpp.
{ int slot = -1; bool found = false; for( TextureSlotVector::iterator i = _slots.begin(); i != _slots.end() && !found; ++i ) { slot = (int)(i - _slots.begin()); // negative UID means the slot is empty. bool slotAvailable = (*i < 0) && (_reservedSlots.find(slot) == _reservedSlots.end()); if ( slotAvailable ) { // record this UID in the new slot: *i = layer->getUID(); // record the render order of this slot: if ( orderIndex >= (int)_order.size() ) { _order.resize( orderIndex + 1, -1 ); _order[orderIndex] = slot; } else { if (_order[orderIndex] == -1) _order[orderIndex] = slot; else _order.insert(_order.begin() + orderIndex, slot); } found = true; break; } } if ( !found ) { // put the UID in the next available slot (that's not reserved). while( _reservedSlots.find(_slots.size()) != _reservedSlots.end() ) _slots.push_back( -1 ); slot = _slots.size(); _slots.push_back( layer->getUID() ); _order.push_back( _slots.size() - 1 ); } OE_INFO << LC << "Allocated SLOT " << slot << "; primary slot for layer \"" << layer->getName() << "\"" << std::endl; }
void TextureLayout::assignSecondarySlot | ( | ImageLayer * | layer | ) | [protected] |
Definition at line 127 of file TextureCompositor.cpp.
{ int slot = -1; bool found = false; for( TextureSlotVector::iterator i = _slots.begin(); i != _slots.end() && !found; ++i ) { slot = (int)(i - _slots.begin()); // negative UID means the slot is empty. bool slotAvailable = (*i < 0) && (_reservedSlots.find(slot) == _reservedSlots.end()); if ( slotAvailable ) { // record this UID in the new slot: *i = layer->getUID(); found = true; break; } } if ( !found ) { // put the UID in the next available slot (that's not reserved). while( _reservedSlots.find(_slots.size()) != _reservedSlots.end() ) _slots.push_back( -1 ); slot = _slots.size(); _slots.push_back( layer->getUID() ); } OE_INFO << LC << "Allocated SLOT " << slot << "; secondary slot for layer \"" << layer->getName() << "\"" << std::endl; }
bool TextureLayout::containsSecondarySlots | ( | unsigned | maxSlotsToSearch = ~0 | ) | const |
Returns "true" if the layout contains at least one secondary slot allocation.
Definition at line 240 of file TextureCompositor.cpp.
{ for( int slot = 0; slot < (int)_slots.size() && slot < (int)maxSlotsToSearch; ++slot ) { UID uid = _slots[slot]; if ( getSlot(uid, 0) != slot ) return true; } return false; }
int TextureLayout::getMaxUsedSlot | ( | ) | const |
Gets the index of the highest populated slot.
Definition at line 68 of file TextureCompositor.cpp.
{ for( int i = _slots.size()-1; i >= 0; --i ) if ( i >= 0 ) return i; return -1; }
int TextureLayout::getOrder | ( | UID | layerUID | ) | const |
Gets the render order index of the layer with the given UID
Definition at line 60 of file TextureCompositor.cpp.
{ int slot = getSlot( layerUID, 0 ); RenderOrderVector::const_iterator i = std::find( _order.begin(), _order.end(), slot ); return i != _order.end() ? (int)(i-_order.begin()) : -1; }
const RenderOrderVector& osgEarth::TextureLayout::getRenderOrder | ( | ) | const [inline] |
Access a vector that specifies the rendering order of texture slots.
Definition at line 78 of file TextureCompositor.
{ return _order; }
int TextureLayout::getSlot | ( | UID | layerUID, |
unsigned | which = 0 , |
||
unsigned | maxSlotsToSearch = ~0 |
||
) | const |
Gets a texture slot corresponding to the layer UID. There may be more than one, the "which" parameter allows you to select one in particular. You can also limit the number of slots to search.
Definition at line 44 of file TextureCompositor.cpp.
{ for( unsigned slot = 0; slot < _slots.size() && slot < maxSlotsToSearch; ++slot ) { if ( _slots[slot] == layerUID ) { if ( which == 0 ) return slot; else --which; } } return -1; }
const TextureSlotVector& osgEarth::TextureLayout::getTextureSlots | ( | ) | const [inline] |
Accesses a vector that maps layer UIDs to texture slots.
Definition at line 75 of file TextureCompositor.
{ return _slots; }
bool TextureLayout::isBlendingEnabled | ( | UID | layerUID | ) | const |
whether LOD blending is enabled on a layer
Definition at line 252 of file TextureCompositor.cpp.
{ std::map<UID,bool>::const_iterator i = _lodBlending.find(layerUID); return i != _lodBlending.end() ? i->second : false; }
bool TextureLayout::isSlotAvailable | ( | int | slot | ) | const |
Whether the indicated slot is available for use
Definition at line 227 of file TextureCompositor.cpp.
{ if ( (i < (int)_slots.size() && _slots[i] < 0) || i >= (int)_slots.size() ) { if ( _reservedSlots.find(i) == _reservedSlots.end() ) { return true; } } return false; }
void TextureLayout::setReservedSlots | ( | const std::set< int > & | reservedSlots | ) | [protected] |
Definition at line 221 of file TextureCompositor.cpp.
{ _reservedSlots = reservedSlots; }
friend class TextureCompositor [friend] |
Definition at line 87 of file TextureCompositor.
std::map<UID,bool> osgEarth::TextureLayout::_lodBlending [protected] |
Definition at line 98 of file TextureCompositor.
RenderOrderVector osgEarth::TextureLayout::_order [protected] |
Definition at line 95 of file TextureCompositor.
std::set<int> osgEarth::TextureLayout::_reservedSlots [protected] |
Definition at line 97 of file TextureCompositor.
TextureSlotVector osgEarth::TextureLayout::_slots [protected] |
Definition at line 94 of file TextureCompositor.
bool osgEarth::TextureLayout::_textureImageUnitPerSlot [protected] |
Definition at line 96 of file TextureCompositor.