private bool Initialize(TextureManager manager, D3d.Format format, int width, int height, int depth, bool dynamic, bool mipmap) { D3d.Pool d3dPool = D3d.Pool.Managed; D3d.Usage d3dUsage = manager.GetUsageFlags(dynamic, mipmap, false); try { d3dTexture = new D3d.VolumeTexture(manager.Device.D3dDevice, width, height, depth, manager.GetMipLevelCount(mipmap), d3dUsage, format, d3dPool); this.Initialize(manager, format, width, height, depth, d3dTexture); return(true); } catch (D3d.InvalidCallException e) { log.Warning("Unable to create 3d texture: {0}", e.Message); } catch (D3d.OutOfVideoMemoryException e) { log.Warning("Unable to create 3d texture: {0}", e.Message); } catch (OutOfMemoryException e) { log.Warning("Unable to create 3d texture: {0}", e.Message); } return(false); }
private bool Initialize(TextureManager manager, D3d.Format format, int size, bool mipmap, int multisample) { D3d.Pool d3dPool = D3d.Pool.Default; D3d.Usage d3dUsage = manager.GetUsageFlags(false, mipmap, true); try { d3dTexture = new D3d.CubeTexture(manager.Device.D3dDevice, size, manager.GetMipLevelCount(mipmap), d3dUsage, format, d3dPool); // Create depth buffer. d3dDepthBuffer = manager.Device.D3dDevice.CreateDepthStencilSurface(size, size, manager.Device.Settings.depthBufferFormat, (D3d.MultiSampleType)multisample, 0, true); this.Initialize(manager, format, size, size, 6, d3dTexture); return(true); } catch (D3d.InvalidCallException e) { log.Warning("Unable to create render cube texture: {0}", e.Message); } catch (D3d.OutOfVideoMemoryException e) { log.Warning("Unable to create render cube texture: {0}", e.Message); } catch (OutOfMemoryException e) { log.Warning("Unable to create render cube texture: {0}", e.Message); } return(false); }
/// <summary> /// Enumerates driver information and their supported display modes. /// </summary> public static Driver GetDriverInfo() { ArrayList driverList = new ArrayList(); // get the information for the default adapter (not checking secondaries) AdapterInformation adapterInfo = D3D.Manager.Adapters[0]; Driver driver = new Driver(adapterInfo); int lastWidth = 0, lastHeight = 0; D3D.Format lastFormat = 0; foreach (DisplayMode mode in adapterInfo.SupportedDisplayModes) { // 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.VideoModes.Add(new VideoMode(mode)); // save current mode settings for comparison on the next iteraion lastWidth = mode.Width; lastHeight = mode.Height; lastFormat = mode.Format; } } return(driver); }
private bool ModifyParameters(D3d.ResourceType type, D3d.Format format, bool dynamic, bool mipmap, bool isTarget, ref int width, ref int height, ref int depth) { // First fix any dimensional errors. width = width / textureDivider; height = height / textureDivider; depth = depth / textureDivider; // Make sure we stay within maximum allowed dimensions. if (width > textureDevice.Capabilities.textureMaxWidth) { width = textureDevice.Capabilities.textureMaxWidth; } if (height > textureDevice.Capabilities.textureMaxHeight) { height = textureDevice.Capabilities.textureMaxHeight; } if (depth > textureDevice.Capabilities.textureMaxDepth) { depth = textureDevice.Capabilities.textureMaxDepth; } D3d.Usage d3dUsage = GetUsageFlags(dynamic, mipmap, isTarget); // Get the current display mode format for later use. D3d.Format displayFormat = D3d.Manager.Adapters[Device.Settings.adapterIndex].CurrentDisplayMode.Format; if (D3d.Manager.CheckDeviceFormat(Device.Settings.adapterIndex, Device.Settings.deviceType, Device.Settings.backBufferFormat, d3dUsage, type, format)) { if (isTarget) { if (D3d.Manager.CheckDepthStencilMatch(Device.Settings.adapterIndex, Device.Settings.deviceType, displayFormat, format, Device.Settings.depthBufferFormat)) { return(true); } } else { return(true); } } return(false); }
public static int GetSize(D3d.Format format) { if (formatSizes.ContainsKey(format)) { return(formatSizes[format]); } return(0); }
protected void Initialize(TextureManager manager, D3d.Format format, int width, int height, int depth, D3d.BaseTexture d3dBase) { textureManager = manager; textureFormat = format; textureWidth = width; textureHeight = height; textureDepth = depth; textureBase = d3dBase; }
protected void Initialize(TextureManager manager, D3d.Format format, int width, int height, int depth,D3d.BaseTexture d3dBase ) { textureManager = manager; textureFormat = format; textureWidth = width; textureHeight = height; textureDepth = depth; textureBase = d3dBase; }
public static RenderTextureCube Create(TextureManager manager, D3d.Format format, int size, bool mipmap, int multisample) { RenderTextureCube newTexture = new RenderTextureCube(); if (newTexture.Initialize(manager, format, size, mipmap, multisample)) { return(newTexture); } return(null); }
public static TextureCube Create(TextureManager manager, D3d.Format format, int size, bool dynamic, bool mipmap) { TextureCube newTexture = new TextureCube(); if (newTexture.Initialize(manager, format, size, dynamic, mipmap)) { return(newTexture); } return(null); }
public static TextureVolume Create(TextureManager manager, D3d.Format format, int width, int height, int depth, bool dynamic, bool mipmap) { TextureVolume newTexture = new TextureVolume(); if (newTexture.Initialize(manager, format, width, height, depth, dynamic, mipmap)) { return(newTexture); } return(null); }
public static RenderTexture2d Create(TextureManager manager, D3d.Format format, int width, int height, bool mipmap, int multisample) { RenderTexture2d newTexture = new RenderTexture2d(); if (newTexture.Initialize(manager, format, width, height, mipmap, multisample)) { return(newTexture); } return(null); }
//TODO: move to general gfx function library private static bool TextureFormatGotAlpha(Microsoft.DirectX.Direct3D.Format f) { return(f == Format.A8B8G8R8 || f == Format.A8R8G8B8 || f == Format.A16B16G16R16 || f == Format.A16B16G16R16F || f == Format.A1R5G5B5 || f == Format.A2B10G10R10 || f == Format.A2R10G10B10 || f == Format.A2W10V10U10 || f == Format.A32B32G32R32F || f == Format.A4R4G4B4 || f == Format.A8R3G3B2); // || f==Format.X8R8G8B8 || f==Format.X8B8G8R8 || // f==Format.X1R5G5B5 || f==Format.X4R4G4B4 // ); }
public TextureVolume CreateTextureVolume(D3d.Format format, int width, int height, int depth, bool dynamic, bool mipmap) { if (ModifyParameters(D3d.ResourceType.VolumeTexture, format, dynamic, mipmap, false, ref width, ref height, ref depth)) { TextureVolume newTexture = TextureVolume.Create(this, format, width, height, depth, dynamic, mipmap); if (newTexture != null) { textures.Add(newTexture); return(newTexture); } } return(null); }
private void Read() { fullScreenWidth = Kernel.Registry.Manager.Instance.GetValue("Graphics.Width", fullScreenWidth); fullScreenHeight = Kernel.Registry.Manager.Instance.GetValue("Graphics.Height", fullScreenHeight); fullScreenRefresh = Kernel.Registry.Manager.Instance.GetValue("Graphics.RefreshRate", fullScreenRefresh); windowed = Kernel.Registry.Manager.Instance.GetValue("Graphics.Windowed", windowed); backBufferFormat = Kernel.Registry.Manager.Instance.GetValue("Graphics.BackBufferFormat", backBufferFormat); depthBufferFormat = Kernel.Registry.Manager.Instance.GetValue("Graphics.DepthBufferFormat", depthBufferFormat); adapterIndex = Kernel.Registry.Manager.Instance.GetValue("Graphics.Adapter", adapterIndex); deviceType = Kernel.Registry.Manager.Instance.GetValue("Graphics.DeviceType", deviceType); multiSampleLevel = Kernel.Registry.Manager.Instance.GetValue("Graphics.Multisample", multiSampleLevel); backBufferCount = Kernel.Registry.Manager.Instance.GetValue("Graphics.BackBufferCount", backBufferCount); }
public bool IsDeviceAcceptable(Microsoft.DirectX.Direct3D.Caps caps, Microsoft.DirectX.Direct3D.Format adapterFormat, Microsoft.DirectX.Direct3D.Format backBufferFormat, bool isWindowed) { // No fallback, need at least PS1.1 if (caps.PixelShaderVersion < new Version(1, 1)) { return(false); } // Skip back buffer formats that don't support alpha blending if (!Manager.CheckDeviceFormat(caps.AdapterOrdinal, caps.DeviceType, adapterFormat, Usage.QueryPostPixelShaderBlending, ResourceType.Textures, backBufferFormat)) { return(false); } return(true); }
public TextureCube CreateTextureCube(D3d.Format format, int size, bool dynamic, bool mipmap) { int height = 128; int depth = 128; if (ModifyParameters(D3d.ResourceType.CubeTexture, format, dynamic, mipmap, false, ref size, ref height, ref depth)) { TextureCube newTexture = TextureCube.Create(this, format, size, dynamic, mipmap); if (newTexture != null) { textures.Add(newTexture); return(newTexture); } } return(null); }
private static int GetFormatNumBytes(Microsoft.DirectX.Direct3D.Format f) { if (f == Format.A8B8G8R8 || f == Format.A8R8G8B8 || f == Format.X8R8G8B8 || f == Format.X8B8G8R8) { return(4); } if (f == Format.A1R5G5B5 || f == Format.X1R5G5B5 || f == Format.A4R4G4B4 || f == Format.A8R3G3B2) { return(2); } return(16); // f==Format.A16B16G16R16 || f==Format.A16B16G16R16F || // f== || f==Format.A2B10G10R10 || // f==Format.A2R10G10B10 || f==Format.A2W10V10U10 || // f==Format.A32B32G32R32F || f== Format.A4R4G4B4 || }
public RenderTexture2d CreateRenderTexture2d(D3d.Format format, int width, int height, bool mipmap, int multisample) { int depth = 128; if (ModifyParameters(D3d.ResourceType.Textures, format, false, mipmap, true, ref width, ref height, ref depth)) { RenderTexture2d newTexture = RenderTexture2d.Create(this, format, width, height, mipmap, multisample); if (newTexture != null) { textures.Add(newTexture); textureTargets.Add(newTexture); return(newTexture); } } return(null); }
public RenderTextureCube CreateRenderTextureCube(D3d.Format format, int size, bool mipmap, int multisample) { int height = 128; int depth = 128; if (ModifyParameters(D3d.ResourceType.CubeTexture, format, false, mipmap, true, ref size, ref height, ref depth)) { RenderTextureCube newTexture = RenderTextureCube.Create(this, format, size, mipmap, multisample); if (newTexture != null) { textures.Add(newTexture); textureTargets.Add(newTexture); return(newTexture); } } return(null); }
//public override Axiom.Core.Texture Create(string name, TextureType type) { // D3DTexture texture = new D3DTexture(name, device, TextureUsage.Default, type); // // Handle 32-bit texture settings // texture.Enable32Bit(is32Bit); // return texture; //} /// <summary> /// Used to create a blank D3D texture. /// </summary> /// <param name="name"></param> /// <param name="type"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="numMipMaps"></param> /// <param name="format"></param> /// <param name="usage"></param> /// <returns></returns> //public override Axiom.Core.Texture CreateManual(string name, TextureType type, int width, int height, int numMipMaps, Axiom.Media.PixelFormat format, TextureUsage usage) { // D3DTexture texture = new D3DTexture(name, device, type, width, height, numMipMaps, format, usage); // texture.Enable32Bit(is32Bit); // return texture; //} // This ends up just discarding the format passed in; the C# methods don't let you supply // a "recommended" format. Ah well. public override Axiom.Media.PixelFormat GetNativeFormat(TextureType ttype, Axiom.Media.PixelFormat format, TextureUsage usage) { // Basic filtering D3D.Format d3dPF = D3DHelper.ConvertEnum(D3DHelper.GetClosestSupported(format)); // Calculate usage D3D.Usage d3dusage = 0; D3D.Pool pool = D3D.Pool.Managed; if ((usage & TextureUsage.RenderTarget) != 0) { d3dusage |= D3D.Usage.RenderTarget; pool = D3D.Pool.Default; } if ((usage & TextureUsage.Dynamic) != 0) { d3dusage |= D3D.Usage.Dynamic; pool = D3D.Pool.Default; } // Use D3DX to adjust pixel format switch (ttype) { case TextureType.OneD: case TextureType.TwoD: TextureRequirements tReqs; TextureLoader.CheckTextureRequirements(device, d3dusage, pool, out tReqs); d3dPF = tReqs.Format; break; case TextureType.ThreeD: VolumeTextureRequirements volReqs; TextureLoader.CheckVolumeTextureRequirements(device, pool, out volReqs); d3dPF = volReqs.Format; break; case TextureType.CubeMap: CubeTextureRequirements cubeReqs; TextureLoader.CheckCubeTextureRequirements(device, d3dusage, pool, out cubeReqs); d3dPF = cubeReqs.Format; break; } ; return(D3DHelper.ConvertEnum(d3dPF)); }
protected void InitDevice() { Debug.Assert(device != null); // get device caps devCaps = device.DeviceCaps; // get our device creation parameters devParms = device.CreationParameters; // get our back buffer pixel format using (D3D.Surface back = device.GetBackBuffer(0, 0, D3D.BackBufferType.Mono)) { bbPixelFormat = back.Description.Format; } }
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.BYTE_LA); 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); } }
public void Load(ref BinaryReader br) { signature = br.ReadInt32(); width = br.ReadInt16(); height = br.ReadInt16(); depth = br.ReadInt16(); type = br.ReadInt16(); format = br.ReadInt16(); flags = br.ReadInt16(); reg_point_x = br.ReadInt16(); reg_point_y = br.ReadInt16(); num_mipmaps = br.ReadInt16(); pixel_offset = br.ReadInt16(); offset = br.ReadInt32(); size = br.ReadInt32(); br.BaseStream.Seek(16, SeekOrigin.Current); switch (type) { case 0x00: DxTextureFormat = MDX.Format.A8; break; case 0x01: //#define BITM_FORMAT_Y8 //DxTextureFormat = MDX.Format.Y; break; case 0x02: //#define BITM_FORMAT_AY8 //DxTextureFormat = MDX.Format.AY; break; case 0x03: //#define BITM_FORMAT_A8Y8 //DxTextureFormat = MDX.Format; break; case 0x06: DxTextureFormat = MDX.Format.R5G6B5; break; case 0x08: DxTextureFormat = MDX.Format.A1R5G5B5; break; case 0x09: DxTextureFormat = MDX.Format.A4R4G4B4; break; case 0x0A: DxTextureFormat = MDX.Format.X8R8G8B8; break; case 0x0B: DxTextureFormat = MDX.Format.A8R8G8B8; break; case 0x0E: DxTextureFormat = MDX.Format.Dxt1; break; case 0x0F: //#define BITM_FORMAT_DXT2AND3 DxTextureFormat = MDX.Format.Dxt2; break; case 0x10: //#define BITM_FORMAT_DXT4AND5 DxTextureFormat = MDX.Format.Dxt4; break; case 0x11: //#define BITM_FORMAT_P8 DxTextureFormat = MDX.Format.P8; break; default: //throw exception break; } }
private void Read() { fullScreenWidth = Kernel.Registry.Manager.Instance.GetValue("Graphics.Width",fullScreenWidth ); fullScreenHeight = Kernel.Registry.Manager.Instance.GetValue("Graphics.Height",fullScreenHeight); fullScreenRefresh = Kernel.Registry.Manager.Instance.GetValue("Graphics.RefreshRate",fullScreenRefresh); windowed = Kernel.Registry.Manager.Instance.GetValue("Graphics.Windowed",windowed ); backBufferFormat = Kernel.Registry.Manager.Instance.GetValue("Graphics.BackBufferFormat",backBufferFormat ); depthBufferFormat = Kernel.Registry.Manager.Instance.GetValue("Graphics.DepthBufferFormat",depthBufferFormat ); adapterIndex = Kernel.Registry.Manager.Instance.GetValue("Graphics.Adapter",adapterIndex ); deviceType = Kernel.Registry.Manager.Instance.GetValue("Graphics.DeviceType",deviceType ); multiSampleLevel = Kernel.Registry.Manager.Instance.GetValue("Graphics.Multisample",multiSampleLevel ); backBufferCount = Kernel.Registry.Manager.Instance.GetValue("Graphics.BackBufferCount",backBufferCount ); }