summaryrefslogtreecommitdiff
path: root/MaskableStream.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-05-19 17:44:28 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-19 17:44:28 -0400
commit268aaced12086ed8376affdf62711abcb651277e (patch)
tree5dbba3fd4192be3579bdf359e880d6ed6c0773bc /MaskableStream.hs
parentccf714a691a95be84ba168a725b6f0187bb903ea (diff)
Experiment: use Data.Data to generate AttributeKeys.
Diffstat (limited to 'MaskableStream.hs')
-rw-r--r--MaskableStream.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/MaskableStream.hs b/MaskableStream.hs
index 5274d28..10f4bff 100644
--- a/MaskableStream.hs
+++ b/MaskableStream.hs
@@ -1,4 +1,4 @@
1{-# LANGUAGE LambdaCase, RecordWildCards, KindSignatures, GADTs #-} 1{-# LANGUAGE LambdaCase, RecordWildCards, KindSignatures, GADTs, DeriveDataTypeable, StandaloneDeriving #-}
2 2
3-- TODO: Formulate this module as a patch against lambdacube-gl. 3-- TODO: Formulate this module as a patch against lambdacube-gl.
4 4
@@ -7,6 +7,7 @@ module MaskableStream where
7import Control.Monad 7import Control.Monad
8import Control.Monad.IO.Class 8import Control.Monad.IO.Class
9import Control.Monad.Writer 9import Control.Monad.Writer
10import Data.Data
10import Data.Foldable 11import Data.Foldable
11import Data.Function 12import Data.Function
12import Data.Int 13import Data.Int
@@ -232,6 +233,8 @@ incrementalUpdateBuffer b byteoffset bytecount ptr = do
232 glBufferSubData GL_ARRAY_BUFFER byteoffset bytecount ptr 233 glBufferSubData GL_ARRAY_BUFFER byteoffset bytecount ptr
233 glBindBuffer GL_ARRAY_BUFFER 0 234 glBindBuffer GL_ARRAY_BUFFER 0
234 235
236instance Typeable c => Data (AttributeKey c) where
237
235data AttributeKey c = AttributeKey (TypeTag c) Buffer CPtrdiff 238data AttributeKey c = AttributeKey (TypeTag c) Buffer CPtrdiff
236 239
237attributeKey :: TypeTagable c => GPUData -> String -> Maybe (AttributeKey c) 240attributeKey :: TypeTagable c => GPUData -> String -> Maybe (AttributeKey c)
@@ -249,6 +252,17 @@ attributeKey dta name = do
249 Just $ AttributeKey typ b (fromIntegral off) 252 Just $ AttributeKey typ b (fromIntegral off)
250 _ -> Nothing 253 _ -> Nothing
251 254
255lookupAttributeKey :: GPUData -> String -> Maybe (Some AttributeKey)
256lookupAttributeKey dta name = do
257 stream <- Map.lookup name (dStreams dta)
258 case stream of
259 Stream t b i _ _ -> do
260 let a = bufArrays b ! i
261 off = arrOffset a
262 This tt <- witnessType (fromStreamType t)
263 Just $ This (AttributeKey tt b (fromIntegral off))
264 _ -> Nothing
265
252(@<-) :: GLData a c => AttributeKey c -> a -> Writer [DSum AttributeKey GLUniformValue] () 266(@<-) :: GLData a c => AttributeKey c -> a -> Writer [DSum AttributeKey GLUniformValue] ()
253k @<- v = tell [k :=> GLUniformValue v] 267k @<- v = tell [k :=> GLUniformValue v]
254 268