diff options
Diffstat (limited to 'PointPrimitiveRing.hs')
-rw-r--r-- | PointPrimitiveRing.hs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/PointPrimitiveRing.hs b/PointPrimitiveRing.hs index 3f2258b..ee5a126 100644 --- a/PointPrimitiveRing.hs +++ b/PointPrimitiveRing.hs | |||
@@ -1,4 +1,4 @@ | |||
1 | {-# LANGUAGE LambdaCase, RecordWildCards #-} | 1 | {-# LANGUAGE LambdaCase, RecordWildCards, DataKinds #-} |
2 | module PointPrimitiveRing where | 2 | module PointPrimitiveRing where |
3 | 3 | ||
4 | import Control.Monad | 4 | import Control.Monad |
@@ -35,6 +35,7 @@ data Ring = Ring | |||
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 | , rStart :: IORef CPtrdiff -- Float-index where next vector will be added. TODO: rename this. |
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 | } | 39 | } |
39 | 40 | ||
40 | newRing :: GLStorage -> Int -> IO Ring | 41 | newRing :: GLStorage -> Int -> IO Ring |
@@ -42,6 +43,7 @@ newRing storage sz = do | |||
42 | startRef <- newIORef 0 | 43 | startRef <- newIORef 0 |
43 | sizeRef <- newIORef 0 | 44 | sizeRef <- newIORef 0 |
44 | gd <- uploadDynamicBuffer sz [Parameter "position" V3F] | 45 | gd <- uploadDynamicBuffer sz [Parameter "position" V3F] |
46 | let Just k = attributeKey gd "position" | ||
45 | obj <- addToObjectArray storage "Points" [] gd | 47 | obj <- addToObjectArray storage "Points" [] gd |
46 | readIORef (objCommands obj) >>= mapM_ print | 48 | readIORef (objCommands obj) >>= mapM_ print |
47 | -- [[GLSetUniform 0 GLUniform M44F,GLSetVertexAttribArray 0 5 3 5126 0x0000000000000000,GLDrawArrays 0 0 1],[],[],[]] | 49 | -- [[GLSetUniform 0 GLUniform M44F,GLSetVertexAttribArray 0 5 3 5126 0x0000000000000000,GLDrawArrays 0 0 1],[],[],[]] |
@@ -53,6 +55,7 @@ newRing storage sz = do | |||
53 | , rSize = sizeRef | 55 | , rSize = sizeRef |
54 | , rStart = startRef | 56 | , rStart = startRef |
55 | , ringCapacity = 3 * fromIntegral sz | 57 | , ringCapacity = 3 * fromIntegral sz |
58 | , rPosition = k | ||
56 | } | 59 | } |
57 | updateRingCommands r | 60 | updateRingCommands r |
58 | return r | 61 | return r |
@@ -76,7 +79,9 @@ pushBack r x y z = allocaArray 3 $ \ptr -> do | |||
76 | pokeElemOff ptr 2 z | 79 | pokeElemOff ptr 2 z |
77 | start <- readIORef $ rStart r | 80 | start <- readIORef $ rStart r |
78 | writeIORef (rStart r) (mod (start + 3) (ringCapacity r)) | 81 | writeIORef (rStart r) (mod (start + 3) (ringCapacity r)) |
79 | incrementalUpdateBuffer (rBufferObject r) (4*start) (4*3) ptr | 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 | -- glFlush | 85 | -- glFlush |
81 | -- glFinish | 86 | -- glFinish |
82 | sz <- readIORef (rSize r) | 87 | sz <- readIORef (rSize r) |