本文整理汇总了C++中osg::State::getContextID方法的典型用法代码示例。如果您正苦于以下问题:C++ State::getContextID方法的具体用法?C++ State::getContextID怎么用?C++ State::getContextID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::State
的用法示例。
在下文中一共展示了State::getContextID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readData
void AtomicCounterBufferBinding::readData(osg::State & state, osg::UIntArray & uintArray) const
{
if (!_bufferObject) return;
GLBufferObject* bo = _bufferObject->getOrCreateGLBufferObject( state.getContextID() );
if (!bo) return;
GLint previousID = 0;
glGetIntegerv(GL_ATOMIC_COUNTER_BUFFER_BINDING, &previousID);
if (static_cast<GLuint>(previousID) != bo->getGLObjectID())
bo->_extensions->glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, bo->getGLObjectID());
GLubyte* src = (GLubyte*)bo->_extensions->glMapBuffer(GL_ATOMIC_COUNTER_BUFFER,
GL_READ_ONLY_ARB);
if(src)
{
size_t size = osg::minimum<int>(_size, uintArray.getTotalDataSize());
memcpy((void*) &(uintArray.front()), src+_offset, size);
bo->_extensions->glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
}
if (static_cast<GLuint>(previousID) != bo->getGLObjectID())
bo->_extensions->glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, static_cast<GLuint>(previousID));
}
示例2: apply
void Validator::apply(osg::State& state) const
{
if (!_effect) return;
if (_effect->_tech_selected[state.getContextID()] == 0) {
Effect::Technique_list::iterator i;
int j = 0;
for (i=_effect->_techs.begin(); i!=_effect->_techs.end(); ++i, ++j) {
if ((*i)->validate(state)) {
_effect->_sel_tech[state.getContextID()] = j;
_effect->_tech_selected[state.getContextID()] = 1;
return;
}
}
OSG_WARN << "Warning: osgFX::Validator: could not find any techniques compatible with the current OpenGL context" << std::endl;
}
}
示例3: validate
bool Technique::validate(osg::State& state) const
{
typedef std::vector<std::string> String_list;
String_list extensions;
getRequiredExtensions(extensions);
for (String_list::const_iterator i=extensions.begin(); i!=extensions.end(); ++i) {
if (!osg::isGLExtensionSupported(state.getContextID(),i->c_str())) return false;
}
return true;
}
示例4: createFileName
std::string DepthPeelBin::createFileName( osg::State& state, int pass, bool depth )
{
unsigned int contextID = state.getContextID();
int frameNumber = state.getFrameStamp()->getFrameNumber();
std::ostringstream ostr;
ostr << std::setfill( '0' );
ostr << "f" << std::setw( 6 ) << frameNumber <<
"_c" << std::setw( 2 ) << contextID << "_";
ostr << "peel_part" << _partitionNumber;
if( pass == -1 )
ostr << "_a";
else
ostr << "_b" << std::setw( 2 ) << pass;
if( depth )
ostr << "_z";
ostr << ".png";
return( ostr.str() );
}
示例5: fboExt
void
DepthPeelBin::PerContextInfo::cleanup( const osg::State& state )
{
TRACEDUMP(" PerContextInfo::cleanup");
glDeleteTextures( 3, _depthTex );
_depthTex[ 0 ] = _depthTex[ 1 ] = _depthTex[ 2 ] = 0;
glDeleteTextures( 1, &_colorTex );
_colorTex = 0;
osg::FBOExtensions* fboExt( osg::FBOExtensions::instance( state.getContextID(), true ) );
osgwTools::glBindFramebuffer( fboExt, GL_FRAMEBUFFER_EXT, 0 );
osgwTools::glDeleteFramebuffers( fboExt, 1, &_fbo );
_fbo = 0;
_glDeleteQueries( 1, &_queryID );
_queryID = 0;
_init = false;
}
示例6: glCallList
void Font::Glyph::draw(osg::State& state) const
{
GLuint& globj = _globjList[state.getContextID()];
// call the globj if already set otherwise compile and execute.
if( globj != 0 )
{
glCallList( globj );
}
else
{
globj = glGenLists( 1 );
glNewList( globj, GL_COMPILE_AND_EXECUTE );
glPixelStorei(GL_UNPACK_ALIGNMENT,getPacking());
glDrawPixels(s(), t(),
(GLenum)getPixelFormat(),
(GLenum)getDataType(),
data() );
glEndList();
}
}
示例7: apply
void GlyphTexture::apply(osg::State& state) const
{
// get the contextID (user defined ID of 0 upwards) for the
// current OpenGL context.
const unsigned int contextID = state.getContextID();
if (contextID>=_glyphsToSubload.size())
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
// graphics context is beyond the number of glyphsToSubloads, so
// we must now copy the glyph list across, this is a potential
// threading issue though is multiple applies are happening the
// same time on this object - to avoid this condition number of
// graphics contexts should be set before create text.
for(unsigned int i=_glyphsToSubload.size();i<=contextID;++i)
{
GlyphPtrList& glyphPtrs = _glyphsToSubload[i];
for(GlyphRefList::const_iterator itr=_glyphs.begin();
itr!=_glyphs.end();
++itr)
{
glyphPtrs.push_back(itr->get());
}
}
}
const Extensions* extensions = getExtensions(contextID,true);
bool generateMipMapSupported = extensions->isGenerateMipMapSupported();
// get the texture object for the current contextID.
TextureObject* textureObject = getTextureObject(contextID);
bool newTextureObject = (textureObject == 0);
if (newTextureObject)
{
GLint maxTextureSize = 256;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
if (maxTextureSize < getTextureWidth() || maxTextureSize < getTextureHeight())
{
OSG_WARN<<"Warning: osgText::Font texture size of ("<<getTextureWidth()<<", "<<getTextureHeight()<<") too large, unable to create font texture."<<std::endl;
OSG_WARN<<" Maximum supported by hardward by native OpenGL implementation is ("<<maxTextureSize<<","<<maxTextureSize<<")."<<std::endl;
OSG_WARN<<" Please set OSG_MAX_TEXTURE_SIZE lenvironment variable to "<<maxTextureSize<<" and re-run application."<<std::endl;
return;
}
// being bound for the first time, need to allocate the texture
_textureObjectBuffer[contextID] = textureObject = osg::Texture::generateTextureObject(
this, contextID,GL_TEXTURE_2D,1,GL_ALPHA,getTextureWidth(), getTextureHeight(),1,0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_2D,state);
// need to look at generate mip map extension if mip mapping required.
switch(_min_filter)
{
case NEAREST_MIPMAP_NEAREST:
case NEAREST_MIPMAP_LINEAR:
case LINEAR_MIPMAP_NEAREST:
case LINEAR_MIPMAP_LINEAR:
if (generateMipMapSupported)
{
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
}
else glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, LINEAR);
break;
default:
// not mip mapping so no problems.
break;
}
unsigned int imageDataSize = getTextureHeight()*getTextureWidth();
unsigned char* imageData = new unsigned char[imageDataSize];
for(unsigned int i=0; i<imageDataSize; ++i)
{
imageData[i] = 0;
}
// allocate the texture memory.
glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA,
getTextureWidth(), getTextureHeight(), 0,
GL_ALPHA,
GL_UNSIGNED_BYTE,
imageData );
delete [] imageData;
}
else
{
// reuse texture by binding.
textureObject->bind();
//.........这里部分代码省略.........
示例8: setArray
void VertexArrayState::setArray(ArrayDispatch* vad, osg::State& state, const osg::Array* new_array)
{
if (new_array)
{
if (!vad->active)
{
vad->active = true;
_activeDispatchers.push_back(vad);
}
if (vad->array==0)
{
GLBufferObject* vbo = isVertexBufferObjectSupported() ? new_array->getOrCreateGLBufferObject(state.getContextID()) : 0;
if (vbo)
{
bindVertexBufferObject(vbo);
vad->enable_and_dispatch(state, new_array, vbo);
}
else
{
unbindVertexBufferObject();
vad->enable_and_dispatch(state, new_array);
}
}
else if (new_array!=vad->array || new_array->getModifiedCount()!=vad->modifiedCount)
{
GLBufferObject* vbo = isVertexBufferObjectSupported() ? new_array->getOrCreateGLBufferObject(state.getContextID()) : 0;
if (vbo)
{
bindVertexBufferObject(vbo);
vad->dispatch(state, new_array, vbo);
}
else
{
unbindVertexBufferObject();
vad->dispatch(state, new_array);
}
}
vad->array = new_array;
vad->modifiedCount = new_array->getModifiedCount();
}
else if (vad->array)
{
disable(vad, state);
}
}
示例9: compileShader
void Shader::compileShader( osg::State& state ) const
{
PerContextShader* pcs = getPCS( state.getContextID() );
if( pcs ) pcs->compileShader( state );
}
示例10: if
void
SparseTexture2DArray::apply( osg::State& state ) const
{
// get the contextID (user defined ID of 0 upwards) for the
// current OpenGL context.
const unsigned int contextID = state.getContextID();
Texture::TextureObjectManager* tom = Texture::getTextureObjectManager(contextID).get();
//ElapsedTime elapsedTime(&(tom->getApplyTime()));
tom->getNumberApplied()++;
const Extensions* extensions = getExtensions(contextID,true);
// if not supported, then return
if (!extensions->isTexture2DArraySupported() || !extensions->isTexture3DSupported())
{
OSG_WARN<<"Warning: Texture2DArray::apply(..) failed, 2D texture arrays are not support by OpenGL driver."<<std::endl;
return;
}
// get the texture object for the current contextID.
TextureObject* textureObject = getTextureObject(contextID);
if (textureObject && _textureDepth>0)
{
const osg::Image* image = firstValidImage();
if (image && getModifiedCount(0, contextID) != image->getModifiedCount())
{
// compute the internal texture format, this set the _internalFormat to an appropriate value.
computeInternalFormat();
GLsizei new_width, new_height, new_numMipmapLevels;
// compute the dimensions of the texture.
computeRequiredTextureDimensions(state, *image, new_width, new_height, new_numMipmapLevels);
if (!textureObject->match(GL_TEXTURE_2D_ARRAY_EXT, new_numMipmapLevels, _internalFormat, new_width, new_height, 1, _borderWidth))
{
Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get());
_textureObjectBuffer[contextID] = 0;
textureObject = 0;
}
}
}
// if we already have an texture object, then
if (textureObject)
{
// bind texture object
textureObject->bind();
// if texture parameters changed, then reset them
if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state);
// if subload is specified, then use it to subload the images to GPU memory
//if (_subloadCallback.valid())
//{
// _subloadCallback->subload(*this,state);
//}
//else
{
// for each image of the texture array do
for (GLsizei n=0; n < _textureDepth; n++)
{
osg::Image* image = _images[n].get();
// if image content is modified, then upload it to the GPU memory
// GW: this means we have to "dirty" an image before setting it!
if (image && getModifiedCount(n,contextID) != image->getModifiedCount())
{
applyTexImage2DArray_subload(state, image, _textureWidth, _textureHeight, n, _internalFormat, _numMipmapLevels);
getModifiedCount(n,contextID) = image->getModifiedCount();
}
}
}
}
// nothing before, but we have valid images, so do manual upload and create texture object manually
else if ( firstValidImage() != 0L ) // if (imagesValid())
{
// compute the internal texture format, this set the _internalFormat to an appropriate value.
computeInternalFormat();
// compute the dimensions of the texture.
osg::Image* firstImage = firstValidImage();
computeRequiredTextureDimensions(state, *firstImage, _textureWidth, _textureHeight, _numMipmapLevels);
// create texture object
textureObject = generateTextureObject(
this, contextID,GL_TEXTURE_2D_ARRAY_EXT,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0);
// bind texture
textureObject->bind();
applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT, state);
_textureObjectBuffer[contextID] = textureObject;
// First we need to allocate the texture memory
int sourceFormat = _sourceFormat ? _sourceFormat : _internalFormat;
//.........这里部分代码省略.........
示例11: exclusive
void
MPGeometry::renderPrimitiveSets(osg::State& state,
bool usingVBOs) const
{
// check the map frame to see if it's up to date
if ( _frame.needsSync() )
{
// this lock protects a MapFrame sync when we have multiple DRAW threads.
Threading::ScopedMutexLock exclusive( _frameSyncMutex );
if ( _frame.needsSync() && _frame.sync() ) // always double check
{
// This should only happen is the layer ordering changes;
// If layers are added or removed, the Tile gets rebuilt and
// the point is moot.
std::vector<Layer> reordered;
const ImageLayerVector& layers = _frame.imageLayers();
reordered.reserve( layers.size() );
for( ImageLayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i )
{
std::vector<Layer>::iterator j = std::find( _layers.begin(), _layers.end(), i->get()->getUID() );
if ( j != _layers.end() )
reordered.push_back( *j );
}
_layers.swap( reordered );
}
}
unsigned layersDrawn = 0;
// access the GL extensions interface for the current GC:
osg::ref_ptr<osg::GL2Extensions> ext = osg::GL2Extensions::Get( state.getContextID(), true );
const osg::Program::PerContextProgram* pcp = state.getLastAppliedProgramObject();
// cannot store these in the object since there could be multiple GCs (and multiple
// PerContextPrograms) at large
GLint tileKeyLocation;
GLint opacityLocation;
GLint uidLocation;
GLint orderLocation;
GLint texMatParentLocation;
// The PCP can change (especially in a VirtualProgram environment). So we do need to
// requery the uni locations each time unfortunately. TODO: explore optimizations.
if ( pcp )
{
tileKeyLocation = pcp->getUniformLocation( _tileKeyUniformNameID );
opacityLocation = pcp->getUniformLocation( _opacityUniformNameID );
uidLocation = pcp->getUniformLocation( _uidUniformNameID );
orderLocation = pcp->getUniformLocation( _orderUniformNameID );
texMatParentLocation = pcp->getUniformLocation( _texMatParentUniformNameID );
}
// apply the tilekey uniform once.
ext->glUniform4fv( tileKeyLocation, 1, _tileKeyValue.ptr() );
// activate the tile coordinate set - same for all layers
state.setTexCoordPointer( _imageUnit+1, _tileCoords.get() );
if ( _layers.size() > 0 )
{
float prev_opacity = -1.0f;
float prev_alphaThreshold = -1.0f;
// first bind any shared layers
// TODO: optimize by pre-storing shared indexes
for(unsigned i=0; i<_layers.size(); ++i)
{
const Layer& layer = _layers[i];
// a "shared" layer binds to a secondary texture unit so that other layers
// can see it and use it.
if ( layer._imageLayer->isShared() )
{
int sharedUnit = layer._imageLayer->shareImageUnit().get();
{
state.setActiveTextureUnit( sharedUnit );
state.setTexCoordPointer( sharedUnit, layer._texCoords.get() );
// bind the texture for this layer to the active share unit.
layer._tex->apply( state );
// no texture LOD blending for shared layers for now. maybe later.
}
}
}
// track the active image unit.
int activeImageUnit = -1;
// interate over all the image layers
//glDepthMask(GL_TRUE);
for(unsigned i=0; i<_layers.size(); ++i)
{
// if ( i > 0 )
// glDepthMask(GL_FALSE);
const Layer& layer = _layers[i];
if ( layer._imageLayer->getVisible() )
//.........这里部分代码省略.........
示例12: readonly
void
VirtualProgram::apply( osg::State& state ) const
{
if (_shaderMap.empty() && !_inheritSet)
{
// If there's no data in the VP, and never has been, unload any existing program.
// NOTE: OSG's State processor creates a "global default attribute" for each type.
// Sine we have no way of knowing whether the user created the VP or OSG created it
// as the default fallback, we use the "_inheritSet" flag to differeniate. This
// prevents any shader leakage from a VP-enabled node.
const unsigned int contextID = state.getContextID();
const osg::GL2Extensions* extensions = osg::GL2Extensions::Get(contextID,true);
if( ! extensions->isGlslSupported() ) return;
extensions->glUseProgram( 0 );
state.setLastAppliedProgramObject(0);
return;
}
// first, find and collect all the VirtualProgram attributes:
ShaderMap accumShaderMap;
AttribBindingList accumAttribBindings;
AttribAliasMap accumAttribAliases;
// Build the active shader map up to this point:
if ( _inherit )
{
accumulateShaders(state, _mask, accumShaderMap, accumAttribBindings, accumAttribAliases);
}
// next add the local shader components to the map, respecting the override values:
{
Threading::ScopedReadLock readonly(_dataModelMutex);
for( ShaderMap::const_iterator i = _shaderMap.begin(); i != _shaderMap.end(); ++i )
{
if ( i->second.accept(state) )
{
addToAccumulatedMap( accumShaderMap, i->first, i->second );
}
}
const AttribBindingList& abl = this->getAttribBindingList();
accumAttribBindings.insert( abl.begin(), abl.end() );
#ifdef USE_ATTRIB_ALIASES
const AttribAliasMap& aliases = this->getAttribAliases();
accumAttribAliases.insert( aliases.begin(), aliases.end() );
#endif
}
// next, assemble a list of the shaders in the map so we can use it as our
// program cache key.
// (Note: at present, the "cache key" does not include any information on the vertex
// attribute bindings. Technically it should, but in practice this might not be an
// issue; it is unlikely one would have two identical shader programs with different
// bindings.)
ShaderVector vec;
vec.reserve( accumShaderMap.size() );
for( ShaderMap::iterator i = accumShaderMap.begin(); i != accumShaderMap.end(); ++i )
{
ShaderEntry& entry = i->second;
if ( i->second.accept(state) )
{
vec.push_back( entry._shader.get() );
}
}
// see if there's already a program associated with this list:
osg::ref_ptr<osg::Program> program;
// look up the program:
{
Threading::ScopedReadLock shared( _programCacheMutex );
ProgramMap::const_iterator p = _programCache.find( vec );
if ( p != _programCache.end() )
{
program = p->second.get();
}
}
// if not found, lock and build it:
if ( !program.valid() )
{
// build a new set of accumulated functions, to support the creation of main()
ShaderComp::FunctionLocationMap accumFunctions;
accumulateFunctions( state, accumFunctions );
// now double-check the program cache, and failing that, build the
// new shader Program.
{
Threading::ScopedWriteLock exclusive( _programCacheMutex );
// double-check: look again ito negate race conditions
ProgramMap::const_iterator p = _programCache.find( vec );
if ( p != _programCache.end() )
{
program = p->second.get();
//.........这里部分代码省略.........
示例13: readonly
void
VirtualProgram::apply( osg::State& state ) const
{
if (_shaderMap.empty() && !_inheritSet)
{
// If there's no data in the VP, and never has been, unload any existing program.
// NOTE: OSG's State processor creates a "global default attribute" for each type.
// Sine we have no way of knowing whether the user created the VP or OSG created it
// as the default fallback, we use the "_inheritSet" flag to differeniate. This
// prevents any shader leakage from a VP-enabled node.
const unsigned int contextID = state.getContextID();
const osg::GL2Extensions* extensions = osg::GL2Extensions::Get(contextID,true);
if( ! extensions->isGlslSupported() ) return;
extensions->glUseProgram( 0 );
state.setLastAppliedProgramObject(0);
return;
}
// first, find and collect all the VirtualProgram attributes:
ShaderMap accumShaderMap;
AttribBindingList accumAttribBindings;
AttribAliasMap accumAttribAliases;
if ( _inherit )
{
const StateHack::AttributeVec* av = StateHack::GetAttributeVec( state, this );
if ( av && av->size() > 0 )
{
// find the deepest VP that doesn't inherit:
unsigned start = 0;
for( start = (int)av->size()-1; start > 0; --start )
{
const VirtualProgram* vp = dynamic_cast<const VirtualProgram*>( (*av)[start].first );
if ( vp && (vp->_mask & _mask) && vp->_inherit == false )
break;
}
// collect shaders from there to here:
for( unsigned i=start; i<av->size(); ++i )
{
const VirtualProgram* vp = dynamic_cast<const VirtualProgram*>( (*av)[i].first );
if ( vp && (vp->_mask && _mask) )
{
ShaderMap vpShaderMap;
vp->getShaderMap( vpShaderMap );
for( ShaderMap::const_iterator i = vpShaderMap.begin(); i != vpShaderMap.end(); ++i )
{
addToAccumulatedMap( accumShaderMap, i->first, i->second );
}
const AttribBindingList& abl = vp->getAttribBindingList();
accumAttribBindings.insert( abl.begin(), abl.end() );
#ifdef USE_ATTRIB_ALIASES
const AttribAliasMap& aliases = vp->getAttribAliases();
accumAttribAliases.insert( aliases.begin(), aliases.end() );
#endif
}
}
}
}
// next add the local shader components to the map, respecting the override values:
{
Threading::ScopedReadLock readonly(_dataModelMutex);
for( ShaderMap::const_iterator i = _shaderMap.begin(); i != _shaderMap.end(); ++i )
{
addToAccumulatedMap( accumShaderMap, i->first, i->second );
}
const AttribBindingList& abl = this->getAttribBindingList();
accumAttribBindings.insert( abl.begin(), abl.end() );
#ifdef USE_ATTRIB_ALIASES
const AttribAliasMap& aliases = this->getAttribAliases();
accumAttribAliases.insert( aliases.begin(), aliases.end() );
#endif
}
if ( true ) //even with nothing in the map, we still want mains! -gw //accumShaderMap.size() )
{
// next, assemble a list of the shaders in the map so we can use it as our
// program cache key.
// (Note: at present, the "cache key" does not include any information on the vertex
// attribute bindings. Technically it should, but in practice this might not be an
// issue; it is unlikely one would have two identical shader programs with different
// bindings.)
ShaderVector vec;
vec.reserve( accumShaderMap.size() );
for( ShaderMap::iterator i = accumShaderMap.begin(); i != accumShaderMap.end(); ++i )
{
ShaderEntry& entry = i->second;
vec.push_back( entry.first.get() );
}
// see if there's already a program associated with this list:
//.........这里部分代码省略.........
示例14: exclusive
void
MPGeometry::renderPrimitiveSets(osg::State& state,
bool usingVBOs) const
{
// check the map frame to see if it's up to date
if ( _frame.needsSync() )
{
// this lock protects a MapFrame sync when we have multiple DRAW threads.
Threading::ScopedMutexLock exclusive( _frameSyncMutex );
if ( _frame.needsSync() && _frame.sync() ) // always double check
{
// This should only happen is the layer ordering changes;
// If layers are added or removed, the Tile gets rebuilt and
// the point is moot.
std::vector<Layer> reordered;
const ImageLayerVector& layers = _frame.imageLayers();
reordered.reserve( layers.size() );
for( ImageLayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i )
{
std::vector<Layer>::iterator j = std::find( _layers.begin(), _layers.end(), i->get()->getUID() );
if ( j != _layers.end() )
reordered.push_back( *j );
}
_layers.swap( reordered );
}
}
unsigned layersDrawn = 0;
osg::ref_ptr<osg::GL2Extensions> ext = osg::GL2Extensions::Get( state.getContextID(), true );
const osg::Program::PerContextProgram* pcp = state.getLastAppliedProgramObject();
GLint opacityLocation;
GLint uidLocation;
GLint orderLocation;
GLint texMatParentLocation;
// yes, it's possible that the PCP is not set up yet.
// TODO: can we optimize this so we don't need to get uni locations every time?
if ( pcp )
{
opacityLocation = pcp->getUniformLocation( _opacityUniform->getNameID() );
uidLocation = pcp->getUniformLocation( _layerUIDUniform->getNameID() );
orderLocation = pcp->getUniformLocation( _layerOrderUniform->getNameID() );
texMatParentLocation = pcp->getUniformLocation( _texMatParentUniform->getNameID() );
}
// activate the tile coordinate set - same for all layers
state.setTexCoordPointer( _imageUnit+1, _tileCoords.get() );
if ( _layers.size() > 0 )
{
float prev_opacity = -1.0f;
float prev_alphaThreshold = -1.0f;
// first bind any shared layers
// TODO: optimize by pre-storing shared indexes
for(unsigned i=0; i<_layers.size(); ++i)
{
const Layer& layer = _layers[i];
// a "shared" layer binds to a secondary texture unit so that other layers
// can see it and use it.
if ( layer._imageLayer->isShared() )
{
int sharedUnit = layer._imageLayer->shareImageUnit().get();
{
state.setActiveTextureUnit( sharedUnit );
state.setTexCoordPointer( sharedUnit, layer._texCoords.get() );
// bind the texture for this layer to the active share unit.
layer._tex->apply( state );
// no texture LOD blending for shared layers for now. maybe later.
}
}
}
// track the active image unit.
int activeImageUnit = -1;
// interate over all the image layers
for(unsigned i=0; i<_layers.size(); ++i)
{
const Layer& layer = _layers[i];
if ( layer._imageLayer->getVisible() )
{
// activate the visible unit if necessary:
if ( activeImageUnit != _imageUnit )
{
state.setActiveTextureUnit( _imageUnit );
activeImageUnit = _imageUnit;
}
// bind the texture for this layer:
layer._tex->apply( state );
// if we're using a parent texture for blending, activate that now
//.........这里部分代码省略.........
示例15: exclusive
void
MPGeometry::renderPrimitiveSets(osg::State& state,
bool renderColor,
bool usingVBOs) const
{
// check the map frame to see if it's up to date
if ( _frame.needsSync() )
{
// this lock protects a MapFrame sync when we have multiple DRAW threads.
Threading::ScopedMutexLock exclusive( _frameSyncMutex );
if ( _frame.needsSync() && _frame.sync() ) // always double check
{
// This should only happen is the layer ordering changes;
// If layers are added or removed, the Tile gets rebuilt and
// the point is moot.
std::vector<Layer> reordered;
const ImageLayerVector& layers = _frame.imageLayers();
reordered.reserve( layers.size() );
for( ImageLayerVector::const_iterator i = layers.begin(); i != layers.end(); ++i )
{
std::vector<Layer>::iterator j = std::find( _layers.begin(), _layers.end(), i->get()->getUID() );
if ( j != _layers.end() )
reordered.push_back( *j );
}
_layers.swap( reordered );
}
}
unsigned layersDrawn = 0;
// access the GL extensions interface for the current GC:
const osg::Program::PerContextProgram* pcp = 0L;
#if OSG_MIN_VERSION_REQUIRED(3,3,3)
osg::ref_ptr<osg::GLExtensions> ext;
#else
osg::ref_ptr<osg::GL2Extensions> ext;
#endif
unsigned contextID;
if (_supportsGLSL)
{
contextID = state.getContextID();
#if OSG_MIN_VERSION_REQUIRED(3,3,3)
ext = osg::GLExtensions::Get(contextID, true);
#else
ext = osg::GL2Extensions::Get( contextID, true );
#endif
pcp = state.getLastAppliedProgramObject();
}
// cannot store these in the object since there could be multiple GCs (and multiple
// PerContextPrograms) at large
GLint tileKeyLocation = -1;
GLint birthTimeLocation = -1;
GLint opacityLocation = -1;
GLint uidLocation = -1;
GLint orderLocation = -1;
GLint texMatParentLocation = -1;
GLint minRangeLocation = -1;
GLint maxRangeLocation = -1;
// The PCP can change (especially in a VirtualProgram environment). So we do need to
// requery the uni locations each time unfortunately. TODO: explore optimizations.
if ( pcp )
{
tileKeyLocation = pcp->getUniformLocation( _tileKeyUniformNameID );
birthTimeLocation = pcp->getUniformLocation( _birthTimeUniformNameID );
opacityLocation = pcp->getUniformLocation( _opacityUniformNameID );
uidLocation = pcp->getUniformLocation( _uidUniformNameID );
orderLocation = pcp->getUniformLocation( _orderUniformNameID );
texMatParentLocation = pcp->getUniformLocation( _texMatParentUniformNameID );
minRangeLocation = pcp->getUniformLocation( _minRangeUniformNameID );
maxRangeLocation = pcp->getUniformLocation( _maxRangeUniformNameID );
}
// apply the tilekey uniform once.
if ( tileKeyLocation >= 0 )
{
ext->glUniform4fv( tileKeyLocation, 1, _tileKeyValue.ptr() );
}
// set the "birth time" - i.e. the time this tile last entered the scene in the current GC.
if ( birthTimeLocation >= 0 )
{
PerContextData& pcd = _pcd[contextID];
if ( pcd.birthTime < 0.0f )
{
const osg::FrameStamp* stamp = state.getFrameStamp();
if ( stamp )
{
pcd.birthTime = stamp->getReferenceTime();
}
}
ext->glUniform1f( birthTimeLocation, pcd.birthTime );
}
// activate the tile coordinate set - same for all layers
if ( renderColor )
//.........这里部分代码省略.........