From cec99c0b6c2638d9d13cf717c7388c6f2215e2d2 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sat, 29 Apr 2023 18:52:49 +0200 Subject: [PATCH] more restructuring --- src/CommandBuffer.hs | 30 +++--------------------------- src/Draw.hs | 31 +++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/CommandBuffer.hs b/src/CommandBuffer.hs index cbf0d29..8d989f6 100644 --- a/src/CommandBuffer.hs +++ b/src/CommandBuffer.hs @@ -172,9 +172,7 @@ recordCommandBuffer -> Vk.Framebuffer -> V2 CInt -> Vk.Pipeline - -> GPUSceneData -> FrameData - -> Int -> m () recordCommandBuffer commandBuffer @@ -182,13 +180,9 @@ recordCommandBuffer frameBuffer (V2 width height) graphicsPipeline - sceneParameters frame - frameNumber = do - liftIO $ pokeData frame frameNumber sceneParameters (width, height) - let commandBufferBeginInfo = Vk.zero { Vk.flags = Vk.COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT , Vk.inheritanceInfo = Nothing @@ -313,9 +307,9 @@ pokeData :: FrameData -> Int -> GPUSceneData - -> (CInt, CInt) + -> GPUCameraData -> IO () -pokeData frame frameNumber sceneParameters (width, height) = do +pokeData frame frameNumber sceneParameters cameraParameters = do let scenePointer = VMA.mappedData (bufferInfo $ frameSceneBuffer frame) memoryPointer = VMA.mappedData (bufferInfo $ frameCameraBuffer frame) framed = fromIntegral frameNumber / 120 @@ -325,26 +319,8 @@ pokeData frame frameNumber sceneParameters (width, height) = do { ambientColor = ambient } - camPosition = V3 - (-10 * sin (fromIntegral frameNumber / 90)) - (-2) - (-10 * cos (fromIntegral frameNumber / 90)) - camCenter = V3 0 0 0 - camUp = V3 0 1 0 - camView = lookAt camPosition camCenter camUp - camProjection = perspective - (pi/4) - (fromIntegral width / fromIntegral height) - 0.1 - 200 - cameraData = GPUCameraData - { view = transpose camView - , projection = transpose camProjection - , viewProjection = transpose $ camProjection !*! camView - } - poke (castPtr scenePointer) ambientParams - poke (castPtr memoryPointer) cameraData + poke (castPtr memoryPointer) cameraParameters diff --git a/src/Draw.hs b/src/Draw.hs index dfdbd67..6f74bb8 100644 --- a/src/Draw.hs +++ b/src/Draw.hs @@ -10,6 +10,7 @@ import Control.Monad.Reader import Control.Monad.Trans.Resource import qualified Data.Map.Strict as M import qualified Data.Vector as V +import Linear import qualified Vulkan.Core10 as Vk import qualified Vulkan.Extensions.VK_KHR_swapchain as Khr import qualified Vulkan.CStruct.Extends as Vk @@ -48,22 +49,44 @@ drawFrame engineData frameNumber = do unless (imageResult == Vk.SUCCESS) $ error "drawFrame: Failed acquiring next image from swapchain" - -- liftIO $ putStrLn "resetting command buffer" Vk.resetCommandBuffer (frameMainCommandBuffer frame) (Vk.CommandBufferResetFlagBits 0) matLibrary <- (liftIO . STM.atomically. STM.readTMVar) =<< asks materialLibrary - -- liftIO $ putStrLn "recording command buffer" + let (V2 width height) = engineWindowDimensions engineData + camPosition = V3 + (-10 * sin (fromIntegral frameNumber / 90)) + (-2) + (-10 * cos (fromIntegral frameNumber / 90)) + camCenter = V3 0 0 0 + camUp = V3 0 1 0 + camView = lookAt camPosition camCenter camUp + camProjection = perspective + (pi/4) + (fromIntegral width / fromIntegral height) + 0.1 + 200 + cameraData = GPUCameraData + { view = transpose camView + , projection = transpose camProjection + , viewProjection = transpose $ camProjection !*! camView + } + + liftIO $ + pokeData + frame + frameNumber + (engineSceneParameters engineData) + cameraData + recordCommandBuffer (frameMainCommandBuffer frame) (engineRenderPass engineData) (engineFramebuffers engineData V.! fromIntegral index) (engineWindowDimensions engineData) (materialPipeline $ matLibrary M.! "defaultMesh") - (engineSceneParameters engineData) frame - frameNumber let submitInfo = Vk.zero { Vk.waitSemaphores =