示例#1
0
文件: test.cpp 项目: gisair/EAView
	void test::createTextureCubeMap(osg::StateSet& ss)
	{
		osg::ref_ptr<osg::TextureCubeMap> texture=new osg::TextureCubeMap;
		texture->setImage(osg::TextureCubeMap::POSITIVE_X,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/posx.jpg")));
		texture->setImage(osg::TextureCubeMap::NEGATIVE_X,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/negx.jpg")));
		texture->setImage(osg::TextureCubeMap::POSITIVE_Y,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/posy.jpg")));
		texture->setImage(osg::TextureCubeMap::NEGATIVE_Y,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/negy.jpg")));
		texture->setImage(osg::TextureCubeMap::POSITIVE_Z,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/posz.jpg")));
		texture->setImage(osg::TextureCubeMap::NEGATIVE_Z,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/negz.jpg")));
		texture->setWrap(osg::Texture::WRAP_S,
			osg::Texture::CLAMP_TO_EDGE);
		texture->setWrap(osg::Texture::WRAP_T,
			osg::Texture::CLAMP_TO_EDGE);
		texture->setWrap(osg::Texture::WRAP_R,
			osg::Texture::CLAMP_TO_EDGE);
		texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
		texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
		ss.setTextureAttributeAndModes(0,texture.get());
		ss.setTextureAttributeAndModes(0,new osg::TexGen);
	}
示例#2
0
文件: test.cpp 项目: gisair/EAView
	void test::createTexture2D(osg::StateSet& ss)
	{
		osg::ref_ptr<osg::Texture2D> texture=new osg::Texture2D;
		texture->setImage(osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Images/clockface.jpg")));
		texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
		texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
		texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_BORDER);
		texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_BORDER);
		texture->setBorderColor(osg::Vec4(1,1,0,1));
		ss.setTextureAttributeAndModes(0,texture.get());
	}
示例#3
0
void createTexture2D( osg::StateSet& ss, bool useCustomizedData )
{
    osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
    if ( useCustomizedData ) texture->setImage( createCustomMipmap(32) );
    else texture->setImage( createInternalMipmap(32) );
    
    texture->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
    texture->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
    texture->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
    texture->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
    ss.setTextureAttributeAndModes( 0, texture.get(), osg::StateAttribute::ON );
}
   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);
   }
   void ShaderParamTextureCubeMap::DetachFromRenderState(osg::StateSet &stateSet)
   {
      osg::TextureCubeMap *texCube = static_cast<osg::TextureCubeMap*>(GetTextureObject());
      if (texCube != NULL)
      {
         if (!IsShared())
         {
            osg::Image *image = new osg::Image();
            texCube->setImage(osg::TextureCubeMap::POSITIVE_X, image);
            texCube->setImage(osg::TextureCubeMap::NEGATIVE_X, image);
            texCube->setImage(osg::TextureCubeMap::POSITIVE_Y, image);
            texCube->setImage(osg::TextureCubeMap::NEGATIVE_Y, image);
            texCube->setImage(osg::TextureCubeMap::POSITIVE_Z, image);
            texCube->setImage(osg::TextureCubeMap::NEGATIVE_Z, image);

         }
         stateSet.setTextureAttributeAndModes(GetTextureUnit(),texCube,osg::StateAttribute::OFF);
      }

      // do normal parameter cleanup
      ShaderParameter::DetachFromRenderState(stateSet);
   }