From 7a54887c623c9328470a1ba302fa4b1c8373cb75 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sun, 21 Apr 2019 05:16:17 -0400 Subject: Signatures, comments, dead-code removal. --- src/LambdaCube/GL/Mesh.hs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/LambdaCube/GL/Mesh.hs') diff --git a/src/LambdaCube/GL/Mesh.hs b/src/LambdaCube/GL/Mesh.hs index 95ca582..384cdd1 100644 --- a/src/LambdaCube/GL/Mesh.hs +++ b/src/LambdaCube/GL/Mesh.hs @@ -46,13 +46,18 @@ data GPUMesh , gpuData :: GPUData } -addMeshToObjectArray :: GLStorage -> String -> [String] -> GPUMesh -> IO Object +addMeshToObjectArray :: GLStorage + -> String -- ^ Slot name for a PrimitiveStream. + -> [String] -- ^ Uniform names. IORefs will be put in 'objUniSetup'. + -> GPUMesh + -> IO Object addMeshToObjectArray input slotName objUniNames (GPUMesh _ (GPUData prim streams indices _)) = do -- select proper attributes let (ObjectArraySchema slotPrim slotStreams) = fromMaybe (error $ "addMeshToObjectArray - missing object array: " ++ slotName) $ Map.lookup slotName $! objectArrays $! schema input filterStream n _ = Map.member n slotStreams addObject input slotName prim indices (Map.filterWithKey filterStream streams) objUniNames +withV :: (v a -> (Ptr a -> io) -> io) -> v a -> (Ptr () -> io) -> io withV w a f = w a (\p -> f $ castPtr p) meshAttrToArray :: MeshAttribute -> Array @@ -77,11 +82,17 @@ meshAttrToStream b i (A_M44F v) = Stream Attribute_M44F b i 0 (V.length v) meshAttrToStream b i (A_Int v) = Stream Attribute_Int b i 0 (V.length v) meshAttrToStream b i (A_Word v) = Stream Attribute_Word b i 0 (V.length v) -updateMesh :: GPUMesh -> [(String,MeshAttribute)] -> Maybe MeshPrimitive -> IO () +-- | Update a mesh without allocating new buffer objects. Each update must +-- provide new values for all existing array elements. +updateMesh :: GPUMesh -- ^ Mesh to be updated. + -> [(String,MeshAttribute)] -- ^ A list of updates. + -> Maybe MeshPrimitive -- ^ Ignored. + -> IO () updateMesh (GPUMesh (Mesh dMA dMP) (GPUData _ dS dI _)) al mp = do -- check type match let arrayChk (Array t1 s1 _) (Array t2 s2 _) = t1 == t2 && s1 == s2 - ok = and [Map.member n dMA && arrayChk (meshAttrToArray a1) (meshAttrToArray a2) | (n,a1) <- al, let a2 = fromMaybe (error $ "missing mesh attribute: " ++ n) $ Map.lookup n dMA] + ok = and [ Map.member n dMA && arrayChk (meshAttrToArray a1) (meshAttrToArray a2) + | (n,a1) <- al, let a2 = fromMaybe (error $ "missing mesh attribute: " ++ n) $ Map.lookup n dMA] if not ok then putStrLn "updateMesh: attribute mismatch!" else do forM_ al $ \(n,a) -> do @@ -98,6 +109,8 @@ updateMesh (GPUMesh (Mesh dMA dMP) (GPUData _ dS dI _)) al mp = do (a,b) -> a == b -} +-- | This allocates buffer objects. Use 'disposeMesh' to free them. Use +-- 'updateMesh' to modify the allocated buffer object data. uploadMeshToGPU :: Mesh -> IO GPUMesh uploadMeshToGPU mesh@(Mesh attrs mPrim) = do let mkIndexBuf v = do -- cgit v1.2.3