[HOpenGL] Specialized versions of renderPrimitives?

Sven Panne sven.panne at aedion.de
Fri Oct 27 03:49:39 EDT 2006


Am Freitag, 27. Oktober 2006 00:04 schrieb Bas van Dijk:
> On Thursday 26 October 2006 18:39, Henning Thielemann wrote:
> > It would be more concise and safer to write
> >    lineLoop [v1, v2, v3, v4]
> >    lines [(v1, v2), (v3, v4)]
>
> If I understand the following correctly:
> http://www.haskell.org/ghc/dist/current/docs/libraries/OpenGL/Graphics-Rend
>ering-OpenGL-GL-BeginEnd.html#v%3ArenderPrimitive
>
> With renderPrimitive you can also add additional properties per vertex.
> Like: [...]

Yes, exactly. In 
http://www.haskell.org/ghc/dist/current/docs/libraries/OpenGL/Graphics-Rendering-OpenGL-GL-VertexSpec.html 
you can see all the attributes a vertex has when using the traditional fixed 
function pipeline. When using GLSL (not yet implemented in my binding), a 
vertex can have an arbitrary number of additional attributes.

> It would be possible to do it in a type safe manner by having a data type
> Vertex that has a list of VertexProperties:
>
> type Vertex = [VertexProperty]
>
> data VertexProperty = Coordinate ...
>
>                     | Color ...
>                     | TextureCoordinate ...
>
>                     ...

This doesn't cover arbitrary attributes used by GLSL, but of course we could 
have a few more alternatives in VertexProperty for this. And of course you 
would need different alternatives for e.g. Color3, Color4, 
TextureCoordinate1, etc.  What makes this a little bit ugly is the fact that 
one would have to use different constructors for places in the API where e.g. 
exactly a color value with 4 floating point components is expected. A 
VertexProperty would be much too general in those cases, therefore I've 
chosen to use type classes.

One thing I don't fully understand: What is not type safe in the current API? 
The only thing I see is that one could use a different monad within 
renderPrimitive to enforce that only correct OpenGL command could be issued 
there. But having direct access to the IO monad is more important to access 
e.g. IORefs etc. within the action passed to renderPrimitive than a 
marginally safer typing. There are tons of places in OpenGL where the caller 
can do something wrong which can't be detected by type inference.

And a final hint: No serious OpenGL program will make heavy use of 
renderPrimitive, vertex arrays and/or buffer objects are the way to go for 
larger sets of data:

http://www.haskell.org/ghc/dist/current/docs/libraries/OpenGL/Graphics-Rendering-OpenGL-GL-VertexArrays.html
http://www.haskell.org/ghc/dist/current/docs/libraries/OpenGL/Graphics-Rendering-OpenGL-GL-BufferObjects.html

The renderPrimitive way of throwing data at the OpenGL pipeline is not even 
included in OpenGL ES, and it is on the death row for future versions of the 
full OpenGL, too.

Cheers,
   S.


More information about the HOpenGL mailing list