public static Texture GetSharedD3D9(this DeviceEx device, SharpDX.Direct3D10.Texture2D renderTarget) { if (renderTarget == null) { return(null); } if ((renderTarget.Description.OptionFlags & SharpDX.Direct3D10.ResourceOptionFlags.Shared) == 0) { throw new ArgumentException("Texture must be created with ResourceOptionFlags.Shared"); } Format format = ToD3D9(renderTarget.Description.Format); if (format == Format.Unknown) { throw new ArgumentException("Texture format is not compatible with OpenSharedResource"); } using (var resource = renderTarget.QueryInterface <SharpDX.DXGI.Resource>()) { IntPtr handle = resource.SharedHandle; if (handle == IntPtr.Zero) { throw new ArgumentNullException("Handle"); } return(new Texture(device, renderTarget.Description.Width, renderTarget.Description.Height, 1, Usage.RenderTarget, format, Pool.Default, ref handle)); } }
private IntPtr GetSharedHandle(SharpDX.Direct3D10.Texture2D Texture) { SharpDX.DXGI.Resource resource = Texture.QueryInterface <SharpDX.DXGI.Resource>(); IntPtr result = resource.SharedHandle; resource.Dispose(); return(result); }
private void OnRender(IntPtr handle, bool isNewSurface) { if (isNewSurface) { if (brush != null) { brush.Dispose(); brush = null; } if (renderTarget != null) { renderTarget.Dispose(); renderTarget = null; } SharpDX.ComObject comObject = new SharpDX.ComObject(handle); SharpDX.DXGI.Resource resource = comObject.QueryInterface <SharpDX.DXGI.Resource>(); SharpDX.Direct3D10.Texture2D texture = resource.QueryInterface <SharpDX.Direct3D10.Texture2D>(); using (var surface = texture.QueryInterface <SharpDX.DXGI.Surface>()) { var properties = new RenderTargetProperties(); properties.DpiX = 96; properties.DpiY = 96; properties.MinLevel = FeatureLevel.Level_DEFAULT; properties.PixelFormat = new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.Unknown, AlphaMode.Premultiplied); properties.Type = RenderTargetType.Default; properties.Usage = RenderTargetUsage.None; renderTarget = new RenderTarget(new Factory(), surface, properties); } } if (brush == null) { brush = new SharpDX.Direct2D1.SolidColorBrush(renderTarget, new SharpDX.Color4(0.2f, 0.2f, 0.2f, 0.5f)); } renderTarget.BeginDraw(); renderTarget.DrawTextLayout(new SharpDX.Vector2(50, 50), textLayout, brush); renderTarget.EndDraw(); }