diff options
author | Marc Sunet <jeannekamikaze@gmail.com> | 2012-08-30 19:18:41 +0200 |
---|---|---|
committer | Marc Sunet <jeannekamikaze@gmail.com> | 2012-08-30 19:18:41 +0200 |
commit | 21cf357ac1f8d0bef6ed7d53d7f1b05b73484b8d (patch) | |
tree | bee22376d50cf7a45972e55b13d999a956150263 /Spear/GLSL/VAO.hs | |
parent | 4f25a24c8bf3f042ce507c56cace508f47ac3a6d (diff) |
Cleaned GLSL interface
Diffstat (limited to 'Spear/GLSL/VAO.hs')
-rw-r--r-- | Spear/GLSL/VAO.hs | 88 |
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 @@ | |||
1 | module 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 | ) | ||
15 | where | ||
16 | |||
17 | |||
18 | import Spear.Setup | ||
19 | import Control.Monad.Trans.Class (lift) | ||
20 | import Foreign.Marshal.Utils as Foreign (with) | ||
21 | import Foreign.Marshal.Alloc (alloca) | ||
22 | import Foreign.Storable (peek) | ||
23 | import Foreign.Ptr | ||
24 | import Unsafe.Coerce | ||
25 | import Graphics.Rendering.OpenGL.Raw.Core31 | ||
26 | |||
27 | |||
28 | -- | Represents a vertex array object. | ||
29 | data VAO = VAO | ||
30 | { getVAO :: GLuint | ||
31 | , rkey :: Resource | ||
32 | } | ||
33 | |||
34 | |||
35 | instance Eq VAO where | ||
36 | vao1 == vao2 = getVAO vao1 == getVAO vao2 | ||
37 | |||
38 | |||
39 | instance Ord VAO where | ||
40 | vao1 < vao2 = getVAO vao1 < getVAO vao2 | ||
41 | |||
42 | |||
43 | -- | Create a new 'VAO'. | ||
44 | newVAO :: Setup VAO | ||
45 | newVAO = 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'. | ||
55 | releaseVAO :: VAO -> Setup () | ||
56 | releaseVAO = release . rkey | ||
57 | |||
58 | |||
59 | -- | Delete the given 'VAO'. | ||
60 | deleteVAO :: GLuint -> IO () | ||
61 | deleteVAO vao = Foreign.with vao $ glDeleteVertexArrays 1 | ||
62 | |||
63 | |||
64 | -- | Bind the given 'VAO'. | ||
65 | bindVAO :: VAO -> IO () | ||
66 | bindVAO = glBindVertexArray . getVAO | ||
67 | |||
68 | |||
69 | -- | Enable the given vertex attribute of the bound 'VAO'. | ||
70 | enableVAOAttrib :: GLuint -> IO () | ||
71 | enableVAOAttrib = glEnableVertexAttribArray | ||
72 | |||
73 | |||
74 | -- | Bind the bound buffer to the given point. | ||
75 | attribVAOPointer :: GLuint -> GLint -> GLenum -> Bool -> GLsizei -> Int -> IO () | ||
76 | attribVAOPointer idx ncomp dattype normalise stride off = | ||
77 | glVertexAttribPointer idx ncomp dattype (unsafeCoerce normalise) stride (unsafeCoerce off) | ||
78 | |||
79 | |||
80 | -- | Draw the bound 'VAO'. | ||
81 | drawArrays :: GLenum -> Int -> Int -> IO () | ||
82 | drawArrays mode first count = glDrawArrays mode (unsafeCoerce first) (unsafeCoerce count) | ||
83 | |||
84 | |||
85 | -- | Draw the bound 'VAO', indexed mode. | ||
86 | drawElements :: GLenum -> Int -> GLenum -> Ptr a -> IO () | ||
87 | drawElements mode count t idxs = glDrawElements mode (unsafeCoerce count) t idxs | ||
88 | |||