private void ClearImage_Paint(object sender, PaintEventArgs e) { System.Drawing.Imaging.BitmapData bitmapData = _Bitmap.LockBits(new Rectangle(0, 0, _Bitmap.Width, _Bitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); _Queue.Submit(new VkSubmitInfo[] { new VkSubmitInfo() { commandBuffers = new VkCommandBuffer[] { _CommandBuffer } } }, _Fence); if (_Fence.WaitForFence(1000)) { // If the submission completed we copy the image data into the bitmap data Copy(bitmapData.Scan0, _ImagePtr, (int)_Image.MemoryRequirements.size); } _Bitmap.UnlockBits(bitmapData); e.Graphics.DrawImage(_Bitmap, new Rectangle(0, 0, Width, Height)); }
private void Triangle_Paint(object sender, PaintEventArgs e) { System.Drawing.Imaging.BitmapData bitmapData = _Bitmap.LockBits(new Rectangle(0, 0, _Bitmap.Width, _Bitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); _Queue.Submit(new VkSubmitInfo[] { new VkSubmitInfo() { commandBuffers = new VkCommandBuffer[] { _CommandBuffer } } }, _Fence); if (_Fence.WaitForFence(1000)) { // If the submission completed we copy the image data into the bitmap data _Framebuffer.BlitFramebufferToPointer(_Queue, bitmapData.Scan0); } else { this.Invalidate(); } _Bitmap.UnlockBits(bitmapData); e.Graphics.DrawImage(_Bitmap, new Rectangle(0, 0, Width, Height)); }
void MainLoop() { var waitSemaphores = new List <VkSemaphore> { imageAvailableSemaphore }; var waitStages = new List <VkPipelineStageFlags> { VkPipelineStageFlags.ColorAttachmentOutputBit }; var signalSemaphores = new List <VkSemaphore> { renderFinishedSemaphore }; var swapchains = new List <VkSwapchain> { swapchain }; var commandBuffer = new List <VkCommandBuffer>() { null }; var index = new List <int>() { 0 }; var submitInfo = new VkSubmitInfo(); submitInfo.waitSemaphores = waitSemaphores; submitInfo.waitDstStageMask = waitStages; submitInfo.commandBuffers = commandBuffer; submitInfo.signalSemaphores = signalSemaphores; var presentInfo = new VkPresentInfo(); presentInfo.waitSemaphores = signalSemaphores; presentInfo.swapchains = swapchains; presentInfo.imageIndices = index; var submitInfos = new List <VkSubmitInfo> { submitInfo }; GLFW.ShowWindow(window); while (true) { GLFW.PollEvents(); if (GLFW.GetKey(window, CSGL.Input.KeyCode.Enter) == CSGL.Input.KeyAction.Press) { break; } if (GLFW.WindowShouldClose(window)) { break; } if (recreateSwapchainFlag) { recreateSwapchainFlag = false; RecreateSwapchain(); } int imageIndex; var result = swapchain.AcquireNextImage(-1, imageAvailableSemaphore, null, out imageIndex); if (result == VkResult.ErrorOutOfDateKhr || result == VkResult.SuboptimalKhr) { RecreateSwapchain(); continue; } commandBuffer[0] = commandBuffers[(int)imageIndex]; swapchains[0] = swapchain; index[0] = imageIndex; graphicsQueue.Submit(submitInfos, null); result = presentQueue.Present(presentInfo); if (result == VkResult.ErrorOutOfDateKhr || result == VkResult.SuboptimalKhr) { RecreateSwapchain(); } } device.WaitIdle(); }
void MainLoop() { var waitSemaphores = new List <VkSemaphore> { imageAvailableSemaphore }; var waitStages = new List <VkPipelineStageFlags> { VkPipelineStageFlags.ColorAttachmentOutputBit }; var signalSemaphores = new List <VkSemaphore> { renderFinishedSemaphore }; var swapchains = new List <VkSwapchain> { swapchain }; var commandBuffers = new List <VkCommandBuffer> { null }; var index = new List <int> { 0 }; var submitInfo = new VkSubmitInfo(); submitInfo.waitSemaphores = waitSemaphores; submitInfo.waitDstStageMask = waitStages; submitInfo.commandBuffers = commandBuffers; submitInfo.signalSemaphores = signalSemaphores; var presentInfo = new VkPresentInfo(); presentInfo.waitSemaphores = signalSemaphores; presentInfo.swapchains = swapchains; presentInfo.imageIndices = index; var submitInfos = new List <VkSubmitInfo> { submitInfo }; GLFW.ShowWindow(window.Native); generator.Start(); while (!window.ShouldClose) { GLFW.PollEvents(); UpdateUniformBuffer(); if (recreateSwapchainFlag) { recreateSwapchainFlag = false; RecreateSwapchain(); } int imageIndex; var result = swapchain.AcquireNextImage(-1, imageAvailableSemaphore, null, out imageIndex); Interop.Copy(generator.Pixels, stagingBufferPtr); commandBuffers[0] = this.commandBuffers[(int)imageIndex]; swapchains[0] = swapchain; index[0] = imageIndex; graphicsQueue.Submit(submitInfos, null); result = presentQueue.Present(presentInfo); } device.WaitIdle(); }