Xna implementation of HardwarePixelBuffer
Inheritance: Axiom.Graphics.HardwarePixelBuffer
Exemple #1
0
 public void Rebind(XnaHardwarePixelBuffer buffer)
 {
     pixelBuffer = buffer;
     width       = pixelBuffer.Width;
     height      = pixelBuffer.Height;
     colorDepth  = PixelUtil.GetNumElemBits(buffer.Format);
 }
Exemple #2
0
		public void Rebind( XnaHardwarePixelBuffer buffer )
		{
			pixelBuffer = buffer;
			Width = pixelBuffer.Width;
			Height = pixelBuffer.Height;
			ColorDepth = PixelUtil.GetNumElemBits( buffer.Format );
		}
Exemple #3
0
        private void CreateSurfaceList()
        {
            //Debug.Assert( this._texture != null, "texture must be intialized." );
            Texture2D texture = null;

            // Make sure number of mips is right
            if (Usage != TextureUsage.RenderTarget)
            {
                mipmapCount = _texture.LevelCount - 1;
            }
            //#if SILVERLIGHT
            if (mipmapCount < 0)
            {
                mipmapCount = 0;
            }
            //#endif

            // Need to know static / dynamic
            BufferUsage bufusage;

            if (((Usage & TextureUsage.Dynamic) != 0) && _dynamicTextures)
            {
                bufusage = BufferUsage.Dynamic;
            }
            else
            {
                bufusage = BufferUsage.Static;
            }

            if ((Usage & TextureUsage.RenderTarget) != 0)
            {
                bufusage = (BufferUsage)((int)bufusage | (int)TextureUsage.RenderTarget);
            }

            // If we already have the right number of surfaces, just update the old list
            var updateOldList = (_surfaceList.Count == (FaceCount * (MipmapCount + 1)));

            if (!updateOldList)
            {
                // Create new list of surfaces
                ClearSurfaceList();
                for (var face = 0; face < FaceCount; ++face)
                {
                    for (var mip = 0; mip <= MipmapCount; ++mip)
                    {
                        var buffer = new XnaHardwarePixelBuffer(bufusage);
                        _surfaceList.Add(buffer);
                    }
                }
            }

            switch (TextureType)
            {
            case TextureType.OneD:
            case TextureType.TwoD:
                Debug.Assert(_normTexture != null, "texture must be intialized.");

                // instead of passing a new texture2d to the hardware pixel buffer that wont have any reference to this normalTexture,
                // we pass the normTexture and bind each mip level
                // not sure but seems to work, each hardwarePixelBuffer will have the same reference to this same texture,
                // but with different mips level, that will be updated with SetData(miplevel,ect...)

                // This is required because .GetData<byte>( level ... ) copies the data from the buffer whereas in DX GetSurfaceLevel
                // creates a new Surface object that references the same data.
                // - borrillis

                if (Usage == TextureUsage.RenderTarget)
                {
                    GetSurfaceAtLevel(0, 0).Bind(_device, renderTarget, updateOldList);
                }
                else                         // For all mipmaps, store surfaces as HardwarePixelBuffer
                {
                    for (ushort mip = 0; mip <= MipmapCount; ++mip)
                    {
                        GetSurfaceAtLevel(0, mip).Bind(_device, _normTexture, mip, updateOldList);
                    }
                }
                break;

            case TextureType.CubeMap:
                Debug.Assert(_cubeTexture != null, "texture must be initialized.");

                // For all faces and mipmaps, store surfaces as HardwarePixelBuffer
                for (ushort face = 0; face < 6; ++face)
                {
                    for (ushort mip = 0; mip <= MipmapCount; ++mip)
                    {
                        GetSurfaceAtLevel(face, mip).Bind(_device, _cubeTexture, face, mip, updateOldList);
                    }
                }

                break;

            case TextureType.ThreeD:
#if !SILVERLIGHT
                Debug.Assert(_volumeTexture != null, "texture must be intialized.");

                // For all mipmaps, store surfaces as HardwarePixelBuffer
                // TODO - Load Volume Textures

                for (var mip = 0; mip <= MipmapCount; ++mip)
                {
                    GetSurfaceAtLevel(0, mip).Bind(_device, _volumeTexture, updateOldList);
                }
#else
                throw new NotSupportedException("TextureType.ThreeD is not supported in Silverlight 5.");
#endif
                break;
            }

            // Set autogeneration of mipmaps for each face of the texture, if it is enabled
            if ((requestedMipmapCount != 0) && ((Usage & TextureUsage.AutoMipMap) != 0))
            {
                for (var face = 0; face < FaceCount; ++face)
                {
                    GetSurfaceAtLevel(face, 0).SetMipmapping(true, MipmapsHardwareGenerated, _texture);
                }
            }
        }
Exemple #4
0
		private void CreateSurfaceList()
		{
			//Debug.Assert( this._texture != null, "texture must be intialized." );
			Texture2D texture = null;

			// Make sure number of mips is right
			if ( Usage != TextureUsage.RenderTarget )
			{
				mipmapCount = _texture.LevelCount - 1;
			}
			//#if SILVERLIGHT
			if (mipmapCount < 0) mipmapCount = 0;
			//#endif

			// Need to know static / dynamic
			BufferUsage bufusage;
			if ( ( ( Usage & TextureUsage.Dynamic ) != 0 ) && _dynamicTextures )
			{
				bufusage = BufferUsage.Dynamic;
			}
			else
			{
				bufusage = BufferUsage.Static;
			}

			if ( ( Usage & TextureUsage.RenderTarget ) != 0 )
			{
				bufusage = (BufferUsage)( (int)bufusage | (int)TextureUsage.RenderTarget );
			}

			// If we already have the right number of surfaces, just update the old list
			var updateOldList = ( _surfaceList.Count == ( FaceCount * ( MipmapCount + 1 ) ) );
			if ( !updateOldList )
			{
				// Create new list of surfaces
				ClearSurfaceList();
				for ( var face = 0; face < FaceCount; ++face )
				{
					for ( var mip = 0; mip <= MipmapCount; ++mip )
					{
						var buffer = new XnaHardwarePixelBuffer( bufusage );
						_surfaceList.Add( buffer );
					}
				}
			}

			switch ( TextureType )
			{
				case TextureType.OneD:
				case TextureType.TwoD:
					Debug.Assert( _normTexture != null, "texture must be intialized." );

					// instead of passing a new texture2d to the hardware pixel buffer that wont have any reference to this normalTexture,
					// we pass the normTexture and bind each mip level
					// not sure but seems to work, each hardwarePixelBuffer will have the same reference to this same texture,
					// but with different mips level, that will be updated with SetData(miplevel,ect...)

					// This is required because .GetData<byte>( level ... ) copies the data from the buffer whereas in DX GetSurfaceLevel
					// creates a new Surface object that references the same data.
					// - borrillis

					if ( Usage == TextureUsage.RenderTarget )
					{
						GetSurfaceAtLevel( 0, 0 ).Bind( _device, renderTarget, updateOldList );
					}
					else // For all mipmaps, store surfaces as HardwarePixelBuffer
					{
						for ( ushort mip = 0; mip <= MipmapCount; ++mip )
						{
							GetSurfaceAtLevel( 0, mip ).Bind( _device, _normTexture, mip, updateOldList );
						}
					}
					break;

				case TextureType.CubeMap:
					Debug.Assert( _cubeTexture != null, "texture must be initialized." );

					// For all faces and mipmaps, store surfaces as HardwarePixelBuffer
					for ( ushort face = 0; face < 6; ++face )
					{
						for ( ushort mip = 0; mip <= MipmapCount; ++mip )
						{
							GetSurfaceAtLevel( face, mip ).Bind( _device, _cubeTexture, face, mip, updateOldList );
						}
					}

					break;

				case TextureType.ThreeD:
#if !SILVERLIGHT
					Debug.Assert( _volumeTexture != null, "texture must be intialized." );

					// For all mipmaps, store surfaces as HardwarePixelBuffer
					// TODO - Load Volume Textures

					for ( var mip = 0; mip <= MipmapCount; ++mip )
					{
						GetSurfaceAtLevel( 0, mip ).Bind( _device, _volumeTexture, updateOldList );
					}
#else
					throw new NotSupportedException("TextureType.ThreeD is not supported in Silverlight 5.");
#endif
					break;
			}

			// Set autogeneration of mipmaps for each face of the texture, if it is enabled
			if ( ( requestedMipmapCount != 0 ) && ( ( Usage & TextureUsage.AutoMipMap ) != 0 ) )
			{
				for ( var face = 0; face < FaceCount; ++face )
				{
					GetSurfaceAtLevel( face, 0 ).SetMipmapping( true, MipmapsHardwareGenerated, _texture );
				}
			}
		}