split up and clean
This commit is contained in:
parent
cde6d15245
commit
b3a1545fd2
2 changed files with 43 additions and 46 deletions
|
@ -5,7 +5,6 @@
|
||||||
module CommandBuffer where
|
module CommandBuffer where
|
||||||
|
|
||||||
import qualified Control.Concurrent.STM as STM
|
import qualified Control.Concurrent.STM as STM
|
||||||
import Control.Exception (bracket)
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import Control.Monad.Reader
|
import Control.Monad.Reader
|
||||||
|
@ -173,7 +172,6 @@ recordCommandBuffer
|
||||||
-> Vk.Framebuffer
|
-> Vk.Framebuffer
|
||||||
-> V2 CInt
|
-> V2 CInt
|
||||||
-> Vk.Pipeline
|
-> Vk.Pipeline
|
||||||
-> VMA.Allocator
|
|
||||||
-> GPUSceneData
|
-> GPUSceneData
|
||||||
-> FrameData
|
-> FrameData
|
||||||
-> Int
|
-> Int
|
||||||
|
@ -184,12 +182,13 @@ recordCommandBuffer
|
||||||
frameBuffer
|
frameBuffer
|
||||||
(V2 width height)
|
(V2 width height)
|
||||||
graphicsPipeline
|
graphicsPipeline
|
||||||
allocator
|
|
||||||
sceneParameters
|
sceneParameters
|
||||||
frame
|
frame
|
||||||
frameNumber
|
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
|
||||||
|
@ -221,62 +220,21 @@ recordCommandBuffer
|
||||||
liftIO $
|
liftIO $
|
||||||
prepareRecording width height commandBuffer renderPass frameBuffer graphicsPipeline
|
prepareRecording width height commandBuffer renderPass frameBuffer graphicsPipeline
|
||||||
|
|
||||||
let framed = fromIntegral frameNumber / 120
|
|
||||||
ambient = normalize $ V4 (sin framed) 0 (cos framed) 1
|
|
||||||
-- ambient = V4 1 0 1 1
|
|
||||||
ambientParams = sceneParameters
|
|
||||||
{ ambientColor = ambient
|
|
||||||
}
|
|
||||||
|
|
||||||
liftIO $ do
|
|
||||||
let scenePointer = VMA.mappedData (bufferInfo (frameSceneBuffer frame))
|
|
||||||
|
|
||||||
liftIO $ poke
|
|
||||||
(castPtr scenePointer)
|
|
||||||
ambientParams
|
|
||||||
|
|
||||||
renderObjects <- (liftIO . STM.atomically . STM.readTMVar) =<< asks renderables
|
renderObjects <- (liftIO . STM.atomically . STM.readTMVar) =<< asks renderables
|
||||||
meshMap <- (liftIO . STM.atomically . STM.readTMVar) =<< asks meshLibrary
|
meshMap <- (liftIO . STM.atomically . STM.readTMVar) =<< asks meshLibrary
|
||||||
|
|
||||||
V.mapM_
|
V.mapM_
|
||||||
(\(index, RenderObject meshID materialID modelMatrix) -> do
|
(\(index, RenderObject meshID materialID modelMatrix) -> do
|
||||||
|
|
||||||
let 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
|
|
||||||
|
|
||||||
materialMap <- (liftIO . STM.atomically . STM.readTMVar) =<< asks materialLibrary
|
materialMap <- (liftIO . STM.atomically . STM.readTMVar) =<< asks materialLibrary
|
||||||
|
|
||||||
let cameraData = GPUCameraData
|
let constants = MeshPushConstants
|
||||||
{ view = transpose camView
|
|
||||||
, projection = transpose camProjection
|
|
||||||
, viewProjection = transpose $ camProjection !*! camView
|
|
||||||
}
|
|
||||||
|
|
||||||
constants = MeshPushConstants
|
|
||||||
{ meshPushData = V4 0 0 0 0
|
{ meshPushData = V4 0 0 0 0
|
||||||
, meshRenderMatrix = transpose modelMatrix
|
, meshRenderMatrix = transpose modelMatrix
|
||||||
}
|
}
|
||||||
mesh = meshMap M.! meshID
|
mesh = meshMap M.! meshID
|
||||||
material = materialMap M.! materialID
|
material = materialMap M.! materialID
|
||||||
|
|
||||||
liftIO $ VMA.withMappedMemory
|
|
||||||
allocator
|
|
||||||
(bufferAllocation $ frameCameraBuffer frame)
|
|
||||||
bracket
|
|
||||||
$ \memoryPointer ->
|
|
||||||
|
|
||||||
liftIO $ poke (castPtr memoryPointer) cameraData
|
|
||||||
|
|
||||||
Vk.cmdBindPipeline commandBuffer Vk.PIPELINE_BIND_POINT_GRAPHICS (materialPipeline material)
|
Vk.cmdBindPipeline commandBuffer Vk.PIPELINE_BIND_POINT_GRAPHICS (materialPipeline material)
|
||||||
|
|
||||||
Vk.cmdBindDescriptorSets
|
Vk.cmdBindDescriptorSets
|
||||||
|
@ -350,3 +308,43 @@ prepareRecording width height commandBuffer renderPass frameBuffer graphicsPipel
|
||||||
|
|
||||||
Vk.cmdSetViewport commandBuffer 0 (V.singleton viewport)
|
Vk.cmdSetViewport commandBuffer 0 (V.singleton viewport)
|
||||||
Vk.cmdSetScissor commandBuffer 0 (V.singleton scissor)
|
Vk.cmdSetScissor commandBuffer 0 (V.singleton scissor)
|
||||||
|
|
||||||
|
pokeData
|
||||||
|
:: FrameData
|
||||||
|
-> Int
|
||||||
|
-> GPUSceneData
|
||||||
|
-> (CInt, CInt)
|
||||||
|
-> IO ()
|
||||||
|
pokeData frame frameNumber sceneParameters (width, height) = do
|
||||||
|
let scenePointer = VMA.mappedData (bufferInfo $ frameSceneBuffer frame)
|
||||||
|
memoryPointer = VMA.mappedData (bufferInfo $ frameCameraBuffer frame)
|
||||||
|
framed = fromIntegral frameNumber / 120
|
||||||
|
ambient = normalize $ V4 (sin framed) 0 (cos framed) 1
|
||||||
|
-- ambient = V4 1 0 1 1
|
||||||
|
ambientParams = sceneParameters
|
||||||
|
{ 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
|
||||||
|
|
|
@ -61,7 +61,6 @@ drawFrame engineData frameNumber = do
|
||||||
(engineFramebuffers engineData V.! fromIntegral index)
|
(engineFramebuffers engineData V.! fromIntegral index)
|
||||||
(engineWindowDimensions engineData)
|
(engineWindowDimensions engineData)
|
||||||
(materialPipeline $ matLibrary M.! "defaultMesh")
|
(materialPipeline $ matLibrary M.! "defaultMesh")
|
||||||
(engineAllocator engineData)
|
|
||||||
(engineSceneParameters engineData)
|
(engineSceneParameters engineData)
|
||||||
frame
|
frame
|
||||||
frameNumber
|
frameNumber
|
||||||
|
|
Loading…
Reference in a new issue