pituicat/src/Classes/Graphics/Buffer.hs

50 lines
1.3 KiB
Haskell
Raw Normal View History

2020-10-17 14:18:42 +00:00
{-# LANGUAGE TypeFamilies #-}
2020-12-05 09:10:37 +00:00
{-# LANGUAGE FlexibleContexts #-}
2020-10-17 14:18:42 +00:00
module Classes.Graphics.Buffer where
import qualified Graphics.Rendering.OpenGL as GL
import SDL (($=), get)
2020-12-05 09:10:37 +00:00
import Foreign.Storable
2020-10-17 14:18:42 +00:00
-- 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
2020-12-05 09:10:37 +00:00
class (Bindable a, Storable (StoreType a)) =>
Buffer a where
-- | datatype inside the buffer
type StoreType a :: *
2020-10-17 14:18:42 +00:00
2020-12-05 09:10:37 +00:00
-- | container datatype for 'StoreType's
type StoreContainer a :: * -> *
2020-10-17 14:18:42 +00:00
2020-12-05 09:10:37 +00:00
-- | what buffer target does the buffer bind to
target :: a -> GL.BufferTarget
2020-10-17 14:18:42 +00:00
2020-12-05 09:10:37 +00:00
-- | retrieve ID from buffer object
glId :: a -> IO (GL.BufferObject)
2020-10-17 14:18:42 +00:00
2020-12-05 09:10:37 +00:00
-- | bind the buffer object and fill it with null data
initialize :: a -> IO ()
2020-12-05 09:10:37 +00:00
-- | fill the buffer with actual data
write
:: a
-> Word
-- ^ write offset from beginning of buffer in bytes
-> StoreContainer a (StoreType a)
-- ^ Data to write
-> IO ()
2020-12-05 09:10:37 +00:00
-- | expand the buffer to double of it's previous size.
expand :: a -> IO ()
2020-12-05 09:10:37 +00:00
-- | free resources and delete the object
delete :: a -> IO ()