public static Texture GetSharedD3D9(this DeviceEx device, SharpDX.Direct3D11.Texture2D renderTarget) { if (renderTarget == null) return null; if ((renderTarget.Description.OptionFlags & SharpDX.Direct3D11.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; }
/// <summary> /// Update all resources /// </summary> /// <param name="backBuffer">BackBuffer</param> internal void UpdateResources(SharpDX.Direct3D11.Texture2D backBuffer) { var d2dFactory = new SharpDX.Direct2D1.Factory(); var d2dSurface = backBuffer.QueryInterface<Surface>(); _direct2DRenderTarget = new SharpDX.Direct2D1.RenderTarget(d2dFactory, d2dSurface, new SharpDX.Direct2D1.RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied))); d2dSurface.Dispose(); d2dFactory.Dispose(); InitFont(); }
private IntPtr GetSharedHandle( SharpDX.Direct3D11.Texture2D texture ) { using ( var resource = texture.QueryInterface<SharpDX.DXGI.Resource>() ) { return resource.SharedHandle; } }
//public bool IsOk() //{ // ThrowIfDisposed(); // return _device.CheckDeviceState(IntPtr.Zero) == DeviceState.Ok; //} /// <summary> /// Creates a Direct3D 9 texture from the specified Direct3D 11 texture. /// (The content is shared between the devices.) /// </summary> /// <param name="texture">The Direct3D 11 texture.</param> /// <returns>The Direct3D 9 texture.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="texture"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// The Direct3D 11 texture is not a shared resource, or the texture format is not supported. /// </exception> public Texture CreateSharedTexture(SharpDX.Direct3D11.Texture2D texture) { ThrowIfDisposed(); if (texture == null) throw new ArgumentNullException("texture"); var format = ToD3D9(texture.Description.Format); IntPtr sharedHandle; using (var resource = texture.QueryInterface<SharpDX.DXGI.Resource>()) sharedHandle = resource.SharedHandle; if (sharedHandle == IntPtr.Zero) throw new ArgumentException("Unable to access resource. The texture needs to be created as a shared resource.", "texture"); int width = texture.Description.Width; int height = texture.Description.Height; return new Texture(_device, width, height, 1, Usage.RenderTarget, format, Pool.Default, ref sharedHandle); }