Skip to content

Instantly share code, notes, and snippets.

@expipiplus1
Created February 25, 2015 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save expipiplus1/f5286ffcc07e532e5be6 to your computer and use it in GitHub Desktop.
Save expipiplus1/f5286ffcc07e532e5be6 to your computer and use it in GitHub Desktop.
module GL where
import Graphics.GL
-- Newtype for Buffers
newtype Buffer = Buffer GLuint
-- A class for types which map to a glenum
class IsGLenum e where
toGLenum :: e -> GLenum
-- All Glenums and their instances for IsGLenum
data ArrayBuffer = ArrayBuffer
data UniformBuffer = UniformBuffer
instance IsGLenum ArrayBuffer where
toGLenum ArrayBuffer = GL_ARRAY_BUFFER
instance IsGLenum UniformBuffer where
toGLenum UniformBuffer = GL_UNIFORM_BUFFER
--
-- Definition for bindBuffer, it takes either GL_ARRAY_BUFFER or
-- GL_UNIFORM_BUFFER
--
class IsGLenum t => BindBufferTarget t where
instance BindBufferTarget ArrayBuffer where
instance BindBufferTarget UniformBuffer where
bindBuffer :: BindBufferTarget t => t -> Buffer -> IO ()
bindBuffer target (Buffer buffer) = glBindBuffer (toGLenum target) buffer
--
-- Definition for bindBufferBase, it doesn't take GL_ARRAY_BUFFER but does
-- take GL_UNIFORM_BUFFER
--
class IsGLenum t => BindBufferBaseTarget t where
instance BindBufferBaseTarget UniformBuffer where
bindBufferBase :: BindBufferBaseTarget t => t -> GLuint -> Buffer -> IO ()
bindBufferBase target index (Buffer buffer) = glBindBufferBase (toGLenum target) index buffer
----------------------------------------------------------------------------------------------------
-- sometime in the future
----------------------------------------------------------------------------------------------------
data SuperNewBuffer = SuperNewBuffer
instance IsGLenum SuperNewBuffer where
toGLenum SuperNewBuffer = GL_SUPER_NEW_BUFFER
instance BindBufferTarget SuperNewBuffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment