2020-05-20 03:54:14 +00:00
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
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
|
|
|
|
|
2020-05-20 03:54:14 +00:00
|
|
|
type ObjName a :: *
|
|
|
|
|
2020-05-18 02:58:45 +00:00
|
|
|
-- what buffer target does te buffer bind to
|
|
|
|
target :: a -> GL.BufferTarget
|
|
|
|
|
|
|
|
-- what ID does the buffer have
|
2020-05-20 03:54:14 +00:00
|
|
|
glId :: a -> ObjName a
|
2020-05-18 02:58:45 +00:00
|
|
|
|
|
|
|
-- bind the buffer object and fill it with data
|
|
|
|
initialize :: a -> IO ()
|
|
|
|
|
|
|
|
-- bind the buffer
|
|
|
|
bind :: a -> IO ()
|
2020-05-20 03:54:14 +00:00
|
|
|
-- bind buf = GL.bindBuffer (target buf) $= Just (glId buf)
|
2020-05-18 02:58:45 +00:00
|
|
|
|
|
|
|
-- unbind the buffer
|
|
|
|
unbind :: a -> IO ()
|
2020-05-20 03:54:14 +00:00
|
|
|
-- unbind buf = GL.bindBuffer (target buf) $= Nothing
|