keid-core-0.1.9.0: Core parts of Keid engine.
Safe HaskellSafe-Inferred
LanguageGHC2021

Render.Code

Synopsis

Documentation

newtype Code Source #

A wrapper to show code into compileShaderQ vars.

Constructors

Code 

Fields

Instances

Instances details
IsString Code Source # 
Instance details

Defined in Render.Code

Methods

fromString :: String -> Code #

Show Code Source # 
Instance details

Defined in Render.Code

Methods

showsPrec :: Int -> Code -> ShowS #

show :: Code -> String #

showList :: [Code] -> ShowS #

Eq Code Source # 
Instance details

Defined in Render.Code

Methods

(==) :: Code -> Code -> Bool #

(/=) :: Code -> Code -> Bool #

Ord Code Source # 
Instance details

Defined in Render.Code

Methods

compare :: Code -> Code -> Ordering #

(<) :: Code -> Code -> Bool #

(<=) :: Code -> Code -> Bool #

(>) :: Code -> Code -> Bool #

(>=) :: Code -> Code -> Bool #

max :: Code -> Code -> Code #

min :: Code -> Code -> Code #

glsl :: QuasiQuoter #

glsl is a QuasiQuoter which produces GLSL source code with #line directives inserted so that error locations point to the correct location in the Haskell source file. It also permits basic string interpolation.

  • Interpolated variables are prefixed with $
  • They can optionally be surrounded with braces like ${foo}
  • Interpolated variables are converted to strings with show
  • To escape a $ use \$

It is intended to be used in concert with compileShaderQ like so

myConstant = 3.141 -- Note that this will have to be in a different module
myFragmentShader = $(compileShaderQ Nothing "frag" Nothing [glsl|
  #version 450
  const float myConstant = ${myConstant};
  main (){
  }
|])

An explicit example (interactive is from doctest):

>>> let version = 450 :: Int in [glsl|#version $version|]
"#version 450\n#extension GL_GOOGLE_cpp_style_line_directive : enable\n#line 32 \"<interactive>\"\n"

Note that line number will be thrown off if any of the interpolated variables contain newlines.

trimming :: QuasiQuoter #

Trimmed quasiquoter variation. Same as untrimming, but also removes the leading and trailing whitespace.