public D3DHardwareIndexBuffer( HardwareBufferManagerBase manager, IndexType type, int numIndices, BufferUsage usage, D3D.Device device, bool useSystemMemory, bool useShadowBuffer )
			: base( manager, type, numIndices, usage, useSystemMemory, useShadowBuffer )
		{
#if !NO_AXIOM_D3D_MANAGE_BUFFERS
			d3dPool = useSystemMemory ? D3D.Pool.SystemMemory :
				// If not system mem, use managed pool UNLESS buffer is discardable
				// if discardable, keeping the software backing is expensive
					  ( ( usage & BufferUsage.Discardable ) != 0 ) ? D3D.Pool.Default : D3D.Pool.Managed;
#else
			d3dPool = useSystemMemory ? Pool.SystemMemory : Pool.Default;
#endif

		    device = D3DRenderSystem.ActiveD3D9Device; // temp hack (update to 1.7)

			// create the buffer
			d3dBuffer = new D3D.IndexBuffer(
				device,
				sizeInBytes,
				D3DHelper.ConvertEnum( usage ),
				d3dPool,
				type == IndexType.Size16 );
		}
示例#2
0
		private void DeterminePool()
		{
			if ( UseDefaultPool() )
			{
				_d3dPool = D3D.Pool.Default;
			}
			else
			{
				_d3dPool = D3D.Pool.Managed;
			}
		}
示例#3
0
		private void LoadVolumeTexture()
		{
			Debug.Assert( this.TextureType == TextureType.ThreeD );

			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.MipVolumeMap ) != D3D.TextureCaps.MipVolumeMap )
				{
					// 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
					_volumeTexture = D3D.VolumeTexture.FromStream( _device, stream, (int)stream.Length, -1, -1, -1, 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 volume texture.", ex );
				}

				// store off a base reference
				_texture = _volumeTexture;

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

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

				internalResourcesCreated = true;

				stream.Close();
			}
			else
			{

				// find & load resource data intro stream to allow resource group changes if required
				Stream strm = ResourceGroupManager.Instance.OpenResource( Name, Group, true, this );
				int pos = Name.LastIndexOf( "." );
				String 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( strm, ext );
				LoadImages( new Image[] { image } );
				image.Dispose();

				strm.Close();
			}
		}
示例#4
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() );
			}
		}
示例#5
0
		protected override void createInternalResources()
		{
			// If SrcWidth and SrcHeight are zero, the requested extents have probably been set
			// through Width and Height. Take those values.
			if ( SrcWidth == 0 || SrcHeight == 0 )
			{
				SrcWidth = Width;
				SrcHeight = Height;
			}

			// Determine D3D pool to use
			// Use managed unless we're a render target or user has asked for a dynamic texture
			if ( ( Usage & TextureUsage.RenderTarget ) != 0 ||
				( Usage & TextureUsage.Dynamic ) != 0 )
			{
				this._d3dPool = D3D.Pool.Default;
			}
			else
			{
				this._d3dPool = D3D.Pool.Managed;
			}

			switch ( this.TextureType )
			{
				case TextureType.OneD:
				case TextureType.TwoD:
					this.CreateNormalTexture();
					break;
				case TextureType.CubeMap:
					this.CreateCubeTexture();
					break;
				case TextureType.ThreeD:
					this.CreateVolumeTexture();
					break;
				default:
					FreeInternalResources();
					throw new Exception( "Unknown texture type!" );
			}
		}
示例#6
0
		protected override void load()
		{
			// create a render texture if need be
			if ( ( Usage & TextureUsage.RenderTarget ) == TextureUsage.RenderTarget )
			{
				CreateInternalResources();
				return;
			}

			if ( !internalResourcesCreated )
			{
				// NB: Need to initialise pool to some value other than D3DPOOL_DEFAULT,
				// otherwise, if the texture loading failed, it might re-create as empty
				// texture when device lost/restore. The actual pool will be determined later.
				this._d3dPool = D3D.Pool.Managed;
			}

			// create a regular texture
			switch ( this.TextureType )
			{
				case TextureType.OneD:
				case TextureType.TwoD:
					this.LoadNormalTexture();
					break;

				case TextureType.ThreeD:
					this.LoadVolumeTexture();
					break;

				case TextureType.CubeMap:
					this.LoadCubeTexture();
					break;

				default:
					throw new Exception( "Unsupported texture type." );
			}
		}