/// <summary> /// This call configure the graphic library for the new device instance. /// </summary> public override void InvalidateDevice() { base.InvalidateDevice(); // - Wait the GPU (we must operate only when GPU is idle) GraphicDevice.Handle.WaitIdle(); // - Dispose render pass DefaultRenderPass.Dispose(); // - Dispose the pipeline Pipeline.Dispose(); // - Dipose current swapchain Swapchain.Dispose(); // - Dispose current VK surface DrawingSurface.Dispose(); // - Dispose vertex and index managers VertexManager.Dispose(); IndexManager.Dispose(); // - Release all VK shaders ShaderManager.Dispose(); for (int i = 0; i < MaxFrameInFlight; ++i) { if (CommandBuffers[i] != null) { foreach (var buffer in CommandBuffers[i]) { buffer.Reset(); } Commands[i].FreeCommandBuffers(CommandBuffers[i]); } } foreach (Fence fence in InFlightFences) { fence.Destroy(); } foreach (Semaphore sem in ImageAvailableSemaphores) { sem.Destroy(); } foreach (Semaphore sem in RenderFinishedSemaphores) { sem.Destroy(); } // - Dispose device GraphicDevice.Dispose(); // - Initialize device Initialize(); // - Reconfigure the renderer ConfigureRendering(); }
/// <summary> /// Configure the render for rendering. /// </summary> public override void ConfigureRendering() { base.ConfigureRendering(); // - Initialize the swap chain Swapchain.Initialize(PhysicalDevice.DrawingSurface, TargetSurface.SurfaceSize); // - Initialzie the swapchain images Swapchain.CreateImageViews(); // - Configure the default render pass DefaultRenderPass.Initialize((Format)Swapchain.CurrentFormat.Format); // - Load shaders ShaderManager.CreateShaders(); // - Gets default shaders var defaultShader = ShaderManager[typeof(DefaultShader)] as VKShaderInstance; Pipeline.Shader = defaultShader; // - Initialize pipeline Pipeline.Initialize(TargetSurface.SurfaceSize); // - Build swapchain framebuffers Swapchain.CreateFrameBuffers(DefaultRenderPass); for (int i = 0; i < Swapchain.Images.Count(); ++i) { ImagesInFlight.Add(null); } }
/// <summary> /// Implement IDisposable. /// </summary> protected override void Dispose(bool disposing) { base.Dispose(disposing); GraphicDevice.Handle.WaitForFences(InFlightFences.ToArray(), true, UInt64.MaxValue); // - Wait the GPU (we must operate only when GPU is idle) GraphicDevice.Handle.WaitIdle(); // - Dispose render pass DefaultRenderPass.Dispose(); // - Dispose the pipeline Pipeline.Dispose(); // - Dipose current swapchain Swapchain.Dispose(); // - Dispose vertex and index managers VertexManager.Dispose(); IndexManager.Dispose(); // - Release all VK shaders ShaderManager.Dispose(); for (int i = 0; i < MaxFrameInFlight; ++i) { if (CommandBuffers[i] != null) { foreach (var buffer in CommandBuffers[i]) { buffer.Reset(); } } } foreach (CommandPool pool in Commands) { pool?.Destroy(); } foreach (Fence fence in InFlightFences) { fence?.Destroy(); } foreach (Semaphore sem in ImageAvailableSemaphores) { sem?.Destroy(); } foreach (Semaphore sem in RenderFinishedSemaphores) { sem?.Destroy(); } // - Dispose device GraphicDevice.Dispose(); // - Dispose vulkan Library.Dispose(); }
/// <summary> /// Configure the graphic library to work with a new surface size. /// </summary> /// <param name="videoSurface">Target surface.</param> public override void InvalidateGraphics() { base.InvalidateGraphics(); // - Wait the GPU (we must operate only when GPU is idle) GraphicDevice.Handle.WaitIdle(); // - Dispose render pass DefaultRenderPass.Dispose(); // - Dispose the pipeline Pipeline.Dispose(); // - Dipose current swapchain Swapchain.Dispose(); // - Reconfigure the renderer ConfigureRendering(); }