/// <summary>
		///		Default constructor.
		/// </summary>
		/// <param name="device">Reference to a Direct3D device.</param>
		public D3DHardwareOcclusionQuery( D3D.Device device )
		{
			this.device = device;

			isQueryResultStillOutstanding = true;

			// check if queries are supported
			isSupported = Root.Instance.RenderSystem.Capabilities.HasCapability( Capabilities.HardwareOcculusion );

			if ( isSupported )
			{
				// attempt to create an occlusion query
				query = new D3D.Query( device, D3D.QueryType.Occlusion );
			}
		}
Esempio n. 2
0
		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 );
		}
Esempio n. 3
0
		public static int ConvertEnum( TexCoordCalcMethod method, D3D.Capabilities caps )
		{
			switch ( method )
			{
				case TexCoordCalcMethod.None:
					return (int)D3D.TextureCoordIndex.PassThru;

				case TexCoordCalcMethod.EnvironmentMapReflection:
					return (int)D3D.TextureCoordIndex.CameraSpaceReflectionVector;

				case TexCoordCalcMethod.EnvironmentMapPlanar:
					//return (int)D3D.TextureCoordinateIndex.CameraSpacePosition;
					if ( ( caps.VertexProcessingCaps & D3D.VertexProcessingCaps.TexGenSphereMap ) == D3D.VertexProcessingCaps.TexGenSphereMap )
					{
						// use sphere map if available
						return (int)D3D.TextureCoordIndex.SphereMap;
					}
					else
					{
						// If not, fall back on camera space reflection vector which isn't as good
						return (int)D3D.TextureCoordIndex.CameraSpaceReflectionVector;
					}

				case TexCoordCalcMethod.EnvironmentMapNormal:
					return (int)D3D.TextureCoordIndex.CameraSpaceNormal;

				case TexCoordCalcMethod.EnvironmentMap:
					if ( ( caps.VertexProcessingCaps & D3D.VertexProcessingCaps.TexGenSphereMap ) == D3D.VertexProcessingCaps.TexGenSphereMap )
					{
						return (int)D3D.TextureCoordIndex.SphereMap;
					}
					else
					{
						// fall back on camera space normal if sphere map isnt supported
						return (int)D3D.TextureCoordIndex.CameraSpaceNormal;
					}

				case TexCoordCalcMethod.ProjectiveTexture:
					return (int)D3D.TextureCoordIndex.CameraSpacePosition;
			} // switch

			return 0;
		}
Esempio n. 4
0
		/// <summary>
		///
		/// </summary>
		/// <param name="type"></param>
		/// <param name="options"></param>
		/// <param name="caps"></param>
		/// <param name="texType"></param>
		/// <returns></returns>
		public static D3D.TextureFilter ConvertEnum( FilterType type, FilterOptions options, D3D.Capabilities devCaps, D3DTextureType texType )
		{
			// setting a default val here to keep compiler from complaining about using unassigned value types
			D3D.FilterCaps filterCaps = devCaps.TextureFilterCaps;

			switch ( texType )
			{
				case D3DTextureType.Normal:
					filterCaps = devCaps.TextureFilterCaps;
					break;
				case D3DTextureType.Cube:
					filterCaps = devCaps.CubeTextureFilterCaps;
					break;
				case D3DTextureType.Volume:
					filterCaps = devCaps.VolumeTextureFilterCaps;
					break;
			}

			switch ( type )
			{
				case FilterType.Min:
					{
						switch ( options )
						{
							case FilterOptions.Anisotropic:
								if ( ( filterCaps & D3D.FilterCaps.MinAnisotropic ) == D3D.FilterCaps.MinAnisotropic )
								{
									return D3D.TextureFilter.Anisotropic;
								}
								else
								{
									return D3D.TextureFilter.Linear;
								}

							case FilterOptions.Linear:
								if ( ( filterCaps & D3D.FilterCaps.MinLinear ) == D3D.FilterCaps.MinLinear )
								{
									return D3D.TextureFilter.Linear;
								}
								else
								{
									return D3D.TextureFilter.Point;
								}

							case FilterOptions.Point:
							case FilterOptions.None:
								return D3D.TextureFilter.Point;
						}
						break;
					}
				case FilterType.Mag:
					{
						switch ( options )
						{
							case FilterOptions.Anisotropic:
								if ( ( filterCaps & D3D.FilterCaps.MagAnisotropic ) == D3D.FilterCaps.MagAnisotropic )
								{
									return D3D.TextureFilter.Anisotropic;
								}
								else
								{
									return D3D.TextureFilter.Linear;
								}

							case FilterOptions.Linear:
								if ( ( filterCaps & D3D.FilterCaps.MagLinear ) == D3D.FilterCaps.MagLinear )
								{
									return D3D.TextureFilter.Linear;
								}
								else
								{
									return D3D.TextureFilter.Point;
								}

							case FilterOptions.Point:
							case FilterOptions.None:
								return D3D.TextureFilter.Point;
						}
						break;
					}
				case FilterType.Mip:
					{
						switch ( options )
						{
							case FilterOptions.Anisotropic:
							case FilterOptions.Linear:
								if ( ( filterCaps & D3D.FilterCaps.MipLinear ) == D3D.FilterCaps.MipLinear )
								{
									return D3D.TextureFilter.Linear;
								}
								else
								{
									return D3D.TextureFilter.Point;
								}

							case FilterOptions.Point:
								if ( ( filterCaps & D3D.FilterCaps.MipPoint ) == D3D.FilterCaps.MipPoint )
								{
									return D3D.TextureFilter.Point;
								}
								else
								{
									return D3D.TextureFilter.None;
								}

							case FilterOptions.None:
								return D3D.TextureFilter.None;
						}
						break;
					}
			}

			// should never get here
			return 0;
		}
Esempio n. 5
0
		protected D3DGpuProgram( ResourceManager parent, string name, ResourceHandle handle, string group, bool isManual, IManualResourceLoader loader, D3D.Device device )
			: base( parent, name, handle, group, isManual, loader )
		{
			this.device = device;
		}
Esempio n. 6
0
		protected override void LoadFromMicrocode( D3D.ShaderBytecode microcode )
		{
			// create a new pixel shader
            device = D3DRenderSystem.ActiveD3D9Device;
			pixelShader = new D3D.PixelShader( device, microcode );
		}
Esempio n. 7
0
		//---------------------------------------------------------------------
		public bool RecreateIfDefaultPool( D3D.Device device )
		{
			if ( d3dPool == D3D.Pool.Default )
			{
				// Create the Index buffer
				d3dBuffer = new D3D.IndexBuffer(
					device,
					sizeInBytes,
					D3DHelper.ConvertEnum( usage ),
					d3dPool,
					type == IndexType.Size16 );

				return true;
			}
			return false;
		}
Esempio n. 8
0
		///<summary>
		///    Function to set mipmap generation
		///</summary>
		public void SetMipmapping( bool doMipmapGen, bool HWMipmaps, D3D.BaseTexture mipTex )
		{
			this.doMipmapGen = doMipmapGen;
			this.HWMipmaps = HWMipmaps;
			this.mipTex = mipTex;
		}
Esempio n. 9
0
		public static Axiom.Media.PixelFormat ConvertEnum( D3D.Format format )
		{
			switch ( format )
			{
				case D3D.Format.A8:
					return Axiom.Media.PixelFormat.A8;
				case D3D.Format.L8:
					return Axiom.Media.PixelFormat.L8;
				case D3D.Format.L16:
					return Axiom.Media.PixelFormat.L16;
				case D3D.Format.A4L4:
					return Axiom.Media.PixelFormat.A4L4;
				case D3D.Format.A8L8:	// Assume little endian here
					return Axiom.Media.PixelFormat.A8L8;
				case D3D.Format.R3G3B2:
					return Axiom.Media.PixelFormat.R3G3B2;
				case D3D.Format.A1R5G5B5:
					return Axiom.Media.PixelFormat.A1R5G5B5;
				case D3D.Format.A4R4G4B4:
					return Axiom.Media.PixelFormat.A4R4G4B4;
				case D3D.Format.R5G6B5:
					return Axiom.Media.PixelFormat.R5G6B5;
				case D3D.Format.R8G8B8:
					return Axiom.Media.PixelFormat.R8G8B8;
				case D3D.Format.X8R8G8B8:
					return Axiom.Media.PixelFormat.X8R8G8B8;
				case D3D.Format.A8R8G8B8:
					return Axiom.Media.PixelFormat.A8R8G8B8;
				case D3D.Format.X8B8G8R8:
					return Axiom.Media.PixelFormat.X8B8G8R8;
				case D3D.Format.A8B8G8R8:
					return Axiom.Media.PixelFormat.A8B8G8R8;
				case D3D.Format.A2R10G10B10:
					return Axiom.Media.PixelFormat.A2R10G10B10;
				case D3D.Format.A2B10G10R10:
					return Axiom.Media.PixelFormat.A2B10G10R10;
				case D3D.Format.R16F:
					return Axiom.Media.PixelFormat.FLOAT16_R;
				case D3D.Format.A16B16G16R16F:
					return Axiom.Media.PixelFormat.FLOAT16_RGBA;
				case D3D.Format.R32F:
					return Axiom.Media.PixelFormat.FLOAT32_R;
				case D3D.Format.A32B32G32R32F:
					return Axiom.Media.PixelFormat.FLOAT32_RGBA;
				case D3D.Format.A16B16G16R16:
					return Axiom.Media.PixelFormat.SHORT_RGBA;
				case D3D.Format.Dxt1:
					return Axiom.Media.PixelFormat.DXT1;
				case D3D.Format.Dxt2:
					return Axiom.Media.PixelFormat.DXT2;
				case D3D.Format.Dxt3:
					return Axiom.Media.PixelFormat.DXT3;
				case D3D.Format.Dxt4:
					return Axiom.Media.PixelFormat.DXT4;
				case D3D.Format.Dxt5:
					return Axiom.Media.PixelFormat.DXT5;
				default:
					return Axiom.Media.PixelFormat.Unknown;
			}
		}
Esempio n. 10
0
		public bool RecreateIfDefaultPool( D3D.Device device )
		{
			bool ret = false;
			if ( this._d3dPool == D3D.Pool.Default )
			{
				ret = true;
				LogManager.Instance.Write( "Recreating D3D9 default pool texture: {0}", Name );

				// We just want to create the texture resources if:
				// 1. This is a render texture, or
				// 2. This is a manual texture with no loader, or
				// 3. This was an unloaded regular texture (preserve unloaded state)
				////Debug.Assert( false, "Recreation of D3D9 textures is not yet implemented" );
				if ( ( IsManuallyLoaded && loader == null ) || ( Usage & TextureUsage.RenderTarget ) != 0 || !IsLoaded )
				{
					// Just recreate any internal resources
					CreateInternalResources();
				}
				else
				{
					// Otherwise, this is a regular loaded texture, or a manual texture with a loader
					// The internal resources already freed, need unload/load here:
					// 1. Make sure resource memory usage statistic correction.
					// 2. Don't call unload() in releaseIfDefaultPool() because we want
					//    the un-touched resource keep unload status after device reset.
					this.Unload();
					if ( IsManuallyLoaded )
					{
						this.CreateInternalResources();
					}

					this.Load();
				}

				LogManager.Instance.Write( "Recreated D3D9 default pool texture: {0}", Name );
			}

			return ret;
		}
Esempio n. 11
0
		private bool CanUseDynamicTextures( D3D.Usage srcUsage, D3D.ResourceType srcType, D3D.Format srcFormat )
		{
			// Check for dynamic texture support
			return _manager.CheckDeviceFormat( this._devParms.AdapterOrdinal, this._devParms.DeviceType, this._bbPixelFormat, srcUsage | D3D.Usage.Dynamic, srcType, srcFormat );
		}
Esempio n. 12
0
		private bool CanAutoGenMipMaps( D3D.Usage srcUsage, D3D.ResourceType srcType, D3D.Format srcFormat )
		{
			Debug.Assert( this._device != null, "D3DDevice not ready!" );

			if ( ( _device.Capabilities.Caps2 & D3D.Caps2.CanAutoGenerateMipMap ) == D3D.Caps2.CanAutoGenerateMipMap )
			{
				// make sure we can do it!
				return _manager.CheckDeviceFormat(
					this._devParms.AdapterOrdinal,
					this._devParms.DeviceType,
					this._bbPixelFormat,
					srcUsage | D3D.Usage.AutoGenerateMipMap,
					srcType,
					srcFormat );
			}

			return false;
		}
Esempio n. 13
0
		public D3DTexture( ResourceManager parent, string name, ResourceHandle handle, string group, bool isManual, IManualResourceLoader loader, D3D.Device device, D3D.Direct3D manager )
			: base( parent, name, handle, group, isManual, loader )
		{
            device = D3DRenderSystem.ActiveD3D9Device; // temp hack till 1.7 upgrade
			Debug.Assert( device != null, "Cannot create a texture without a valid D3D Device." );
			this._device = device;
			this._manager = manager;

			InitDevice();
		}
Esempio n. 14
0
		/// <summary>
		///		Accepts a existing Direct3D.DisplayMode object.
		/// </summary>
		public VideoMode( D3D.DisplayMode videoMode )
		{
			modeNum = ++modeCount;
			displayMode = videoMode;
		}
Esempio n. 15
0
		/// <summary>
		///
		/// </summary>
		/// <param name="driver">The root driver</param>
		/// <param name="deviceIfSwapChain">The existing D3D device to create an additional swap chain from, if this is not	the first window.</param>
		public D3DRenderWindow( Driver driver, D3D.Device deviceIfSwapChain )
			: this( driver )
		{
			_isSwapChain = ( deviceIfSwapChain != null );
		}
Esempio n. 16
0
		/// <summary>
		///    Converts the D3D ShadingMode to our Shading enum equivalent.
		/// </summary>
		/// <param name="shading"></param>
		/// <returns></returns>
		public static Shading ConvertEnum( D3D.ShadeMode shading )
		{
			switch ( shading )
			{
				case D3D.ShadeMode.Flat:
					return Shading.Flat;
				case D3D.ShadeMode.Gouraud:
					return Shading.Gouraud;
				//case D3D.ShadeMode.Phong:
				//    return Shading.Phong;
			}

			return 0;
		}
Esempio n. 17
0
		/// <summary>
		///		Enumerates driver information and their supported display modes.
		/// </summary>
		public static DriverCollection GetDriverInfo( D3D.Direct3D manager )
		{
			DriverCollection driverList = new DriverCollection();

			foreach ( D3D.AdapterInformation adapterInfo in manager.Adapters )
			{
				List<D3D.DisplayMode> displaymodeList = new List<D3D.DisplayMode>();
				Driver driver = new Driver( adapterInfo.Adapter,
                    adapterInfo.GetCaps(DeviceType.Hardware), adapterInfo.Details, adapterInfo.CurrentDisplayMode);

				int lastWidth = 0, lastHeight = 0;
				D3D.Format lastFormat = 0;

				// 32bit Modes
				foreach ( D3D.DisplayMode mode in adapterInfo.GetDisplayModes( D3D.Format.X8R8G8B8 ) )
				{
					displaymodeList.Add( mode );
				}

				// 16Bit modes
				foreach ( D3D.DisplayMode mode in adapterInfo.GetDisplayModes( D3D.Format.R5G6B5 ) )
				{
					displaymodeList.Add( mode );
				}

				foreach ( D3D.DisplayMode mode in displaymodeList )
				{
					// filter out lower resolutions, and make sure this isnt a dupe (ignore variations on refresh rate)
					if ( ( mode.Width >= 640 && mode.Height >= 480 ) &&
						( ( mode.Width != lastWidth ) || mode.Height != lastHeight || mode.Format != lastFormat ) )
					{
						// add the video mode to the list
						driver.VideoModeList.Add( new VideoMode( mode ) );

						// save current mode settings for comparison on the next iteraion
						lastWidth = mode.Width;
						lastHeight = mode.Height;
						lastFormat = mode.Format;
					}
				}
				driverList.Add( driver );
			}
			return driverList;
		}
Esempio n. 18
0
		/// <summary>
		///     Loads a shader object from the supplied microcode.
		/// </summary>
		/// <param name="microcode">
		///     GraphicsStream that contains the assembler instructions for the program.
		/// </param>
		protected abstract void LoadFromMicrocode( D3D.ShaderBytecode microcode );
Esempio n. 19
0
		///<summary>
		///    Call this to associate a D3D volume with this pixel buffer
		///</summary>
		public void Bind( D3D.Device device, D3D.Volume volume, bool update )
		{
			this.device = device;
			this.volume = volume;

			D3D.VolumeDescription desc = volume.Description;
			Width = desc.Width;
			Height = desc.Height;
			Depth = desc.Depth;
			Format = D3DHelper.ConvertEnum( desc.Format );
			// Default
			RowPitch = Width;
			SlicePitch = Height * Width;
			sizeInBytes = PixelUtil.GetMemorySize( Width, Height, Depth, Format );

			if ( ( (int)usage & (int)TextureUsage.RenderTarget ) != 0 )
				CreateRenderTextures( update );
		}
Esempio n. 20
0
		protected override void LoadFromMicrocode( D3D.ShaderBytecode microcode )
		{
			// create the new vertex shader
		    device = D3DRenderSystem.ActiveD3D9Device;
			vertexShader = new D3D.VertexShader( device, microcode );
		}
Esempio n. 21
0
		public void Open( D3D.IncludeType includeType, string fileName, Stream parentStream, out Stream stream )
		{
			stream = ResourceGroupManager.Instance.OpenResource( fileName, this.program.Group, true, this.program );
		}
Esempio n. 22
0
		internal D3DFragmentProgram( ResourceManager parent, string name, ResourceHandle handle, string group, bool isManual, IManualResourceLoader loader, D3D.Device device )
			: base( parent, name, handle, group, isManual, loader, device )
		{
			Type = GpuProgramType.Fragment;
		}