From ab43ecb77e381b83448a0ea324dd5377333538a0 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sun, 19 May 2019 04:56:51 -0400 Subject: Type-safe incremental attribute update. --- PointPrimitiveRing.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'PointPrimitiveRing.hs') diff --git a/PointPrimitiveRing.hs b/PointPrimitiveRing.hs index 3f2258b..ee5a126 100644 --- a/PointPrimitiveRing.hs +++ b/PointPrimitiveRing.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE LambdaCase, RecordWildCards #-} +{-# LANGUAGE LambdaCase, RecordWildCards, DataKinds #-} module PointPrimitiveRing where import Control.Monad @@ -35,6 +35,7 @@ data Ring = Ring , rSize :: IORef CPtrdiff -- Current count of Floats in the ring buffer. , rStart :: IORef CPtrdiff -- Float-index where next vector will be added. TODO: rename this. , ringCapacity :: CPtrdiff -- Maximum number of floats in buffer. + , rPosition :: AttributeKey (GLVector 3 Float) } newRing :: GLStorage -> Int -> IO Ring @@ -42,6 +43,7 @@ newRing storage sz = do startRef <- newIORef 0 sizeRef <- newIORef 0 gd <- uploadDynamicBuffer sz [Parameter "position" V3F] + let Just k = attributeKey gd "position" obj <- addToObjectArray storage "Points" [] gd readIORef (objCommands obj) >>= mapM_ print -- [[GLSetUniform 0 GLUniform M44F,GLSetVertexAttribArray 0 5 3 5126 0x0000000000000000,GLDrawArrays 0 0 1],[],[],[]] @@ -53,6 +55,7 @@ newRing storage sz = do , rSize = sizeRef , rStart = startRef , ringCapacity = 3 * fromIntegral sz + , rPosition = k } updateRingCommands r return r @@ -76,7 +79,9 @@ pushBack r x y z = allocaArray 3 $ \ptr -> do pokeElemOff ptr 2 z start <- readIORef $ rStart r writeIORef (rStart r) (mod (start + 3) (ringCapacity r)) - incrementalUpdateBuffer (rBufferObject r) (4*start) (4*3) ptr + -- incrementalUpdateBuffer (rBufferObject r) (4*start) (4*3) ptr + updateAttributes (fromIntegral (start `div` 3)) $ do + rPosition r @<- V3 x y z -- (fromList [x,y,z] :: Vector Float) -- glFlush -- glFinish sz <- readIORef (rSize r) -- cgit v1.2.3