osgEarth 2.1.1
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends

osgEarth::TextureLayout Class Reference

List of all members.

Public Types

typedef std::vector< UIDTextureSlotVector
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 TextureSlotVectorgetTextureSlots () const
const RenderOrderVectorgetRenderOrder () 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

Detailed Description

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.


Member Typedef Documentation

Definition at line 53 of file TextureCompositor.

Definition at line 50 of file TextureCompositor.


Constructor & Destructor Documentation

TextureLayout::TextureLayout ( )

Definition at line 38 of file TextureCompositor.cpp.

{
    //nop
}

Member Function Documentation

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

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;
}

Here is the caller graph for this function:

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;
}

Here is the caller graph for this function:

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;
}

Here is the caller graph for this function:

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; }

Here is the caller graph for this function:

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;
}

Here is the caller graph for this function:

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; }

Here is the caller graph for this function:

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;
}

Here is the caller graph for this function:

void TextureLayout::setReservedSlots ( const std::set< int > &  reservedSlots) [protected]

Definition at line 221 of file TextureCompositor.cpp.

{
    _reservedSlots = reservedSlots;
}

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class TextureCompositor [friend]

Definition at line 87 of file TextureCompositor.


Member Data Documentation

std::map<UID,bool> osgEarth::TextureLayout::_lodBlending [protected]

Definition at line 98 of file TextureCompositor.

Definition at line 95 of file TextureCompositor.

std::set<int> osgEarth::TextureLayout::_reservedSlots [protected]

Definition at line 97 of file TextureCompositor.

Definition at line 94 of file TextureCompositor.

Definition at line 96 of file TextureCompositor.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines