caramia-0.2.0.1: Less painful OpenGL 3.3 rendering

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

Documentation

newShader Source

Arguments

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

newPipelineVF Source

Arguments

:: Text

Vertex shader source.

-> Text

Fragment shader source.

-> IO 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 
Ord Shader

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

Typeable * Shader 

data Pipeline Source

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

Minimal complete definition

setUniform_

Instances

Uniformable Double 
Uniformable Float 
Uniformable Int 
Uniformable Int8 
Uniformable Int16 
Uniformable Int32 
Uniformable Int64 
Uniformable Integer 
Uniformable Word8 
Uniformable Word16 
Uniformable Word32 
Uniformable Word64 
Uniformable CInt 
Uniformable CUInt 
Uniformable CFloat 
Uniformable CDouble 
Uniformable Quaternion 
Uniformable Vector3 
Uniformable Matrix33 
Uniformable Matrix44 
Uniformable (Double, Double) 
Uniformable (Float, Float) 
Uniformable (Int, Int) 
Uniformable (Int8, Int8) 
Uniformable (Int16, Int16) 
Uniformable (Int32, Int32) 
Uniformable (Int64, Int64) 
Uniformable (Integer, Integer) 
Uniformable (Word8, Word8) 
Uniformable (Word16, Word16) 
Uniformable (Word32, Word32) 
Uniformable (Word64, Word64) 
Uniformable (CInt, CInt) 
Uniformable (CUInt, CUInt) 
Uniformable (CFloat, CFloat) 
Uniformable (CDouble, CDouble) 
Uniformable (Double, Double, Double) 
Uniformable (Float, Float, Float) 
Uniformable (Int, Int, Int) 
Uniformable (Int8, Int8, Int8) 
Uniformable (Int16, Int16, Int16) 
Uniformable (Int32, Int32, Int32) 
Uniformable (Int64, Int64, Int64) 
Uniformable (Integer, Integer, Integer) 
Uniformable (Word8, Word8, Word8) 
Uniformable (Word16, Word16, Word16) 
Uniformable (Word32, Word32, Word32) 
Uniformable (Word64, Word64, Word64) 
Uniformable (CInt, CInt, CInt) 
Uniformable (CUInt, CUInt, CUInt) 
Uniformable (CFloat, CFloat, CFloat) 
Uniformable (CDouble, CDouble, CDouble) 
Uniformable (Double, Double, Double, Double) 
Uniformable (Float, Float, Float, Float) 
Uniformable (Int, Int, Int, Int) 
Uniformable (Int8, Int8, Int8, Int8) 
Uniformable (Int16, Int16, Int16, Int16) 
Uniformable (Int32, Int32, Int32, Int32) 
Uniformable (Int64, Int64, Int64, Int64) 
Uniformable (Integer, Integer, Integer, Integer) 
Uniformable (Word8, Word8, Word8, Word8) 
Uniformable (Word16, Word16, Word16, Word16) 
Uniformable (Word32, Word32, Word32, Word32) 
Uniformable (Word64, Word64, Word64, Word64) 
Uniformable (CInt, CInt, CInt, CInt) 
Uniformable (CUInt, CUInt, CUInt, CUInt) 
Uniformable (CFloat, CFloat, CFloat, CFloat) 
Uniformable (CDouble, CDouble, CDouble, CDouble) 

Shader stages

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.

Constructors

ShaderLinkingError !Text 

data ShaderBuildingError Source

Thrown when either a compilation or linking error occurs.

Constructors

forall e . Exception e => ShaderBuildingError e