public D3DHardwarePixelBuffer(BufferUsage usage) : base(0, 0, 0, Axiom.Media.PixelFormat.Unknown, usage, false, false) { device = null; surface = null; volume = null; tempSurface = null; tempVolume = null; doMipmapGen = false; HWMipmaps = false; mipTex = null; sliceTRT = new List <RenderTexture>(); }
///<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); } }
///<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(); } }
///<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); }
public D3DHardwarePixelBuffer(BufferUsage usage) : base(0, 0, 0, Axiom.Media.PixelFormat.Unknown, usage, false, false) { device = null; surface = null; volume = null; tempSurface = null; tempVolume = null; doMipmapGen = false; HWMipmaps = false; mipTex = null; sliceTRT = new List<RenderTexture>(); }