public void Draw(FrameTracker frameTracker) { if (commandbuffers == null || commandbuffers.Length == 0) { throw new Exception($"[{nameof(Window)}] No command buffers have been created yet"); } ThrowIfDisposed(); //If the scene is dirty we re-record the command-buffers if (scene?.Dirty == true) { logicalDevice.WaitIdle(); CreateRenderCommands(scene); } int swapchainIndex = swapchain.AcquireNextImage(semaphore: imageAvailableSemaphore); //Wait for the previous submit of this buffer to be done waitFences[swapchainIndex].Wait(); waitFences[swapchainIndex].Reset(); //Give the scene a chance to prepare some data for drawing scene?.PreDraw(frameTracker, swapchainIndex); //Once we have acquired an image we submit a commandbuffer for writing to it graphicsQueue.Submit( waitSemaphore: imageAvailableSemaphore, waitDstStageMask: PipelineStages.ColorAttachmentOutput, commandBuffer: commandbuffers[swapchainIndex], signalSemaphore: renderFinishedSemaphore, fence: waitFences[swapchainIndex] ); //Once rendering to the framebuffer is done we can present it presentQueue.PresentKhr( waitSemaphore: renderFinishedSemaphore, swapchain: swapchain, imageIndex: swapchainIndex); //Set the window title mostly for debugging purposes nativeWindow.Title = $"{title} - {hostDevice.Name} - {nativeWindow.ClientRect.Size} - Fps: {frameTracker.SmoothedFps:N1}"; }
internal int AcquireNextImage(Semaphore sem) { int imageIndex = mSwapChain.AcquireNextImage(-1, sem); return(imageIndex); }