Refactor shapes, prepare for different normals at single vertex pos

This commit is contained in:
2023-03-15 21:43:00 +00:00
parent 989140d46e
commit 249262b2b6
7 changed files with 114 additions and 136 deletions
+15 -16
View File
@@ -85,7 +85,7 @@ pokeW ptr i' ((V2 a b,V2 c d),V4 e f g h) = do
pokeShape :: Ptr Float -> Ptr GLushort -> Ptr GLushort
-> (Int,Int,Int)
-> [ShapeObj]
-> [Surface]
-> IO (Int,Int,Int)
pokeShape ptr iptr ieptr is = VFSM.foldlM' (pokeShapeObj ptr iptr ieptr) is . VFSM.fromList
@@ -94,22 +94,23 @@ pokeShapeObj
-> Ptr GLushort
-> Ptr GLushort
-> (Int,Int,Int)
-> ShapeObj
-> Surface
-> IO (Int,Int,Int)
{-# INLINE pokeShapeObj #-}
pokeShapeObj ptr iptr ieptr counts (ShapeObj shtype shVerts) = case shtype of
TopPrism size -> pokeTopPrism midp (size - 2) ptr iptr ieptr counts (VFSM.fromList shVerts)
pokeShapeObj ptr iptr ieptr counts (Surface shtype shVerts col) = case shtype of
TopPrism size -> pokeTopPrism midp col (size - 2) ptr iptr ieptr counts (VFSM.fromList shVerts)
-- TopCylinder size -> pokeTopPrism midp (size - 2) ptr iptr ieptr counts (VFSM.fromList shVerts)
where
midp = centroidNum $ map _svPos shVerts
midp = centroidNum shVerts
pokeTopPrism :: Point3 -> Int -> Ptr Float -> Ptr GLushort
pokeTopPrism :: Point3 -> Point4 -> Int -> Ptr Float -> Ptr GLushort
-> Ptr GLushort
-> (Int,Int,Int)
-> VFSM.Stream IO ShapeV
-> VFSM.Stream IO Point3
-> IO (Int,Int,Int)
{-# INLINE pokeTopPrism #-}
pokeTopPrism cp size ptr iptr ieptr (nv,nshapeindices,nedgeindices) svs = do
nv' <- VFSM.foldlM' (pokeJustV cp ptr) nv svs
pokeTopPrism cp col size ptr iptr ieptr (nv,nshapeindices,nedgeindices) svs = do
nv' <- VFSM.foldlM' (pokeJustV cp col ptr) nv svs
nshapeindices' <- UV.foldM' (pokeTopPrismIndex nv iptr) nshapeindices
(memoTopPrismIndices V.! size)
nedgeindices' <- UV.foldM' (pokeTopPrismEdgeIndex nv ieptr) nedgeindices
@@ -170,22 +171,20 @@ topPrismIndices n = concatMap f [1..n-2] -- triangles on top face
-- and just doing two pokes rather than seven
-- (especially if adding normal data)
pokeJustV :: Point3
-> Point4
-> Ptr Float
-> Int
-> ShapeV
-> Point3
-> IO Int
{-# INLINE pokeJustV #-}
pokeJustV cp ptr nv sh = do
pokeJustV cp col ptr nv sh = do
zipWithM_ f [0..] [x,y,z,1,r,g,b,a,nx,ny,nz,1]
return (nv + 1)
where
f i = pokeElemOff ptr (nv*nShapeVerxComp + i)
V3 x y z = _svPos sh
V4 r g b a = _svCol sh
V3 x y z = sh
V4 r g b a = col
V3 nx ny nz = cp
--nx = x
--ny = y
--nz = z - 1
pokeLayVerxs
:: MV.MVector (PrimState IO) (FullShader ,VBO)