aboutsummaryrefslogtreecommitdiff
path: root/Spear/GL.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Spear/GL.hs')
-rw-r--r--Spear/GL.hs79
1 files changed, 41 insertions, 38 deletions
diff --git a/Spear/GL.hs b/Spear/GL.hs
index 21ed9ec..81a433e 100644
--- a/Spear/GL.hs
+++ b/Spear/GL.hs
@@ -87,29 +87,32 @@ module Spear.GL
87 ) 87 )
88where 88where
89 89
90import Control.Monad 90import Control.Monad
91import Control.Monad.Trans.Class 91import Control.Monad.Trans.Class
92import Control.Monad.Trans.State as State 92import Control.Monad.Trans.State as State
93import qualified Data.ByteString.Char8 as B 93import qualified Data.ByteString.Char8 as B
94import Data.StateVar 94import Data.StateVar
95import Data.Word 95import Data.Word
96import Foreign.C.String 96import Foreign.C.String
97import Foreign.C.Types 97import Foreign.C.Types
98import Foreign.Marshal.Alloc (alloca) 98import Foreign.Marshal.Alloc (alloca)
99import Foreign.Marshal.Array (withArray) 99import Foreign.Marshal.Array (withArray)
100import Foreign.Marshal.Utils as Foreign (with) 100import Foreign.Marshal.Utils as Foreign (with)
101import Foreign.Ptr 101import Foreign.Ptr
102import Foreign.Storable 102import Foreign.Storable
103import Foreign.Storable (peek) 103import Foreign.Storable (peek)
104import Graphics.GL.Core46 104import Graphics.GL.Core46
105import Spear.Assets.Image 105import Prelude hiding ((*))
106import Spear.Game 106import Spear.Assets.Image
107import Spear.Math.Matrix3 (Matrix3) 107import Spear.Game
108import Spear.Math.Matrix4 (Matrix4) 108import Spear.Math.Algebra
109import Spear.Math.Vector 109import Spear.Math.Matrix3 (Matrix3)
110import System.Directory (doesFileExist, getCurrentDirectory, setCurrentDirectory) 110import Spear.Math.Matrix4 (Matrix4)
111import System.IO (hPutStrLn, stderr) 111import Spear.Math.Vector
112import Unsafe.Coerce 112import System.Directory (doesFileExist, getCurrentDirectory,
113 setCurrentDirectory)
114import System.IO (hPutStrLn, stderr)
115import Unsafe.Coerce
113 116
114-- 117--
115-- MANAGEMENT 118-- MANAGEMENT
@@ -117,7 +120,7 @@ import Unsafe.Coerce
117 120
118-- | A GLSL shader handle. 121-- | A GLSL shader handle.
119data GLSLShader = GLSLShader 122data GLSLShader = GLSLShader
120 { getShader :: GLuint, 123 { getShader :: GLuint,
121 getShaderKey :: Resource 124 getShaderKey :: Resource
122 } 125 }
123 126
@@ -126,7 +129,7 @@ instance ResourceClass GLSLShader where
126 129
127-- | A GLSL program handle. 130-- | A GLSL program handle.
128data GLSLProgram = GLSLProgram 131data GLSLProgram = GLSLProgram
129 { getProgram :: GLuint, 132 { getProgram :: GLuint,
130 getProgramKey :: Resource 133 getProgramKey :: Resource
131 } 134 }
132 135
@@ -137,7 +140,7 @@ instance ResourceClass GLSLProgram where
137data ShaderType = VertexShader | FragmentShader | GeometryShader deriving (Eq, Show) 140data ShaderType = VertexShader | FragmentShader | GeometryShader deriving (Eq, Show)
138 141
139toGLShader :: ShaderType -> GLenum 142toGLShader :: ShaderType -> GLenum
140toGLShader VertexShader = GL_VERTEX_SHADER 143toGLShader VertexShader = GL_VERTEX_SHADER
141toGLShader FragmentShader = GL_FRAGMENT_SHADER 144toGLShader FragmentShader = GL_FRAGMENT_SHADER
142toGLShader GeometryShader = GL_GEOMETRY_SHADER 145toGLShader GeometryShader = GL_GEOMETRY_SHADER
143 146
@@ -529,7 +532,7 @@ drawElements mode count t idxs = glDrawElements mode (unsafeCoerce count) t idxs
529-- | An OpenGL buffer. 532-- | An OpenGL buffer.
530data GLBuffer = GLBuffer 533data GLBuffer = GLBuffer
531 { getBuffer :: GLuint, 534 { getBuffer :: GLuint,
532 rkey :: Resource 535 rkey :: Resource
533 } 536 }
534 537
535instance ResourceClass GLBuffer where 538instance ResourceClass GLBuffer where
@@ -544,10 +547,10 @@ data TargetBuffer
544 deriving (Eq, Show) 547 deriving (Eq, Show)
545 548
546fromTarget :: TargetBuffer -> GLenum 549fromTarget :: TargetBuffer -> GLenum
547fromTarget ArrayBuffer = GL_ARRAY_BUFFER 550fromTarget ArrayBuffer = GL_ARRAY_BUFFER
548fromTarget ElementArrayBuffer = GL_ELEMENT_ARRAY_BUFFER 551fromTarget ElementArrayBuffer = GL_ELEMENT_ARRAY_BUFFER
549fromTarget PixelPackBuffer = GL_PIXEL_PACK_BUFFER 552fromTarget PixelPackBuffer = GL_PIXEL_PACK_BUFFER
550fromTarget PixelUnpackBuffer = GL_PIXEL_UNPACK_BUFFER 553fromTarget PixelUnpackBuffer = GL_PIXEL_UNPACK_BUFFER
551 554
552-- | A buffer usage. 555-- | A buffer usage.
553data BufferUsage 556data BufferUsage
@@ -563,12 +566,12 @@ data BufferUsage
563 deriving (Eq, Show) 566 deriving (Eq, Show)
564 567
565fromUsage :: BufferUsage -> GLenum 568fromUsage :: BufferUsage -> GLenum
566fromUsage StreamDraw = GL_STREAM_DRAW 569fromUsage StreamDraw = GL_STREAM_DRAW
567fromUsage StreamRead = GL_STREAM_READ 570fromUsage StreamRead = GL_STREAM_READ
568fromUsage StreamCopy = GL_STREAM_COPY 571fromUsage StreamCopy = GL_STREAM_COPY
569fromUsage StaticDraw = GL_STATIC_DRAW 572fromUsage StaticDraw = GL_STATIC_DRAW
570fromUsage StaticRead = GL_STATIC_READ 573fromUsage StaticRead = GL_STATIC_READ
571fromUsage StaticCopy = GL_STATIC_COPY 574fromUsage StaticCopy = GL_STATIC_COPY
572fromUsage DynamicDraw = GL_DYNAMIC_DRAW 575fromUsage DynamicDraw = GL_DYNAMIC_DRAW
573fromUsage DynamicRead = GL_DYNAMIC_READ 576fromUsage DynamicRead = GL_DYNAMIC_READ
574fromUsage DynamicCopy = GL_DYNAMIC_COPY 577fromUsage DynamicCopy = GL_DYNAMIC_COPY
@@ -780,7 +783,7 @@ getGLError = fmap translate glGetError
780printGLError :: IO () 783printGLError :: IO ()
781printGLError = 784printGLError =
782 getGLError >>= \err -> case err of 785 getGLError >>= \err -> case err of
783 Nothing -> return () 786 Nothing -> return ()
784 Just str -> hPutStrLn stderr str 787 Just str -> hPutStrLn stderr str
785 788
786-- | Run the given setup action and check for OpenGL errors. 789-- | Run the given setup action and check for OpenGL errors.
@@ -793,4 +796,4 @@ assertGL action err = do
793 status <- gameIO getGLError 796 status <- gameIO getGLError
794 case status of 797 case status of
795 Just str -> gameError $ "OpenGL error raised: " ++ err ++ "; " ++ str 798 Just str -> gameError $ "OpenGL error raised: " ++ err ++ "; " ++ str
796 Nothing -> return result 799 Nothing -> return result