public static Image CopyTextureToBitmap(D3D.Texture2D texture) { int width = texture.Description.Width; if (width % 16 != 0) width = MathExtensions.Round(width, 16) + 16; Bitmap bmp = new Bitmap(texture.Description.Width, texture.Description.Height, PixelFormat.Format32bppArgb); BitmapData bData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat); using (DataStream stream = new DataStream(bData.Scan0, bData.Stride * bData.Height, false, true)) { DataRectangle rect = texture.Map(0, D3D.MapMode.Read, D3D.MapFlags.None); using (DataStream texStream = rect.Data) { for (int y = 0; y < texture.Description.Height; y++) for (int x = 0; x < rect.Pitch; x+=4) { byte[] bytes = texStream.ReadRange<byte>(4); if (x < bmp.Width*4) { stream.Write<byte>(bytes[2]); // DXGI format is BGRA, GDI format is RGBA. stream.Write<byte>(bytes[1]); stream.Write<byte>(bytes[0]); stream.Write<byte>(255); } } } } bmp.UnlockBits(bData); return bmp; }
public RenderTarget(D3D.Device device, D3D.Texture2DDescription rdesc) : base(device) { rdesc.BindFlags |= D3D.BindFlags.ShaderResource; D3D.Texture2D te = new D3D.Texture2D(device, rdesc); Resource = te; RenderView = new D3D.RenderTargetView(device, te); View = new D3D.ShaderResourceView(device, Resource); }
public static void CopyTextureToClipboard(D3D.Device device,D3D.Texture2D source) { if (System.Threading.Thread.CurrentThread.GetApartmentState() != System.Threading.ApartmentState.STA) { MessageBox.Show("Screenshot capture failed. Current thread apartment state not set to STA."); } Image img = ConvertRenderTargetToImage(device, source); Clipboard.SetImage(img); MessageBox.Show("Screenshot copied to clipboard."); }
public RenderTarget(D3D.Device device, int width, int height) : base(device) { D3D.Texture2DDescription rdesc = new D3D.Texture2DDescription() { Width = width, Height = height, MipLevels = 1, ArraySize = 1, Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm, SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0), Usage = D3D.ResourceUsage.Default, BindFlags = D3D.BindFlags.RenderTarget | D3D.BindFlags.ShaderResource, CpuAccessFlags = D3D.CpuAccessFlags.None, OptionFlags = D3D.ResourceOptionFlags.None }; Resource = new D3D.Texture2D(device, rdesc); RenderView = new D3D.RenderTargetView(device, Texture); View = new D3D.ShaderResourceView(device, Resource); }
public SpriteTexture(D3D.Device device, string filename) : base(device) { D3D.ImageLoadInformation iml = new D3D.ImageLoadInformation() { BindFlags = D3D.BindFlags.ShaderResource, CpuAccessFlags = D3D.CpuAccessFlags.None, Depth = 1, FilterFlags = D3D.FilterFlags.None, FirstMipLevel = 0, Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm, MipFilterFlags = D3D.FilterFlags.None, MipLevels = 1, OptionFlags = D3D.ResourceOptionFlags.None, Usage = D3D.ResourceUsage.Default }; Resource = D3D.Texture2D.FromFile(device, filename, iml); View = new D3D.ShaderResourceView(device, Resource); Instance = new D3D.SpriteInstance(this.View, new Vector2(0, 0), new Vector2(1, 1)); UpdateTransform(); }
private static Image ConvertRenderTargetToImage(D3D.Device device, D3D.Texture2D source) { D3D.Texture2DDescription renderDesc = source.Description;// engine.D3DDevice.RenderTarget.Texture.Description; StagingTexture staging = new StagingTexture(device, renderDesc.Width, renderDesc.Height, SlimDX.DXGI.Format.R8G8B8A8_UNorm); device.CopySubresourceRegion(source, 0, staging.Resource, 0, 0, 0, 0); Image img = CopyTextureToBitmap(staging.Resource as D3D.Texture2D); return img; }
public ResourceView(D3D.Device device) { this.device = device; }
/* public SpriteTexture(D3D.Device device, RenderTarget renderTarget) : base(device) { this.View = renderTarget.View; this.Resource = renderTarget.Resource; Instance = new D3D.SpriteInstance(this.View, new Vector2(0, 0), new Vector2(1, 1)); UpdateTransform(); } */ public SpriteTexture(D3D.Device device, int width, int height) : base(device, width, height) { UpdateTransform(); }
public static D3D10.InputLayout GetLayoutWithTexCoord(D3D10.EffectPass pass) { return new SlimDX.Direct3D10.InputLayout(Game.gameClass.GetDevice(), elementsWithTexCoord, pass.Description.Signature); }
public static D3D.InputLayout GetInputLayout(D3D.Device device, D3D.EffectPass pass, Type vertexType) { D3D.InputElement[] inputElements = GetInputElements(vertexType); D3D.InputLayout layout = new D3D.InputLayout(device, pass.Description.Signature, inputElements); return layout; }
public void SetRenderTargets(D3D.RenderTargetView[] renderTargets) { Device.OutputMerger.SetTargets(DepthBufferView, renderTargets); }
public void SetRasterizer(D3D.FillMode fillMode) { D3D.RasterizerStateDescription rsd = new D3D.RasterizerStateDescription() { CullMode = D3D.CullMode.Back, FillMode = fillMode }; D3D.RasterizerState rsdState = D3D.RasterizerState.FromDescription(Device, rsd); Device.Rasterizer.State = rsdState; }
private void RestoreRenderTargets(D3D.RenderTargetView[] previousRenderTargets) { gsOutput.UnbindTarget(); Device.SetRenderTargets(previousRenderTargets); Device.SetBlendState(true); }