当前位置: 首页>>代码示例>>C++>>正文


C++ StateSet::addUniform方法代码示例

本文整理汇总了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);
   }
开发者ID:VRAC-WATCH,项目名称:deltajug,代码行数:51,代码来源:shaderparamtexturecubemap.cpp

示例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());
	}
开发者ID:gisair,项目名称:EAView,代码行数:18,代码来源:test.cpp


注:本文中的osg::StateSet::addUniform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。