caramia-0.7.2.2: High-level OpenGL bindings

Safe HaskellNone
LanguageHaskell2010

Graphics.Caramia.Shader

Contents

Description

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.

https://www.opengl.org/wiki/OpenGL_Shading_Language

Synopsis

Creating new shaders.

newShader Source

Arguments

:: 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.

newPipelineVF Source

Arguments

:: 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.

data Shader Source

A shader object for a specific shader stage.

OpenGL equivalent is the shader object.

Instances

Eq Shader Source 
Ord Shader Source

The ordering has no inherent meaning but it allows shaders to be stored correctly in containers that have Ord constraint.

OpenGLResource GLuint Shader Source 

data Pipeline Source

A pipeline object that references a collection of shaders.

OpenGL equivalent is the shader program object.

Instances

Eq Pipeline Source 
Ord Pipeline Source 
OpenGLResource GLuint Pipeline Source

Despite the Haskell name, Pipeline, the object is a 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).

Minimal complete definition

setUniform_

Instances

Uniformable Double Source 
Uniformable Float Source 
Uniformable Int Source 
Uniformable Int8 Source 
Uniformable Int16 Source 
Uniformable Int32 Source 
Uniformable Int64 Source 
Uniformable Integer Source 
Uniformable Word8 Source 
Uniformable Word16 Source 
Uniformable Word32 Source 
Uniformable Word64 Source 
Uniformable CInt Source 
Uniformable CUInt Source 
Uniformable CFloat Source 
Uniformable CDouble Source 
Uniformable Color Source 
Uniformable (M33 Double) Source 
Uniformable (M33 Float) Source 
Uniformable (M33 CFloat) Source 
Uniformable (M33 CDouble) Source 
Uniformable (M44 Double) Source 
Uniformable (M44 Float) Source 
Uniformable (M44 CFloat) Source 
Uniformable (M44 CDouble) Source 
Uniformable (Quaternion Double) Source 
Uniformable (Quaternion Float) Source 
Uniformable (Quaternion CFloat) Source 
Uniformable (Quaternion CDouble) Source 
Uniformable (V4 Double) Source 
Uniformable (V4 Float) Source 
Uniformable (V4 CFloat) Source 
Uniformable (V4 CDouble) Source 
Uniformable (V3 Double) Source 
Uniformable (V3 Float) Source 
Uniformable (V3 CFloat) Source 
Uniformable (V3 CDouble) Source 
Uniformable (V2 Double) Source 
Uniformable (V2 Float) Source 
Uniformable (V2 CFloat) Source 
Uniformable (V2 CDouble) Source 
Uniformable (V1 Double) Source 
Uniformable (V1 Float) Source 
Uniformable (V1 CFloat) Source 
Uniformable (V1 CDouble) Source 
Uniformable (Double, Double) Source 
Uniformable (Float, Float) Source 
Uniformable (Int, Int) Source 
Uniformable (Int8, Int8) Source 
Uniformable (Int16, Int16) Source 
Uniformable (Int32, Int32) Source 
Uniformable (Int64, Int64) Source 
Uniformable (Integer, Integer) Source 
Uniformable (Word8, Word8) Source 
Uniformable (Word16, Word16) Source 
Uniformable (Word32, Word32) Source 
Uniformable (Word64, Word64) Source 
Uniformable (CInt, CInt) Source 
Uniformable (CUInt, CUInt) Source 
Uniformable (CFloat, CFloat) Source 
Uniformable (CDouble, CDouble) Source 
Uniformable (Double, Double, Double) Source 
Uniformable (Float, Float, Float) Source 
Uniformable (Int, Int, Int) Source 
Uniformable (Int8, Int8, Int8) Source 
Uniformable (Int16, Int16, Int16) Source 
Uniformable (Int32, Int32, Int32) Source 
Uniformable (Int64, Int64, Int64) Source 
Uniformable (Integer, Integer, Integer) Source 
Uniformable (Word8, Word8, Word8) Source 
Uniformable (Word16, Word16, Word16) Source 
Uniformable (Word32, Word32, Word32) Source 
Uniformable (Word64, Word64, Word64) Source 
Uniformable (CInt, CInt, CInt) Source 
Uniformable (CUInt, CUInt, CUInt) Source 
Uniformable (CFloat, CFloat, CFloat) Source 
Uniformable (CDouble, CDouble, CDouble) Source 
Uniformable (Double, Double, Double, Double) Source 
Uniformable (Float, Float, Float, Float) Source 
Uniformable (Int, Int, Int, Int) Source 
Uniformable (Int8, Int8, Int8, Int8) Source 
Uniformable (Int16, Int16, Int16, Int16) Source 
Uniformable (Int32, Int32, Int32, Int32) Source 
Uniformable (Int64, Int64, Int64, Int64) Source 
Uniformable (Integer, Integer, Integer, Integer) Source 
Uniformable (Word8, Word8, Word8, Word8) Source 
Uniformable (Word16, Word16, Word16, Word16) Source 
Uniformable (Word32, Word32, Word32, Word32) Source 
Uniformable (Word64, Word64, Word64, Word64) Source 
Uniformable (CInt, CInt, CInt, CInt) Source 
Uniformable (CUInt, CUInt, CUInt, CUInt) Source 
Uniformable (CFloat, CFloat, CFloat, CFloat) Source 
Uniformable (CDouble, CDouble, CDouble, CDouble) Source 

Shader stages

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 ShaderLinkingError Source

Thrown when a shader linking error occurs. The text is the error log for linking.

Can also be caught as ShaderBuildingError.

Constructors

ShaderLinkingError !Text 

data ShaderBuildingError Source

Thrown when either a compilation or linking error occurs.

Constructors

forall e . Exception e => ShaderBuildingError e