summaryrefslogtreecommitdiff
path: root/src/LambdaCube
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-02-14 12:12:15 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-02-14 12:12:15 +0100
commit87cefc9cacb9e82c4340c8552d9373175980faca (patch)
treea4d63aec7adc2cff04640016adfed078fec5c2c4 /src/LambdaCube
parentf2fa7476f0c19bb374c24324edda110333288926 (diff)
more lines in generated shader code
Diffstat (limited to 'src/LambdaCube')
-rw-r--r--src/LambdaCube/Compiler/CoreToIR.hs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs
index 3f8343ca..17e2133d 100644
--- a/src/LambdaCube/Compiler/CoreToIR.hs
+++ b/src/LambdaCube/Compiler/CoreToIR.hs
@@ -11,7 +11,6 @@ module LambdaCube.Compiler.CoreToIR
11 ) where 11 ) where
12 12
13import Data.Char 13import Data.Char
14import Data.List
15import Data.Monoid 14import Data.Monoid
16import Data.Map (Map) 15import Data.Map (Map)
17import Data.Maybe 16import Data.Maybe
@@ -27,6 +26,7 @@ import qualified LambdaCube.IR as IR
27import qualified LambdaCube.Linear as IR 26import qualified LambdaCube.Linear as IR
28 27
29import LambdaCube.Compiler.Pretty 28import LambdaCube.Compiler.Pretty
29import Text.PrettyPrint.Compact (nest)
30import LambdaCube.Compiler.Infer hiding (Con, Lam, Pi, TType, Var, ELit) 30import LambdaCube.Compiler.Infer hiding (Con, Lam, Pi, TType, Var, ELit)
31import qualified LambdaCube.Compiler.Infer as I 31import qualified LambdaCube.Compiler.Infer as I
32import LambdaCube.Compiler.Parser (up, Up (..)) 32import LambdaCube.Compiler.Parser (up, Up (..))
@@ -524,8 +524,8 @@ genGLSLs backend
524 <> [unwords [inputDef backend, toGLSLType "3" t, n, ";"] | (n, t) <- zip vertIn verti] 524 <> [unwords [inputDef backend, toGLSLType "3" t, n, ";"] | (n, t) <- zip vertIn verti]
525 <> [unwords $ varyingOut backend i ++ [t, n, ";"] | (n, (i, t)) <- zip vertOut'' vertOut] 525 <> [unwords $ varyingOut backend i ++ [t, n, ";"] | (n, (i, t)) <- zip vertOut'' vertOut]
526 <> ["void main() {"] 526 <> ["void main() {"]
527 <> [n <> " = " <> x <> ";" | (n, x) <- zip vertOut''WithPosition vertGLSL] 527 <> [showNest $ text n <+> "=" </> x <> ";" | (n, x) <- zip vertOut''WithPosition vertGLSL]
528 <> ["gl_PointSize = " <> x <> ";" | Just x <- [ptGLSL]] 528 <> [showNest $ "gl_PointSize" <+> "=" </> x <> ";" | Just x <- [ptGLSL]]
529 <> ["}"] 529 <> ["}"]
530 530
531 , -- fragment shader code 531 , -- fragment shader code
@@ -534,11 +534,13 @@ genGLSLs backend
534 <> [unwords $ varyingIn backend i ++ [t, n, ";"] | (n, (i, t)) <- zip vertOut'' vertOut] 534 <> [unwords $ varyingIn backend i ++ [t, n, ";"] | (n, (i, t)) <- zip vertOut'' vertOut]
535 <> [unwords ["out", toGLSLType "4" tfrag,fragColorName backend,";"] | noUnit tfrag, backend == OpenGL33] 535 <> [unwords ["out", toGLSLType "4" tfrag,fragColorName backend,";"] | noUnit tfrag, backend == OpenGL33]
536 <> ["void main() {"] 536 <> ["void main() {"]
537 <> ["if (!(" <> filt <> ")) discard;" | Just filt <- [filtGLSL]] 537 <> [showNest $ "if" <+> parens ("!" <> parens filt) <+> "discard" <> ";" | Just filt <- [filtGLSL]]
538 <> [fragColorName backend <> " = " <> fromMaybe "vo1"{-hack-} fragGLSL <> ";" | noUnit tfrag] 538 <> [showNest $ text (fragColorName backend) <+> "=" <+> fromMaybe (text $ head vertOut'') fragGLSL <> ";" | noUnit tfrag]
539 <> ["}"] 539 <> ["}"]
540 ) 540 )
541 where 541 where
542 showNest = show . nest 4
543
542 (verti, verts) = case vert of 544 (verti, verts) = case vert of
543 Just (etaRed -> Just (verti, verts)) -> (verti, eTuple verts) 545 Just (etaRed -> Just (verti, verts)) -> (verti, eTuple verts)
544 Nothing -> ([], [mkTVar 0 tvert]) 546 Nothing -> ([], [mkTVar 0 tvert])
@@ -560,7 +562,7 @@ genGLSLs backend
560 562
561 red (etaRed -> Just (ps, o)) = (ps, o) 563 red (etaRed -> Just (ps, o)) = (ps, o)
562 genGLSL' vertOut (ps, o) 564 genGLSL' vertOut (ps, o)
563 | length ps == length vertOut = show <$> genGLSL (reverse vertOut) o 565 | length ps == length vertOut = genGLSL (reverse vertOut) o
564 | otherwise = error $ "makeSubst illegal input " ++ show ps ++ "\n" ++ show vertOut 566 | otherwise = error $ "makeSubst illegal input " ++ show ps ++ "\n" ++ show vertOut
565 567
566 noUnit TTuple0 = False 568 noUnit TTuple0 = False
@@ -749,7 +751,7 @@ genGLSL dns e = case e of
749 call f xs = case f of 751 call f xs = case f of
750 (c:_) | isAlpha c -> case xs of 752 (c:_) | isAlpha c -> case xs of
751 [] -> return $ text f 753 [] -> return $ text f
752 xs -> (text f <+>) . parens . hcat . intersperse "," <$> mapM gen xs 754 xs -> (text f </>) . tupled <$> mapM gen xs
753 [op, '_'] -> case xs of [a] -> (text [op] <+>) . parens <$> gen a 755 [op, '_'] -> case xs of [a] -> (text [op] <+>) . parens <$> gen a
754 o -> case xs of [a, b] -> hsep <$> sequence [parens <$> gen a, pure $ text o, parens <$> gen b] 756 o -> case xs of [a, b] -> hsep <$> sequence [parens <$> gen a, pure $ text o, parens <$> gen b]
755 757