Skip to content

Commit

Permalink
Draw blank screen with render pipeline!
Browse files Browse the repository at this point in the history
The linear types are finally paying off (GREAT!) in handling references
to pipelines and such, and guaranteeing they are freed exactly once. I'm
getting no runtime errors at all :)
  • Loading branch information
alt-romes committed Oct 11, 2023
1 parent 1476cb4 commit 8243d84
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ghengin-core/ghengin-core/Ghengin/Core/Render/Packet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ described in bytes.
-}

-- TODO: Each render packet is then assigned with an ID and sorted in an optimal draw order.
-- Alternative: Meshes, Materials and RenderPipelines have an Ord instance and we make a 3-layer map
-- Alternative: Meshes, Materials and RenderPipelines have an Ord instance and we make a 3-layer map <-- this is what we've done...

-- | Render packet wrapper that creates the key identifier.
-- {-# DEPRECATED renderPacket "FIXME: Compute materialUID" #-}
Expand Down
20 changes: 20 additions & 0 deletions ghengin-core/ghengin-core/Ghengin/Core/Render/Queue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ instance Monoid (RenderQueue α) where
-- fromList = foldr ((<>) . (`insert` mempty)) mempty :)
-- {-# INLINE fromList #-}

-- | ... We assume there are no two pipelines with the exact same shaders
newtype PipelineKey π p = UnsafePipelineKey TypeRep

-- | Inserts a pipeline in a render queue, and returns a pipeline key indexing
-- into that render queue.
insertPipeline :: forall π p α. Typeable π
=> RenderPipeline π p
RenderQueue α
(RenderQueue α, Ur (PipelineKey π p))
insertPipeline
-- Map.insert isn't linear still, so...
= Unsafe.toLinear2 \pipeline (RenderQueue q) ->
let pkey = typeRep (Proxy @π)
rq' = RenderQueue $
M.insertWith
(\_ _ -> error "Inserting a duplicate pipeline??")
pkey
(Some2 pipeline, M.empty)
q
in (rq', Ur $ UnsafePipelineKey pkey)

-- TODO: Rather, to create a renderpacket we need a render queue, since we
-- extract the render key from the render queue and the references into the
Expand Down
7 changes: 4 additions & 3 deletions ghengin-games/planets-core/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ main = do
pipeline <- (makeMainPipeline )
(p1mesh, Ur minmax) <- newPlanetMesh defaultPlanetSettings
(pmat, pipeline) <- newPlanetMaterial minmax tex pipeline
(rq, Ur pkey) <- pure (insertPipeline pipeline LMon.mempty)

rq <- gameLoop currTime LMon.mempty
rq' <- gameLoop currTime rq

(freeMaterial pmat )
(freeMesh p1mesh )
(freeRenderQueue rq )
(destroyRenderPipeline pipeline )
(freeRenderQueue rq' )
-- (destroyRenderPipeline pipeline ↑)

return (Ur ())

0 comments on commit 8243d84

Please sign in to comment.