From efed7ba3aec1f77d35e2b3725000640936478a77 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sun, 19 May 2019 05:11:16 -0400 Subject: Use per-primitive index head rather than per-component in PointPrimitiveRing. --- PointPrimitiveRing.hs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'PointPrimitiveRing.hs') diff --git a/PointPrimitiveRing.hs b/PointPrimitiveRing.hs index ee5a126..4c4b516 100644 --- a/PointPrimitiveRing.hs +++ b/PointPrimitiveRing.hs @@ -33,7 +33,7 @@ data Ring = Ring , rStorage :: GLStorage , rObject :: Object , 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. + , rBack :: IORef Int -- Where next vector will be added. , ringCapacity :: CPtrdiff -- Maximum number of floats in buffer. , rPosition :: AttributeKey (GLVector 3 Float) } @@ -53,7 +53,7 @@ newRing storage sz = do , rStorage = storage , rObject = obj , rSize = sizeRef - , rStart = startRef + , rBack = startRef , ringCapacity = 3 * fromIntegral sz , rPosition = k } @@ -62,30 +62,24 @@ newRing storage sz = do updateRingCommands :: Ring -> IO () updateRingCommands r = do - start <- fmap (fromIntegral . (`div` 3)) $ readIORef $ rStart r + back <- fromIntegral <$> readIORef (rBack r) size <- fmap (fromIntegral . (`div` 3)) $ readIORef $ rSize r let mask 0 = [] - mask cnt = case cnt + start - size of - st | st > cnt -> [(st - cnt,size)] - | otherwise -> [(0,start), (st,cnt - st)] + mask cnt = case cnt + back - size of + front | front > cnt -> [(front - cnt,size)] + | otherwise -> [(0,back), (front,cnt - front)] updateCommands (rStorage r) (rObject r) mask readIORef (objCommands $ rObject r) >>= mapM_ print return () pushBack :: Ring -> Float -> Float -> Float -> IO () -pushBack r x y z = allocaArray 3 $ \ptr -> do - pokeElemOff ptr 0 x - pokeElemOff ptr 1 y - pokeElemOff ptr 2 z - start <- readIORef $ rStart r - writeIORef (rStart r) (mod (start + 3) (ringCapacity r)) - -- incrementalUpdateBuffer (rBufferObject r) (4*start) (4*3) ptr - updateAttributes (fromIntegral (start `div` 3)) $ do +pushBack r x y z = do + back <- readIORef $ rBack r + writeIORef (rBack r) (mod (back + 1) (fromIntegral $ ringCapacity r `div` 3)) + updateAttributes back $ do rPosition r @<- V3 x y z -- (fromList [x,y,z] :: Vector Float) - -- glFlush - -- glFinish sz <- readIORef (rSize r) - putStrLn $ "pushBack "++show (sz,start,(x,y,z)) + putStrLn $ "pushBack "++show (sz,back,(x,y,z)) when (sz < ringCapacity r) $ do writeIORef (rSize r) (sz + 3) updateRingCommands r -- cgit v1.2.3