diff options
Diffstat (limited to 'Spear/GL.hs')
-rw-r--r-- | Spear/GL.hs | 79 |
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 | ) |
88 | where | 88 | where |
89 | 89 | ||
90 | import Control.Monad | 90 | import Control.Monad |
91 | import Control.Monad.Trans.Class | 91 | import Control.Monad.Trans.Class |
92 | import Control.Monad.Trans.State as State | 92 | import Control.Monad.Trans.State as State |
93 | import qualified Data.ByteString.Char8 as B | 93 | import qualified Data.ByteString.Char8 as B |
94 | import Data.StateVar | 94 | import Data.StateVar |
95 | import Data.Word | 95 | import Data.Word |
96 | import Foreign.C.String | 96 | import Foreign.C.String |
97 | import Foreign.C.Types | 97 | import Foreign.C.Types |
98 | import Foreign.Marshal.Alloc (alloca) | 98 | import Foreign.Marshal.Alloc (alloca) |
99 | import Foreign.Marshal.Array (withArray) | 99 | import Foreign.Marshal.Array (withArray) |
100 | import Foreign.Marshal.Utils as Foreign (with) | 100 | import Foreign.Marshal.Utils as Foreign (with) |
101 | import Foreign.Ptr | 101 | import Foreign.Ptr |
102 | import Foreign.Storable | 102 | import Foreign.Storable |
103 | import Foreign.Storable (peek) | 103 | import Foreign.Storable (peek) |
104 | import Graphics.GL.Core46 | 104 | import Graphics.GL.Core46 |
105 | import Spear.Assets.Image | 105 | import Prelude hiding ((*)) |
106 | import Spear.Game | 106 | import Spear.Assets.Image |
107 | import Spear.Math.Matrix3 (Matrix3) | 107 | import Spear.Game |
108 | import Spear.Math.Matrix4 (Matrix4) | 108 | import Spear.Math.Algebra |
109 | import Spear.Math.Vector | 109 | import Spear.Math.Matrix3 (Matrix3) |
110 | import System.Directory (doesFileExist, getCurrentDirectory, setCurrentDirectory) | 110 | import Spear.Math.Matrix4 (Matrix4) |
111 | import System.IO (hPutStrLn, stderr) | 111 | import Spear.Math.Vector |
112 | import Unsafe.Coerce | 112 | import System.Directory (doesFileExist, getCurrentDirectory, |
113 | setCurrentDirectory) | ||
114 | import System.IO (hPutStrLn, stderr) | ||
115 | import 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. |
119 | data GLSLShader = GLSLShader | 122 | data 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. |
128 | data GLSLProgram = GLSLProgram | 131 | data 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 | |||
137 | data ShaderType = VertexShader | FragmentShader | GeometryShader deriving (Eq, Show) | 140 | data ShaderType = VertexShader | FragmentShader | GeometryShader deriving (Eq, Show) |
138 | 141 | ||
139 | toGLShader :: ShaderType -> GLenum | 142 | toGLShader :: ShaderType -> GLenum |
140 | toGLShader VertexShader = GL_VERTEX_SHADER | 143 | toGLShader VertexShader = GL_VERTEX_SHADER |
141 | toGLShader FragmentShader = GL_FRAGMENT_SHADER | 144 | toGLShader FragmentShader = GL_FRAGMENT_SHADER |
142 | toGLShader GeometryShader = GL_GEOMETRY_SHADER | 145 | toGLShader 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. |
530 | data GLBuffer = GLBuffer | 533 | data GLBuffer = GLBuffer |
531 | { getBuffer :: GLuint, | 534 | { getBuffer :: GLuint, |
532 | rkey :: Resource | 535 | rkey :: Resource |
533 | } | 536 | } |
534 | 537 | ||
535 | instance ResourceClass GLBuffer where | 538 | instance ResourceClass GLBuffer where |
@@ -544,10 +547,10 @@ data TargetBuffer | |||
544 | deriving (Eq, Show) | 547 | deriving (Eq, Show) |
545 | 548 | ||
546 | fromTarget :: TargetBuffer -> GLenum | 549 | fromTarget :: TargetBuffer -> GLenum |
547 | fromTarget ArrayBuffer = GL_ARRAY_BUFFER | 550 | fromTarget ArrayBuffer = GL_ARRAY_BUFFER |
548 | fromTarget ElementArrayBuffer = GL_ELEMENT_ARRAY_BUFFER | 551 | fromTarget ElementArrayBuffer = GL_ELEMENT_ARRAY_BUFFER |
549 | fromTarget PixelPackBuffer = GL_PIXEL_PACK_BUFFER | 552 | fromTarget PixelPackBuffer = GL_PIXEL_PACK_BUFFER |
550 | fromTarget PixelUnpackBuffer = GL_PIXEL_UNPACK_BUFFER | 553 | fromTarget PixelUnpackBuffer = GL_PIXEL_UNPACK_BUFFER |
551 | 554 | ||
552 | -- | A buffer usage. | 555 | -- | A buffer usage. |
553 | data BufferUsage | 556 | data BufferUsage |
@@ -563,12 +566,12 @@ data BufferUsage | |||
563 | deriving (Eq, Show) | 566 | deriving (Eq, Show) |
564 | 567 | ||
565 | fromUsage :: BufferUsage -> GLenum | 568 | fromUsage :: BufferUsage -> GLenum |
566 | fromUsage StreamDraw = GL_STREAM_DRAW | 569 | fromUsage StreamDraw = GL_STREAM_DRAW |
567 | fromUsage StreamRead = GL_STREAM_READ | 570 | fromUsage StreamRead = GL_STREAM_READ |
568 | fromUsage StreamCopy = GL_STREAM_COPY | 571 | fromUsage StreamCopy = GL_STREAM_COPY |
569 | fromUsage StaticDraw = GL_STATIC_DRAW | 572 | fromUsage StaticDraw = GL_STATIC_DRAW |
570 | fromUsage StaticRead = GL_STATIC_READ | 573 | fromUsage StaticRead = GL_STATIC_READ |
571 | fromUsage StaticCopy = GL_STATIC_COPY | 574 | fromUsage StaticCopy = GL_STATIC_COPY |
572 | fromUsage DynamicDraw = GL_DYNAMIC_DRAW | 575 | fromUsage DynamicDraw = GL_DYNAMIC_DRAW |
573 | fromUsage DynamicRead = GL_DYNAMIC_READ | 576 | fromUsage DynamicRead = GL_DYNAMIC_READ |
574 | fromUsage DynamicCopy = GL_DYNAMIC_COPY | 577 | fromUsage DynamicCopy = GL_DYNAMIC_COPY |
@@ -780,7 +783,7 @@ getGLError = fmap translate glGetError | |||
780 | printGLError :: IO () | 783 | printGLError :: IO () |
781 | printGLError = | 784 | printGLError = |
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 |