summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-05-19 05:11:16 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-19 05:11:16 -0400
commitefed7ba3aec1f77d35e2b3725000640936478a77 (patch)
tree5d7768d3363a64a73f284b8a53b1ac1bb94b5975
parentab43ecb77e381b83448a0ea324dd5377333538a0 (diff)
Use per-primitive index head rather than per-component in PointPrimitiveRing.
-rw-r--r--MaskableStream.hs7
-rw-r--r--PointPrimitiveRing.hs28
2 files changed, 14 insertions, 21 deletions
diff --git a/MaskableStream.hs b/MaskableStream.hs
index 5ef5b28..5274d28 100644
--- a/MaskableStream.hs
+++ b/MaskableStream.hs
@@ -265,12 +265,11 @@ updateAttributes i writer = forM_ (execWriter writer) $ \case
265 putStrLn $ "vector sz = " ++ show sz 265 putStrLn $ "vector sz = " ++ show sz
266 glBufferSubData GL_ARRAY_BUFFER (base + fromIntegral i * sz') sz' ptr 266 glBufferSubData GL_ARRAY_BUFFER (base + fromIntegral i * sz') sz' ptr
267 267
268 Just (MarshalGLMatrix with) -> with $ \sz isrowcol ptr -> do 268 Just (MarshalGLMatrix with) -> with $ \sz isrowcol ptr -> case isrowcol of
269 if isrowcol then 269 0 -> do
270 hPutStrLn stderr $ "WARNING: (TODO) row-major matrix attribute update unimplemented."
271 else do
272 let sz' = fromIntegral $ attribSize * (fromIntegral sz) 270 let sz' = fromIntegral $ attribSize * (fromIntegral sz)
273 glBufferSubData GL_ARRAY_BUFFER (base + fromIntegral i * sz') sz' ptr 271 glBufferSubData GL_ARRAY_BUFFER (base + fromIntegral i * sz') sz' ptr
272 _ -> hPutStrLn stderr $ "WARNING: (TODO) row-major matrix attribute update unimplemented."
274 273
275 Nothing -> hPutStrLn stderr $ "Warning: dimension mismatch updating " ++ show (unwitnessType typ) ++ " attribute." 274 Nothing -> hPutStrLn stderr $ "Warning: dimension mismatch updating " ++ show (unwitnessType typ) ++ " attribute."
276 glBindBuffer GL_ARRAY_BUFFER 0 275 glBindBuffer GL_ARRAY_BUFFER 0
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
33 , rStorage :: GLStorage 33 , rStorage :: GLStorage
34 , rObject :: Object 34 , rObject :: Object
35 , rSize :: IORef CPtrdiff -- Current count of Floats in the ring buffer. 35 , rSize :: IORef CPtrdiff -- Current count of Floats in the ring buffer.
36 , rStart :: IORef CPtrdiff -- Float-index where next vector will be added. TODO: rename this. 36 , rBack :: IORef Int -- Where next vector will be added.
37 , ringCapacity :: CPtrdiff -- Maximum number of floats in buffer. 37 , ringCapacity :: CPtrdiff -- Maximum number of floats in buffer.
38 , rPosition :: AttributeKey (GLVector 3 Float) 38 , rPosition :: AttributeKey (GLVector 3 Float)
39 } 39 }
@@ -53,7 +53,7 @@ newRing storage sz = do
53 , rStorage = storage 53 , rStorage = storage
54 , rObject = obj 54 , rObject = obj
55 , rSize = sizeRef 55 , rSize = sizeRef
56 , rStart = startRef 56 , rBack = startRef
57 , ringCapacity = 3 * fromIntegral sz 57 , ringCapacity = 3 * fromIntegral sz
58 , rPosition = k 58 , rPosition = k
59 } 59 }
@@ -62,30 +62,24 @@ newRing storage sz = do
62 62
63updateRingCommands :: Ring -> IO () 63updateRingCommands :: Ring -> IO ()
64updateRingCommands r = do 64updateRingCommands r = do
65 start <- fmap (fromIntegral . (`div` 3)) $ readIORef $ rStart r 65 back <- fromIntegral <$> readIORef (rBack r)
66 size <- fmap (fromIntegral . (`div` 3)) $ readIORef $ rSize r 66 size <- fmap (fromIntegral . (`div` 3)) $ readIORef $ rSize r
67 let mask 0 = [] 67 let mask 0 = []
68 mask cnt = case cnt + start - size of 68 mask cnt = case cnt + back - size of
69 st | st > cnt -> [(st - cnt,size)] 69 front | front > cnt -> [(front - cnt,size)]
70 | otherwise -> [(0,start), (st,cnt - st)] 70 | otherwise -> [(0,back), (front,cnt - front)]
71 updateCommands (rStorage r) (rObject r) mask 71 updateCommands (rStorage r) (rObject r) mask
72 readIORef (objCommands $ rObject r) >>= mapM_ print 72 readIORef (objCommands $ rObject r) >>= mapM_ print
73 return () 73 return ()
74 74
75pushBack :: Ring -> Float -> Float -> Float -> IO () 75pushBack :: Ring -> Float -> Float -> Float -> IO ()
76pushBack r x y z = allocaArray 3 $ \ptr -> do 76pushBack r x y z = do
77 pokeElemOff ptr 0 x 77 back <- readIORef $ rBack r
78 pokeElemOff ptr 1 y 78 writeIORef (rBack r) (mod (back + 1) (fromIntegral $ ringCapacity r `div` 3))
79 pokeElemOff ptr 2 z 79 updateAttributes back $ do
80 start <- readIORef $ rStart r
81 writeIORef (rStart r) (mod (start + 3) (ringCapacity r))
82 -- incrementalUpdateBuffer (rBufferObject r) (4*start) (4*3) ptr
83 updateAttributes (fromIntegral (start `div` 3)) $ do
84 rPosition r @<- V3 x y z -- (fromList [x,y,z] :: Vector Float) 80 rPosition r @<- V3 x y z -- (fromList [x,y,z] :: Vector Float)
85 -- glFlush
86 -- glFinish
87 sz <- readIORef (rSize r) 81 sz <- readIORef (rSize r)
88 putStrLn $ "pushBack "++show (sz,start,(x,y,z)) 82 putStrLn $ "pushBack "++show (sz,back,(x,y,z))
89 when (sz < ringCapacity r) $ do 83 when (sz < ringCapacity r) $ do
90 writeIORef (rSize r) (sz + 3) 84 writeIORef (rSize r) (sz + 3)
91 updateRingCommands r 85 updateRingCommands r