40 lines
1.0 KiB
Haskell
40 lines
1.0 KiB
Haskell
{-# LANGUAGE TypeFamilies #-}
|
|
module Classes.Graphics.Buffer where
|
|
|
|
import qualified Graphics.Rendering.OpenGL as GL
|
|
|
|
import SDL (($=), get)
|
|
|
|
-- internal imports
|
|
|
|
import Classes.Graphics.Bindable
|
|
|
|
-- | this aims to be a typeclass for all used buffer objects throughout the
|
|
-- game. all buffer objects have to instanciate the Bindable typeclass.
|
|
-- think of it as some kind of interface in the object oriented context
|
|
class (Bindable a) => Buffer a where
|
|
|
|
type ObjName a :: *
|
|
|
|
-- | what buffer target does the buffer bind to
|
|
target :: a -> GL.BufferTarget
|
|
|
|
-- | retrieve ID from buffer object
|
|
glId :: a -> IO (ObjName a)
|
|
|
|
-- | bind the buffer object and fill it with null data
|
|
initialize :: a -> IO ()
|
|
|
|
-- | fill the buffer with actual data
|
|
write
|
|
:: a
|
|
-> Word -- ^ write offset from beginning of buffer in bytes
|
|
-> b -- ^ Data to write
|
|
-> IO ()
|
|
|
|
-- | expand the buffer to double of it's previous size.
|
|
expand :: a -> IO ()
|
|
|
|
-- | free resources and delete the object
|
|
delete :: a -> IO ()
|