diff --git a/ghengin-core/ghengin-core/Ghengin/Core/Render/Packet.hs b/ghengin-core/ghengin-core/Ghengin/Core/Render/Packet.hs index 373c994..136a16c 100644 --- a/ghengin-core/ghengin-core/Ghengin/Core/Render/Packet.hs +++ b/ghengin-core/ghengin-core/Ghengin/Core/Render/Packet.hs @@ -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" #-} diff --git a/ghengin-core/ghengin-core/Ghengin/Core/Render/Queue.hs b/ghengin-core/ghengin-core/Ghengin/Core/Render/Queue.hs index 8ae01d0..d3ea6f2 100644 --- a/ghengin-core/ghengin-core/Ghengin/Core/Render/Queue.hs +++ b/ghengin-core/ghengin-core/Ghengin/Core/Render/Queue.hs @@ -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 diff --git a/ghengin-games/planets-core/Main.hs b/ghengin-games/planets-core/Main.hs index 2d4b183..c1e6a8f 100644 --- a/ghengin-games/planets-core/Main.hs +++ b/ghengin-games/planets-core/Main.hs @@ -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 ())