summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-05-19 23:43:15 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-19 23:43:15 -0400
commitbc6fd1c71e22ef54a4aed8774dcec4dd190b9dbc (patch)
tree67ce581d7ce8532ebffea9375153dcb1a869c55d
parent2d89afcf5a50aac49709c90a293374b18aaa2db2 (diff)
Fleshed-out Data instance for AttributeKey.
-rw-r--r--AttributeData.hs29
-rw-r--r--MaskableStream.hs55
2 files changed, 55 insertions, 29 deletions
diff --git a/AttributeData.hs b/AttributeData.hs
index 59b9e6d..d962a06 100644
--- a/AttributeData.hs
+++ b/AttributeData.hs
@@ -41,35 +41,6 @@ import Control.Monad.State.Lazy
41 41
42import MaskableStream 42import MaskableStream
43 43
44data Witness c = c => Witness
45
46tagTypable :: TypeTag c -> Witness (Typeable c)
47tagTypable TypeBool = Witness
48tagTypable TypeV2B = Witness
49tagTypable TypeV3B = Witness
50tagTypable TypeV4B = Witness
51tagTypable TypeWord = Witness
52tagTypable TypeV2U = Witness
53tagTypable TypeV3U = Witness
54tagTypable TypeV4U = Witness
55tagTypable TypeInt = Witness
56tagTypable TypeV2I = Witness
57tagTypable TypeV3I = Witness
58tagTypable TypeV4I = Witness
59tagTypable TypeFloat = Witness
60tagTypable TypeV2F = Witness
61tagTypable TypeV3F = Witness
62tagTypable TypeV4F = Witness
63tagTypable TypeM22F = Witness
64tagTypable TypeM23F = Witness
65tagTypable TypeM24F = Witness
66tagTypable TypeM32F = Witness
67tagTypable TypeM33F = Witness
68tagTypable TypeM34F = Witness
69tagTypable TypeM42F = Witness
70tagTypable TypeM43F = Witness
71tagTypable TypeM44F = Witness
72
73 44
74lookupAttrKeys :: forall attrkeys. Data attrkeys => (String -> Maybe (Some AttributeKey)) -> Maybe attrkeys 45lookupAttrKeys :: forall attrkeys. Data attrkeys => (String -> Maybe (Some AttributeKey)) -> Maybe attrkeys
75lookupAttrKeys lookupA = do 46lookupAttrKeys lookupA = do
diff --git a/MaskableStream.hs b/MaskableStream.hs
index 10f4bff..d836f37 100644
--- a/MaskableStream.hs
+++ b/MaskableStream.hs
@@ -1,4 +1,7 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE LambdaCase, RecordWildCards, KindSignatures, GADTs, DeriveDataTypeable, StandaloneDeriving #-} 2{-# LANGUAGE LambdaCase, RecordWildCards, KindSignatures, GADTs, DeriveDataTypeable, StandaloneDeriving #-}
3{-# LANGUAGE ConstraintKinds #-}
4{-# LANGUAGE ScopedTypeVariables #-}
2 5
3-- TODO: Formulate this module as a patch against lambdacube-gl. 6-- TODO: Formulate this module as a patch against lambdacube-gl.
4 7
@@ -38,6 +41,36 @@ import LambdaCube.GL.Input hiding (createObjectCommands)
38 41
39import Graphics.GL.Core33 42import Graphics.GL.Core33
40 43
44data Witness c = c => Witness
45
46tagTypable :: TypeTag c -> Witness (Typeable c)
47tagTypable TypeBool = Witness
48tagTypable TypeV2B = Witness
49tagTypable TypeV3B = Witness
50tagTypable TypeV4B = Witness
51tagTypable TypeWord = Witness
52tagTypable TypeV2U = Witness
53tagTypable TypeV3U = Witness
54tagTypable TypeV4U = Witness
55tagTypable TypeInt = Witness
56tagTypable TypeV2I = Witness
57tagTypable TypeV3I = Witness
58tagTypable TypeV4I = Witness
59tagTypable TypeFloat = Witness
60tagTypable TypeV2F = Witness
61tagTypable TypeV3F = Witness
62tagTypable TypeV4F = Witness
63tagTypable TypeM22F = Witness
64tagTypable TypeM23F = Witness
65tagTypable TypeM24F = Witness
66tagTypable TypeM32F = Witness
67tagTypable TypeM33F = Witness
68tagTypable TypeM34F = Witness
69tagTypable TypeM42F = Witness
70tagTypable TypeM43F = Witness
71tagTypable TypeM44F = Witness
72
73
41 74
42-- based on addMeshToObjectArray 75-- based on addMeshToObjectArray
43addToObjectArray :: GLStorage 76addToObjectArray :: GLStorage
@@ -233,7 +266,29 @@ incrementalUpdateBuffer b byteoffset bytecount ptr = do
233 glBufferSubData GL_ARRAY_BUFFER byteoffset bytecount ptr 266 glBufferSubData GL_ARRAY_BUFFER byteoffset bytecount ptr
234 glBindBuffer GL_ARRAY_BUFFER 0 267 glBindBuffer GL_ARRAY_BUFFER 0
235 268
269deriving instance Data InputType
270deriving instance Data ArrayType
271deriving instance Data ArrayDesc
272deriving instance Data Buffer
236instance Typeable c => Data (AttributeKey c) where 273instance Typeable c => Data (AttributeKey c) where
274 gfoldl f z (AttributeKey tt b offset) = z mk
275 `f` unwitnessType tt
276 `f` b
277 `f` fromIntegral offset
278 where
279 mk :: Typeable c => InputType -> Buffer -> Int64 -> AttributeKey c
280 mk t bo i = fix $ \ret -> case witnessType t of
281 Just (This tt) -> case tagTypable tt of
282 Witness -> case withTypes tt ret <$> eqT of
283 Just Refl -> AttributeKey tt bo (fromIntegral i)
284 toConstr _ = error "AttributeKey.toConstr"
285 gunfold _ _ = error "AttributeKey.gunfold"
286#if MIN_VERSION_base(4,2,0)
287 dataTypeOf _ = mkNoRepType "MaskableStream.AttributeKey"
288#else
289 dataTypeOf _ = mkNorepType "MaskableStream.AttributeKey"
290#endif
291
237 292
238data AttributeKey c = AttributeKey (TypeTag c) Buffer CPtrdiff 293data AttributeKey c = AttributeKey (TypeTag c) Buffer CPtrdiff
239 294