Specialized versions of renderPrimitives?

Things like renderPrimitive LineLoop $ do vertex v1 ; vertex v2; vertex v3; vertex v4 renderPrimitive Lines $ do vertex v1 ; vertex v2; vertex v3; vertex v4 are indeed close to the OpenGL interface. But we lose a lot of type safety. It would be more concise and safer to write lineLoop [v1, v2, v3, v4] lines [(v1, v2), (v3, v4)] Is this implemented somewhere?

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-Rende... With renderPrimitive you can also add additional properties per vertex. Like: renderPrimitive LineLoop $ do color c1 texCoord t1 vertex v1 color c2 texCoord t2 vertex v2 color c3 texCoord t3 vertex v3 color c4 texCoord t4 vertex v4 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 ... ... then you can have something like: v1, v2, v3, v4 :: Vertex lineLoop [v1, v2, v3, v4] Regards, Bas van Dijk

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-Rende... 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-Rende... http://www.haskell.org/ghc/dist/current/docs/libraries/OpenGL/Graphics-Rende... 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.
participants (3)
-
Bas van Dijk
-
Henning Thielemann
-
Sven Panne