next chapter, but broken
This commit is contained in:
parent
fdc86a3c03
commit
526b9ba281
5 changed files with 47 additions and 20 deletions
|
@ -110,7 +110,7 @@ createFrames physicalDevice logicalDevice allocator descriptorPool setLayout obj
|
|||
let cameraInfo = Vk.zero
|
||||
{ Vk.buffer = allocatedBuffer cameraBuffer
|
||||
, Vk.offset = 0
|
||||
, Vk.range = fromIntegral $ sizeOf (GPUCameraData identity identity identity)
|
||||
, Vk.range = fromIntegral $ sizeOf (undefined :: GPUCameraData)
|
||||
} :: Vk.DescriptorBufferInfo
|
||||
sceneInfo = Vk.zero
|
||||
{ Vk.buffer = allocatedBuffer sceneBuffer
|
||||
|
@ -129,7 +129,7 @@ createFrames physicalDevice logicalDevice allocator descriptorPool setLayout obj
|
|||
cameraInfo
|
||||
0
|
||||
sceneWrite = writeDescriptorBuffer
|
||||
Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER -- _DYNAMIC
|
||||
Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER
|
||||
(V.head globalDescriptor)
|
||||
sceneInfo
|
||||
1
|
||||
|
@ -301,14 +301,18 @@ prepareRecording (V2 width height) commandBuffer graphicsPipeline = do
|
|||
Vk.cmdSetScissor commandBuffer 0 (V.singleton scissor)
|
||||
|
||||
pokeData
|
||||
:: FrameData
|
||||
:: (MonadResource m, MonadReader ReadState m, MonadIO m)
|
||||
=> FrameData
|
||||
-> Int
|
||||
-> GPUSceneData
|
||||
-> GPUCameraData
|
||||
-> IO ()
|
||||
-> m ()
|
||||
pokeData frame frameNumber sceneParameters cameraParameters = do
|
||||
renderObjects <- (liftIO . STM.atomically . STM.readTMVar) =<< asks renderables
|
||||
|
||||
let scenePointer = VMA.mappedData (bufferInfo $ frameSceneBuffer frame)
|
||||
memoryPointer = VMA.mappedData (bufferInfo $ frameCameraBuffer frame)
|
||||
objectPointer = VMA.mappedData (bufferInfo $ frameObjectBuffer frame)
|
||||
framed = fromIntegral frameNumber / 120
|
||||
ambient = normalize $ V4 (sin framed) 0 (cos framed) 1
|
||||
-- ambient = V4 1 0 1 1
|
||||
|
@ -316,8 +320,25 @@ pokeData frame frameNumber sceneParameters cameraParameters = do
|
|||
{ ambientColor = ambient
|
||||
}
|
||||
|
||||
poke
|
||||
(castPtr scenePointer)
|
||||
ambientParams
|
||||
V.mapM_
|
||||
(\(index, obj) -> do
|
||||
|
||||
poke (castPtr memoryPointer) cameraParameters
|
||||
let modelMatrix = GPUObjectData (objectMatrix obj)
|
||||
|
||||
liftIO $ poke
|
||||
(objectPointer `plusPtr` (index * sizeOf (undefined :: GPUObjectData)))
|
||||
modelMatrix
|
||||
)
|
||||
(V.zip
|
||||
(V.fromList [0 ..])
|
||||
renderObjects
|
||||
)
|
||||
|
||||
liftIO $ do
|
||||
poke
|
||||
(castPtr scenePointer)
|
||||
ambientParams
|
||||
|
||||
poke
|
||||
(castPtr memoryPointer)
|
||||
cameraParameters
|
||||
|
|
|
@ -9,7 +9,7 @@ import Control.Monad.Trans.Resource
|
|||
import qualified Data.Vector as V
|
||||
import Data.Maybe (fromMaybe, isNothing)
|
||||
import Data.Bits
|
||||
import Data.Word (Word32)
|
||||
import Foreign
|
||||
import Foreign.C.Types (CInt)
|
||||
import Linear
|
||||
import qualified Vulkan as Vk
|
||||
|
@ -105,9 +105,16 @@ createLogicalDevice physDevice surface = do
|
|||
{ Vk.queueCreateInfos = V.singleton (Vk.SomeStruct queueCreateInfo)
|
||||
, Vk.enabledExtensionNames = extensionNames
|
||||
}
|
||||
shaderDrawParametersFeatures = Vk.zero
|
||||
{ Vk.shaderDrawParameters = True
|
||||
} :: Vk.PhysicalDeviceShaderDrawParametersFeatures
|
||||
|
||||
(_, logDevice) <-
|
||||
Vk.withDevice physDevice deviceCreateInfo Nothing allocate
|
||||
Vk.withDevice
|
||||
physDevice
|
||||
(deviceCreateInfo Vk.::& shaderDrawParametersFeatures Vk.:& ())
|
||||
Nothing
|
||||
allocate
|
||||
|
||||
(result, formats) <- Vk.getPhysicalDeviceSurfaceFormatsKHR physDevice surface
|
||||
unless (result == Vk.SUCCESS) $
|
||||
|
|
11
src/Draw.hs
11
src/Draw.hs
|
@ -73,12 +73,11 @@ drawFrame engineData frameNumber = do
|
|||
, viewProjection = transpose $ camProjection !*! camView
|
||||
}
|
||||
|
||||
liftIO $
|
||||
pokeData
|
||||
frame
|
||||
frameNumber
|
||||
(engineSceneParameters engineData)
|
||||
cameraData
|
||||
pokeData
|
||||
frame
|
||||
frameNumber
|
||||
(engineSceneParameters engineData)
|
||||
cameraData
|
||||
|
||||
recordCommandBuffer
|
||||
(frameMainCommandBuffer frame)
|
||||
|
|
|
@ -97,7 +97,7 @@ initVulkan window = do
|
|||
(swapchain, surfaceFormat, depthImageView, depthAllocatedImage) <-
|
||||
createSwapchain vulkanSurface surfaceFormats dimensions vulkanLogicalDevice allocator
|
||||
imageViews <- getImageViewHandles swapchain surfaceFormat vulkanLogicalDevice
|
||||
meshVertexShader <- loadShader vulkanLogicalDevice "shadersrc/mesh.vert" "vert"
|
||||
meshVertexShader <- loadShader vulkanLogicalDevice "shadersrc/tri_mesh.vert" "vert"
|
||||
meshFragmentShader <- loadShader vulkanLogicalDevice "shadersrc/rainbow_lit.frag" "frag"
|
||||
renderPass <- createRenderPass vulkanLogicalDevice (Khr.format surfaceFormat) Vk.FORMAT_D32_SFLOAT
|
||||
meshLayout <- createMeshPipelineLayout
|
||||
|
@ -219,7 +219,7 @@ initDescriptors device = do
|
|||
, Vk.descriptorCount = 10
|
||||
}
|
||||
, Vk.zero
|
||||
{ Vk.type' = Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER -- _DYNAMIC
|
||||
{ Vk.type' = Vk.DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
|
||||
, Vk.descriptorCount = 10
|
||||
}
|
||||
, Vk.zero
|
||||
|
|
|
@ -230,8 +230,8 @@ data GPUCameraData = GPUCameraData
|
|||
|
||||
instance Storable GPUCameraData where
|
||||
|
||||
sizeOf (GPUCameraData pview pprojection pviewProjection) =
|
||||
sizeOf pview + sizeOf pprojection + sizeOf pviewProjection
|
||||
sizeOf _ =
|
||||
3* sizeOf (undefined :: M44 Float)
|
||||
|
||||
alignment _ = 0
|
||||
|
||||
|
|
Loading…
Reference in a new issue