aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Spear.cabal2
-rw-r--r--Spear/GL.hs (renamed from Spear/GLSL.hs)2
-rw-r--r--Spear/Render/AnimatedModel.hs2
-rw-r--r--Spear/Render/Program.hs17
-rw-r--r--Spear/Render/StaticModel.hs2
-rw-r--r--Spear/Scene/GameObject.hs2
-rw-r--r--Spear/Scene/Loader.hs24
-rw-r--r--Spear/Scene/SceneResources.hs12
8 files changed, 19 insertions, 44 deletions
diff --git a/Spear.cabal b/Spear.cabal
index 2f21fad..316c1eb 100644
--- a/Spear.cabal
+++ b/Spear.cabal
@@ -20,7 +20,7 @@ library
20 Spear.Physics.Types Spear.App Spear.App.Application Spear.App.Input 20 Spear.Physics.Types Spear.App Spear.App.Application Spear.App.Input
21 Spear.Assets.Image Spear.Assets.Model Spear.Collision 21 Spear.Assets.Image Spear.Assets.Model Spear.Collision
22 Spear.Math.AABB Spear.Math.Circle Spear.Math.Triangle Spear.Game 22 Spear.Math.AABB Spear.Math.Circle Spear.Math.Triangle Spear.Game
23 Spear.GLSL Spear.Math.Camera Spear.Math.Entity Spear.Math.Matrix3 23 Spear.GL Spear.Math.Camera Spear.Math.Entity Spear.Math.Matrix3
24 Spear.Math.Matrix4 Spear.Math.MatrixUtils Spear.Math.Plane 24 Spear.Math.Matrix4 Spear.Math.MatrixUtils Spear.Math.Plane
25 Spear.Math.Quaternion Spear.Math.Vector Spear.Math.Vector.Class 25 Spear.Math.Quaternion Spear.Math.Vector Spear.Math.Vector.Class
26 Spear.Math.Vector.Vector3 Spear.Math.Vector.Vector4 26 Spear.Math.Vector.Vector3 Spear.Math.Vector.Vector4
diff --git a/Spear/GLSL.hs b/Spear/GL.hs
index 8541e1f..05e439a 100644
--- a/Spear/GLSL.hs
+++ b/Spear/GL.hs
@@ -1,4 +1,4 @@
1module Spear.GLSL 1module Spear.GL
2( 2(
3 -- * General Management 3 -- * General Management
4 GLSLShader 4 GLSLShader
diff --git a/Spear/Render/AnimatedModel.hs b/Spear/Render/AnimatedModel.hs
index e554272..be3e2e3 100644
--- a/Spear/Render/AnimatedModel.hs
+++ b/Spear/Render/AnimatedModel.hs
@@ -30,7 +30,7 @@ where
30import Spear.Assets.Model 30import Spear.Assets.Model
31import Spear.Collision 31import Spear.Collision
32import Spear.Game 32import Spear.Game
33import Spear.GLSL 33import Spear.GL
34import Spear.Math.AABB 34import Spear.Math.AABB
35import Spear.Math.Matrix4 (Matrix4) 35import Spear.Math.Matrix4 (Matrix4)
36import Spear.Math.Vector 36import Spear.Math.Vector
diff --git a/Spear/Render/Program.hs b/Spear/Render/Program.hs
index ab2a548..6e94ca5 100644
--- a/Spear/Render/Program.hs
+++ b/Spear/Render/Program.hs
@@ -11,34 +11,28 @@ module Spear.Render.Program
11) 11)
12where 12where
13 13
14 14import Spear.GL (GLSLProgram)
15import Spear.GLSL (GLSLProgram)
16
17 15
18import Graphics.Rendering.OpenGL.Raw.Core31 16import Graphics.Rendering.OpenGL.Raw.Core31
19 17
20
21data StaticProgram = StaticProgram 18data StaticProgram = StaticProgram
22 { staticProgram :: GLSLProgram 19 { staticProgram :: GLSLProgram
23 , staticProgramChannels :: StaticProgramChannels 20 , staticProgramChannels :: StaticProgramChannels
24 , staticProgramUniforms :: StaticProgramUniforms 21 , staticProgramUniforms :: StaticProgramUniforms
25 } 22 }
26 23
27
28data AnimatedProgram = AnimatedProgram 24data AnimatedProgram = AnimatedProgram
29 { animatedProgram :: GLSLProgram 25 { animatedProgram :: GLSLProgram
30 , animatedProgramChannels :: AnimatedProgramChannels 26 , animatedProgramChannels :: AnimatedProgramChannels
31 , animatedProgramUniforms :: AnimatedProgramUniforms 27 , animatedProgramUniforms :: AnimatedProgramUniforms
32 } 28 }
33 29
34
35data StaticProgramChannels = StaticProgramChannels 30data StaticProgramChannels = StaticProgramChannels
36 { vertexChannel :: GLuint -- ^ Vertex channel. 31 { vertexChannel :: GLuint -- ^ Vertex channel.
37 , normalChannel :: GLuint -- ^ Normal channel. 32 , normalChannel :: GLuint -- ^ Normal channel.
38 , stexChannel :: GLuint -- ^ Texture channel. 33 , stexChannel :: GLuint -- ^ Texture channel.
39 } 34 }
40 35
41
42data AnimatedProgramChannels = AnimatedProgramChannels 36data AnimatedProgramChannels = AnimatedProgramChannels
43 { vertexChannel1 :: GLuint -- ^ Vertex channel 1. 37 { vertexChannel1 :: GLuint -- ^ Vertex channel 1.
44 , vertexChannel2 :: GLuint -- ^ Vertex channel 2. 38 , vertexChannel2 :: GLuint -- ^ Vertex channel 2.
@@ -47,7 +41,6 @@ data AnimatedProgramChannels = AnimatedProgramChannels
47 , atexChannel :: GLuint -- ^ Texture channel. 41 , atexChannel :: GLuint -- ^ Texture channel.
48 } 42 }
49 43
50
51data StaticProgramUniforms = StaticProgramUniforms 44data StaticProgramUniforms = StaticProgramUniforms
52 { skaLoc :: GLint -- ^ Material ambient uniform location. 45 { skaLoc :: GLint -- ^ Material ambient uniform location.
53 , skdLoc :: GLint -- ^ Material diffuse uniform location. 46 , skdLoc :: GLint -- ^ Material diffuse uniform location.
@@ -59,7 +52,6 @@ data StaticProgramUniforms = StaticProgramUniforms
59 , sprojLoc :: GLint -- ^ Projection matrix location. 52 , sprojLoc :: GLint -- ^ Projection matrix location.
60 } 53 }
61 54
62
63data AnimatedProgramUniforms = AnimatedProgramUniforms 55data AnimatedProgramUniforms = AnimatedProgramUniforms
64 { akaLoc :: GLint -- ^ Material ambient uniform location. 56 { akaLoc :: GLint -- ^ Material ambient uniform location.
65 , akdLoc :: GLint -- ^ Material diffuse uniform location. 57 , akdLoc :: GLint -- ^ Material diffuse uniform location.
@@ -72,19 +64,15 @@ data AnimatedProgramUniforms = AnimatedProgramUniforms
72 , aprojLoc :: GLint -- ^ Projection matrix location. 64 , aprojLoc :: GLint -- ^ Projection matrix location.
73 } 65 }
74 66
75
76class Program a where 67class Program a where
77 program :: a -> GLSLProgram 68 program :: a -> GLSLProgram
78 69
79
80instance Program StaticProgram where 70instance Program StaticProgram where
81 program = staticProgram 71 program = staticProgram
82 72
83
84instance Program AnimatedProgram where 73instance Program AnimatedProgram where
85 program = animatedProgram 74 program = animatedProgram
86 75
87
88class ProgramUniforms a where 76class ProgramUniforms a where
89 kaLoc :: a -> GLint 77 kaLoc :: a -> GLint
90 kdLoc :: a -> GLint 78 kdLoc :: a -> GLint
@@ -95,7 +83,6 @@ class ProgramUniforms a where
95 normalmatLoc :: a -> GLint 83 normalmatLoc :: a -> GLint
96 projLoc :: a -> GLint 84 projLoc :: a -> GLint
97 85
98
99instance ProgramUniforms StaticProgramUniforms where 86instance ProgramUniforms StaticProgramUniforms where
100 kaLoc = skaLoc 87 kaLoc = skaLoc
101 kdLoc = skdLoc 88 kdLoc = skdLoc
@@ -106,8 +93,6 @@ instance ProgramUniforms StaticProgramUniforms where
106 normalmatLoc = snormalmatLoc 93 normalmatLoc = snormalmatLoc
107 projLoc = sprojLoc 94 projLoc = sprojLoc
108 95
109
110
111instance ProgramUniforms AnimatedProgramUniforms where 96instance ProgramUniforms AnimatedProgramUniforms where
112 kaLoc = akaLoc 97 kaLoc = akaLoc
113 kdLoc = akdLoc 98 kdLoc = akdLoc
diff --git a/Spear/Render/StaticModel.hs b/Spear/Render/StaticModel.hs
index fc7006e..42cf9d0 100644
--- a/Spear/Render/StaticModel.hs
+++ b/Spear/Render/StaticModel.hs
@@ -20,7 +20,7 @@ where
20import Spear.Assets.Model 20import Spear.Assets.Model
21import Spear.Collision 21import Spear.Collision
22import Spear.Game 22import Spear.Game
23import Spear.GLSL 23import Spear.GL
24import Spear.Math.AABB 24import Spear.Math.AABB
25import Spear.Math.Matrix4 (Matrix4) 25import Spear.Math.Matrix4 (Matrix4)
26import Spear.Math.Vector 26import Spear.Math.Vector
diff --git a/Spear/Scene/GameObject.hs b/Spear/Scene/GameObject.hs
index 37f9260..b981c00 100644
--- a/Spear/Scene/GameObject.hs
+++ b/Spear/Scene/GameObject.hs
@@ -32,7 +32,7 @@ where
32 32
33 33
34import Spear.Collision as Col 34import Spear.Collision as Col
35import Spear.GLSL 35import Spear.GL
36import Spear.Math.AABB 36import Spear.Math.AABB
37import qualified Spear.Math.Camera as Cam 37import qualified Spear.Math.Camera as Cam
38import qualified Spear.Math.Matrix3 as M3 38import qualified Spear.Math.Matrix3 as M3
diff --git a/Spear/Scene/Loader.hs b/Spear/Scene/Loader.hs
index 09d69eb..22657bd 100644
--- a/Spear/Scene/Loader.hs
+++ b/Spear/Scene/Loader.hs
@@ -20,7 +20,7 @@ where
20import Spear.Assets.Model as Model 20import Spear.Assets.Model as Model
21import Spear.Collision 21import Spear.Collision
22import Spear.Game 22import Spear.Game
23import qualified Spear.GLSL as GLSL 23import qualified Spear.GL as GL
24import Spear.Math.Matrix3 as M3 24import Spear.Math.Matrix3 as M3
25import Spear.Math.Matrix4 as M4 25import Spear.Math.Matrix4 as M4
26import Spear.Math.MatrixUtils (fastNormalMatrix) 26import Spear.Math.MatrixUtils (fastNormalMatrix)
@@ -201,20 +201,20 @@ rotateModel (Rotation ax ay az order) model =
201 in 201 in
202 flip Model.transformVerts vTransform . flip Model.transformNormals nTransform $ model 202 flip Model.transformVerts vTransform . flip Model.transformNormals nTransform $ model
203 203
204loadTexture :: FilePath -> Loader GLSL.Texture 204loadTexture :: FilePath -> Loader GL.Texture
205loadTexture file = 205loadTexture file =
206 loadResource file textures addTexture $ 206 loadResource file textures addTexture $
207 GLSL.loadTextureImage file gl_LINEAR gl_LINEAR 207 GL.loadTextureImage file gl_LINEAR gl_LINEAR
208 208
209newShaderProgram :: SceneGraph -> Loader () 209newShaderProgram :: SceneGraph -> Loader ()
210newShaderProgram (SceneLeaf _ props) = do 210newShaderProgram (SceneLeaf _ props) = do
211 (vsName, vertShader) <- Spear.Scene.Loader.loadShader GLSL.VertexShader props 211 (vsName, vertShader) <- Spear.Scene.Loader.loadShader GL.VertexShader props
212 (fsName, fragShader) <- Spear.Scene.Loader.loadShader GLSL.FragmentShader props 212 (fsName, fragShader) <- Spear.Scene.Loader.loadShader GL.FragmentShader props
213 name <- asString $ mandatory' "name" props 213 name <- asString $ mandatory' "name" props
214 stype <- asString $ mandatory' "type" props 214 stype <- asString $ mandatory' "type" props
215 prog <- GLSL.newProgram [vertShader, fragShader] 215 prog <- GL.newProgram [vertShader, fragShader]
216 216
217 let getUniformLoc name = (gameIO . SV.get $ GLSL.uniformLocation prog name) `GLSL.assertGL` name 217 let getUniformLoc name = (gameIO . SV.get $ GL.uniformLocation prog name) `GL.assertGL` name
218 218
219 case stype of 219 case stype of
220 "static" -> do 220 "static" -> do
@@ -285,17 +285,17 @@ newShaderProgram (SceneLeaf _ props) = do
285 loadResource name customPrograms addCustomProgram $ return prog 285 loadResource name customPrograms addCustomProgram $ return prog
286 return () 286 return ()
287 287
288loadShader :: GLSL.ShaderType -> [Property] -> Loader (String, GLSL.GLSLShader) 288loadShader :: GL.ShaderType -> [Property] -> Loader (String, GL.GLSLShader)
289loadShader _ [] = gameError $ "Loader::vertexShader: empty list" 289loadShader _ [] = gameError $ "Loader::vertexShader: empty list"
290loadShader shaderType ((stype, file):xs) = 290loadShader shaderType ((stype, file):xs) =
291 if shaderType == GLSL.VertexShader && stype == "vertex-shader" || 291 if shaderType == GL.VertexShader && stype == "vertex-shader" ||
292 shaderType == GLSL.FragmentShader && stype == "fragment-shader" 292 shaderType == GL.FragmentShader && stype == "fragment-shader"
293 then let f = concat file 293 then let f = concat file
294 in loadShader' f shaderType >>= \shader -> return (f, shader) 294 in loadShader' f shaderType >>= \shader -> return (f, shader)
295 else Spear.Scene.Loader.loadShader shaderType xs 295 else Spear.Scene.Loader.loadShader shaderType xs
296 296
297loadShader' :: String -> GLSL.ShaderType -> Loader GLSL.GLSLShader 297loadShader' :: String -> GL.ShaderType -> Loader GL.GLSLShader
298loadShader' file shaderType = loadResource file shaders addShader $ GLSL.loadShader file shaderType 298loadShader' file shaderType = loadResource file shaders addShader $ GL.loadShader file shaderType
299 299
300newLight :: SceneGraph -> Loader () 300newLight :: SceneGraph -> Loader ()
301newLight _ = return () 301newLight _ = return ()
diff --git a/Spear/Scene/SceneResources.hs b/Spear/Scene/SceneResources.hs
index c2dabcf..d75db56 100644
--- a/Spear/Scene/SceneResources.hs
+++ b/Spear/Scene/SceneResources.hs
@@ -17,9 +17,8 @@ module Spear.Scene.SceneResources
17) 17)
18where 18where
19 19
20
21import Spear.Assets.Model as Model 20import Spear.Assets.Model as Model
22import Spear.GLSL as GLSL 21import Spear.GL as GL
23import Spear.Math.Vector 22import Spear.Math.Vector
24import Spear.Render.AnimatedModel 23import Spear.Render.AnimatedModel
25import Spear.Render.Material 24import Spear.Render.Material
@@ -29,7 +28,6 @@ import Spear.Scene.Light
29 28
30import Data.Map as M 29import Data.Map as M
31 30
32
33data SceneResources = SceneResources 31data SceneResources = SceneResources
34 { shaders :: Map String GLSLShader 32 { shaders :: Map String GLSLShader
35 , customPrograms :: Map String GLSLProgram 33 , customPrograms :: Map String GLSLProgram
@@ -41,42 +39,34 @@ data SceneResources = SceneResources
41 , lights :: [Light] 39 , lights :: [Light]
42 } 40 }
43 41
44
45-- | Build an empty instance of 'SceneResources'. 42-- | Build an empty instance of 'SceneResources'.
46emptySceneResources = 43emptySceneResources =
47 SceneResources M.empty M.empty M.empty M.empty M.empty M.empty M.empty [] 44 SceneResources M.empty M.empty M.empty M.empty M.empty M.empty M.empty []
48 45
49
50-- | Get the shader specified by the given string. 46-- | Get the shader specified by the given string.
51getShader :: SceneResources -> String -> Maybe GLSLShader 47getShader :: SceneResources -> String -> Maybe GLSLShader
52getShader res key = M.lookup key $ shaders res 48getShader res key = M.lookup key $ shaders res
53 49
54
55-- | Get the custom program specified by the given string. 50-- | Get the custom program specified by the given string.
56getCustomProgram :: SceneResources -> String -> Maybe GLSLProgram 51getCustomProgram :: SceneResources -> String -> Maybe GLSLProgram
57getCustomProgram res key = M.lookup key $ customPrograms res 52getCustomProgram res key = M.lookup key $ customPrograms res
58 53
59
60-- | Get the static program specified by the given string. 54-- | Get the static program specified by the given string.
61getStaticProgram :: SceneResources -> String -> Maybe StaticProgram 55getStaticProgram :: SceneResources -> String -> Maybe StaticProgram
62getStaticProgram res key = M.lookup key $ staticPrograms res 56getStaticProgram res key = M.lookup key $ staticPrograms res
63 57
64
65-- | Get the animated program specified by the given string. 58-- | Get the animated program specified by the given string.
66getAnimatedProgram :: SceneResources -> String -> Maybe AnimatedProgram 59getAnimatedProgram :: SceneResources -> String -> Maybe AnimatedProgram
67getAnimatedProgram res key = M.lookup key $ animatedPrograms res 60getAnimatedProgram res key = M.lookup key $ animatedPrograms res
68 61
69
70-- | Get the texture specified by the given string. 62-- | Get the texture specified by the given string.
71getTexture :: SceneResources -> String -> Maybe Texture 63getTexture :: SceneResources -> String -> Maybe Texture
72getTexture res key = M.lookup key $ textures res 64getTexture res key = M.lookup key $ textures res
73 65
74
75-- | Get the static model resource specified by the given string. 66-- | Get the static model resource specified by the given string.
76getStaticModel :: SceneResources -> String -> Maybe StaticModelResource 67getStaticModel :: SceneResources -> String -> Maybe StaticModelResource
77getStaticModel res key = M.lookup key $ staticModels res 68getStaticModel res key = M.lookup key $ staticModels res
78 69
79
80-- | Get the animated model resource specified by the given string. 70-- | Get the animated model resource specified by the given string.
81getAnimatedModel :: SceneResources -> String -> Maybe AnimatedModelResource 71getAnimatedModel :: SceneResources -> String -> Maybe AnimatedModelResource
82getAnimatedModel res key = M.lookup key $ animatedModels res 72getAnimatedModel res key = M.lookup key $ animatedModels res