private void CreateSurfaceList()
{
//Debug.Assert( this._texture != null, "texture must be intialized." );
XFG.Texture2D texture = null;
// Make sure number of mips is right
if ( Usage != TextureUsage.RenderTarget )
_mipmapCount = this._texture.LevelCount - 1;
// Need to know static / dynamic
BufferUsage bufusage;
if ( ( ( Usage & TextureUsage.Dynamic ) != 0 ) && this._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
bool updateOldList = ( this._surfaceList.Count == ( faceCount * ( MipmapCount + 1 ) ) );
if ( !updateOldList )
{
// Create new list of surfaces
this.ClearSurfaceList();
for ( int face = 0; face < faceCount; ++face )
{
for ( int mip = 0; mip <= MipmapCount; ++mip )
{
XnaHardwarePixelBuffer buffer = new XnaHardwarePixelBuffer( bufusage );
this._surfaceList.Add( buffer );
}
}
}
switch ( TextureType )
{
case TextureType.OneD:
case TextureType.TwoD:
Debug.Assert( this._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 )
{
this.GetSurfaceAtLevel( 0, 0 ).Bind( this._device, renderTarget, updateOldList );
}
else// For all mipmaps, store surfaces as HardwarePixelBuffer
{
for ( ushort mip = 0; mip <= MipmapCount; ++mip )
{
this.GetSurfaceAtLevel( 0, mip ).Bind( this._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 ( int face = 0; face < 6; ++face )
//{
// for ( int mip = 0; mip <= MipmapCount; ++mip )
// {
// this.GetSurfaceAtLevel( face, mip ).Bind( this._device, _cubeTexture, face, mip, updateOldList );
// }
//}
break;
case TextureType.ThreeD:
Debug.Assert( _volumeTexture != null, "texture must be intialized." );
// For all mipmaps, store surfaces as HardwarePixelBuffer
// TODO - Load Volume Textures
for ( int mip = 0; mip <= MipmapCount; ++mip )
{
this.GetSurfaceAtLevel( 0, mip ).Bind( this._device, _volumeTexture, updateOldList );
}
break;
}
// Set autogeneration of mipmaps for each face of the texture, if it is enabled
if ( ( RequestedMipmapCount != 0 ) && ( ( Usage & TextureUsage.AutoMipMap ) != 0 ) )
{
for ( int face = 0; face < faceCount; ++face )
{
this.GetSurfaceAtLevel( face, 0 ).SetMipmapping( true, MipmapsHardwareGenerated, this._texture );
}
}
}