GPipe-1.0.1: A functional graphics API for programmable GPUsSource codeContentsIndex
Graphics.GPipe.Stream.Primitive
Contents
Data types
Creating primitive streams
Description

PrimitiveStreams implement the Functor class, which provides the fmap method that you can use to manipulate those streams. This corresponds to writing and using vertex shaders, but in a much more modular way. You may for instance apply fmap several times in a sequence, effectively creating complex shaders.

Instances are also provided for the Monoid class, so several streams (of the same type) can be concatenated. The order is preserved, meaning that the primitives in stream a in a mappend b will be drawn before the primitives in b.

All atomic values except textures in vertex streams uses the Vertex type constructor. Composite types are created by composing the atomic Vertex types, rather than wrapping the composite type in the Vertex type constructors.

Vertex instances for are provided for most of Prelude's numerical classes. Since Eq, Ord and Show are prerequisites for these classes, instances are provided for them too, even though their methods all will generate errors if used (except min and max). Use the instances of EqB, OrdB and IfB from the Boolean package if you want to compare Vertex values. Hyperbolic trigonometrical functions aren't provided either.

Rewrite rule specializations are provided for the Vec package functions norm, normalize, dot and cross on vectors of Vertex Float, so the use of these functions (and others from that package that is defined in terms of them) are highly encouraged.

Synopsis
data PrimitiveStream p a
data Vertex a
class GPU a => VertexInput a where
toVertex :: CPU a -> InputAssembler a
data InputAssembler a
data Triangle
= TriangleStrip
| TriangleList
| TriangleFan
data Line
= LineStrip
| LineList
data Point = PointList
class Primitive p
toGPUStream :: (VertexInput a, Primitive p) => p -> [CPU a] -> PrimitiveStream p a
toIndexedGPUStream :: (VertexInput a, Primitive p) => p -> [CPU a] -> [Int] -> PrimitiveStream p a
Data types
data PrimitiveStream p a Source
A stream of primitives built by vertices on the GPU. The first parameter is the primitive type (currently Triangle, Line or Point) and the second the the type of each primitives' vertices' type (built up of atoms of type Vertex).
show/hide Instances
data Vertex a Source
An opaque type constructor for atomic values in a vertex on the GPU, e.g. Vertex Float.
show/hide Instances
Creating primitive streams
class GPU a => VertexInput a whereSource
The context of types that can be converted into vertices in PrimitiveStreams. Create your own instances in terms of the existing ones, e.g. convert your vertex data to Floats, turn them into Vertex Floats with toVertex and then convert them to your vertex data representation.
Methods
toVertex :: CPU a -> InputAssembler aSource
Turns an ordinary value into a vertex value in the InputAssembler monad. This should not be strict on its argument. Its definition should also always use the same series of toVertex calls to convert values of the same type. This unfortunatly rules out ordinary lists (but instances for fixed length lists from the Vec package are however provided).
show/hide Instances
data InputAssembler a Source
A monad in which CPU data gets converted to vertex data. Use toVertex in the existing instances of VertexInput to operate in this monad.
show/hide Instances
data Triangle Source
Constructors
TriangleStrip
TriangleList
TriangleFan
show/hide Instances
data Line Source
Constructors
LineStrip
LineList
show/hide Instances
data Point Source
Constructors
PointList
show/hide Instances
class Primitive p Source
show/hide Instances
toGPUStreamSource
:: (VertexInput a, Primitive p)
=> pThe primitive type.
-> [CPU a]A list of vertices, with the layout specified by the primitive type.
-> PrimitiveStream p aThe resulting PrimitiveStream.
Converts a list of values to a PrimitiveStream, using a specified Primitive type. This function is lazy in the aspect that if parts of the values aren't used on the GPU, they won't get evaluated and transferred there either.
toIndexedGPUStreamSource
:: (VertexInput a, Primitive p)
=> pThe primitive type.
-> [CPU a]A list of vertices.
-> [Int]A list of indexes into the vertex list, with the layout specified by the primitive type.
-> PrimitiveStream p aThe resulting PrimitiveStream.
Converts a list of values to a PrimitiveStream, using a specified Primitive type and an index list. This will use index buffer objects on the GPU, and is recommended if several primitives share vertices. This function is lazy in the aspect that if parts of the values aren't used on the GPU, they won't get evaluated and transferred there either.
Produced by Haddock version 2.4.2