Safe Haskell | None |
---|---|
Language | Haskell2010 |
Shaders.
This module lets you use GLSL shaders in rendering.
This abstracts OpenGL shaders and shader objects. In the future, we might implement separate shader programs (that is, GL_ARB_separate_shader_objects).
At the moment, you need to use explicit attribute locations in shaders themselves. There is no functionality to retrieve attribute locations in this API; you simply have to know them.
- newShader :: MonadIO m => Text -> ShaderStage -> m Shader
- newShaderB :: MonadIO m => ByteString -> ShaderStage -> m Shader
- newShaderBL :: MonadIO m => ByteString -> ShaderStage -> m Shader
- newPipeline :: MonadIO m => [Shader] -> AttributeBindings -> m Pipeline
- newPipelineVF :: MonadIO m => Text -> Text -> AttributeBindings -> m Pipeline
- data Shader
- data Pipeline
- type AttributeBindings = Map ByteString GLuint
- setUniform :: MonadIO m => Uniformable a => a -> UniformLocation -> Pipeline -> m ()
- getUniformLocation :: MonadIO m => Text -> Pipeline -> m UniformLocation
- class Uniformable a
- type UniformLocation = Int
- data ShaderStage
- viewStage :: Shader -> ShaderStage
- nopPipeline :: MonadIO m => m Pipeline
- data ShaderCompilationError = ShaderCompilationError !Text
- data ShaderLinkingError = ShaderLinkingError !Text
- data ShaderBuildingError = forall e . Exception e => ShaderBuildingError e
Creating new shaders.
:: MonadIO m | |
=> Text | The shader source code. |
-> ShaderStage | |
-> m Shader |
Creates a shader from GLSL shader source, encoding a Text into an UTF-8 string.
This can throw ShaderCompilationError
if compilation fails.
newShaderB :: MonadIO m => ByteString -> ShaderStage -> m Shader Source
Creates a shader from GLSL shader source, using a strict bytestring.
newShaderBL :: MonadIO m => ByteString -> ShaderStage -> m Shader Source
Creates a shader from GLSL shader source, using a lazy bytestring.
The bytestring will be forced and converted to a strict bytestring internally, so this is not so efficient, if you care about storage efficiency in shader compilation.
newPipeline :: MonadIO m => [Shader] -> AttributeBindings -> m Pipeline Source
Creates a pipeline composed of different shaders.
:: MonadIO m | |
=> Text | Vertex shader source. |
-> Text | Fragment shader source. |
-> AttributeBindings | Attribute bindings. |
-> m Pipeline |
Creates a pipeline from vertex and fragment shader source.
This is a convenience function for a common use case.
A shader object for a specific shader stage.
OpenGL equivalent is the shader object.
A pipeline object that references a collection of shaders.
OpenGL equivalent is the shader program object.
Attribute bindings
type AttributeBindings = Map ByteString GLuint Source
Binds attribute names to specific attribute indices.
See glBindAttribLocation
from OpenGL documentation.
The Map
is from containers and is a member of Monoid
so you can use
mempty
if you are not doing any special binding.
You can use mapKeys
or mapKeysMonotonic
to change the key and fmap
to
map indices.
Uniforms
setUniform :: MonadIO m => Uniformable a => a -> UniformLocation -> Pipeline -> m () Source
Sets a uniform in a pipeline.
getUniformLocation :: MonadIO m => Text -> Pipeline -> m UniformLocation Source
Returns a uniform location for a given name.
The uniform may not be in the shader or it may not be active. If this
happens, a special uniform location is returned that can be used in
setUniform
to make it do nothing.
class Uniformable a Source
Class of data types that can be set to a uniform in a shader pipeline.
We provide instances for large integer values (such as Integer
) but you
should know that uniforms are rarely larger than 32-bit. We throw a user
error if you pass a value that is larger than what the OpenGL API can accept
(which is 2^32-1 for unsigned integer types and 2^31-1 for signed integer
types).
setUniform_
type UniformLocation = Int Source
Shader stages
data ShaderStage Source
Views
viewStage :: Shader -> ShaderStage Source
Which stage does this shader belong to.
Misc
nopPipeline :: MonadIO m => m Pipeline Source
Returns a pipeline that does not do anything.
Within the same context, this returns the same pipeline for each invocation.
Exception
data ShaderCompilationError Source
Thrown when a shader compilation error occurs. The text is the error log for compilation.
Can also be caught as ShaderBuildingError
.
data ShaderLinkingError Source
Thrown when a shader linking error occurs. The text is the error log for linking.
Can also be caught as ShaderBuildingError
.
data ShaderBuildingError Source
Thrown when either a compilation or linking error occurs.
forall e . Exception e => ShaderBuildingError e |