diff options
Diffstat (limited to 'Spear/GL.hs')
-rw-r--r-- | Spear/GL.hs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/Spear/GL.hs b/Spear/GL.hs index 65f985b..aa3e930 100644 --- a/Spear/GL.hs +++ b/Spear/GL.hs | |||
@@ -5,6 +5,7 @@ module Spear.GL | |||
5 | , newProgram | 5 | , newProgram |
6 | , linkProgram | 6 | , linkProgram |
7 | , useProgram | 7 | , useProgram |
8 | , unuseProgram | ||
8 | , withGLSLProgram | 9 | , withGLSLProgram |
9 | -- ** Locations | 10 | -- ** Locations |
10 | , attribLocation | 11 | , attribLocation |
@@ -36,6 +37,7 @@ module Spear.GL | |||
36 | , VAO | 37 | , VAO |
37 | , newVAO | 38 | , newVAO |
38 | , bindVAO | 39 | , bindVAO |
40 | , unbindVAO | ||
39 | , enableVAOAttrib | 41 | , enableVAOAttrib |
40 | , attribVAOPointer | 42 | , attribVAOPointer |
41 | -- ** Rendering | 43 | -- ** Rendering |
@@ -47,6 +49,7 @@ module Spear.GL | |||
47 | , BufferUsage(..) | 49 | , BufferUsage(..) |
48 | , newBuffer | 50 | , newBuffer |
49 | , bindBuffer | 51 | , bindBuffer |
52 | , unbindBuffer | ||
50 | , BufferData(..) | 53 | , BufferData(..) |
51 | , bufferData' | 54 | , bufferData' |
52 | , withGLBuffer | 55 | , withGLBuffer |
@@ -59,6 +62,7 @@ module Spear.GL | |||
59 | , loadTextureImage | 62 | , loadTextureImage |
60 | -- ** Manipulation | 63 | -- ** Manipulation |
61 | , bindTexture | 64 | , bindTexture |
65 | , unbindTexture | ||
62 | , loadTextureData | 66 | , loadTextureData |
63 | , texParami | 67 | , texParami |
64 | , texParamf | 68 | , texParamf |
@@ -162,10 +166,8 @@ newProgram shaders = do | |||
162 | when (h == 0) $ gameError "glCreateProgram failed" | 166 | when (h == 0) $ gameError "glCreateProgram failed" |
163 | rkey <- register $ deleteProgram h | 167 | rkey <- register $ deleteProgram h |
164 | let program = GLSLProgram h rkey | 168 | let program = GLSLProgram h rkey |
165 | |||
166 | mapM_ (gameIO . attachShader program) shaders | 169 | mapM_ (gameIO . attachShader program) shaders |
167 | linkProgram program | 170 | linkProgram program |
168 | |||
169 | return program | 171 | return program |
170 | 172 | ||
171 | -- | Delete the program. | 173 | -- | Delete the program. |
@@ -196,6 +198,10 @@ linkProgram prog = do | |||
196 | useProgram :: GLSLProgram -> IO () | 198 | useProgram :: GLSLProgram -> IO () |
197 | useProgram prog = glUseProgram $ getProgram prog | 199 | useProgram prog = glUseProgram $ getProgram prog |
198 | 200 | ||
201 | -- | Deactivate the active program. | ||
202 | unuseProgram :: IO () | ||
203 | unuseProgram = glUseProgram 0 | ||
204 | |||
199 | -- | Attach the given shader to the given program. | 205 | -- | Attach the given shader to the given program. |
200 | attachShader :: GLSLProgram -> GLSLShader -> IO () | 206 | attachShader :: GLSLProgram -> GLSLShader -> IO () |
201 | attachShader prog shader = glAttachShader (getProgram prog) (getShader shader) | 207 | attachShader prog shader = glAttachShader (getProgram prog) (getShader shader) |
@@ -411,6 +417,10 @@ deleteVAO vao = Foreign.with vao $ glDeleteVertexArrays 1 | |||
411 | bindVAO :: VAO -> IO () | 417 | bindVAO :: VAO -> IO () |
412 | bindVAO = glBindVertexArray . getVAO | 418 | bindVAO = glBindVertexArray . getVAO |
413 | 419 | ||
420 | -- | Unbind the bound vao. | ||
421 | unbindVAO :: IO () | ||
422 | unbindVAO = glBindVertexArray 0 | ||
423 | |||
414 | -- | Enable the given vertex attribute of the bound vao. | 424 | -- | Enable the given vertex attribute of the bound vao. |
415 | -- | 425 | -- |
416 | -- See also 'bindVAO'. | 426 | -- See also 'bindVAO'. |
@@ -516,6 +526,10 @@ deleteBuffer buf = Foreign.with buf $ glDeleteBuffers 1 | |||
516 | bindBuffer :: GLBuffer -> TargetBuffer -> IO () | 526 | bindBuffer :: GLBuffer -> TargetBuffer -> IO () |
517 | bindBuffer buf target = glBindBuffer (fromTarget target) $ getBuffer buf | 527 | bindBuffer buf target = glBindBuffer (fromTarget target) $ getBuffer buf |
518 | 528 | ||
529 | -- | Unbind the bound buffer. | ||
530 | unbindBuffer :: TargetBuffer -> IO () | ||
531 | unbindBuffer target = glBindBuffer (fromTarget target) 0 | ||
532 | |||
519 | class Storable a => BufferData a where | 533 | class Storable a => BufferData a where |
520 | -- | Set the buffer's data. | 534 | -- | Set the buffer's data. |
521 | bufferData :: TargetBuffer -> [a] -> BufferUsage -> IO () | 535 | bufferData :: TargetBuffer -> [a] -> BufferUsage -> IO () |
@@ -616,6 +630,10 @@ loadTextureImage file minFilter magFilter = do | |||
616 | bindTexture :: Texture -> IO () | 630 | bindTexture :: Texture -> IO () |
617 | bindTexture = glBindTexture gl_TEXTURE_2D . getTex | 631 | bindTexture = glBindTexture gl_TEXTURE_2D . getTex |
618 | 632 | ||
633 | -- | Unbind the bound texture. | ||
634 | unbindTexture :: IO () | ||
635 | unbindTexture = glBindTexture gl_TEXTURE_2D 0 | ||
636 | |||
619 | -- | Load data onto the bound texture. | 637 | -- | Load data onto the bound texture. |
620 | -- | 638 | -- |
621 | -- See also 'bindTexture'. | 639 | -- See also 'bindTexture'. |