{-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-} {- | - Module : GLSL.Internal.Compile - Description : prints - Copyright : 2025 Andromeda - License : BSD 3-Clause - Maintainer : @Andromeda:tchncs.de - Stability : Experimental -} module GLSL.Internal.Compile where import GLSL.Internal -- | prints version as version header showVersion :: Version -> String showVersion Version'330_core = "#version 330 core" -- | prints variable with uniform qualifier showUniform :: Var -> String showUniform var = "uniform " ++ showVar var -- | prints variable with in qualifier showIn :: Var -> String showIn var = "in " ++ showVar var -- | prints variable with layout (location = <>) in qualifier showLayoutIn :: (Int, Var) -> String showLayoutIn (i, var) = "layout (location = " ++ show i ++ ") in " ++ showVar var -- | prints variable with out qualifier showOut :: Var -> String showOut var = "out " ++ showVar var -- | prints variable declaration showVar :: Var -> String showVar (Var name typ) = showType typ ++ " " ++ showId name -- | prints a dynamic expression showDExp :: DExp -> String showDExp (Lit'float f) = show f showDExp (E'var (Var name _)) = showId name showDExp (E'let (Var name _) exp0) = showId name ++ " = " ++ showDExp exp0 showDExp (E'if cond exp0 exp1) = "if " ++ showDExp cond ++ "\nthen\n" ++ showDExp exp0 ++ "\nelse\n" ++ showDExp exp1 showDExp (E'add exp0 exp1) = showDExp exp0 ++ " + " ++ showDExp exp1 showDExp (E'mul exp0 exp1) = showDExp exp0 ++ " * " ++ showDExp exp1 showDExp (E'normalize exp0) = "normalize(" ++ showDExp exp0 ++ ")" showDExp (Lit'bool cond) = if cond then "true" else "false" showDExp (Lit'vec2 exp0) = showDExp exp0 showDExp (Lit'vec3 exp0) = showDExp exp0 showDExp (Lit'vec4 exp0) = showDExp exp0 showDExp (E'vec2_2 f0 f1) = "vec2(" ++ showDExp f0 ++ ", " ++ showDExp f1 ++ ")" showDExp (E'vec3_2 f0 f1) = "vec3(" ++ showDExp f0 ++ ", " ++ showDExp f1 ++ ")" showDExp (E'vec4_2 f0 f1) = "vec4(" ++ showDExp f0 ++ ", " ++ showDExp f1 ++ ")" showDExp (E'vec3_3 f0 f1 f2) = "vec3(" ++ showDExp f0 ++ ", " ++ showDExp f1 ++ ", " ++ showDExp f2 ++ ")" showDExp (E'vec4_3 f0 f1 f2) = "vec4(" ++ showDExp f0 ++ ", " ++ showDExp f1 ++ ", " ++ showDExp f2 ++ ")" showDExp (E'vec4_4 f0 f1 f2 f3) = "vec4(" ++ showDExp f0 ++ ", " ++ showDExp f1 ++ ", " ++ showDExp f2 ++ ", " ++ showDExp f3 ++ ")" -- | toString for Type showType :: Type -> String showType T'bool = "bool" showType T'float = "float" showType T'vec2 = "vec2" showType T'vec3 = "vec3" showType T'vec4 = "vec4" showType T'mat4 = "mat4" -- | prints verbatim identifier showId :: Id -> String showId (Id s) = s