// TODO: Test this method: public override void WritePixels(PixelBuffer buffer, Point startPoint) { Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0); Rectangle updateRect = new Rectangle(startPoint, buffer.Size); int pitch; int pixelPitch = mDisplay.GetPixelPitch(surf.Description.Format); PixelFormat pixelFormat = mDisplay.GetPixelFormat(surf.Description.Format); surf.Dispose(); GraphicsStream stm = mTexture.Value.LockRectangle(0, Interop.Convert(updateRect), 0, out pitch); if (buffer.PixelFormat != pixelFormat) { buffer = buffer.ConvertTo(pixelFormat); } unsafe { for (int i = updateRect.Top; i < updateRect.Bottom; i++) { int startIndex = buffer.GetPixelIndex(0, i); int rowStride = buffer.RowStride; IntPtr dest = (IntPtr)((byte *)stm.InternalData + i * pitch + updateRect.Left * pixelPitch); Marshal.Copy(buffer.Data, startIndex, dest, rowStride); } } mTexture.Value.UnlockRectangle(0); }
// TODO: Test this method: public override void WritePixels(PixelBuffer buffer, Point startPoint) { Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0); Rectangle updateRect = new Rectangle(startPoint, buffer.Size); int pixelPitch = mDisplay.GetPixelPitch(surf.Description.Format); PixelFormat pixelFormat = mDisplay.GetPixelFormat(surf.Description.Format); surf.Dispose(); // This should probably only lock the region of the surface we intend to update. // However, as is usually the case with DirectX, doing so gives weird errors // with no real explanation as to what is wrong. DataRectangle stm = mTexture.Value.LockRectangle (0, LockFlags.None); if (buffer.PixelFormat != pixelFormat) { buffer = buffer.ConvertTo(pixelFormat); } unsafe { for (int i = 0; i < buffer.Height; i++) { int startIndex = buffer.GetPixelIndex(0, i); int rowStride = buffer.RowStride; IntPtr dest = (IntPtr) ((byte *)stm.Data.DataPointer + (i + updateRect.Top) * stm.Pitch + updateRect.Left * pixelPitch); Marshal.Copy(buffer.Data, startIndex, dest, rowStride); } } mTexture.Value.UnlockRectangle(0); }
public override void WritePixels(PixelBuffer buffer) { Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0); if (surf.Description.Pool == Pool.Default) { throw new AgateLib.AgateException( "Cannot write to FrameBuffer surface in Direct3D."); } int pixelPitch = mDisplay.GetPixelPitch(surf.Description.Format); PixelFormat pixelFormat = mDisplay.GetPixelFormat(surf.Description.Format); surf.Dispose(); DataRectangle stm = mTexture.Value.LockRectangle(0, 0); if (buffer.PixelFormat != pixelFormat) { buffer = buffer.ConvertTo(pixelFormat); } unsafe { for (int i = 0; i < SurfaceHeight; i++) { int startIndex = buffer.GetPixelIndex(0, i); int rowStride = buffer.RowStride; IntPtr dest = (IntPtr)((byte *)stm.Data.DataPointer + i * stm.Pitch); Marshal.Copy(buffer.Data, startIndex, dest, rowStride); } } mTexture.Value.UnlockRectangle(0); }