本文整理汇总了C++中osg::StateSet::addUniform方法的典型用法代码示例。如果您正苦于以下问题:C++ StateSet::addUniform方法的具体用法?C++ StateSet::addUniform怎么用?C++ StateSet::addUniform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::StateSet
的用法示例。
在下文中一共展示了StateSet::addUniform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AttachToRenderState
void ShaderParamTextureCubeMap::AttachToRenderState(osg::StateSet &stateSet)
{
dtCore::RefPtr<osg::TextureCubeMap> texCube;
if (GetTexture().empty() && GetTextureSourceType() != ShaderParamTexture::TextureSourceType::AUTO)
{
throw dtUtil::Exception(ShaderParameterException::INVALID_ATTRIBUTE,"Cannot attach to render state. Texture "
"for parameter " + GetName() + " has not been specified.", __FILE__, __LINE__);
}
osg::Uniform *uniform = NULL;
if (IsShared())
uniform = GetUniformParam();
// Create a new one if unshared or if shared but not set yet
if (uniform == NULL)
{
uniform = new osg::Uniform(osg::Uniform::SAMPLER_CUBE,GetName());
uniform->set((int)GetTextureUnit());
SetUniformParam(*uniform);
}
stateSet.addUniform(uniform);
// Load (if necessary) and Set the Tex cube map on the StateSet
if(GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_POSITIVE_X ||
GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_NEGATIVE_X ||
GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_POSITIVE_Y ||
GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_NEGATIVE_Y ||
GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_POSITIVE_Z ||
GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_NEGATIVE_Z
)
{
texCube = static_cast<osg::TextureCubeMap*>(GetTextureObject());
// load or reload the image - allows caching from the template
// Note - ImageSourceDirty may not be relevant anymore cause it now loads the image when you call SetTexture().
// note - If shared, load only happens the first time it is assigned.
// check only if face 0 exists. Is this sufficient?
if (texCube->getImage(osg::TextureCubeMap::POSITIVE_X) == NULL || IsImageSourceDirty())
{
LoadImage();
ApplyTextureCubeMapValues();
}
//Assign the completed texture attribute to the render state.
stateSet.setTextureAttributeAndModes(GetTextureUnit(), texCube.get(), osg::StateAttribute::ON);
}
SetDirty(false);
}
示例2: createShaders
void createShaders(osg::StateSet& ss)
{
osg::ref_ptr<osg::Shader> verShader=
new osg::Shader(osg::Shader::VERTEX,vertSource);
osg::ref_ptr<osg::Shader> fragShader=
new osg::Shader(osg::Shader::FRAGMENT,fragSource);
osg::ref_ptr<osg::Program> program=new osg::Program;
program->addShader(verShader.get());
program->addShader(fragShader.get());
osg::ref_ptr<osg::Uniform> mainColor=
new osg::Uniform("mainColor",osg::Vec4(1,0.5,0.5,1));
mainColor->setUpdateCallback(new ColorCallback);
ss.addUniform(mainColor.get());
ss.setAttributeAndModes(program.get());
}