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 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; }
public static void FillTexture(VolumeTexture texture, Fill3DTextureCallback callbackFunction) { throw new NotImplementedException(); }
public static void FillTexture(VolumeTexture texture, TextureShader textureShader) { throw new NotImplementedException(); }
public unsafe Volume(IDirect3DVolume9 *lp, VolumeTexture device) { throw new NotImplementedException(); }
///<summary> /// @copydoc HardwarePixelBuffer.BlitToMemory ///</summary> public override void BlitToMemory(BasicBox srcBox, PixelBox dst) { // Decide on pixel format of temp surface PixelFormat tmpFormat = format; if (D3DHelper.ConvertEnum(dst.Format) == D3D.Format.Unknown) { tmpFormat = dst.Format; } if (surface != null) { Debug.Assert(srcBox.Depth == 1 && dst.Depth == 1); // Create temp texture D3D.Texture tmp = new D3D.Texture(device, dst.Width, dst.Height, 1, // 1 mip level ie topmost, generate no mipmaps 0, D3DHelper.ConvertEnum(tmpFormat), Pool.Scratch); D3D.Surface subSurface = tmp.GetSurfaceLevel(0); // Copy texture to this temp surface Rectangle destRect, srcRect; srcRect = ToD3DRectangle(srcBox); destRect = ToD3DRectangleExtent(dst); SurfaceLoader.FromSurface(subSurface, destRect, surface, srcRect, Filter.None, 0); // Lock temp surface and copy it to memory int pitch; // Filled in by D3D GraphicsStream data = subSurface.LockRectangle(D3D.LockFlags.ReadOnly, out pitch); // Copy it PixelBox locked = new PixelBox(dst.Width, dst.Height, dst.Depth, tmpFormat); FromD3DLock(locked, pitch, data); PixelUtil.BulkPixelConversion(locked, dst); subSurface.UnlockRectangle(); // Release temporary surface and texture subSurface.Dispose(); tmp.Dispose(); } else { // Create temp texture D3D.VolumeTexture tmp = new D3D.VolumeTexture(device, dst.Width, dst.Height, dst.Depth, 0, D3D.Usage.None, D3DHelper.ConvertEnum(tmpFormat), Pool.Scratch); D3D.Volume subVolume = tmp.GetVolumeLevel(0); // Volume D3D.Box ddestBox = ToD3DBoxExtent(dst); D3D.Box dsrcBox = ToD3DBox(srcBox); VolumeLoader.FromVolume(subVolume, ddestBox, volume, dsrcBox, Filter.None, 0); // Lock temp surface and copy it to memory D3D.LockedBox lbox; // Filled in by D3D GraphicsStream data = subVolume.LockBox(LockFlags.ReadOnly, out lbox); // Copy it PixelBox locked = new PixelBox(dst.Width, dst.Height, dst.Depth, tmpFormat); FromD3DLock(locked, lbox, data); PixelUtil.BulkPixelConversion(locked, dst); subVolume.UnlockBox(); // Release temporary surface and texture subVolume.Dispose(); tmp.Dispose(); } }
protected override void FreeInternalResourcesImpl() { if (texture != null) { texture.Dispose(); texture = null; } if (normTexture != null) { normTexture.Dispose(); normTexture = null; } if (cubeTexture != null) { cubeTexture.Dispose(); cubeTexture = null; } if (volumeTexture != null) { volumeTexture.Dispose(); volumeTexture = null; } foreach (IDisposable buf in managedObjects) buf.Dispose(); managedObjects.Clear(); }
/// <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 }
private void CreateVolumeTexture() { // we must have those defined here Debug.Assert(srcWidth > 0 && srcHeight > 0); // determine which D3D9 pixel format we'll use D3D.Format d3dPixelFormat = ChooseD3DFormat(); // at this point, Ogre checks to see if this texture format works, // but we go on and figure out the rest of our info first. // set the appropriate usage based on the usage of this texture D3D.Usage d3dUsage = ((usage & TextureUsage.RenderTarget) == TextureUsage.RenderTarget) ? D3D.Usage.RenderTarget : D3D.Usage.None; // how many mips to use? int numMips = numRequestedMipmaps + 1; // Check dynamic textures if ((usage & TextureUsage.Dynamic) != 0) { if (CanUseDynamicTextures(d3dUsage, ResourceType.VolumeTexture, d3dPixelFormat)) { d3dUsage |= D3D.Usage.Dynamic; dynamicTextures = true; } else { dynamicTextures = false; } } // check if mip maps are supported on hardware mipmapsHardwareGenerated = false; if (devCaps.TextureCaps.SupportsMipVolumeMap) { if (((usage & TextureUsage.AutoMipMap) == TextureUsage.AutoMipMap) && numRequestedMipmaps > 0) { // use auto.gen. if available mipmapsHardwareGenerated = this.CanAutoGenMipMaps(d3dUsage, ResourceType.VolumeTexture, d3dPixelFormat); if (mipmapsHardwareGenerated) { d3dUsage |= D3D.Usage.AutoGenerateMipMap; numMips = 0; } } } else { // no mip map support for this kind of texture numMipmaps = 0; numMips = 1; } // check texture requirements D3D.TextureRequirements texRequire = new D3D.TextureRequirements(); texRequire.Width = srcWidth; texRequire.Height = srcHeight; texRequire.NumberMipLevels = numMips; texRequire.Format = d3dPixelFormat; // NOTE: Although texRequire is an out parameter, it actually does // use the data passed in with that object. TextureLoader.CheckTextureRequirements(device, d3dUsage, Pool.Default, out texRequire); numMips = texRequire.NumberMipLevels; d3dPixelFormat = texRequire.Format; Debug.Assert(volumeTexture == null); Debug.Assert(texture == null); log.InfoFormat("Created normal texture {0}", this.Name); // create the texture volumeTexture = new D3D.VolumeTexture( device, srcWidth, srcHeight, srcDepth, numMips, d3dUsage, d3dPixelFormat, d3dPool); // store base reference to the texture texture = volumeTexture; // set the final texture attributes VolumeDescription desc = volumeTexture.GetLevelDescription(0); SetFinalAttributes(desc.Width, desc.Height, desc.Depth, D3DHelper.ConvertEnum(desc.Format)); if (mipmapsHardwareGenerated) texture.AutoGenerateFilterType = GetBestFilterMethod(); }
///<summary> /// @copydoc HardwarePixelBuffer.BlitToMemory ///</summary> public override void BlitToMemory(BasicBox srcBox, PixelBox dst) { // Decide on pixel format of temp surface PixelFormat tmpFormat = format; if (D3DHelper.ConvertEnum(dst.Format) == D3D.Format.Unknown) tmpFormat = dst.Format; if (surface != null) { Debug.Assert(srcBox.Depth == 1 && dst.Depth == 1); // Create temp texture D3D.Texture tmp = new D3D.Texture(device, dst.Width, dst.Height, 1, // 1 mip level ie topmost, generate no mipmaps 0, D3DHelper.ConvertEnum(tmpFormat), Pool.Scratch); D3D.Surface subSurface = tmp.GetSurfaceLevel(0); // Copy texture to this temp surface Rectangle destRect, srcRect; srcRect = ToD3DRectangle(srcBox); destRect = ToD3DRectangleExtent(dst); SurfaceLoader.FromSurface(subSurface, destRect, surface, srcRect, Filter.None, 0); // Lock temp surface and copy it to memory int pitch; // Filled in by D3D GraphicsStream data = subSurface.LockRectangle(D3D.LockFlags.ReadOnly, out pitch); // Copy it PixelBox locked = new PixelBox(dst.Width, dst.Height, dst.Depth, tmpFormat); FromD3DLock(locked, pitch, data); PixelUtil.BulkPixelConversion(locked, dst); subSurface.UnlockRectangle(); // Release temporary surface and texture subSurface.Dispose(); tmp.Dispose(); } else { // Create temp texture D3D.VolumeTexture tmp = new D3D.VolumeTexture(device, dst.Width, dst.Height, dst.Depth, 0, D3D.Usage.None, D3DHelper.ConvertEnum(tmpFormat), Pool.Scratch); D3D.Volume subVolume = tmp.GetVolumeLevel(0); // Volume D3D.Box ddestBox = ToD3DBoxExtent(dst); D3D.Box dsrcBox = ToD3DBox(srcBox); VolumeLoader.FromVolume(subVolume, ddestBox, volume, dsrcBox, Filter.None, 0); // Lock temp surface and copy it to memory D3D.LockedBox lbox; // Filled in by D3D GraphicsStream data = subVolume.LockBox(LockFlags.ReadOnly, out lbox); // Copy it PixelBox locked = new PixelBox(dst.Width, dst.Height, dst.Depth, tmpFormat); FromD3DLock(locked, lbox, data); PixelUtil.BulkPixelConversion(locked, dst); subVolume.UnlockBox(); // Release temporary surface and texture subVolume.Dispose(); tmp.Dispose(); } }