caramia-0.7.2.2: High-level OpenGL bindings

Safe HaskellNone
LanguageHaskell2010

Graphics.Caramia.VAO

Contents

Description

Vertex array objects, or VAOs as we abbreviate them.

These are used to specify how data in a Buffer is made available in a shader program.

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

Either OpenGL 3.0 or GL_ARB_vertex_array_object extension is required to use operations from this module.

Synopsis

Creation

newVAO :: MonadIO m => m VAO Source

Creates a vertex array object.

Initially, the vertex array object makes no data available to a shader program.

data VAO Source

The vertex array object data type.

Sourcing

sourceVertexData Source

Arguments

:: MonadIO m 
=> Buffer

From which buffer to source the data.

-> Sourcing

Specifies how the sourcing is done.

-> VAO 
-> m () 

Specifies that some data from a buffer should be sourced for each vertex.

The vertex array object retains a reference to the buffer which means it will not be garbage collected as long as the VAO remains active.

Consequences are undefined if your Sourcing does not make sense. There is some error checking but it can only detect obviously invalid values in the sourcing.

data Sourcing Source

Specifies how to source data.

For forward compatibility, you might want to use defaultSourcing or defaultSourcingType and then set the fields that are of interest to you.

Constructors

Sourcing 

Fields

offset :: Int

Offset, in bytes, at which point from buffer to start sourcing.

attributeIndex :: Int

Which attribute index in a shader program to source this data. See Shader on attributes.

components :: Int

Number of components in one piece of data (that is, per vertex). This must be an integer between 1 and 4.

stride :: Int

How many bytes there are between pieces of data. Because of OpenGL inconsistencies behind the scenes, 0 means the data is tightly packed, that is, stride = components * sizeOf sourceType

normalize :: Bool

This only applies when an integer type is used in sourceType and integerMapping is false. It determines whether integer values should be normalized.

Normalization maps the integer value to [-1..1] or [0..1] range. For example, if you use Word16 as the type parameter, then 0 is mapped to 0.0 and 65535 is mapped to 1.0. Signed types (for example, Int16) are mapped to [-1..1] instead so for Int16 32767 is mapped to 1 and -32768 is mapped to -1.

This value is ignored and unevaluated for types that are one of the floating point types.

integerMapping :: Bool

Don't convert integers to floats in any way. Normally integers are converted to floating point. If this is set, then normalize is ignored and not evalutated.

instancingDivisor :: Int

When doing instanced rendering (numInstances > 1), this value tells how many instances must be rendered before the attribute from this source advances.

If zero (the default) then the attribute is advanced after every vertex.

You can look up glVertexAttribDivisor from OpenGL to find more information about this.

sourceType :: SourceType

The data type of values in the buffer. It tells the type of a single component.

defaultSourcing :: Sourcing Source

The default sourcing.

Offset and stride are set to 0.

At the very least you must set components and attributeIndex.

You must also set normalize, integerMapping and sourceType in a consistent way. See Sourcing.

defaultSourcingType Source

Arguments

:: SourceableType a 
=> a

Used to pass the type; not evaluated.

-> Sourcing 

Same as defaultSourcing but sets sourceType according to a Haskell type.

Sourceable types

class SourceableType a where Source

Class of types that are valid for sourcing data.

This is a convenience class to turn Haskell types to SourceType.

Methods

reifyType :: a -> SourceType Source

Reify the type to a compatible SourceType.

data SourceType Source

Types allowed for sourcing.

These are mostly Haskell types except for SHalfFloat which has no Haskell equivalent.

Constructors

SWord8 
SWord16 
SWord32 
SInt8 
SInt16 
SInt32 
SHalfFloat

16-bit floating point value.

SFloat 
SDouble 

sourceTypeSize :: SourceType -> Int Source

This returns the size of a SourceType, in bytes.