public override void OnRecreated() { base.OnRecreated(); // Recreate swap chain swapChain = CreateSwapChain(); // Get newly created native texture var backBufferTexture = swapChain.GetBackBuffer <SharpDX.Direct3D11.Texture2D>(0); // Put it in our back buffer texture // TODO: Update new size backBuffer.InitializeFrom(backBufferTexture, Description.BackBufferFormat.IsSRgb()); backBuffer.LifetimeState = GraphicsResourceLifetimeState.Active; }
public override void Present() { try { swapChain.Present((int)PresentInterval, PresentFlags.None); #if SILICONSTUDIO_XENKO_GRAPHICS_API_DIRECT3D12 // Manually swap back buffer backBuffer.NativeResource.Dispose(); backBuffer.InitializeFrom(swapChain.GetBackBuffer <BackBufferResourceType>((++bufferSwapIndex) % bufferCount), Description.BackBufferFormat.IsSRgb()); #endif } catch (SharpDXException sharpDxException) { throw new GraphicsException("Unexpected error on Present", sharpDxException, GraphicsDevice.GraphicsDeviceStatus); } }
/// <summary> /// Creates a Texture from a DirectX11 native texture /// This method internally will call AddReference on the dxTexture2D texture. /// </summary> /// <param name="device">The GraphicsDevice in use</param> /// <param name="dxTexture2D">The DX11 texture</param> /// <param name="takeOwnership">If false AddRef will be called on the texture, if true will not, effectively taking ownership</param> /// <returns></returns> private static Texture CreateTextureFromNativeImpl(GraphicsDevice device, Resource dxTexture2D, bool takeOwnership) { var tex = new Texture(device); if (takeOwnership) { var unknown = dxTexture2D as IUnknown; unknown.AddReference(); } tex.InitializeFrom(dxTexture2D, false); return(tex); }
protected override void ResizeBackBuffer(int width, int height, PixelFormat format) { graphicsDevice.OnDestroyed(); startingPresentationParameters.BackBufferWidth = width; startingPresentationParameters.BackBufferHeight = height; graphicsDevice.InitDefaultRenderTarget(startingPresentationParameters); var newTextureDescrition = backBuffer.Description; newTextureDescrition.Width = width; newTextureDescrition.Height = height; // Manually update the texture backBuffer.OnDestroyed(); // Put it in our back buffer texture backBuffer.InitializeFrom(newTextureDescrition); }