diff options
author | Joe Crayne <joe@jerkface.net> | 2019-05-02 17:07:35 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-05-11 20:02:51 -0400 |
commit | 9c8b68d747cb28047e444447a3398c136ba26c8d (patch) | |
tree | cba0e3ecceba190be471b6ae5087c722d3596607 | |
parent | 8e3c978fc86c7a7dea0ab7820cb0f81ccd87c706 (diff) |
TextureCube support.
-rw-r--r-- | lc/Builtins.lc | 4 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/CoreToIR.hs | 9 |
2 files changed, 13 insertions, 0 deletions
diff --git a/lc/Builtins.lc b/lc/Builtins.lc index 15840268..1657fc8f 100644 --- a/lc/Builtins.lc +++ b/lc/Builtins.lc | |||
@@ -555,6 +555,9 @@ data Texture where | |||
555 | -> Image 1 (Color (Vec 4 Float)) | 555 | -> Image 1 (Color (Vec 4 Float)) |
556 | -> Texture | 556 | -> Texture |
557 | 557 | ||
558 | data TextureCube where | ||
559 | TextureCubeSlot :: String -- texture slot name | ||
560 | -> TextureCube | ||
558 | data Filter | 561 | data Filter |
559 | = PointFilter | 562 | = PointFilter |
560 | | LinearFilter | 563 | | LinearFilter |
@@ -568,6 +571,7 @@ data Sampler = Sampler Filter EdgeMode Texture | |||
568 | 571 | ||
569 | -- builtin | 572 | -- builtin |
570 | texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float | 573 | texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float |
574 | textureCube :: TextureCube -> Vec 3 Float -> Vec 4 Float | ||
571 | 575 | ||
572 | 576 | ||
573 | -- todo: remove | 577 | -- todo: remove |
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs index 30353129..7e4bfbd8 100644 --- a/src/LambdaCube/Compiler/CoreToIR.hs +++ b/src/LambdaCube/Compiler/CoreToIR.hs | |||
@@ -491,6 +491,7 @@ showGLSLType msg = \case | |||
491 | IR.M42F -> "mat4x2" | 491 | IR.M42F -> "mat4x2" |
492 | IR.M43F -> "mat4x3" | 492 | IR.M43F -> "mat4x3" |
493 | IR.FTexture2D -> "sampler2D" | 493 | IR.FTexture2D -> "sampler2D" |
494 | IR.FTextureCube -> "samplerCube" | ||
494 | t -> error $ "toGLSLType: " ++ msg ++ " " ++ show t | 495 | t -> error $ "toGLSLType: " ++ msg ++ " " ++ show t |
495 | 496 | ||
496 | supType :: ExpTV -> Bool | 497 | supType :: ExpTV -> Bool |
@@ -800,6 +801,7 @@ genGLSLs backend | |||
800 | data Uniform | 801 | data Uniform |
801 | = UUniform | 802 | = UUniform |
802 | | UTexture2DSlot | 803 | | UTexture2DSlot |
804 | | UTextureCubeSlot | ||
803 | | UTexture2D IR.Filter IR.EdgeMode Integer Integer ExpTV | 805 | | UTexture2D IR.Filter IR.EdgeMode Integer Integer ExpTV |
804 | 806 | ||
805 | type Uniforms = Map String (Uniform, IR.InputType) | 807 | type Uniforms = Map String (Uniform, IR.InputType) |
@@ -840,6 +842,11 @@ genGLSL backend dns e = case e of | |||
840 | s <- newName | 842 | s <- newName |
841 | tellUniform $ Map.singleton s $ (,) (UTexture2D (compFilter textureFilter) (compEdgeMode edgeMode) w h b) IR.FTexture2D | 843 | tellUniform $ Map.singleton s $ (,) (UTexture2D (compFilter textureFilter) (compEdgeMode edgeMode) w h b) IR.FTexture2D |
842 | pure $ text s | 844 | pure $ text s |
845 | "TextureCubeSlot" -> case xs of | ||
846 | [EString s] -> do | ||
847 | tellUniform $ Map.singleton s $ (,) UTextureCubeSlot IR.FTextureCube | ||
848 | pure $ text s | ||
849 | |||
843 | 850 | ||
844 | 'P':'r':'i':'m':n | n'@(_:_) <- trName (dropS n) -> call n' xs | 851 | 'P':'r':'i':'m':n | n'@(_:_) <- trName (dropS n) -> call n' xs |
845 | where | 852 | where |
@@ -933,6 +940,7 @@ genGLSL backend dns e = case e of | |||
933 | where | 940 | where |
934 | trName n = case n of | 941 | trName n = case n of |
935 | "texture2D" -> "texture2D" | 942 | "texture2D" -> "texture2D" |
943 | "textureCube" -> "textureCube" | ||
936 | 944 | ||
937 | "True" -> "true" | 945 | "True" -> "true" |
938 | "False" -> "false" | 946 | "False" -> "false" |
@@ -1536,6 +1544,7 @@ genHLSLs backend | |||
1536 | 1544 | ||
1537 | shader xs = vcat $ | 1545 | shader xs = vcat $ |
1538 | [shaderFunc "vec4" "texture2D" ["sampler2D s", "vec2 uv"] [shaderReturn "texture(s,uv)"] | backend == OpenGL33] | 1546 | [shaderFunc "vec4" "texture2D" ["sampler2D s", "vec2 uv"] [shaderReturn "texture(s,uv)"] | backend == OpenGL33] |
1547 | <> [shaderFunc "vec4" "textureCube" ["samplerCube s", "vec3 x"] [shaderReturn "texture(s,x)"] | backend == OpenGL33] | ||
1539 | <> [shaderFunc "mat4" "transpose" ["mat4 m"] -- todo: not just for 4 dimension | 1548 | <> [shaderFunc "mat4" "transpose" ["mat4 m"] -- todo: not just for 4 dimension |
1540 | [ shaderLet "vec4 i0" "m[0]" | 1549 | [ shaderLet "vec4 i0" "m[0]" |
1541 | , shaderLet "vec4 i1" "m[1]" | 1550 | , shaderLet "vec4 i1" "m[1]" |