|
| 1 | +{-# LANGUAGE OverloadedRecordDot #-} |
| 2 | +{-# LANGUAGE OverloadedStrings #-} |
| 3 | +{-# LANGUAGE UndecidableInstances #-} |
| 4 | +{-# LANGUAGE PartialTypeSignatures #-} |
| 5 | +{-# LANGUAGE PostfixOperators #-} |
| 6 | +{-# OPTIONS_GHC -Wno-name-shadowing #-} |
| 7 | +module Main where |
| 8 | + |
| 9 | +import Ghengin.Core |
| 10 | +import Ghengin.Core.Prelude as Linear |
| 11 | +import Ghengin.Core.Render |
| 12 | +import Ghengin.Core.Render.Pipeline |
| 13 | +import Ghengin.Core.Render.Queue |
| 14 | +import qualified Data.Monoid.Linear as LMon |
| 15 | +import qualified Prelude |
| 16 | +import qualified Data.Linear.Alias as Alias |
| 17 | +import Shaders |
| 18 | + |
| 19 | +import qualified Ghengin.DearImGui.Vulkan as ImGui |
| 20 | + |
| 21 | +-------------------------------------------------------------------------------- |
| 22 | +-- Bufferless rendering as seen in: |
| 23 | +-- https://www.saschawillems.de/blog/2016/08/13/vulkan-tutorial-on-rendering-a-fullscreen-quad-without-buffers/ |
| 24 | +-------------------------------------------------------------------------------- |
| 25 | + |
| 26 | +gameLoop :: Alias RenderPass ⊸ RenderQueue () ⊸ Core (RenderQueue ()) |
| 27 | +gameLoop rp rq = Linear.do |
| 28 | + should_close <- (shouldCloseWindow ↑) |
| 29 | + if should_close then (Alias.forget rp ↑) >> return rq else Linear.do |
| 30 | + (pollWindowEvents ↑) |
| 31 | + |
| 32 | + -- Prepare Imgui data |
| 33 | + ImGui.withNewFrame $ do |
| 34 | + |
| 35 | + ImGui.showDemoWindow |
| 36 | + |
| 37 | + (rp, rq) <- renderWith $ Linear.do |
| 38 | + |
| 39 | + (rp1, rp2) <- lift (Alias.share rp) |
| 40 | + |
| 41 | + Ur extent <- lift getRenderExtent |
| 42 | + |
| 43 | + renderPassCmd extent rp1 $ Linear.do |
| 44 | + |
| 45 | + rq <- renderQueueCmd rq |
| 46 | + draw 3 |
| 47 | + |
| 48 | + -- Render Imgui data! |
| 49 | + ImGui.renderDrawData |
| 50 | + |
| 51 | + return (rp2, rq) |
| 52 | + |
| 53 | + gameLoop rp rq |
| 54 | + |
| 55 | +main :: Prelude.IO () |
| 56 | +main = do |
| 57 | + withLinearIO $ |
| 58 | + runCore (width, height) Linear.do |
| 59 | + |
| 60 | + (rp1, rp2) <- (Alias.share =<< createSimpleRenderPass ↑) |
| 61 | + |
| 62 | + -- Init imgui |
| 63 | + (rp1, imctx) <- (Alias.useM rp1 ImGui.initImGui ↑) |
| 64 | + |
| 65 | + pipeline <- (makeRenderPipelineWith defaultGraphicsPipelineSettings{cullMode=CullFront} rp1 shaderPipelineSimple GHNil ↑) |
| 66 | + (rq, Ur pkey) <- pure (insertPipeline pipeline LMon.mempty) |
| 67 | + |
| 68 | + rq <- gameLoop rp2 rq |
| 69 | + |
| 70 | + (freeRenderQueue rq ↑) |
| 71 | + -- Then destroy it |
| 72 | + (ImGui.destroyImCtx imctx ↑) |
| 73 | + |
| 74 | + return (Ur ()) |
| 75 | + |
| 76 | + |
| 77 | + |
0 commit comments