renderer-tutorial/src/BufferClass.hs

28 lines
707 B
Haskell
Raw Normal View History

2020-05-18 02:58:45 +00:00
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
-- what buffer target does te buffer bind to
target :: a -> GL.BufferTarget
-- what ID does the buffer have
glId :: a -> GL.BufferObject
-- 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