Exemple #1
0
		public override void Unload()
		{
			base.Unload();

			if ( IsLoaded )
			{
				if ( this._texture != null )
				{
					this._texture.Dispose();
					this._texture = null;
				}

				if ( this._normTexture != null )
				{
					LogManager.Instance.Write( "Disposed normal texture {0}", this.Name );
					this._normTexture.Dispose();
					this._normTexture = null;
				}

				if ( this._cubeTexture != null )
				{
					this._cubeTexture.Dispose();
					this._cubeTexture = null;
				}

				if ( this._volumeTexture != null )
				{
					this._volumeTexture.Dispose();
					this._volumeTexture = null;
				}
			}
		}
Exemple #2
0
		private void LoadCubeTexture()
		{
			Debug.Assert( this.TextureType == TextureType.CubeMap, "this.TextureType == TextureType.CubeMap" );

			if ( Name.EndsWith( ".dds" ) )
			{
				Stream stream = ResourceGroupManager.Instance.OpenResource( Name, Group, true, this );

				int numMips = this.RequestedMipmapCount + 1;
				// check if mip map volume textures are supported
				if ( ( _devCaps.TextureCaps & D3D.TextureCaps.MipCubeMap ) != D3D.TextureCaps.MipCubeMap )
				{
					// no mip map support for this kind of textures :(
					this.MipmapCount = 0;
					numMips = 1;
				}

				_d3dPool = ( Usage & TextureUsage.Dynamic ) != 0 ? D3D.Pool.Default : D3D.Pool.Managed;

				try
				{
					// load the cube texture from the image data stream directly
					_cubeTexture = D3D.CubeTexture.FromStream( _device, stream, (int)stream.Length, numMips, D3D.Usage.None, D3D.Format.Unknown, _d3dPool, D3D.Filter.None, D3D.Filter.None, 0 );
				}
				catch ( Exception ex )
				{
					FreeInternalResources();
					throw new Exception( "Can't create cube texture.", ex );
				}

				// store off a base reference
				_texture = _cubeTexture;

				// set src and dest attributes to the same, we can't know
				D3D.SurfaceDescription desc = _cubeTexture.GetLevelDescription( 0 );
				_d3dPool = desc.Pool;

				SetSrcAttributes( desc.Width, desc.Height, 1, D3DHelper.ConvertEnum( desc.Format ) );
				SetFinalAttributes( desc.Width, desc.Height, 1, D3DHelper.ConvertEnum( desc.Format ) );

				internalResourcesCreated = true;

				stream.Close();
			}
			else
			{
				// Load from 6 separate files
				// Use Axiom codecs
				string[] postfixes = { "_rt", "_lf", "_up", "_dn", "_fr", "_bk" };
				List<Image> images = new List<Image>();

				int pos = Name.LastIndexOf( "." );
				string baseName = Name.Substring( 0, pos );
				string ext = Name.Substring( pos + 1 );

				for ( int i = 0; i < 6; i++ )
				{
					string fullName = baseName + postfixes[ i ] + "." + ext;

					Stream strm = ResourceGroupManager.Instance.OpenResource( fullName, Group, true, this );
					var image = Image.FromStream( strm, ext );
					images.Add( image );
					strm.Close();
				}

				LoadImages( images.ToArray() );
			}
		}
Exemple #3
0
		private void CreateCubeTexture()
		{
			Debug.Assert( SrcWidth > 0 && SrcHeight > 0 );

			// use current back buffer format for render textures, else use the one
			// defined by this texture format
			D3D.Format d3dPixelFormat =
				( Usage == TextureUsage.RenderTarget ) ? _bbPixelFormat : ChooseD3DFormat();

			// set the appropriate usage based on the usage of this texture
			D3D.Usage d3dUsage =
				( Usage == TextureUsage.RenderTarget ) ? D3D.Usage.RenderTarget : 0;

			// how many mips to use?  make sure its at least one
			int numMips = ( MipmapCount > 0 ) ? MipmapCount : 1;

			if ( ( _devCaps.TextureCaps & D3D.TextureCaps.MipCubeMap ) != D3D.TextureCaps.MipCubeMap )
			{
				if ( this.CanAutoGenMipMaps( d3dUsage, D3D.ResourceType.CubeTexture, d3dPixelFormat ) )
				{
					d3dUsage |= D3D.Usage.AutoGenerateMipMap;
					numMips = 0;
				}
			}
			else
			{
				// no mip map support for this kind of texture
				MipmapCount = 0;
				numMips = 1;
			}

			// create the cube texture
			_cubeTexture = new D3D.CubeTexture(
				_device,
				SrcWidth,
				numMips,
				d3dUsage,
				d3dPixelFormat,
				( Usage == TextureUsage.RenderTarget ) ? D3D.Pool.Default : D3D.Pool.Managed );
			// store base reference to the texture
			_texture = _cubeTexture;

			// set the final texture attributes
			D3D.SurfaceDescription desc = _cubeTexture.GetLevelDescription( 0 );
			SetFinalAttributes( desc.Width, desc.Height, 1, D3DHelper.ConvertEnum( desc.Format ) );

			// store base reference to the texture
			_texture = _cubeTexture;

			if ( this.MipmapsHardwareGenerated )
				_texture.AutoMipGenerationFilter = GetBestFilterMethod();
		}
Exemple #4
0
		protected override void freeInternalResources()
		{
			if ( this._texture != null && !_texture.Disposed )
			{
				this._texture.Dispose();
				this._texture = null;
			}

			if ( this._normTexture != null && !_normTexture.Disposed )
			{
				this._normTexture.Dispose();
				this._normTexture = null;
			}

			if ( this._cubeTexture != null && !_cubeTexture.Disposed )
			{
				this._cubeTexture.Dispose();
				this._cubeTexture = null;
			}

			if ( this._volumeTexture != null && !_volumeTexture.Disposed )
			{
				this._volumeTexture.Dispose();
				this._volumeTexture = null;
			}
		}