diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2017-01-30 20:45:52 +0000 |
---|---|---|
committer | Csaba Hruska <csaba.hruska@gmail.com> | 2017-01-30 20:45:52 +0000 |
commit | 3c00654473d7ad225ee984f58bbc24bceb11278d (patch) | |
tree | d2f8996cf96207afcc84ca7d8399f8e0db4fad39 | |
parent | 8a56448921e7633d35ab7182c3c715f97d9de840 (diff) |
use sampler's texture filter and edge mode setting
-rw-r--r-- | src/LambdaCube/Compiler/CoreToIR.hs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs index 6eef4cc3..4b75c182 100644 --- a/src/LambdaCube/Compiler/CoreToIR.hs +++ b/src/LambdaCube/Compiler/CoreToIR.hs | |||
@@ -163,7 +163,7 @@ getCommands backend e = case e of | |||
163 | where | 163 | where |
164 | getRenderTextureCommands :: String -> Uniform -> CG ([SamplerBinding],[IR.Command]) | 164 | getRenderTextureCommands :: String -> Uniform -> CG ([SamplerBinding],[IR.Command]) |
165 | getRenderTextureCommands n = \case | 165 | getRenderTextureCommands n = \case |
166 | UTexture2D (fromIntegral -> width) (fromIntegral -> height) img -> do | 166 | UTexture2D textureFilter edgeMode (fromIntegral -> width) (fromIntegral -> height) img -> do |
167 | 167 | ||
168 | let (a, tf) = case img of | 168 | let (a, tf) = case img of |
169 | A1 "PrjImageColor" a -> (,) a $ \[_, x] -> x | 169 | A1 "PrjImageColor" a -> (,) a $ \[_, x] -> x |
@@ -174,11 +174,11 @@ getCommands backend e = case e of | |||
174 | , IR.textureSize = IR.VV2U $ IR.V2 (fromIntegral width) (fromIntegral height) | 174 | , IR.textureSize = IR.VV2U $ IR.V2 (fromIntegral width) (fromIntegral height) |
175 | , IR.textureSemantic = semantic | 175 | , IR.textureSemantic = semantic |
176 | , IR.textureSampler = IR.SamplerDescriptor | 176 | , IR.textureSampler = IR.SamplerDescriptor |
177 | { IR.samplerWrapS = IR.Repeat | 177 | { IR.samplerWrapS = edgeMode |
178 | , IR.samplerWrapT = Nothing | 178 | , IR.samplerWrapT = Just edgeMode |
179 | , IR.samplerWrapR = Nothing | 179 | , IR.samplerWrapR = Nothing |
180 | , IR.samplerMinFilter = IR.Linear | 180 | , IR.samplerMinFilter = textureFilter |
181 | , IR.samplerMagFilter = IR.Linear | 181 | , IR.samplerMagFilter = textureFilter |
182 | , IR.samplerBorderColor = IR.VV4F (IR.V4 0 0 0 1) | 182 | , IR.samplerBorderColor = IR.VV4F (IR.V4 0 0 0 1) |
183 | , IR.samplerMinLod = Nothing | 183 | , IR.samplerMinLod = Nothing |
184 | , IR.samplerMaxLod = Nothing | 184 | , IR.samplerMaxLod = Nothing |
@@ -232,6 +232,17 @@ compList (A2 ":" a x) = a : compList x | |||
232 | compList (A0 "Nil") = [] | 232 | compList (A0 "Nil") = [] |
233 | compList x = error $ "compList: " ++ ppShow x | 233 | compList x = error $ "compList: " ++ ppShow x |
234 | 234 | ||
235 | compFilter = \case | ||
236 | A0 "PointFilter" -> IR.Nearest | ||
237 | A0 "LinearFilter" -> IR.Linear | ||
238 | x -> error $ "compFilter: " ++ ppShow x | ||
239 | |||
240 | compEdgeMode = \case | ||
241 | A0 "Repeat" -> IR.Repeat | ||
242 | A0 "MirroredRepeat" -> IR.MirroredRepeat | ||
243 | A0 "ClampToEdge" -> IR.ClampToEdge | ||
244 | x -> error $ "compEdgeMode: " ++ ppShow x | ||
245 | |||
235 | compSemantic = \case | 246 | compSemantic = \case |
236 | A0 "Depth" -> IR.Depth | 247 | A0 "Depth" -> IR.Depth |
237 | A0 "Stencil" -> IR.Stencil | 248 | A0 "Stencil" -> IR.Stencil |
@@ -624,7 +635,7 @@ genGLSLs backend | |||
624 | data Uniform | 635 | data Uniform |
625 | = UUniform | 636 | = UUniform |
626 | | UTexture2DSlot | 637 | | UTexture2DSlot |
627 | | UTexture2D Integer Integer ExpTV | 638 | | UTexture2D IR.Filter IR.EdgeMode Integer Integer ExpTV |
628 | 639 | ||
629 | type Uniforms = Map String (Uniform, IR.InputType) | 640 | type Uniforms = Map String (Uniform, IR.InputType) |
630 | 641 | ||
@@ -658,9 +669,9 @@ genGLSL dns e = case e of | |||
658 | [_, _, A1 "Texture2DSlot" (EString s)] -> do | 669 | [_, _, A1 "Texture2DSlot" (EString s)] -> do |
659 | tellUniform $ Map.singleton s $ (,) UTexture2DSlot IR.FTexture2D{-compInputType $ tyOf e -- TODO-} | 670 | tellUniform $ Map.singleton s $ (,) UTexture2DSlot IR.FTexture2D{-compInputType $ tyOf e -- TODO-} |
660 | pure $ text s | 671 | pure $ text s |
661 | [_, _, A2 "Texture2D" (A2 "V2" (EInt w) (EInt h)) b] -> do | 672 | [textureFilter, edgeMode, A2 "Texture2D" (A2 "V2" (EInt w) (EInt h)) b] -> do |
662 | s <- newName | 673 | s <- newName |
663 | tellUniform $ Map.singleton s $ (,) (UTexture2D w h b) IR.FTexture2D | 674 | tellUniform $ Map.singleton s $ (,) (UTexture2D (compFilter textureFilter) (compEdgeMode edgeMode) w h b) IR.FTexture2D |
664 | pure $ text s | 675 | pure $ text s |
665 | 676 | ||
666 | 'P':'r':'i':'m':n | n'@(_:_) <- trName (dropS n) -> call n' xs | 677 | 'P':'r':'i':'m':n | n'@(_:_) <- trName (dropS n) -> call n' xs |
@@ -1034,9 +1045,9 @@ genHLSL dns e = case e of | |||
1034 | [_, _, A1 "Texture2DSlot" (EString s)] -> do | 1045 | [_, _, A1 "Texture2DSlot" (EString s)] -> do |
1035 | tellUniform $ Map.singleton s $ (,) UTexture2DSlot IR.FTexture2D{-compInputType $ tyOf e -- TODO-} | 1046 | tellUniform $ Map.singleton s $ (,) UTexture2DSlot IR.FTexture2D{-compInputType $ tyOf e -- TODO-} |
1036 | pure $ text s | 1047 | pure $ text s |
1037 | [_, _, A2 "Texture2D" (A2 "V2" (EInt w) (EInt h)) b] -> do | 1048 | [textureFilter, edgeMode, A2 "Texture2D" (A2 "V2" (EInt w) (EInt h)) b] -> do |
1038 | s <- newName | 1049 | s <- newName |
1039 | tellUniform $ Map.singleton s $ (,) (UTexture2D w h b) IR.FTexture2D | 1050 | tellUniform $ Map.singleton s $ (,) (UTexture2D (compFilter textureFilter) (compEdgeMode edgeMode) w h b) IR.FTexture2D |
1040 | pure $ text s | 1051 | pure $ text s |
1041 | 1052 | ||
1042 | 'P':'r':'i':'m':n | n'@(_:_) <- trName (dropS n) -> call n' xs | 1053 | 'P':'r':'i':'m':n | n'@(_:_) <- trName (dropS n) -> call n' xs |