本文整理汇总了C++中osg::StateSet::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ StateSet::getAttribute方法的具体用法?C++ StateSet::getAttribute怎么用?C++ StateSet::getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::StateSet
的用法示例。
在下文中一共展示了StateSet::getAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: apply
void apply(osg::StateSet& stateset)
{
if (_modAlphaFunc)
{
osg::AlphaFunc* alphaFunc = dynamic_cast<osg::AlphaFunc*>(stateset.getAttribute(osg::StateAttribute::ALPHAFUNC));
if (alphaFunc)
{
OSG_INFO<<"Adjusting alpha func"<<std::endl;
float alpha = alphaFunc->getReferenceValue();
alpha = osg::clampBetween((1.0f-_currentY)*0.5f,0.0f,1.0f);
alphaFunc->setReferenceValue(alpha);
}
}
if (_modMaterial)
{
osg::Material* material = dynamic_cast<osg::Material*>(stateset.getAttribute(osg::StateAttribute::MATERIAL));
if (material)
{
OSG_INFO<<"Adjusting material func"<<std::endl;
float alpha = osg::clampBetween((_currentY+1.0f)*0.5f,0.0f,1.0f);
material->setAlpha(osg::Material::FRONT_AND_BACK,alpha);
}
}
}
示例2: backFaceCullingWithoutNormals
std::string GLSLUtils::backFaceCullingWithoutNormals( osg::StateSet &sset )
{
std::string glsl_code;
bool opposite = false;
osg::StateAttribute *sa = sset.getAttribute( osg::StateAttribute::CULLFACE );
if ( sa ) {
osg::CullFace *cf = dynamic_cast<osg::CullFace*>(sa);
if ( cf ) {
// If culling front facing polygons, we consider it the opposite direction
opposite = cf->getMode() == osg::CullFace::FRONT;
}
}
// Check if the StateSet has backface culling enabled
// and add code to the shader to perform it
if ( sset.getMode(GL_CULL_FACE) == osg::StateAttribute::ON ) {
if ( opposite ) {
glsl_code +=
" if ( gl_FrontFacing )\n"
" discard;\n";
}
else {
glsl_code +=
" if ( !gl_FrontFacing )\n"
" discard;\n";
}
}
return glsl_code;
}
示例3: apply
void GLObjectsVisitor::apply(osg::StateSet& stateset)
{
if (_stateSetAppliedSet.count(&stateset)!=0) return;
_stateSetAppliedSet.insert(&stateset);
if (_mode & COMPILE_STATE_ATTRIBUTES && _renderInfo.getState())
{
stateset.compileGLObjects(*_renderInfo.getState());
osg::Program* program = dynamic_cast<osg::Program*>(stateset.getAttribute(osg::StateAttribute::PROGRAM));
if (program) {
if( program->isFixedFunction() )
_lastCompiledProgram = NULL; // It does not make sense to apply uniforms on fixed pipe
else
_lastCompiledProgram = program;
}
if (_lastCompiledProgram.valid() && !stateset.getUniformList().empty())
{
osg::Program::PerContextProgram* pcp = _lastCompiledProgram->getPCP(*_renderInfo.getState());
if (pcp)
{
pcp->useProgram();
_renderInfo.getState()->setLastAppliedProgramObject(pcp);
const osg::StateSet::UniformList& ul = stateset.getUniformList();
for(osg::StateSet::UniformList::const_iterator itr = ul.begin();
itr != ul.end();
++itr)
{
pcp->apply(*(itr->second.first));
}
}
}
else if(_renderInfo.getState()->getLastAppliedProgramObject())
{
osg::State* state = _renderInfo.getState();
osg::GLExtensions* extensions = state->get<osg::GLExtensions>();
extensions->glUseProgram(0);
_renderInfo.getState()->setLastAppliedProgramObject(0);
}
}
if (_mode & RELEASE_STATE_ATTRIBUTES)
{
stateset.releaseGLObjects(_renderInfo.getState());
}
if (_mode & CHECK_BLACK_LISTED_MODES)
{
stateset.checkValidityOfAssociatedModes(*_renderInfo.getState());
}
}
示例4: apply
void apply(osg::StateSet& stateset)
{
if (_visited.count(&stateset)!=0) return;
_visited.insert(&stateset);
return;
osg::notify(osg::NOTICE)<<"Found stateset "<<&stateset<<std::endl;
osg::Program* program = dynamic_cast<osg::Program*>(stateset.getAttribute(osg::StateAttribute::PROGRAM));
if (program)
{
osg::notify(osg::NOTICE)<<" Found Program "<<program<<std::endl;
for(unsigned int i=0; i<program->getNumShaders(); ++i)
{
apply(*program, *(program->getShader(i)));
}
}
}
示例5: isTransparent
virtual bool isTransparent(osg::StateSet& stateset)
{
bool hasTranslucentTexture = false;
bool hasBlendFunc = dynamic_cast<osg::BlendFunc*>(stateset.getAttribute(osg::StateAttribute::BLENDFUNC))!=0;
bool hasTransparentRenderingHint = stateset.getRenderingHint()==osg::StateSet::TRANSPARENT_BIN;
bool hasDepthSortBin = (stateset.getRenderBinMode()==osg::StateSet::USE_RENDERBIN_DETAILS)?(stateset.getBinName()=="DepthSortedBin"):false;
bool hasTexture = false;
// search for the existence of any texture object attributes
for(unsigned int i=0;i<stateset.getTextureAttributeList().size();++i)
{
osg::Texture* texture = dynamic_cast<osg::Texture*>(stateset.getTextureAttribute(i,osg::StateAttribute::TEXTURE));
if (texture)
{
hasTexture = true;
for (unsigned int im=0;im<texture->getNumImages();++im)
{
osg::Image* image = texture->getImage(im);
if (image && image->isImageTranslucent()) hasTranslucentTexture = true;
}
}
}
if (hasTranslucentTexture || hasBlendFunc || hasTransparentRenderingHint || hasDepthSortBin)
{
++_numTransparent;
bool makeNonTransparent = false;
switch(_mode)
{
case(MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE):
if (hasTexture && !hasTranslucentTexture)
{
makeNonTransparent = true;
}
break;
case(MAKE_ALL_STATESET_OPAQUE):
makeNonTransparent = true;
break;
default:
makeNonTransparent = false;
break;
}
if (makeNonTransparent)
{
stateset.removeAttribute(osg::StateAttribute::BLENDFUNC);
stateset.removeMode(GL_BLEND);
stateset.setRenderingHint(osg::StateSet::DEFAULT_BIN);
++_numTransparentMadeOpaque;
}
return true;
}
else
{
++_numOpaque;
return false;
}
}