more restructuring

This commit is contained in:
nek0 2023-04-29 18:52:49 +02:00
parent b3a1545fd2
commit cec99c0b6c
2 changed files with 30 additions and 31 deletions

View file

@ -172,9 +172,7 @@ recordCommandBuffer
-> Vk.Framebuffer -> Vk.Framebuffer
-> V2 CInt -> V2 CInt
-> Vk.Pipeline -> Vk.Pipeline
-> GPUSceneData
-> FrameData -> FrameData
-> Int
-> m () -> m ()
recordCommandBuffer recordCommandBuffer
commandBuffer commandBuffer
@ -182,13 +180,9 @@ recordCommandBuffer
frameBuffer frameBuffer
(V2 width height) (V2 width height)
graphicsPipeline graphicsPipeline
sceneParameters
frame frame
frameNumber
= do = do
liftIO $ pokeData frame frameNumber sceneParameters (width, height)
let commandBufferBeginInfo = Vk.zero let commandBufferBeginInfo = Vk.zero
{ Vk.flags = Vk.COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT { Vk.flags = Vk.COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
, Vk.inheritanceInfo = Nothing , Vk.inheritanceInfo = Nothing
@ -313,9 +307,9 @@ pokeData
:: FrameData :: FrameData
-> Int -> Int
-> GPUSceneData -> GPUSceneData
-> (CInt, CInt) -> GPUCameraData
-> IO () -> IO ()
pokeData frame frameNumber sceneParameters (width, height) = do pokeData frame frameNumber sceneParameters cameraParameters = do
let scenePointer = VMA.mappedData (bufferInfo $ frameSceneBuffer frame) let scenePointer = VMA.mappedData (bufferInfo $ frameSceneBuffer frame)
memoryPointer = VMA.mappedData (bufferInfo $ frameCameraBuffer frame) memoryPointer = VMA.mappedData (bufferInfo $ frameCameraBuffer frame)
framed = fromIntegral frameNumber / 120 framed = fromIntegral frameNumber / 120
@ -325,26 +319,8 @@ pokeData frame frameNumber sceneParameters (width, height) = do
{ ambientColor = ambient { 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 poke
(castPtr scenePointer) (castPtr scenePointer)
ambientParams ambientParams
poke (castPtr memoryPointer) cameraData poke (castPtr memoryPointer) cameraParameters

View file

@ -10,6 +10,7 @@ import Control.Monad.Reader
import Control.Monad.Trans.Resource import Control.Monad.Trans.Resource
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
import qualified Data.Vector as V import qualified Data.Vector as V
import Linear
import qualified Vulkan.Core10 as Vk import qualified Vulkan.Core10 as Vk
import qualified Vulkan.Extensions.VK_KHR_swapchain as Khr import qualified Vulkan.Extensions.VK_KHR_swapchain as Khr
import qualified Vulkan.CStruct.Extends as Vk import qualified Vulkan.CStruct.Extends as Vk
@ -48,22 +49,44 @@ drawFrame engineData frameNumber = do
unless (imageResult == Vk.SUCCESS) $ unless (imageResult == Vk.SUCCESS) $
error "drawFrame: Failed acquiring next image from swapchain" error "drawFrame: Failed acquiring next image from swapchain"
-- liftIO $ putStrLn "resetting command buffer"
Vk.resetCommandBuffer Vk.resetCommandBuffer
(frameMainCommandBuffer frame) (Vk.CommandBufferResetFlagBits 0) (frameMainCommandBuffer frame) (Vk.CommandBufferResetFlagBits 0)
matLibrary <- (liftIO . STM.atomically. STM.readTMVar) =<< asks materialLibrary 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 recordCommandBuffer
(frameMainCommandBuffer frame) (frameMainCommandBuffer frame)
(engineRenderPass engineData) (engineRenderPass engineData)
(engineFramebuffers engineData V.! fromIntegral index) (engineFramebuffers engineData V.! fromIntegral index)
(engineWindowDimensions engineData) (engineWindowDimensions engineData)
(materialPipeline $ matLibrary M.! "defaultMesh") (materialPipeline $ matLibrary M.! "defaultMesh")
(engineSceneParameters engineData)
frame frame
frameNumber
let submitInfo = Vk.zero let submitInfo = Vk.zero
{ Vk.waitSemaphores = { Vk.waitSemaphores =