diff options
Diffstat (limited to 'src/LambdaCube/GL/Input.hs')
-rw-r--r-- | src/LambdaCube/GL/Input.hs | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/src/LambdaCube/GL/Input.hs b/src/LambdaCube/GL/Input.hs index 88b2654..f2216fb 100644 --- a/src/LambdaCube/GL/Input.hs +++ b/src/LambdaCube/GL/Input.hs | |||
@@ -3,14 +3,12 @@ module LambdaCube.GL.Input where | |||
3 | import Control.Applicative | 3 | import Control.Applicative |
4 | import Control.Exception | 4 | import Control.Exception |
5 | import Control.Monad | 5 | import Control.Monad |
6 | import Data.ByteString.Char8 (ByteString,pack) | ||
7 | import Data.IORef | 6 | import Data.IORef |
8 | import Data.Map (Map) | 7 | import Data.Map (Map) |
9 | import Data.IntMap (IntMap) | 8 | import Data.IntMap (IntMap) |
10 | import Data.Vector (Vector,(//),(!)) | 9 | import Data.Vector (Vector,(//),(!)) |
11 | import Data.Word | 10 | import Data.Word |
12 | import Foreign | 11 | import Foreign |
13 | import qualified Data.ByteString.Char8 as SB | ||
14 | import qualified Data.IntMap as IM | 12 | import qualified Data.IntMap as IM |
15 | import qualified Data.Set as S | 13 | import qualified Data.Set as S |
16 | import qualified Data.Map as Map | 14 | import qualified Data.Map as Map |
@@ -29,8 +27,8 @@ import qualified IR as IR | |||
29 | schemaFromPipeline :: IR.Pipeline -> PipelineSchema | 27 | schemaFromPipeline :: IR.Pipeline -> PipelineSchema |
30 | schemaFromPipeline a = PipelineSchema (Map.fromList sl) (foldl Map.union Map.empty ul) | 28 | schemaFromPipeline a = PipelineSchema (Map.fromList sl) (foldl Map.union Map.empty ul) |
31 | where | 29 | where |
32 | (sl,ul) = unzip [( (pack sName,ObjectArraySchema sPrimitive (fmap cvt (toTrie sStreams))) | 30 | (sl,ul) = unzip [( (sName,ObjectArraySchema sPrimitive (fmap cvt sStreams)) |
33 | , toTrie sUniforms | 31 | , sUniforms |
34 | ) | 32 | ) |
35 | | IR.Slot sName sStreams sUniforms sPrimitive _ <- V.toList $ IR.slots a | 33 | | IR.Slot sName sStreams sUniforms sPrimitive _ <- V.toList $ IR.slots a |
36 | ] | 34 | ] |
@@ -38,7 +36,7 @@ schemaFromPipeline a = PipelineSchema (Map.fromList sl) (foldl Map.union Map.emp | |||
38 | Just v -> v | 36 | Just v -> v |
39 | Nothing -> error "internal error (schemaFromPipeline)" | 37 | Nothing -> error "internal error (schemaFromPipeline)" |
40 | 38 | ||
41 | mkUniform :: [(ByteString,InputType)] -> IO (Map ByteString InputSetter, Map ByteString GLUniform) | 39 | mkUniform :: [(String,InputType)] -> IO (Map String InputSetter, Map String GLUniform) |
42 | mkUniform l = do | 40 | mkUniform l = do |
43 | unisAndSetters <- forM l $ \(n,t) -> do | 41 | unisAndSetters <- forM l $ \(n,t) -> do |
44 | (uni, setter) <- mkUniformSetter t | 42 | (uni, setter) <- mkUniformSetter t |
@@ -70,7 +68,7 @@ disposeStorage :: GLStorage -> IO () | |||
70 | disposeStorage = error "not implemented: disposeStorage" | 68 | disposeStorage = error "not implemented: disposeStorage" |
71 | 69 | ||
72 | -- object | 70 | -- object |
73 | addObject :: GLStorage -> ByteString -> Primitive -> Maybe (IndexStream Buffer) -> Map ByteString (Stream Buffer) -> [ByteString] -> IO Object | 71 | addObject :: GLStorage -> String -> Primitive -> Maybe (IndexStream Buffer) -> Map String (Stream Buffer) -> [String] -> IO Object |
74 | addObject input slotName prim indices attribs uniformNames = do | 72 | addObject input slotName prim indices attribs uniformNames = do |
75 | let sch = schema input | 73 | let sch = schema input |
76 | forM_ uniformNames $ \n -> case Map.lookup n (uniforms sch) of | 74 | forM_ uniformNames $ \n -> case Map.lookup n (uniforms sch) of |
@@ -149,7 +147,7 @@ setObjectOrder p obj i = do | |||
149 | writeIORef (objOrder obj) i | 147 | writeIORef (objOrder obj) i |
150 | modifyIORef (slotVector p ! objSlot obj) $ \(GLSlot objs sorted _) -> GLSlot objs sorted Reorder | 148 | modifyIORef (slotVector p ! objSlot obj) $ \(GLSlot objs sorted _) -> GLSlot objs sorted Reorder |
151 | 149 | ||
152 | objectUniformSetter :: Object -> Map ByteString InputSetter | 150 | objectUniformSetter :: Object -> Map String InputSetter |
153 | objectUniformSetter = objUniSetter | 151 | objectUniformSetter = objUniSetter |
154 | 152 | ||
155 | setScreenSize :: GLStorage -> Word -> Word -> IO () | 153 | setScreenSize :: GLStorage -> Word -> Word -> IO () |
@@ -177,7 +175,7 @@ sortSlotObjects p = V.forM_ (slotVector p) $ \slotRef -> do | |||
177 | return (ord,obj) | 175 | return (ord,obj) |
178 | doSort objs | 176 | doSort objs |
179 | 177 | ||
180 | createObjectCommands :: Map ByteString (IORef GLint) -> Map ByteString GLUniform -> Object -> GLProgram -> [GLObjectCommand] | 178 | createObjectCommands :: Map String (IORef GLint) -> Map String GLUniform -> Object -> GLProgram -> [GLObjectCommand] |
181 | createObjectCommands texUnitMap topUnis obj prg = objUniCmds ++ objStreamCmds ++ [objDrawCmd] | 179 | createObjectCommands texUnitMap topUnis obj prg = objUniCmds ++ objStreamCmds ++ [objDrawCmd] |
182 | where | 180 | where |
183 | -- object draw command | 181 | -- object draw command |
@@ -247,41 +245,41 @@ createObjectCommands texUnitMap topUnis obj prg = objUniCmds ++ objStreamCmds ++ | |||
247 | -- constant generic attribute | 245 | -- constant generic attribute |
248 | constAttr -> GLSetVertexAttrib i constAttr | 246 | constAttr -> GLSetVertexAttrib i constAttr |
249 | 247 | ||
250 | nullSetter :: ByteString -> String -> a -> IO () | 248 | nullSetter :: String -> String -> a -> IO () |
251 | --nullSetter n t _ = return () -- Prelude.putStrLn $ "WARNING: unknown uniform: " ++ SB.unpack n ++ " :: " ++ t | 249 | --nullSetter n t _ = return () -- Prelude.putStrLn $ "WARNING: unknown uniform: " ++ SB.unpack n ++ " :: " ++ t |
252 | nullSetter n t _ = Prelude.putStrLn $ "WARNING: unknown uniform: " ++ SB.unpack n ++ " :: " ++ t | 250 | nullSetter n t _ = Prelude.putStrLn $ "WARNING: unknown uniform: " ++ n ++ " :: " ++ t |
253 | 251 | ||
254 | uniformBool :: ByteString -> Map ByteString InputSetter -> SetterFun Bool | 252 | uniformBool :: String -> Map String InputSetter -> SetterFun Bool |
255 | uniformV2B :: ByteString -> Map ByteString InputSetter -> SetterFun V2B | 253 | uniformV2B :: String -> Map String InputSetter -> SetterFun V2B |
256 | uniformV3B :: ByteString -> Map ByteString InputSetter -> SetterFun V3B | 254 | uniformV3B :: String -> Map String InputSetter -> SetterFun V3B |
257 | uniformV4B :: ByteString -> Map ByteString InputSetter -> SetterFun V4B | 255 | uniformV4B :: String -> Map String InputSetter -> SetterFun V4B |
258 | 256 | ||
259 | uniformWord :: ByteString -> Map ByteString InputSetter -> SetterFun Word32 | 257 | uniformWord :: String -> Map String InputSetter -> SetterFun Word32 |
260 | uniformV2U :: ByteString -> Map ByteString InputSetter -> SetterFun V2U | 258 | uniformV2U :: String -> Map String InputSetter -> SetterFun V2U |
261 | uniformV3U :: ByteString -> Map ByteString InputSetter -> SetterFun V3U | 259 | uniformV3U :: String -> Map String InputSetter -> SetterFun V3U |
262 | uniformV4U :: ByteString -> Map ByteString InputSetter -> SetterFun V4U | 260 | uniformV4U :: String -> Map String InputSetter -> SetterFun V4U |
263 | 261 | ||
264 | uniformInt :: ByteString -> Map ByteString InputSetter -> SetterFun Int32 | 262 | uniformInt :: String -> Map String InputSetter -> SetterFun Int32 |
265 | uniformV2I :: ByteString -> Map ByteString InputSetter -> SetterFun V2I | 263 | uniformV2I :: String -> Map String InputSetter -> SetterFun V2I |
266 | uniformV3I :: ByteString -> Map ByteString InputSetter -> SetterFun V3I | 264 | uniformV3I :: String -> Map String InputSetter -> SetterFun V3I |
267 | uniformV4I :: ByteString -> Map ByteString InputSetter -> SetterFun V4I | 265 | uniformV4I :: String -> Map String InputSetter -> SetterFun V4I |
268 | 266 | ||
269 | uniformFloat :: ByteString -> Map ByteString InputSetter -> SetterFun Float | 267 | uniformFloat :: String -> Map String InputSetter -> SetterFun Float |
270 | uniformV2F :: ByteString -> Map ByteString InputSetter -> SetterFun V2F | 268 | uniformV2F :: String -> Map String InputSetter -> SetterFun V2F |
271 | uniformV3F :: ByteString -> Map ByteString InputSetter -> SetterFun V3F | 269 | uniformV3F :: String -> Map String InputSetter -> SetterFun V3F |
272 | uniformV4F :: ByteString -> Map ByteString InputSetter -> SetterFun V4F | 270 | uniformV4F :: String -> Map String InputSetter -> SetterFun V4F |
273 | 271 | ||
274 | uniformM22F :: ByteString -> Map ByteString InputSetter -> SetterFun M22F | 272 | uniformM22F :: String -> Map String InputSetter -> SetterFun M22F |
275 | uniformM23F :: ByteString -> Map ByteString InputSetter -> SetterFun M23F | 273 | uniformM23F :: String -> Map String InputSetter -> SetterFun M23F |
276 | uniformM24F :: ByteString -> Map ByteString InputSetter -> SetterFun M24F | 274 | uniformM24F :: String -> Map String InputSetter -> SetterFun M24F |
277 | uniformM32F :: ByteString -> Map ByteString InputSetter -> SetterFun M32F | 275 | uniformM32F :: String -> Map String InputSetter -> SetterFun M32F |
278 | uniformM33F :: ByteString -> Map ByteString InputSetter -> SetterFun M33F | 276 | uniformM33F :: String -> Map String InputSetter -> SetterFun M33F |
279 | uniformM34F :: ByteString -> Map ByteString InputSetter -> SetterFun M34F | 277 | uniformM34F :: String -> Map String InputSetter -> SetterFun M34F |
280 | uniformM42F :: ByteString -> Map ByteString InputSetter -> SetterFun M42F | 278 | uniformM42F :: String -> Map String InputSetter -> SetterFun M42F |
281 | uniformM43F :: ByteString -> Map ByteString InputSetter -> SetterFun M43F | 279 | uniformM43F :: String -> Map String InputSetter -> SetterFun M43F |
282 | uniformM44F :: ByteString -> Map ByteString InputSetter -> SetterFun M44F | 280 | uniformM44F :: String -> Map String InputSetter -> SetterFun M44F |
283 | 281 | ||
284 | uniformFTexture2D :: ByteString -> Map ByteString InputSetter -> SetterFun TextureData | 282 | uniformFTexture2D :: String -> Map String InputSetter -> SetterFun TextureData |
285 | 283 | ||
286 | uniformBool n is = case Map.lookup n is of | 284 | uniformBool n is = case Map.lookup n is of |
287 | Just (SBool fun) -> fun | 285 | Just (SBool fun) -> fun |