Пример #1
0
        protected override void freeInternalResources()
        {
            if (_texture != null)
            {
                _texture.Dispose();
                _texture = null;
            }

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

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

#if !SILVERLIGHT
            if (_volumeTexture != null)
            {
                _volumeTexture.Dispose();
                _volumeTexture = null;
            }
#endif
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        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
            var xnaPixelFormat =
                (Usage == TextureUsage.RenderTarget) ? _bbPixelFormat : (ChooseXnaFormat());

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

            //see comment in CreateNormalTexture() -DoubleA

            //MipmapsHardwareGenerated = false;
            //if ( _devCaps.TextureCapabilities.SupportsMipCubeMap )
            //{
            //    MipmapsHardwareGenerated = true /*this.CanAutoGenMipMaps( xnaUsage, XFG.ResourceType.TextureCube, xnaPixelFormat ) */;
            //    if ( MipmapsHardwareGenerated )
            //    {
            //        numMips = 0;
            //    }
            //}
            //else
            //{
            //    // no mip map support for this kind of texture
            //    MipmapCount = 0;
            //    numMips = 1;
            //}

            if (Usage == TextureUsage.RenderTarget)
            {
                renderTarget =
                    (Microsoft.Xna.Framework.Graphics.Texture)
                        (new RenderTargetCube(_device, SrcWidth, mipmapCount > 0 ? true : false, xnaPixelFormat,
                                              DepthFormat.Depth24Stencil8)) as RenderTarget2D;
                _cubeTexture = ((Microsoft.Xna.Framework.Graphics.Texture)renderTarget) as RenderTargetCube;

                CreateDepthStencil();
            }
            else
            {
                // create the cube texture
                _cubeTexture = new TextureCube(_device, SrcWidth, (mipmapCount > 0) ? true : false, xnaPixelFormat);
                // store base reference to the texture
            }

            _texture = _cubeTexture;

            SetFinalAttributes(SrcWidth, SrcHeight, 1, XnaHelper.Convert(xnaPixelFormat));

            if (MipmapsHardwareGenerated)
            {
                //Generating mip maps API is no longer exposed. RenderTargets will auto-generate their mipmaps
                //but for other textures you're S.O.L. -DoubleA. See Shawn Hargreaves response to this thread: http://forums.create.msdn.com/forums/p/71559/436835.aspx
                //_texture.GenerateMipMaps( GetBestFilterMethod() );
            }
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        private void LoadVolumeTexture()
        {
#if SILVERLIGHT
            throw new NotSupportedException("TextureType.ThreeD is not supported in Silverlight 5.");
#else
            Debug.Assert(TextureType == TextureType.ThreeD);
            if (Root.Instance.RenderSystem.ConfigOptions["Use Content Pipeline"].Value == "Yes")
            {
                var acm = new AxiomContentManager((XnaRenderSystem)Root.Instance.RenderSystem, "");
                _volumeTexture           = acm.Load <Texture3D>(Name);
                _texture                 = _volumeTexture;
                internalResourcesCreated = true;
            }
#endif
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        private void LoadCubeTexture()
        {
            Debug.Assert(TextureType == TextureType.CubeMap, "this.TextureType == TextureType.CubeMap");

            if (Root.Instance.RenderSystem.ConfigOptions["Use Content Pipeline"].Value == "Yes")
            {
                var acm = new AxiomContentManager((XnaRenderSystem)Root.Instance.RenderSystem, "");
                _cubeTexture             = acm.Load <TextureCube>(Name);
                _texture                 = _cubeTexture;
                internalResourcesCreated = true;
            }
#if !(XBOX || XBOX360)
            else
            {
                /* Use internal .dds loader instead */
                //if ( Name.EndsWith( ".dds" ) )
                //{
                //    Stream stream = ResourceGroupManager.Instance.OpenResource( Name );
                //    _cubeTexture = XFG.TextureCube.FromFile( _device, stream );
                //    stream.Close();
                //}
                //else
                {
                    ConstructCubeFaceNames(Name);
                    // Load from 6 separate files
                    // Use Axiom codecs
                    var images = new List <Image>();

                    var pos = Name.LastIndexOf(".");
                    var ext = Name.Substring(pos + 1);

                    for (var i = 0; i < 6; i++)
                    {
                        var strm  = ResourceGroupManager.Instance.OpenResource(cubeFaceNames[i], Group, true, this);
                        var image = Image.FromStream(strm, ext);
                        images.Add(image);
                        strm.Close();
                    }

                    LoadImages(images.ToArray());
                }
                _texture = _cubeTexture;
                internalResourcesCreated = true;
            }
#endif
        }
Пример #5
0
        private void CreateNormalTexture()
        {
            Debug.Assert(SrcWidth > 0 && SrcHeight > 0);

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


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

            //bloody 'ell, it's great that Xa 4.0 checks capabilities for the programmer, but it's incredibly annoying
            //that it doesn't tell the programer anything about them. Anyway, there's no way for us to know if MipMaps are supported,
            //but in the c'tor of the Texture is a paramater bool mipMap, which, if set to true and mipMaps aren't supported, Xna will take care of it
            //-DoubleA

            //MipmapsHardwareGenerated = false;
            //if ( _devCaps.TextureCapabilities.SupportsMipMap )
            //{
            //    MipmapsHardwareGenerated = CanAutoGenMipMaps( xnaUsage, XFG.ResourceType.Texture2D, xnaPixelFormat );
            //    if ( MipmapsHardwareGenerated )
            //    {
            //        numMips = 0;
            //    }
            //}
            //else
            //{
            //    // no mip map support for this kind of texture
            //    this.MipmapCount = 0;
            //    numMips = 1;
            //}

            if (Usage == TextureUsage.RenderTarget)
            {
                renderTarget = new RenderTarget2D(_device, SrcWidth, SrcHeight, MipmapCount > 0,
                                                  xnaPixelFormat, DepthFormat.Depth24Stencil8);
                _normTexture = renderTarget;
                CreateDepthStencil();
            }
            else
            {
#if SILVERLIGHT
                if (!IsPowerOfTwo)
                {
                    MipmapCount = 0;
                }
#endif
                _normTexture = new Texture2D(_device, SrcWidth, SrcHeight, MipmapCount > 0, xnaPixelFormat);
            }
            _texture = _normTexture;

            SetFinalAttributes(SrcWidth, SrcHeight, 1, XnaHelper.Convert(xnaPixelFormat));

            if (MipmapsHardwareGenerated)
            {
                //Generating mip maps API is no longer exposed. RenderTargets will auto-generate their mipmaps
                //but for other textures you're S.O.L. -DoubleA. See Shawn Hargreaves response to this thread: http://forums.create.msdn.com/forums/p/71559/436835.aspx
                //_texture.GenerateMipMaps( GetBestFilterMethod() );
            }
        }
Пример #6
0
        private void LoadNormalTexture()
        {
            Debug.Assert(TextureType == TextureType.OneD || TextureType == TextureType.TwoD);

            if (Root.Instance.RenderSystem.ConfigOptions["Use Content Pipeline"].Value == "Yes")
            {
                var acm = new AxiomContentManager((XnaRenderSystem)Root.Instance.RenderSystem, "Content");
                _normTexture             = acm.Load <Texture2D>(Name);
                _texture                 = _normTexture;
                Width                    = _normTexture.Width;
                Height                   = _normTexture.Height;
                internalResourcesCreated = true;
            }
#if !(XBOX || XBOX360)
            else
            {
                Stream stream;
                if (Name.EndsWith(".dds"))
                {
                    stream = ResourceGroupManager.Instance.OpenResource(Name);

                    // use Xna to load the image directly from the stream
                    //XFG.TextureCreationParameters tcp = new XFG.TextureCreationParameters();
                    //tcp.Filter = Microsoft.Xna.Framework.Graphics.FilterOptions.Triangle;
                    //tcp.MipLevels = MipmapCount;

                    //Not sure how to set MipLevels. _normTexture.LevelCount is get-only...
#if SILVERLIGHT
                    var im = new BitmapImage();
                    im.SetSource(stream);
                    _normTexture = new Texture2D(_device, im.PixelWidth, im.PixelHeight, false, SurfaceFormat.Color);
                    im.CopyTo(_normTexture);
#else
                    _normTexture = Texture2D.FromStream(_device, stream);                       //.FromFile( _device, stream, tcp );
#endif

                    // store a ref for the base texture interface
                    _texture = _normTexture;

                    //reset stream position to read Texture information
                    ////stream.Position = 0;

                    // set the image data attributes

                    //Not sure if these lines accomplish the same thing as the below commented-out ones.
                    SetSrcAttributes(_normTexture.Width, _normTexture.Height, 1,
                                     XnaHelper.Convert(_normTexture.Format));
                    SetFinalAttributes(_normTexture.Width, _normTexture.Height, 1,
                                       XnaHelper.Convert(_normTexture.Format));

                    //XFG.TextureInformation info = XFG.Texture2D.GetTextureInformation( stream );
                    //SetSrcAttributes( info.Width, info.Height, 1, XnaHelper.Convert( info.Format ) );
                    //SetFinalAttributes( info.Width, info.Height, 1, XnaHelper.Convert( info.Format ) );

                    internalResourcesCreated = true;
                }
                else
                {
                    // find & load resource data intro stream to allow resource group changes if required
                    stream = ResourceGroupManager.Instance.OpenResource(Name, Group, true, this);
//#if SILVERLIGHT
//                    if (stream == null)
//                    {
//                        Name += ".png";
//                        stream = ResourceGroupManager.Instance.OpenResource( Name, Group, true, this );
//                    }
//#endif
                    var pos = Name.LastIndexOf(".");
                    var ext = Name.Substring(pos + 1);

                    // Call internal LoadImages, not LoadImage since that's external and
                    // will determine load status etc again
                    var image = Image.FromStream(stream, ext);
                    LoadImages(new[]
                    {
                        image
                    });
                    image.Dispose();
                }

                if (stream != null)
                {
                    stream.Close();
                }
            }
#endif
        }
Пример #7
0
		private void CreateNormalTexture()
		{
			Debug.Assert( SrcWidth > 0 && SrcHeight > 0 );

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


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

			//bloody 'ell, it's great that Xa 4.0 checks capabilities for the programmer, but it's incredibly annoying
			//that it doesn't tell the programer anything about them. Anyway, there's no way for us to know if MipMaps are supported,
			//but in the c'tor of the Texture is a paramater bool mipMap, which, if set to true and mipMaps aren't supported, Xna will take care of it
			//-DoubleA

			//MipmapsHardwareGenerated = false;
			//if ( _devCaps.TextureCapabilities.SupportsMipMap )
			//{
			//    MipmapsHardwareGenerated = CanAutoGenMipMaps( xnaUsage, XFG.ResourceType.Texture2D, xnaPixelFormat );
			//    if ( MipmapsHardwareGenerated )
			//    {
			//        numMips = 0;
			//    }
			//}
			//else
			//{
			//    // no mip map support for this kind of texture
			//    this.MipmapCount = 0;
			//    numMips = 1;
			//}

			if ( Usage == TextureUsage.RenderTarget )
			{
				renderTarget = new RenderTarget2D( _device, SrcWidth, SrcHeight, MipmapCount > 0,
												   xnaPixelFormat, DepthFormat.Depth24Stencil8 );
				_normTexture = renderTarget;
				CreateDepthStencil();
			}
			else
			{
#if SILVERLIGHT
				if (!IsPowerOfTwo)
					MipmapCount = 0;
#endif
				_normTexture = new Texture2D(_device, SrcWidth, SrcHeight, MipmapCount > 0, xnaPixelFormat);
			}
			_texture = _normTexture;

			SetFinalAttributes( SrcWidth, SrcHeight, 1, XnaHelper.Convert( xnaPixelFormat ) );

			if ( MipmapsHardwareGenerated )
			{
				//Generating mip maps API is no longer exposed. RenderTargets will auto-generate their mipmaps
				//but for other textures you're S.O.L. -DoubleA. See Shawn Hargreaves response to this thread: http://forums.create.msdn.com/forums/p/71559/436835.aspx
				//_texture.GenerateMipMaps( GetBestFilterMethod() );
			}
		}
Пример #8
0
		/// <summary>
		///
		/// </summary>
		private void LoadVolumeTexture()
		{
#if SILVERLIGHT
			throw new NotSupportedException("TextureType.ThreeD is not supported in Silverlight 5.");
#else
			Debug.Assert( TextureType == TextureType.ThreeD );
			if ( Root.Instance.RenderSystem.ConfigOptions[ "Use Content Pipeline" ].Value == "Yes" )
			{
				var acm = new AxiomContentManager( (XnaRenderSystem)Root.Instance.RenderSystem, "" );
				_volumeTexture = acm.Load<Texture3D>( Name );
				_texture = _volumeTexture;
				internalResourcesCreated = true;
			}
#endif
		}
Пример #9
0
		/// <summary>
		///
		/// </summary>
		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
			var xnaPixelFormat =
				( Usage == TextureUsage.RenderTarget ) ? _bbPixelFormat : ( ChooseXnaFormat() );

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

			//see comment in CreateNormalTexture() -DoubleA

			//MipmapsHardwareGenerated = false;
			//if ( _devCaps.TextureCapabilities.SupportsMipCubeMap )
			//{
			//    MipmapsHardwareGenerated = true /*this.CanAutoGenMipMaps( xnaUsage, XFG.ResourceType.TextureCube, xnaPixelFormat ) */;
			//    if ( MipmapsHardwareGenerated )
			//    {
			//        numMips = 0;
			//    }
			//}
			//else
			//{
			//    // no mip map support for this kind of texture
			//    MipmapCount = 0;
			//    numMips = 1;
			//}

			if ( Usage == TextureUsage.RenderTarget )
			{
				renderTarget =
					(Microsoft.Xna.Framework.Graphics.Texture)
					( new RenderTargetCube( _device, SrcWidth, mipmapCount > 0 ? true : false, xnaPixelFormat,
											DepthFormat.Depth24Stencil8 ) ) as RenderTarget2D;
				_cubeTexture = ( (Microsoft.Xna.Framework.Graphics.Texture)renderTarget ) as RenderTargetCube;

				CreateDepthStencil();
			}
			else
			{
				// create the cube texture
				_cubeTexture = new TextureCube( _device, SrcWidth, ( mipmapCount > 0 ) ? true : false, xnaPixelFormat );
				// store base reference to the texture
			}

			_texture = _cubeTexture;

			SetFinalAttributes( SrcWidth, SrcHeight, 1, XnaHelper.Convert( xnaPixelFormat ) );

			if ( MipmapsHardwareGenerated )
			{
				//Generating mip maps API is no longer exposed. RenderTargets will auto-generate their mipmaps
				//but for other textures you're S.O.L. -DoubleA. See Shawn Hargreaves response to this thread: http://forums.create.msdn.com/forums/p/71559/436835.aspx
				//_texture.GenerateMipMaps( GetBestFilterMethod() );
			}
		}
Пример #10
0
		/// <summary>
		///
		/// </summary>
		private void LoadCubeTexture()
		{
			Debug.Assert( TextureType == TextureType.CubeMap, "this.TextureType == TextureType.CubeMap" );

			if ( Root.Instance.RenderSystem.ConfigOptions[ "Use Content Pipeline" ].Value == "Yes" )
			{
				var acm = new AxiomContentManager( (XnaRenderSystem)Root.Instance.RenderSystem, "" );
				_cubeTexture = acm.Load<TextureCube>( Name );
				_texture = _cubeTexture;
				internalResourcesCreated = true;
			}
#if !( XBOX || XBOX360 )
			else
			{
				/* Use internal .dds loader instead */
				//if ( Name.EndsWith( ".dds" ) )
				//{
				//    Stream stream = ResourceGroupManager.Instance.OpenResource( Name );
				//    _cubeTexture = XFG.TextureCube.FromFile( _device, stream );
				//    stream.Close();
				//}
				//else
				{
					ConstructCubeFaceNames( Name );
					// Load from 6 separate files
					// Use Axiom codecs
					var images = new List<Image>();

					var pos = Name.LastIndexOf( "." );
					var ext = Name.Substring( pos + 1 );

					for ( var i = 0; i < 6; i++ )
					{
						var strm = ResourceGroupManager.Instance.OpenResource( cubeFaceNames[ i ], Group, true, this );
						var image = Image.FromStream( strm, ext );
						images.Add( image );
						strm.Close();
					}

					LoadImages( images.ToArray() );
				}
				_texture = _cubeTexture;
				internalResourcesCreated = true;
			}
#endif
		}
Пример #11
0
		private void LoadNormalTexture()
		{
			Debug.Assert( TextureType == TextureType.OneD || TextureType == TextureType.TwoD );

			if ( Root.Instance.RenderSystem.ConfigOptions[ "Use Content Pipeline" ].Value == "Yes" )
			{
				var acm = new AxiomContentManager( (XnaRenderSystem)Root.Instance.RenderSystem, "Content" );
				_normTexture = acm.Load<Texture2D>( Name );
				_texture = _normTexture;
				Width = _normTexture.Width;
				Height = _normTexture.Height;
				internalResourcesCreated = true;
			}
#if !( XBOX || XBOX360 )
			else
			{
				Stream stream;
				if ( Name.EndsWith( ".dds" ) )
				{
					stream = ResourceGroupManager.Instance.OpenResource( Name );

					// use Xna to load the image directly from the stream
					//XFG.TextureCreationParameters tcp = new XFG.TextureCreationParameters();
					//tcp.Filter = Microsoft.Xna.Framework.Graphics.FilterOptions.Triangle;
					//tcp.MipLevels = MipmapCount;

					//Not sure how to set MipLevels. _normTexture.LevelCount is get-only...
#if SILVERLIGHT
					var im = new BitmapImage();
					im.SetSource(stream);
					_normTexture = new Texture2D(_device, im.PixelWidth, im.PixelHeight, false, SurfaceFormat.Color);
					im.CopyTo(_normTexture);
#else
					_normTexture = Texture2D.FromStream( _device, stream ); //.FromFile( _device, stream, tcp );
#endif

					// store a ref for the base texture interface
					_texture = _normTexture;

					//reset stream position to read Texture information
					////stream.Position = 0;

					// set the image data attributes

					//Not sure if these lines accomplish the same thing as the below commented-out ones.
					SetSrcAttributes( _normTexture.Width, _normTexture.Height, 1,
									  XnaHelper.Convert( _normTexture.Format ) );
					SetFinalAttributes( _normTexture.Width, _normTexture.Height, 1,
										XnaHelper.Convert( _normTexture.Format ) );

					//XFG.TextureInformation info = XFG.Texture2D.GetTextureInformation( stream );
					//SetSrcAttributes( info.Width, info.Height, 1, XnaHelper.Convert( info.Format ) );
					//SetFinalAttributes( info.Width, info.Height, 1, XnaHelper.Convert( info.Format ) );

					internalResourcesCreated = true;
				}
				else
				{
					// find & load resource data intro stream to allow resource group changes if required
					stream = ResourceGroupManager.Instance.OpenResource( Name, Group, true, this );
//#if SILVERLIGHT
//                    if (stream == null)
//                    {
//                        Name += ".png";
//                        stream = ResourceGroupManager.Instance.OpenResource( Name, Group, true, this );
//                    }
//#endif
					var pos = Name.LastIndexOf( "." );
					var ext = Name.Substring( pos + 1 );

					// Call internal LoadImages, not LoadImage since that's external and
					// will determine load status etc again
					var image = Image.FromStream( stream, ext );
					LoadImages( new[]
								{
									image
								} );
					image.Dispose();
				}

				if (stream != null)
					stream.Close();
			}
#endif
		}
Пример #12
0
		protected override void freeInternalResources()
		{
			if ( _texture != null )
			{
				_texture.Dispose();
				_texture = null;
			}

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

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

#if !SILVERLIGHT
			if ( _volumeTexture != null )
			{
				_volumeTexture.Dispose();
				_volumeTexture = null;
			}
#endif
		}
Пример #13
0
		/// <summary>
		///
		/// </summary>
		private void LoadVolumeTexture()
		{
			Debug.Assert( this.TextureType == TextureType.ThreeD );
			if ( Root.Instance.RenderSystem.ConfigOptions[ "Use Content Pipeline" ].Value == "Yes" )
			{
				AxiomContentManager acm = new AxiomContentManager( (XnaRenderSystem)Root.Instance.RenderSystem, "" );
				_volumeTexture = acm.Load<XFG.Texture3D>( Name );
				_texture = _volumeTexture;
				internalResourcesCreated = true;
			}
#if !( XBOX || XBOX360 )
			//TODO: XNA40 removed Texture3D.FromFile

			//else
			//{
			//    Stream stream = ResourceGroupManager.Instance.OpenResource( Name );
			//    // load the cube texture from the image data stream directly
			//    _volumeTexture = XFG.Texture3D.FromFile( _device, stream );
                
			//    // store off a base reference
			//    _texture = _volumeTexture;

			//    // set src and dest attributes to the same, we can't know
			//    stream.Position = 0;
			//    SetSrcAttributes(_volumeTexture.Width, _volumeTexture.Height, _volumeTexture.Depth, XnaHelper.Convert(_volumeTexture.Format));
			//    SetFinalAttributes(_volumeTexture.Width, _volumeTexture.Height, _volumeTexture.Depth, XnaHelper.Convert(_volumeTexture.Format));
			//    stream.Close();
			//    internalResourcesCreated = true;
			//}
#endif
		}
Пример #14
0
		protected override void freeInternalResources()
		{
			if ( this._texture != null )
			{
				this._texture.Dispose();
				this._texture = null;
			}

			if ( this._normTexture != null )
			{
				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;
			}
		}