[Haskell-cafe] ANN (sorta): OpenGL with extra type safety
Neal Alexander
wqeqweuqy at hotmail.com
Mon Nov 10 15:30:14 EST 2008
I recently modified the hOpenGL (and GLFW) source tree to force extra
type checking on its various IO actions using the
-XGeneralizedNewtypeDeriving extension (see
http://hackage.haskell.org/trac/ghc/ticket/736).
The main motivation was for writing concurrent OpenGL applications. Here
its important to know what functions contain OpenGL commands so they can
be directed to the proper threads (ones with active rendering contexts).
Plus it aids in partitioning work that can be offloaded or done
asynchronously.
The second motivation was to enforce static type checking on commands
that can only be executed in certain OpenGL contexts (sending vertex
data for example).
As it is now, there are 3 new monads (their names will probably change):
OpenGLM: the basic opengl command
PrimitiveM: commands that can only be issued between begin/end()
class MonadGL: commands that can be issued in any GL context
Now for the big question: Does anyone care? If so, should i make it a
new hackageDB package, or try to merge it into the official GL package.
Ideally, it'd be nice to get some more input on the API changes, since
they're more or less a rough draft as is. Also, the GLU modules were all
placed in the OpenGLM monad, which is probably wrong, assuming some
commands can be called between begin/end.
I'll post the code later if anyone is interested.
----------------
class MonadIO m => MonadGL m
instance MonadGL OpenGLM
instance MonadGL PrimitiveM
newtype OpenGLM a = OpenGLM (IO a) deriving (Functor, Monad, MonadIO)
newtype PrimitiveM a = PrimitiveM (IO a) deriving (Functor, Monad, MonadIO)
More information about the Haskell-Cafe
mailing list