renderer-tutorial/src/BufferClass.hs
2020-05-20 05:54:43 +02:00

31 lines
760 B
Haskell

{-# LANGUAGE TypeFamilies #-}
module BufferClass where
import qualified Graphics.Rendering.OpenGL as GL
import SDL (($=), get)
-- this aims to be a typeclass for all used buffer objects throughout the
-- tutorial.
-- think of it as some kind of interface in the object oriented context
class Buffer a where
type ObjName a :: *
-- what buffer target does te buffer bind to
target :: a -> GL.BufferTarget
-- what ID does the buffer have
glId :: a -> ObjName a
-- bind the buffer object and fill it with data
initialize :: a -> IO ()
-- bind the buffer
bind :: a -> IO ()
-- bind buf = GL.bindBuffer (target buf) $= Just (glId buf)
-- unbind the buffer
unbind :: a -> IO ()
-- unbind buf = GL.bindBuffer (target buf) $= Nothing