packages feed

GPipe 1.1.3 → 1.1.4

raw patch · 2 files changed

+7/−55 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

GPipe.cabal view
@@ -1,5 +1,5 @@ name: GPipe-version: 1.1.3+version: 1.1.4 cabal-version: >= 1.2.3 build-type: Simple license: BSD3
src/Shader.hs view
@@ -90,10 +90,10 @@           vpos = fromVertex $ vFromVec "vec4" pos
           vdag@(vpos':varyings',_) = createDAG (vpos:varyings)
           inputs = extractInputs vdag
-          vcodeAssigns = getCodeAssignments (fromJust . flip elemIndex inputs) "v" vdag
+          vcodeAssigns = getCodeAssignments (fromJust . flip elemIndex inputs) (length inputs) "v" vdag
           vCodeFinish = setVaryings varyings' ++
                         "gl_Position = t" ++ show vpos' ++ ";\n"
-          fcodeAssigns = getCodeAssignments id "f" fdag
+          fcodeAssigns = getCodeAssignments id (length varyings') "f" fdag
           depthAssign = case mdepth' of [d] -> "gl_FragDepth = t" ++ show d ++ ";\n"
                                         []  -> ""
           fcodeFinish = "if (!t" ++ show ndisc' ++ ") discard;\n" ++
@@ -549,8 +549,8 @@     where extractIn s (ShaderInput a) = IntSet.insert a s
           extractIn x _ = x  
 
-getCodeAssignments :: (Int -> Int) -> String -> ShaderDAG -> String
-getCodeAssignments inF inName (_,xs) = concat $ snd $ mapAccumL getCode ((0,0,0,Map.empty),Map.empty) $ zip [0..] xs
+getCodeAssignments :: (Int -> Int) -> Int -> String -> ShaderDAG -> String
+getCodeAssignments inF numIns inName (_,xs) = concat $ snd $ mapAccumL getCode ((0,0,0,Map.empty),Map.empty) $ zip [0..] xs
     where getCode ((f,i,b,s),inlns) (n, (ShaderUniform (UniformFloat _), _)) = (((f+1,i,b,s),inlns), assign "float" (const $ inName ++ "uf[" ++ show f ++ "]") (var n) [])
           getCode ((f,i,b,s),inlns) (n, (ShaderUniform (UniformInt _), _)) = (((f,i+1,b,s),inlns), assign "int" (const $ inName ++ "ui[" ++ show i ++ "]") (var n) [])
           getCode ((f,i,b,s),inlns) (n, (ShaderUniform (UniformBool _), _)) = (((f,i,b+1,s),inlns), assign "bool" (const $ inName ++ "ub[" ++ show b ++ "]") (var n) [])
@@ -560,14 +560,14 @@           getCode x (n, (ShaderConstant (ConstFloat f), _)) = (x, assign "float" (const $ show f) (var n) [])
           getCode x (n, (ShaderConstant (ConstInt i), _)) = (x, assign "int" (const $ show i) (var n) [])
           getCode x (n, (ShaderConstant (ConstBool b), _)) = (x, assign "bool" (const $ if b then "true" else "false") (var n) [])
-          getCode x (n, (ShaderInput i, _)) = (x, assign "float" (const $ inName ++ inoutAccessor (inF i)) (var n) [])
+          getCode x (n, (ShaderInput i, _)) = (x, assign "float" (const $ inName ++ inoutAccessor (inF i) numIns) (var n) [])
           getCode x@(_,inlns) (n, (ShaderOp _ f _, xs)) = (x, f (var n) (map (varMaybeInline inlns) xs))
           getCode _ (_, (ShaderInputTree _, _)) = error "Shader.getCodeAssignments: Use splitShaders first!"
           var n = 't' : show n
           varMaybeInline inlns n = case Map.lookup n inlns of Just str -> str
                                                               Nothing -> var n
 
-inoutAccessor i = case divMod i 4 of (d,m) -> show d ++ "." ++ (["x","y","z","w"]!!m)
+inoutAccessor i tot = case divMod i 4 of (d,m) -> if i+1 == tot && m == 0 then show d else show d ++ "." ++ (["x","y","z","w"]!!m)
 
 sampName Sampler3D = "sampler3D"
 sampName Sampler2D = "sampler2D"
@@ -604,51 +604,3 @@ fFromVec t = Fragment . ShaderOp "" (assign t (((t ++ "(") ++) . (++ ")") . intercalate ",")) . map fromFragment . Vec.toList 
 fToVec t n a = Vec.fromList $ map (\s -> Fragment $ ShaderOp s (assign t (\[x]->x++"["++s++"]")) [fromFragment a]) [show n' | n' <-[0..n - 1]]
 
-
--------------------------
--- Lifted list
-{-
-data MaybeB bool a = Never | Sometimes bool a
-
-nothing :: MaybeB bool a
-nothing = Never
-just :: a -> MaybeB bool a
-just a = Sometimes true a
-
-maybeB :: b -> (a -> b) -> MaybeB bool a -> b 
-maybeB b f Never = b
-maybeB b f (Sometimes bool a) = ifB bool (f a) b
- 
-isJustB :: MaybeB bool a -> bool
-isJustB Never = false
-isJustB (Sometimes bool a) = bool
-
-isNothingB :: MaybeB bool a -> bool
-isNothingB Never = true
-isNothingB (Sometimes bool a) = notB bool
-
-fromMaybeB :: a -> Maybe a -> a 
-fromMaybeB a = maybeB a id
-
-instance (EqB bool, IfB bool a) => IfB bool (MaybeB bool a) where
-    ifB c (Sometimes boola a) (Sometimes boolb b) = Sometimes ((c &&* boola) ||* (notB c &&* boolb)) (ifB c a b)
-    ifB c (Sometimes bool a) Never  = Sometimes (c &&* bool) a
-    ifB c Never (Sometimes bool a) = Sometimes (notB c &&* bool) a
-    ifB c Never Never = Never
-
-
-newtype ListB bool a = ListB [MaybeB bool a]
-
-(.:) :: a -> ListB bool a -> ListB bool a
-a .: (ListB b) = ListB (just a:b)
-
-maxLength :: ListB bool a -> Int
-maxLength (ListB a) = length a
-
-lengthB :: (Num i, IfB bool i) => ListB bool a -> i
-lengthB (ListB a) 
-
-(.!!) :: ListB bool a -> Int -> a
-ListB xs .!! i = getElem xs i
-    where getElem a@(Never:xs) i = ifB (i ==* 0) (ifB )
-    -}