public static void CopyToVolume(OpsContext context, VolumeTexture newTexture, string srcArg, Filter filter) { if (srcArg == null || srcArg.Length == 0) { return; } ArrayList srcList = context.FindTextures(srcArg); if (srcList == null || srcList.Count == 0) { throw new OpsException("Could not find source texture: " + srcArg); } if (((OpsTexture)srcList[0]).Texture is VolumeTexture) { VolumeLoader.FromVolume(newTexture.GetVolumeLevel(0), ((VolumeTexture)((OpsTexture)srcList[0]).Texture).GetVolumeLevel(0), filter, 0); } else { for (int i = 0; i < srcList.Count; i++) { OpsTexture src = srcList[i] as OpsTexture; if (!(src.Texture is Texture)) { throw new OpsException("Source texture pattern is not 1 volume texture or all 2D textures: " + srcArg); } OpsTextureHelper.LoadVolumeSliceFromSurface(newTexture, 0, i, filter, ((Texture)src.Texture).GetSurfaceLevel(0)); } } newTexture.GenerateMipSubLevels(); }
public static VolumeTexture CloneVolume(VolumeTexture oldTexture, int width, int height, int depth, int mips, Format format, Usage usage, Filter filter, Pool pool) { VolumeTexture newTexture = new VolumeTexture(oldTexture.Device, width, height, depth, mips, usage, format, pool); VolumeLoader.FromVolume(newTexture.GetVolumeLevel(0), oldTexture.GetVolumeLevel(0), filter, 0); return(newTexture); }
///<summary> /// @copydoc HardwarePixelBuffer.Blit ///</summary> public override void Blit(HardwarePixelBuffer _src, BasicBox srcBox, BasicBox dstBox) { D3DHardwarePixelBuffer src = (D3DHardwarePixelBuffer)_src; if (surface != null && src.surface != null) { // Surface-to-surface Rectangle dsrcRect = ToD3DRectangle(srcBox); Rectangle ddestRect = ToD3DRectangle(dstBox); // D3DXLoadSurfaceFromSurface SurfaceLoader.FromSurface(surface, ddestRect, src.surface, dsrcRect, Filter.None, 0); } else if (volume != null && src.volume != null) { // Volume-to-volume Box dsrcBox = ToD3DBox(srcBox); Box ddestBox = ToD3DBox(dstBox); // D3DXLoadVolumeFromVolume VolumeLoader.FromVolume(volume, ddestBox, src.volume, dsrcBox, Filter.None, 0); } else { // Software fallback base.Blit(_src, srcBox, dstBox); } }
///<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(); } }