Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
 public static bool GetKey(KeyCode keyCode)
 {
     return(GLFW.GetKey(Game.Game.Window.Handle, (int)keyCode));
 }