Copyright | (C) 2015 Dimitri Sabadie |
---|---|
License | BSD3 |
Maintainer | Dimitri Sabadie <dimitri.sabadie@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
- data Program
- programID :: Program -> GLuint
- createProgram :: (HasProgramError e, MonadError e m, MonadIO m, MonadResource m) => [Stage] -> ((forall a. UniformName a -> UniformInterface m (U a)) -> UniformInterface m i) -> m (Program, i)
- createProgram_ :: (HasProgramError e, MonadError e m, MonadIO m, MonadResource m) => [Stage] -> m Program
- class Uniform a
- data U a
- data UniformInterface m a
- data UniformName :: * -> * where
- UniformName :: Uniform a => String -> UniformName a
- UniformSemantic :: Uniform a => Natural -> UniformName a
- UniformBlockName :: UniformBlock a => String -> UniformName (Region rw (UB a))
- data SomeUniformName = forall a . SomeUniformName (UniformName a)
- class UniformBlock a
- newtype UB a = UB {
- unUB :: a
- data ProgramError
- class HasProgramError a where
- fromProgramError :: ProgramError -> a
Shader program creation
data Program
Shader program.
createProgram :: (HasProgramError e, MonadError e m, MonadIO m, MonadResource m) => [Stage] -> ((forall a. UniformName a -> UniformInterface m (U a)) -> UniformInterface m i) -> m (Program, i)
Create a new shader Program
.
That function takes a list of Stage
s and a uniform interface builder function and yields a
Program
and the interface.
The builder function takes a function you can use to retrieve uniforms. You can pass
values of type UniformName
to identify the uniform you want to retrieve. If the uniform can’t
be retrieved, throws InactiveUniform
.
In the end, you get the new Program
and a polymorphic value you can choose the type of in
the function you pass as argument. You can use that value to gather uniforms for instance.
createProgram_ :: (HasProgramError e, MonadError e m, MonadIO m, MonadResource m) => [Stage] -> m Program
A simpler version of createProgram
. That function assumes you don’t need a uniform interface
and then just returns the Program
.
Uniform
class Uniform a
Class of types that can be sent down to shaders. That class is closed because shaders cannot
handle a lot of uniform types. However, you should have a look at the U
documentation for
further information about how to augment the scope of the types you can send down to shaders.
toU
data U a
A shader uniform.
doesn’t hold any value. It’s more like a mapping between the host
code and the shader the uniform was retrieved from.U
a
U
is contravariant in its argument. That means that you can use contramap
to build more
interesting uniform types. It’s also a divisible contravariant functor, then you can divide
structures to take advantage of divisible contravariant properties and then glue several U
with different types. That can be useful to build a uniform type by gluing its fields.
Another interesting part is the fact that U
is also monoidal. You can accumulate several of
them with '(<>)' if they have the same type. That means that you can join them so that when you
pass an actual value, it gets shared inside the resulting value.
The '()' instance doesn’t do anything and doesn’t even use its argument ('()').
data UniformInterface m a
Monad m => Monad (UniformInterface m) | |
Functor m => Functor (UniformInterface m) | |
Monad m => Applicative (UniformInterface m) |
data UniformName :: * -> * where
Possible way to name uniform values.
UniformName :: Uniform a => String -> UniformName a | |
UniformSemantic :: Uniform a => Natural -> UniformName a | |
UniformBlockName :: UniformBlock a => String -> UniformName (Region rw (UB a)) |
data SomeUniformName
A uniform name with type-erasure. You can only access the constructors and the carried name but you can’t reconstruct the phantom type.
forall a . SomeUniformName (UniformName a) |
Uniform block
class UniformBlock a
UniformBlock Bool | |
UniformBlock Float | |
UniformBlock Int32 | |
UniformBlock Word32 | |
(Storable a, UniformBlock a) => UniformBlock (V4 a) | |
(Storable a, UniformBlock a) => UniformBlock (V3 a) | |
(Storable a, UniformBlock a) => UniformBlock (V2 a) | |
(UniformBlock a, UniformBlock b) => UniformBlock (a, b) | |
(UniformBlock a, UniformBlock b) => UniformBlock ((:.) a b) | |
(UniformBlock a, UniformBlock b, UniformBlock c) => UniformBlock (a, b, c) | |
(UniformBlock a, UniformBlock b, UniformBlock c, UniformBlock d) => UniformBlock (a, b, c, d) |
newtype UB a
Error handling
data ProgramError
Shader program error.
'LinkFailed reason' happens when a program fails to link. reason
contains the error message.
'InactiveUniform uni' happens at linking when a uniform is inactive in the program; that is, unused or semantically set to a negative value.
class HasProgramError a where
Types that can handle ProgramError
– read as, “have”.
fromProgramError :: ProgramError -> a