diff options
-rw-r--r-- | lc/Builtins.lc | 6 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/CoreToIR.hs | 11 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lc/Builtins.lc b/lc/Builtins.lc index 1657fc8f..c2e2e7a9 100644 --- a/lc/Builtins.lc +++ b/lc/Builtins.lc | |||
@@ -558,6 +558,11 @@ data Texture where | |||
558 | data TextureCube where | 558 | data TextureCube where |
559 | TextureCubeSlot :: String -- texture slot name | 559 | TextureCubeSlot :: String -- texture slot name |
560 | -> TextureCube | 560 | -> TextureCube |
561 | |||
562 | data TextureBuffer where | ||
563 | TextureBufferSlot :: String -- texture slot name | ||
564 | -> TextureBuffer | ||
565 | |||
561 | data Filter | 566 | data Filter |
562 | = PointFilter | 567 | = PointFilter |
563 | | LinearFilter | 568 | | LinearFilter |
@@ -572,6 +577,7 @@ data Sampler = Sampler Filter EdgeMode Texture | |||
572 | -- builtin | 577 | -- builtin |
573 | texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float | 578 | texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float |
574 | textureCube :: TextureCube -> Vec 3 Float -> Vec 4 Float | 579 | textureCube :: TextureCube -> Vec 3 Float -> Vec 4 Float |
580 | textureBuffer :: TextureBuffer -> Int -> Float | ||
575 | 581 | ||
576 | 582 | ||
577 | -- todo: remove | 583 | -- todo: remove |
diff --git a/src/LambdaCube/Compiler/CoreToIR.hs b/src/LambdaCube/Compiler/CoreToIR.hs index 7e4bfbd8..b587096e 100644 --- a/src/LambdaCube/Compiler/CoreToIR.hs +++ b/src/LambdaCube/Compiler/CoreToIR.hs | |||
@@ -492,6 +492,7 @@ showGLSLType msg = \case | |||
492 | IR.M43F -> "mat4x3" | 492 | IR.M43F -> "mat4x3" |
493 | IR.FTexture2D -> "sampler2D" | 493 | IR.FTexture2D -> "sampler2D" |
494 | IR.FTextureCube -> "samplerCube" | 494 | IR.FTextureCube -> "samplerCube" |
495 | IR.FTextureBuffer -> "samplerBuffer" | ||
495 | t -> error $ "toGLSLType: " ++ msg ++ " " ++ show t | 496 | t -> error $ "toGLSLType: " ++ msg ++ " " ++ show t |
496 | 497 | ||
497 | supType :: ExpTV -> Bool | 498 | supType :: ExpTV -> Bool |
@@ -773,6 +774,8 @@ genGLSLs backend | |||
773 | <> ["precision highp float;" | backend == WebGL1] | 774 | <> ["precision highp float;" | backend == WebGL1] |
774 | <> ["precision highp int;" | backend == WebGL1] | 775 | <> ["precision highp int;" | backend == WebGL1] |
775 | <> [shaderFunc "vec4" "texture2D" ["sampler2D s", "vec2 uv"] [shaderReturn "texture(s,uv)"] | backend == OpenGL33] | 776 | <> [shaderFunc "vec4" "texture2D" ["sampler2D s", "vec2 uv"] [shaderReturn "texture(s,uv)"] | backend == OpenGL33] |
777 | <> [shaderFunc "vec4" "textureCube" ["samplerCube s", "vec3 x"] [shaderReturn "texture(s,x)"] | backend == OpenGL33] | ||
778 | <> [shaderFunc "float" "textureBuffer" ["samplerBuffer s", "int x"] [shaderReturn "texelFetch(s,x).r"] | backend == OpenGL33] | ||
776 | <> [shaderFunc "mat4" "transpose" ["mat4 m"] -- todo: not just for 4 dimension | 779 | <> [shaderFunc "mat4" "transpose" ["mat4 m"] -- todo: not just for 4 dimension |
777 | [ shaderLet "vec4 i0" "m[0]" | 780 | [ shaderLet "vec4 i0" "m[0]" |
778 | , shaderLet "vec4 i1" "m[1]" | 781 | , shaderLet "vec4 i1" "m[1]" |
@@ -802,6 +805,7 @@ data Uniform | |||
802 | = UUniform | 805 | = UUniform |
803 | | UTexture2DSlot | 806 | | UTexture2DSlot |
804 | | UTextureCubeSlot | 807 | | UTextureCubeSlot |
808 | | UTextureBufferSlot | ||
805 | | UTexture2D IR.Filter IR.EdgeMode Integer Integer ExpTV | 809 | | UTexture2D IR.Filter IR.EdgeMode Integer Integer ExpTV |
806 | 810 | ||
807 | type Uniforms = Map String (Uniform, IR.InputType) | 811 | type Uniforms = Map String (Uniform, IR.InputType) |
@@ -846,6 +850,11 @@ genGLSL backend dns e = case e of | |||
846 | [EString s] -> do | 850 | [EString s] -> do |
847 | tellUniform $ Map.singleton s $ (,) UTextureCubeSlot IR.FTextureCube | 851 | tellUniform $ Map.singleton s $ (,) UTextureCubeSlot IR.FTextureCube |
848 | pure $ text s | 852 | pure $ text s |
853 | "TextureBufferSlot" -> case xs of | ||
854 | [EString s] -> do | ||
855 | tellUniform $ Map.singleton s $ (,) UTextureBufferSlot IR.FTextureBuffer | ||
856 | pure $ text s | ||
857 | |||
849 | 858 | ||
850 | 859 | ||
851 | 'P':'r':'i':'m':n | n'@(_:_) <- trName (dropS n) -> call n' xs | 860 | 'P':'r':'i':'m':n | n'@(_:_) <- trName (dropS n) -> call n' xs |
@@ -941,6 +950,7 @@ genGLSL backend dns e = case e of | |||
941 | trName n = case n of | 950 | trName n = case n of |
942 | "texture2D" -> "texture2D" | 951 | "texture2D" -> "texture2D" |
943 | "textureCube" -> "textureCube" | 952 | "textureCube" -> "textureCube" |
953 | "textureBuffer" -> "textureBuffer" | ||
944 | 954 | ||
945 | "True" -> "true" | 955 | "True" -> "true" |
946 | "False" -> "false" | 956 | "False" -> "false" |
@@ -1545,6 +1555,7 @@ genHLSLs backend | |||
1545 | shader xs = vcat $ | 1555 | shader xs = vcat $ |
1546 | [shaderFunc "vec4" "texture2D" ["sampler2D s", "vec2 uv"] [shaderReturn "texture(s,uv)"] | backend == OpenGL33] | 1556 | [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] | 1557 | <> [shaderFunc "vec4" "textureCube" ["samplerCube s", "vec3 x"] [shaderReturn "texture(s,x)"] | backend == OpenGL33] |
1558 | <> [shaderFunc "float" "textureBuffer" ["samplerBuffer s", "int x"] [shaderReturn "texelFetch(s,x).r"] | backend == OpenGL33] | ||
1548 | <> [shaderFunc "mat4" "transpose" ["mat4 m"] -- todo: not just for 4 dimension | 1559 | <> [shaderFunc "mat4" "transpose" ["mat4 m"] -- todo: not just for 4 dimension |
1549 | [ shaderLet "vec4 i0" "m[0]" | 1560 | [ shaderLet "vec4 i0" "m[0]" |
1550 | , shaderLet "vec4 i1" "m[1]" | 1561 | , shaderLet "vec4 i1" "m[1]" |