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> /// Loads the specified image into the texture. /// </summary> /// <param name="device">The DirectX device to load the texture into.</param> /// <param name="image">The image to load.</param> /// <param name="usage">The Direct3D Usage parameter for the image.</param> /// <param name="pool">The Direct3D Pool parameter for the image.</param> public void SetImage(D3D.Device device, Bitmap image, D3D.Usage usage, D3D.Pool pool) { if (_texture != null) { _texture.Dispose(); } _texture = new D3D.Texture(device, image, usage, pool); }
private bool Initialize(GeometryManager manager, Type vertexType, int size, bool pointsprites, bool dynamic) { if (IsTypeValid(vertexType)) { try { D3d.Pool d3dPool = D3d.Pool.Managed; D3d.Usage d3dUsage = D3d.Usage.WriteOnly; if (dynamic) { d3dUsage |= D3d.Usage.Dynamic; } if (pointsprites) { d3dUsage |= D3d.Usage.Points; } d3dManager = manager; d3dVertexType = vertexType; d3dVertexSize = size; d3dVertexBuffer = new D3d.VertexBuffer(vertexType, size, manager.Device.D3dDevice, d3dUsage, D3d.VertexFormats.None, d3dPool); return(true); } catch (D3d.InvalidCallException e) { log.Warning("Unable to create vertex stream: {0}", e.Message); } catch (D3d.OutOfVideoMemoryException e) { log.Warning("Unable to create vertex stream: {0}", e.Message); } catch (OutOfMemoryException e) { log.Warning("Unable to create vertex stream: {0}", e.Message); } } return(false); }
//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)); }
public D3DHardwareVertexBuffer(int vertexSize, int numVertices, BufferUsage usage, D3D.Device device, bool useSystemMemory, bool useShadowBuffer) : base(vertexSize, numVertices, usage, useSystemMemory, useShadowBuffer) { #if !NO_OGRE_D3D_MANAGE_BUFFERS d3dPool = useSystemMemory? 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) ? Pool.Default : Pool.Managed; #else d3dPool = useSystemMemory ? Pool.SystemMemory : Pool.Default; #endif // Create the d3d vertex buffer d3dBuffer = new D3D.VertexBuffer(device, sizeInBytes, D3DHelper.ConvertEnum(usage), VertexFormats.None, d3dPool); }
public D3DHardwareIndexBuffer(IndexType type, int numIndices, BufferUsage usage, D3D.Device device, bool useSystemMemory, bool useShadowBuffer) : base(type, numIndices, usage, useSystemMemory, useShadowBuffer) { #if !NO_OGRE_D3D_MANAGE_BUFFERS d3dPool = useSystemMemory? 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) ? Pool.Default : Pool.Managed; #else d3dPool = useSystemMemory ? Pool.SystemMemory : Pool.Default; #endif Type bufferType = (type == IndexType.Size16) ? typeof(short) : typeof(int); // create the buffer d3dBuffer = new IndexBuffer( bufferType, //sizeInBytes, // sizeInBytes is wrong, because the D3D API is expecting the number of indices numIndices, device, D3DHelper.ConvertEnum(usage), d3dPool); }
private bool Initialize(GeometryManager manager, int size, bool isLarge, bool dynamic) { try { D3d.Pool d3dPool = D3d.Pool.Managed; D3d.Usage d3dUsage = D3d.Usage.WriteOnly; if (dynamic) { d3dUsage |= D3d.Usage.Dynamic; } d3dManager = manager; d3dIndexSize = size; d3dIsLarge = isLarge; d3dIndexBuffer = new D3d.IndexBuffer(this.Type, d3dIndexSize, manager.Device.D3dDevice, d3dUsage, d3dPool); return(true); } catch (D3d.InvalidCallException e) { log.Warning("Unable to create index stream: {0}", e.Message); } catch (D3d.OutOfVideoMemoryException e) { log.Warning("Unable to create index stream: {0}", e.Message); } catch (OutOfMemoryException e) { log.Warning("Unable to create index stream: {0}", e.Message); } return(false); }
protected override void LoadImpl() { if ((usage & TextureUsage.RenderTarget) != 0) { CreateInternalResources(); isLoaded = true; return; } if (!internalResourcesCreated) { // NB: Need to initialize pool to some value other than D3D.Pool.Managed, // otherwise, if the texture loading failed, it might re-create as empty // texture when device lost/restore. The actual pool will determine later. d3dPool = D3D.Pool.Managed; } // create a regular texture switch (this.TextureType) { case TextureType.OneD: case TextureType.TwoD: LoadNormalTexture(); break; case TextureType.ThreeD: LoadVolumeTexture(); break; case TextureType.CubeMap: LoadCubeTexture(); break; default: throw new AxiomException("Unknown texture type in D3DTexture.LoadImpl"); } }
/// <summary> /// /// </summary> protected override void CreateInternalResourcesImpl() { // If srcWidth and srcHeight are zero, the requested extents have probably been set // through a method which set 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) { d3dPool = D3D.Pool.Default; } else { d3dPool = D3D.Pool.Managed; } switch (this.TextureType) { case TextureType.OneD: case TextureType.TwoD: CreateNormalTexture(); break; case TextureType.CubeMap: CreateCubeTexture(); break; case TextureType.ThreeD: CreateVolumeTexture(); break; default: FreeInternalResources(); throw new Exception("Unknown texture type!"); } }
/// <summary> /// /// </summary> private void LoadVolumeTexture() { Debug.Assert(this.TextureType == TextureType.ThreeD); using (AutoTimer auto = new AutoTimer(textureLoadMeter)) { // DDS load? if (name.EndsWith(".dds")) { Stream stream = TextureManager.Instance.FindResourceData(name); // use D3DX to load the image directly from the stream int numMips = numRequestedMipmaps + 1; // check if mip map volume textures are supported if (!(devCaps.TextureCaps.SupportsMipVolumeMap)) { // no mip map support for this kind of textures :( numMipmaps = 0; numMips = 1; } // Determine D3D pool to use D3D.Pool pool; if ((usage & TextureUsage.Dynamic) != 0) pool = D3D.Pool.Default; else pool = D3D.Pool.Managed; Debug.Assert(volumeTexture == null); Debug.Assert(texture == null); // load the cube texture from the image data stream directly volumeTexture = TextureLoader.FromVolumeStream(device, stream, (int)stream.Length, 0, 0, 0, numMips, D3D.Usage.None, D3D.Format.Unknown, pool, Filter.Triangle | Filter.Dither, Filter.Box, 0); // store off a base reference texture = volumeTexture; // set the image data attributes VolumeDescription desc = volumeTexture.GetLevelDescription(0); d3dPool = desc.Pool; // set src and dest attributes to the same, we can't know SetSrcAttributes(desc.Width, desc.Height, desc.Depth, D3DHelper.ConvertEnum(desc.Format)); SetFinalAttributes(desc.Width, desc.Height, desc.Depth, D3DHelper.ConvertEnum(desc.Format)); isLoaded = true; internalResourcesCreated = true; stream.Dispose(); } else { // find & load resource data into stream Stream stream = TextureManager.Instance.FindResourceData(name); int pos = name.LastIndexOf('.'); string ext = name.Substring(pos + 1); Image img = Image.FromStream(stream, ext); LoadImage(img); stream.Dispose(); } } // using }