33module Ghengin.Core.Mesh
44 ( Mesh (.. ) -- Export these from an Internals module, not from here
55 , Some (.. )
6+
67 , createMesh
78 , createMeshWithIxs
8- -- , calculateFlatNormals
9- -- , calculateSmoothNormals
9+
10+ , createMeshSV
11+ , createMeshWithIxsSV
12+
1013 , freeMesh
1114
1215 , meshId
@@ -15,7 +18,6 @@ module Ghengin.Core.Mesh
1518 , module Ghengin.Core.Mesh.Vertex
1619 ) where
1720
18- import GHC.Stack
1921import Ghengin.Core.Prelude as Linear
2022import Data.Unique
2123
@@ -40,17 +42,6 @@ import qualified Data.IntMap.Strict as IM
4042
4143import qualified Data.Linear.Alias as Alias
4244
43- {-
44- Note [Meshes]
45- ~~~~~~~~~~~~~
46-
47- OUTDATED!
48-
49- All meshes are freed when the window is closed. However, if you change/discard a
50- mesh during the game you must free it explicitly. TODO: Enforce it somehow: linear types+reference counting
51-
52- -}
53-
5445type Mesh :: [Type ] -- ^ Vertex attributes
5546 -> [Type ] -- ^ Mesh properties
5647 -> Type
@@ -126,11 +117,18 @@ createMesh :: (CompatibleMesh props π, CompatibleVertex ts π, Storable (Vertex
126117 -- ^ The render pipeline
127118 ⊸ PropertyBindings props
128119 -- ^ The 'PropertyBindings' for the properties of this mesh (the second type argument to 'Mesh')
129- ⊸ [Vertex ts ] -- TODO: Use Vector
120+ ⊸ [Vertex ts ]
130121 -- ^ Vertices
131122 -> Renderer (Mesh ts props , RenderPipeline π bs )
132- createMesh (RenderProperty pr rps) props0 vs = createMesh rps props0 vs >>= \ case (m, rp) -> pure (m, RenderProperty pr rp)
133- createMesh (RenderPipeline gpip rpass (rdset, rres, (Ur bmap), dpool0) shaders uq) props0 (SV. fromList -> vs) = enterD " createMesh" Linear. do
123+ createMesh a b c = createMeshSV a b (SV. fromList c)
124+
125+ -- | Like 'createMesh', but takes a storable vector directly rather than a list.
126+ createMeshSV
127+ :: (CompatibleMesh props π , CompatibleVertex ts π , Storable (Vertex ts ))
128+ => RenderPipeline π bs ⊸ PropertyBindings props ⊸ SV. Vector (Vertex ts )
129+ -> Renderer (Mesh ts props , RenderPipeline π bs )
130+ createMeshSV (RenderProperty pr rps) props0 vs = createMeshSV rps props0 vs >>= \ case (m, rp) -> pure (m, RenderProperty pr rp)
131+ createMeshSV (RenderPipeline gpip rpass (rdset, rres, (Ur bmap), dpool0) shaders uq) props0 vs = enterD " createMesh" Linear. do
134132 Ur uniq <- liftSystemIOU newUnique
135133 vertexBuffer <- createVertexBuffer vs
136134
@@ -142,16 +140,23 @@ createMesh (RenderPipeline gpip rpass (rdset, rres, (Ur bmap), dpool0) shaders u
142140
143141-- | Like 'createMesh', but create the mesh using a vertex buffer created from
144142-- the vertices and an indexbuffer created from the indices
145- createMeshWithIxs :: HasCallStack => (CompatibleMesh props π , CompatibleVertex ts π , Storable (Vertex ts ))
143+ createMeshWithIxs :: (CompatibleMesh props π , CompatibleVertex ts π , Storable (Vertex ts ))
146144 => RenderPipeline π bs
147145 ⊸ PropertyBindings props
148- ⊸ [Vertex ts ] -- TODO: Use Vector
146+ ⊸ [Vertex ts ]
149147 -- ^ Vertices
150- -> [Int32 ] -- TODO: Use Vector
148+ -> [Int32 ]
151149 -- ^ Indices
152150 -> Renderer (Mesh ts props , RenderPipeline π bs )
153- createMeshWithIxs (RenderProperty pr rps) props0 vs ixs = createMeshWithIxs rps props0 vs ixs >>= \ case (m, rp) -> pure (m, RenderProperty pr rp)
154- createMeshWithIxs (RenderPipeline gpip rpass (rdset, rres, (Ur bmap), dpool0) shaders uq) props0 (SV. fromList -> vertices) (SV. fromList -> ixs) = enterD " createMeshWithIxs" Linear. do
151+ createMeshWithIxs a b c d = createMeshWithIxsSV a b (SV. fromList c) (SV. fromList d)
152+
153+ createMeshWithIxsSV
154+ :: (CompatibleMesh props π , CompatibleVertex ts π , Storable (Vertex ts ))
155+ => RenderPipeline π bs ⊸ PropertyBindings props
156+ ⊸ SV. Vector (Vertex ts ) -> SV. Vector Int32
157+ -> Renderer (Mesh ts props , RenderPipeline π bs )
158+ createMeshWithIxsSV (RenderProperty pr rps) props0 vs ixs = createMeshWithIxsSV rps props0 vs ixs >>= \ case (m, rp) -> pure (m, RenderProperty pr rp)
159+ createMeshWithIxsSV (RenderPipeline gpip rpass (rdset, rres, (Ur bmap), dpool0) shaders uq) props0 vertices ixs = enterD " createMeshWithIxs" Linear. do
155160 Ur uniq <- liftSystemIOU newUnique
156161 vertexBuffer <- createVertexBuffer vertices
157162 indexBuffer <- createIndex32Buffer ixs
@@ -199,5 +204,3 @@ freeMesh mesh = Linear.do
199204 Alias. forget ds >> destroyDeviceLocalBuffer vb >> destroyDeviceLocalBuffer ib
200205 MeshProperty prop xs ->
201206 Alias. forget prop >> freeMesh xs
202-
203- -- TODO: Nub vertices (make indexes pointing at different vertices which are equal to point at the same vertice and remove the other)?
0 commit comments