Safe Haskell | None |
---|---|
Language | Haskell98 |
A Shader
is a monad in which PrimitiveStream
s and FragmentStream
s live, together with samplers and uniform values. Any computations made on the streams and values in
the Shader
monad will be performed on the GPU. A Shader
needs to be compiled before it can be used. In order to make it work over different environments after it
has been compiled, it closes over an environment value just like a Reader
monad, with the distinction that there is no ask
action, since we cannot make the
actual monad operation depend on the environment.
A Shader
is an instance of Alternative
and MonadPlus
which makes it possible to express choice with functions like guard
. The left most alternative will always be the
resulting monad.
- data Shader os f s a
- compileShader :: (MonadIO m, MonadException m) => Shader os f x () -> ContextT w os f' m (CompiledShader os f x)
- withoutContext :: Render os () () -> Render os f ()
- type CompiledShader os f s = s -> Render os f ()
- data Render os f a
- render :: (MonadIO m, MonadException m) => Render os f () -> ContextT w os f m ()
- guard' :: (s -> Bool) -> Shader os f s ()
- mapShader :: (s -> s') -> Shader os f s' a -> Shader os f s a
- maybeShader :: (s -> Maybe s') -> Shader os f s' () -> Shader os f s ()
- chooseShader :: (s -> Either s' s'') -> Shader os f s' a -> Shader os f s'' a -> Shader os f s a
- silenceShader :: Shader os f' s a -> Shader os f s a
The Shader monad
The monad in which all GPU computations are done. 'Shader os f s a' lives in an object space os
and a context with format f
, closing over an environent of type s
.
Alternative (Shader os f s) | |
Monad (Shader os f s) | |
Functor (Shader os f s) | |
MonadPlus (Shader os f s) | |
Applicative (Shader os f s) |
compileShader :: (MonadIO m, MonadException m) => Shader os f x () -> ContextT w os f' m (CompiledShader os f x) Source
Compiles a shader into a CompiledShader
. This action will usually take a second or more, so put it during a loading sequence or something.
May throw a GPipeException
if the graphics driver doesn't support something in this shader (e.g. too many interpolated floats sent between a vertex and a fragment shader),
or if shader evaluates to mzero
.
withoutContext :: Render os () () -> Render os f () Source
Use this to run a shader that doesn't reference the context frame buffer, allowing the same shader to be run in another context with a different context format (but still with same object space).
type CompiledShader os f s = s -> Render os f () Source
A compiled shader is just a function that takes an environment and returns a Render
action
The Render monad
A monad in which shaders are run.
render :: (MonadIO m, MonadException m) => Render os f () -> ContextT w os f m () Source
Run a Render
monad, that may have the effect of the context window or textures being drawn to.
May throw a GPipeException
if a combination of draw images (FBO) used by this render call is unsupported by the graphics driver
Shader monad combinators
guard' :: (s -> Bool) -> Shader os f s () Source
Like guard
, but dependent on the Shaders
environment value. Since this will be evaluated at shader run time, as opposed to shader compile time for guard
,
using this to do recursion will make compileShader
diverge. You can break that divergence by combining it with a normal guard
and a maximum loop count.
mapShader :: (s -> s') -> Shader os f s' a -> Shader os f s a Source
Map the environment to a different environment and run a Shader in that sub environment, returning it's result.
maybeShader :: (s -> Maybe s') -> Shader os f s' () -> Shader os f s () Source