GPipe-1.2.0: A functional graphics API for programmable GPUs

Graphics.GPipe.FrameBuffer

Contents

Description

FrameBuffers are 2D images in which fragments from FragmentStreams are painted. A FrameBuffer may contain any combination of a color buffer, a depth buffer and a stencil buffer. FrameBuffers may be shown in windows, saved to memory or converted to textures. FrameBuffers have no size, but takes the size of the window when shown, or are given a size when saved to memory or converted to a texture.

Synopsis

The data type

data FrameBuffer c d s Source

A polymorphic frame buffer. It is parameterized on the type of color buffer, depth buffer and stencil buffer. Any instances of ColorFormat can be used for color buffer, or '()' to denote no color buffer. For depth and stencil buffers, DepthFormat and StencilFormat marks the existance of buffer, while '()' marks the inexistance.

Displaying framebuffers

newWindowSource

Arguments

:: String

The window title

-> Vec2 Int

The window position

-> Vec2 Int

The window size

-> (Vec2 Int -> IO (FrameBuffer c d s))

This function is evaluated every time the window needs to be redrawn, and the resulting FrameBuffer will be drawn in the window. The parameter is the current size of the window.

-> (Window -> IO ())

Extra optional initialization of the window. The provided Window should not be used outside this function.

-> IO () 

Cretes and shows a new GPipe window. Use the last parameter to add extra GLUT callbacks to the window. Note that you can't register your own displayCallback and reshapeCallback.

Creation

These functions create new FrameBuffers with initial color, depth values and/or stencil values.

Data retrieval

These functions provides the means for saving a FrameBuffer to main memory without the need to show it in a window.

getFrameBufferColorSource

Arguments

:: forall c d s a . GPUFormat c 
=> CPUFormat c

The format to store data to

-> Vec2 Int

The size to give the frame buffer

-> FrameBuffer c d s

A frame buffer with a color buffer

-> Ptr a

A pointer to the memory where the data will be saved

-> IO () 

Saves a FrameBuffers color buffer to main memory.

getFrameBufferDepthSource

Arguments

:: CPUFormat DepthFormat

The format to store data to

-> Vec2 Int

The size to give the frame buffer

-> FrameBuffer c DepthFormat s

A frame buffer with a depth buffer

-> Ptr a

A pointer to the memory where the data will be saved

-> IO () 

Saves a FrameBuffers depth buffer to main memory.

getFrameBufferStencilSource

Arguments

:: CPUFormat StencilFormat

The format to store data to

-> Vec2 Int

The size to give the frame buffer

-> FrameBuffer c d StencilFormat

A frame buffer with a stencil buffer

-> Ptr a

A pointer to the memory where the data will be saved

-> IO () 

Saves a FrameBuffers stencil buffer to main memory.

getFrameBufferCPUFormatByteSizeSource

Arguments

:: StorableCPUFormat f 
=> f

The format to store data to

-> Vec2 Int

The size to give the frame buffer

-> Int

The size in bytes of the data

Returns the byte size needed to store a certain format and size of a framebuffer. Use this to allocate memory before using getFrameBufferColor, getFrameBufferDepth or getFrameBufferStencil.

Paint operations

These functions paint FragmentStreams on FrameBuffers. A lot of different functions are provided for different types of FrameBuffers and FragmentStreams, all which takes more or less state values. The preffered way of using those is to curry them into the specific functions you need in your GPipe program, e.g.

paintSolid = paintColorRastDepth Lequal True NoBlending (RGB (vec True))

The RastDepth-functions uses the rasterized depth for the fragments.

Functions with two StencilOps arguments use them in this order: First if stencil test fail, second if stencil test pass. Functions with three StencilOps arguments use them in this order: First if stencil test fail, second if depth test fail, third if depth test pass.

type ColorMask f = Color f BoolSource

True for each color component that should be written to the FrameBuffer.

data Blending Source

Sets how the painted colors are blended with the FrameBuffers previous value.

Constructors

NoBlending

The painted fragment completely overwrites the previous value.

Blend (BlendEquation, BlendEquation) ((BlendingFactor, BlendingFactor), (BlendingFactor, BlendingFactor)) (Color RGBAFormat Float)

Use blending equations to combine the fragment with the previous value. The first BlendEquation and BlendingFactors is used for front faced triangles and other primitives, and the second for back faced triangles.

BlendLogicOp LogicOp

Use a LogicOp to combine the fragment with the previous value.

type DepthFunction = ComparisonFunctionSource

The function used to compare the fragment's depth and the depth buffers depth with.

type DepthMask = BoolSource

True if the depth component should be written to the FrameBuffer.

data StencilOps Source

Sets the operations that should be performed on the FrameBuffers stencil value

Constructors

StencilOps 

Fields

frontStencilOp :: StencilOp

Used for front faced triangles and other primitives.

backStencilOp :: StencilOp

Used for back faced triangles.

data StencilTest Source

Sets a test that should be performed on the stencil value.

Constructors

StencilTest 

Fields

stencilComparision :: ComparisonFunction

The function used to compare the stencilReference and the stencil buffers value with.

stencilReference :: Int32

The value to compare with the stencil buffer's value.

stencilMask :: Word32

A bit mask with ones in each position that should be compared and written to the stencil buffer.

data StencilTests Source

Sets the tests that should be performed on the stencil value, first for front facing triangles and other primitives, then for back facing triangles.