module Graphics.GLUtil.VertexArrayObjects
(VertexArrayObject(..), VAO, makeVAO, deleteVAO, bindVertexArray) where
import Foreign.Marshal.Array (allocaArray)
import Foreign.Marshal.Utils (with)
import Foreign.Storable (peek)
import Graphics.Rendering.OpenGL.Raw.Core31
newtype VertexArrayObject = VertexArrayObject GLuint
type VAO = VertexArrayObject
makeVAO :: IO () -> IO VertexArrayObject
makeVAO m = do vao <- allocaArray 1 $ \ptr ->
glGenVertexArrays 1 ptr >> peek ptr
glBindVertexArray vao
m
glBindVertexArray 0
return $ VertexArrayObject vao
deleteVAO :: VertexArrayObject -> IO ()
deleteVAO (VertexArrayObject i) = with i $ glDeleteVertexArrays 1
bindVertexArray :: Maybe VertexArrayObject -> IO ()
bindVertexArray (Just (VertexArrayObject i)) = glBindVertexArray i
bindVertexArray Nothing = glBindVertexArray 0