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 :: Text -> ShaderStage -> IO Shader
- newShaderB :: ByteString -> ShaderStage -> IO Shader
- newShaderBL :: ByteString -> ShaderStage -> IO Shader
- newPipeline :: [Shader] -> IO Pipeline
- newPipelineVF :: Text -> Text -> IO Pipeline
- data Shader
- data Pipeline
- setUniform :: Uniformable a => a -> UniformLocation -> Pipeline -> IO ()
- getUniformLocation :: Text -> Pipeline -> IO UniformLocation
- class Uniformable a
- type UniformLocation = Int
- data ShaderStage
- viewStage :: Shader -> ShaderStage
- nopPipeline :: IO Pipeline
- data ShaderCompilationError = ShaderCompilationError !Text
- data ShaderLinkingError = ShaderLinkingError !Text
- data ShaderBuildingError = forall e . Exception e => ShaderBuildingError e
Documentation
:: Text | The shader source code. |
-> ShaderStage | |
-> IO Shader |
Creates a shader from GLSL shader source, encoding a Text into an UTF-8 string.
This can throw ShaderCompilationError
if compilation fails.
newShaderB :: ByteString -> ShaderStage -> IO Shader Source
Creates a shader from GLSL shader source, using a strict bytestring.
newShaderBL :: ByteString -> ShaderStage -> IO 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 :: [Shader] -> IO Pipeline Source
Creates a pipeline composed of different shaders.
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.
Uniforms
setUniform :: Uniformable a => a -> UniformLocation -> Pipeline -> IO () Source
Sets a uniform in a pipeline.
getUniformLocation :: Text -> Pipeline -> IO 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 :: IO 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 |