public override void BeginRender() { // it looks like Direct3D creates a new surface. // so here we will create a new texture, and draw the current texture to it // then discard the old one. Texture t = new Texture(mDevice.Device, SurfaceWidth, SurfaceHeight, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); Direct3D.Surface surfaceTarget = t.GetSurfaceLevel(0); mRenderToSurface = new RenderToSurface(mDevice.Device, SurfaceWidth, SurfaceHeight, Format.A8R8G8B8, false, DepthFormat.D16); Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Width = SurfaceWidth; vp.Height = SurfaceHeight; mRenderToSurface.BeginScene(surfaceTarget, vp); Display.Clear(); Draw(); mTexture.Dispose(); mTexture = new Ref <Texture>(t); }
// 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); }
public override void SetSourceSurface(SurfaceImpl surf, Rectangle srcRect) { mTexture.Dispose(); mTexture = new Ref <Texture>((surf as MDX1_Surface).mTexture); mSrcRect = srcRect; Direct3D.Surface d3dsurf = mTexture.Value.GetSurfaceLevel(0); mTextureSize = new Size(d3dsurf.Description.Width, d3dsurf.Description.Height); SetVertsTextureCoordinates(mVerts, 0, mSrcRect); }
public override PixelBuffer ReadPixels(PixelFormat format, Rectangle rect) { Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0); rect.X += mSrcRect.X; rect.Y += mSrcRect.Y; int stride; int pixelPitch = mDisplay.GetPixelPitch(surf.Description.Format); PixelFormat pixelFormat = mDisplay.GetPixelFormat(surf.Description.Format); if (format == PixelFormat.Any) { format = pixelFormat; } GraphicsStream stm = surf.LockRectangle( new Drawing.Rectangle(0, 0, mTextureSize.Width, mTextureSize.Height), LockFlags.ReadOnly, out stride); byte[] array = new byte[SurfaceWidth * SurfaceHeight * pixelPitch]; int length = SurfaceWidth * pixelPitch; int index = 0; unsafe { byte *ptr = (byte *)stm.InternalDataPointer; for (int i = rect.Top; i < rect.Bottom; i++) { // hack if the size requested is too large. if (i >= mTextureSize.Height) { break; } //IntPtr ptr = (IntPtr)((int)stm.InternalData + i * stride + rect.Left * pixelPitch); IntPtr mptr = (IntPtr)(ptr + i * stride + rect.Left * pixelPitch); Marshal.Copy(mptr, array, index, length); index += length; } } surf.UnlockRectangle(); surf.Dispose(); return(new PixelBuffer(format, rect.Size, array, pixelFormat)); }
public override bool IsColumnBlank(int col) { Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0); int stride; GraphicsStream stm = surf.LockRectangle(Interop.Convert(mSrcRect), LockFlags.ReadOnly, out stride); bool retval = this.IsColBlankScanARGB(stm.InternalData, col, this.SurfaceHeight, stride, (int)(Display.AlphaThreshold * 255.0), 0xff000000, 24); surf.UnlockRectangle(); return(retval); }
public override void SaveTo(string frameFile, ImageFileFormat format) { Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0); Direct3D.ImageFileFormat d3dformat = Microsoft.DirectX.Direct3D.ImageFileFormat.Png; switch (format) { case ImageFileFormat.Bmp: d3dformat = Direct3D.ImageFileFormat.Bmp; break; case ImageFileFormat.Png: d3dformat = Direct3D.ImageFileFormat.Png; break; case ImageFileFormat.Jpg: d3dformat = Direct3D.ImageFileFormat.Jpg; break; case ImageFileFormat.Tga: d3dformat = Direct3D.ImageFileFormat.Tga; break; } SurfaceLoader.Save(frameFile, d3dformat, surf, Interop.Convert(mSrcRect)); }