aboutsummaryrefslogtreecommitdiff
path: root/Spear/GLSL/VAO.hs
diff options
context:
space:
mode:
authorMarc Sunet <jeannekamikaze@gmail.com>2012-08-30 19:18:41 +0200
committerMarc Sunet <jeannekamikaze@gmail.com>2012-08-30 19:18:41 +0200
commit21cf357ac1f8d0bef6ed7d53d7f1b05b73484b8d (patch)
treebee22376d50cf7a45972e55b13d999a956150263 /Spear/GLSL/VAO.hs
parent4f25a24c8bf3f042ce507c56cace508f47ac3a6d (diff)
Cleaned GLSL interface
Diffstat (limited to 'Spear/GLSL/VAO.hs')
-rw-r--r--Spear/GLSL/VAO.hs88
1 files changed, 0 insertions, 88 deletions
diff --git a/Spear/GLSL/VAO.hs b/Spear/GLSL/VAO.hs
deleted file mode 100644
index f121636..0000000
--- a/Spear/GLSL/VAO.hs
+++ /dev/null
@@ -1,88 +0,0 @@
1module Spear.GLSL.VAO
2(
3 VAO
4 -- * Creation and destruction
5, newVAO
6, releaseVAO
7 -- * Manipulation
8, bindVAO
9, enableVAOAttrib
10, attribVAOPointer
11 -- * Rendering
12, drawArrays
13, drawElements
14)
15where
16
17
18import Spear.Setup
19import Control.Monad.Trans.Class (lift)
20import Foreign.Marshal.Utils as Foreign (with)
21import Foreign.Marshal.Alloc (alloca)
22import Foreign.Storable (peek)
23import Foreign.Ptr
24import Unsafe.Coerce
25import Graphics.Rendering.OpenGL.Raw.Core31
26
27
28-- | Represents a vertex array object.
29data VAO = VAO
30 { getVAO :: GLuint
31 , rkey :: Resource
32 }
33
34
35instance Eq VAO where
36 vao1 == vao2 = getVAO vao1 == getVAO vao2
37
38
39instance Ord VAO where
40 vao1 < vao2 = getVAO vao1 < getVAO vao2
41
42
43-- | Create a new 'VAO'.
44newVAO :: Setup VAO
45newVAO = do
46 h <- setupIO . alloca $ \ptr -> do
47 glGenVertexArrays 1 ptr
48 peek ptr
49
50 rkey <- register $ deleteVAO h
51 return $ VAO h rkey
52
53
54-- | Release the given 'VAO'.
55releaseVAO :: VAO -> Setup ()
56releaseVAO = release . rkey
57
58
59-- | Delete the given 'VAO'.
60deleteVAO :: GLuint -> IO ()
61deleteVAO vao = Foreign.with vao $ glDeleteVertexArrays 1
62
63
64-- | Bind the given 'VAO'.
65bindVAO :: VAO -> IO ()
66bindVAO = glBindVertexArray . getVAO
67
68
69-- | Enable the given vertex attribute of the bound 'VAO'.
70enableVAOAttrib :: GLuint -> IO ()
71enableVAOAttrib = glEnableVertexAttribArray
72
73
74-- | Bind the bound buffer to the given point.
75attribVAOPointer :: GLuint -> GLint -> GLenum -> Bool -> GLsizei -> Int -> IO ()
76attribVAOPointer idx ncomp dattype normalise stride off =
77 glVertexAttribPointer idx ncomp dattype (unsafeCoerce normalise) stride (unsafeCoerce off)
78
79
80-- | Draw the bound 'VAO'.
81drawArrays :: GLenum -> Int -> Int -> IO ()
82drawArrays mode first count = glDrawArrays mode (unsafeCoerce first) (unsafeCoerce count)
83
84
85-- | Draw the bound 'VAO', indexed mode.
86drawElements :: GLenum -> Int -> GLenum -> Ptr a -> IO ()
87drawElements mode count t idxs = glDrawElements mode (unsafeCoerce count) t idxs
88