summaryrefslogtreecommitdiff
path: root/LambdaCube
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-04-22 03:13:44 -0400
committerJoe Crayne <joe@jerkface.net>2019-04-22 03:36:23 -0400
commitac89ee199abfe893b03cdbb89a426cd0594e06c9 (patch)
treec3542c880eb610e9a2d5d863ec9ba518a32a0b02 /LambdaCube
parent36bd8e7133eca5d4e04252c555ee0cc2cc78106e (diff)
objdemo: pass view matrix from haskell.
Diffstat (limited to 'LambdaCube')
-rw-r--r--LambdaCube/GL/HMatrix.hs49
1 files changed, 49 insertions, 0 deletions
diff --git a/LambdaCube/GL/HMatrix.hs b/LambdaCube/GL/HMatrix.hs
new file mode 100644
index 0000000..ff5e7a7
--- /dev/null
+++ b/LambdaCube/GL/HMatrix.hs
@@ -0,0 +1,49 @@
1{-# LANGUAGE PatternSynonyms #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE MultiParamTypeClasses #-}
4module LambdaCube.GL.HMatrix where
5
6import GHC.TypeLits
7
8import LambdaCube.GL.Uniform
9import Numeric.LinearAlgebra
10import Numeric.LinearAlgebra.Devel
11
12import Graphics.Rendering.OpenGL.GL (GLboolean)
13
14instance Uniformable (Matrix Float) where
15 uniformContexts _ = contexts floatMatrices
16
17instance (KnownNat r, KnownNat c) => IsUniform (Matrix Float) (UMatrix r c Float) where
18 marshalUniform abi mat = case matrixDimensions abi of
19 (r,c) | fromIntegral (natVal r) /= rows mat -> Nothing
20 | fromIntegral (natVal c) /= cols mat -> Nothing
21 _ -> let isRowOrder = case orderOf mat of
22 RowMajor -> 1 :: GLboolean
23 ColumnMajor -> 0 :: GLboolean
24 in Just $ MarshalUMatrix
25 $ \f -> apply mat (\ptr -> f 1 isRowOrder ptr) (\r c sr sc ptr -> ptr)
26
27{-
28
29-- apply :: Storable a => Matrix a -> (f -> IO r) -> (CInt -> CInt -> CInt -> CInt -> Ptr a -> f) -> IO r
30{-# INLINE amat #-}
31amat :: Storable a => Matrix a -> (f -> IO r) -> (CInt -> CInt -> CInt -> CInt -> Ptr a -> f) -> IO r
32amat x f g = unsafeWith (xdat x) (f . g r c sr sc)
33 where
34 r = fi (rows x)
35 c = fi (cols x)
36 sr = fi (xRow x)
37 sc = fi (xCol x)
38
39
40apply (0 :: Matrix Float)
41 :: (b -> IO r)
42 -> (Foreign.C.Types.CInt
43 -> Foreign.C.Types.CInt
44 -> Foreign.C.Types.CInt
45 -> Foreign.C.Types.CInt
46 -> GHC.Ptr.Ptr Float
47 -> b)
48 -> IO r
49-}