diff options
author | Jeanne-Kamikaze <jeannekamikaze@gmail.com> | 2013-02-22 15:19:59 +0100 |
---|---|---|
committer | Jeanne-Kamikaze <jeannekamikaze@gmail.com> | 2013-02-22 15:19:59 +0100 |
commit | 1f4b8ec3b58e329f27432a3fbc9ab37f3da84899 (patch) | |
tree | c048fde3213a02c792cb11dc858f293d7fe0ce83 | |
parent | 8ed4094013e769d2b57002b5f2bdecbcf8200f57 (diff) |
GLSL -> GL
-rw-r--r-- | Spear.cabal | 2 | ||||
-rw-r--r-- | Spear/GL.hs (renamed from Spear/GLSL.hs) | 2 | ||||
-rw-r--r-- | Spear/Render/AnimatedModel.hs | 2 | ||||
-rw-r--r-- | Spear/Render/Program.hs | 17 | ||||
-rw-r--r-- | Spear/Render/StaticModel.hs | 2 | ||||
-rw-r--r-- | Spear/Scene/GameObject.hs | 2 | ||||
-rw-r--r-- | Spear/Scene/Loader.hs | 24 | ||||
-rw-r--r-- | Spear/Scene/SceneResources.hs | 12 |
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 @@ | |||
1 | module Spear.GLSL | 1 | module 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 | |||
30 | import Spear.Assets.Model | 30 | import Spear.Assets.Model |
31 | import Spear.Collision | 31 | import Spear.Collision |
32 | import Spear.Game | 32 | import Spear.Game |
33 | import Spear.GLSL | 33 | import Spear.GL |
34 | import Spear.Math.AABB | 34 | import Spear.Math.AABB |
35 | import Spear.Math.Matrix4 (Matrix4) | 35 | import Spear.Math.Matrix4 (Matrix4) |
36 | import Spear.Math.Vector | 36 | import 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 | ) |
12 | where | 12 | where |
13 | 13 | ||
14 | 14 | import Spear.GL (GLSLProgram) | |
15 | import Spear.GLSL (GLSLProgram) | ||
16 | |||
17 | 15 | ||
18 | import Graphics.Rendering.OpenGL.Raw.Core31 | 16 | import Graphics.Rendering.OpenGL.Raw.Core31 |
19 | 17 | ||
20 | |||
21 | data StaticProgram = StaticProgram | 18 | data 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 | |||
28 | data AnimatedProgram = AnimatedProgram | 24 | data 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 | |||
35 | data StaticProgramChannels = StaticProgramChannels | 30 | data 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 | |||
42 | data AnimatedProgramChannels = AnimatedProgramChannels | 36 | data 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 | |||
51 | data StaticProgramUniforms = StaticProgramUniforms | 44 | data 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 | |||
63 | data AnimatedProgramUniforms = AnimatedProgramUniforms | 55 | data 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 | |||
76 | class Program a where | 67 | class Program a where |
77 | program :: a -> GLSLProgram | 68 | program :: a -> GLSLProgram |
78 | 69 | ||
79 | |||
80 | instance Program StaticProgram where | 70 | instance Program StaticProgram where |
81 | program = staticProgram | 71 | program = staticProgram |
82 | 72 | ||
83 | |||
84 | instance Program AnimatedProgram where | 73 | instance Program AnimatedProgram where |
85 | program = animatedProgram | 74 | program = animatedProgram |
86 | 75 | ||
87 | |||
88 | class ProgramUniforms a where | 76 | class 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 | |||
99 | instance ProgramUniforms StaticProgramUniforms where | 86 | instance 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 | |||
111 | instance ProgramUniforms AnimatedProgramUniforms where | 96 | instance 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 | |||
20 | import Spear.Assets.Model | 20 | import Spear.Assets.Model |
21 | import Spear.Collision | 21 | import Spear.Collision |
22 | import Spear.Game | 22 | import Spear.Game |
23 | import Spear.GLSL | 23 | import Spear.GL |
24 | import Spear.Math.AABB | 24 | import Spear.Math.AABB |
25 | import Spear.Math.Matrix4 (Matrix4) | 25 | import Spear.Math.Matrix4 (Matrix4) |
26 | import Spear.Math.Vector | 26 | import 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 | ||
34 | import Spear.Collision as Col | 34 | import Spear.Collision as Col |
35 | import Spear.GLSL | 35 | import Spear.GL |
36 | import Spear.Math.AABB | 36 | import Spear.Math.AABB |
37 | import qualified Spear.Math.Camera as Cam | 37 | import qualified Spear.Math.Camera as Cam |
38 | import qualified Spear.Math.Matrix3 as M3 | 38 | import 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 | |||
20 | import Spear.Assets.Model as Model | 20 | import Spear.Assets.Model as Model |
21 | import Spear.Collision | 21 | import Spear.Collision |
22 | import Spear.Game | 22 | import Spear.Game |
23 | import qualified Spear.GLSL as GLSL | 23 | import qualified Spear.GL as GL |
24 | import Spear.Math.Matrix3 as M3 | 24 | import Spear.Math.Matrix3 as M3 |
25 | import Spear.Math.Matrix4 as M4 | 25 | import Spear.Math.Matrix4 as M4 |
26 | import Spear.Math.MatrixUtils (fastNormalMatrix) | 26 | import 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 | ||
204 | loadTexture :: FilePath -> Loader GLSL.Texture | 204 | loadTexture :: FilePath -> Loader GL.Texture |
205 | loadTexture file = | 205 | loadTexture 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 | ||
209 | newShaderProgram :: SceneGraph -> Loader () | 209 | newShaderProgram :: SceneGraph -> Loader () |
210 | newShaderProgram (SceneLeaf _ props) = do | 210 | newShaderProgram (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 | ||
288 | loadShader :: GLSL.ShaderType -> [Property] -> Loader (String, GLSL.GLSLShader) | 288 | loadShader :: GL.ShaderType -> [Property] -> Loader (String, GL.GLSLShader) |
289 | loadShader _ [] = gameError $ "Loader::vertexShader: empty list" | 289 | loadShader _ [] = gameError $ "Loader::vertexShader: empty list" |
290 | loadShader shaderType ((stype, file):xs) = | 290 | loadShader 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 | ||
297 | loadShader' :: String -> GLSL.ShaderType -> Loader GLSL.GLSLShader | 297 | loadShader' :: String -> GL.ShaderType -> Loader GL.GLSLShader |
298 | loadShader' file shaderType = loadResource file shaders addShader $ GLSL.loadShader file shaderType | 298 | loadShader' file shaderType = loadResource file shaders addShader $ GL.loadShader file shaderType |
299 | 299 | ||
300 | newLight :: SceneGraph -> Loader () | 300 | newLight :: SceneGraph -> Loader () |
301 | newLight _ = return () | 301 | newLight _ = 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 | ) |
18 | where | 18 | where |
19 | 19 | ||
20 | |||
21 | import Spear.Assets.Model as Model | 20 | import Spear.Assets.Model as Model |
22 | import Spear.GLSL as GLSL | 21 | import Spear.GL as GL |
23 | import Spear.Math.Vector | 22 | import Spear.Math.Vector |
24 | import Spear.Render.AnimatedModel | 23 | import Spear.Render.AnimatedModel |
25 | import Spear.Render.Material | 24 | import Spear.Render.Material |
@@ -29,7 +28,6 @@ import Spear.Scene.Light | |||
29 | 28 | ||
30 | import Data.Map as M | 29 | import Data.Map as M |
31 | 30 | ||
32 | |||
33 | data SceneResources = SceneResources | 31 | data 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'. |
46 | emptySceneResources = | 43 | emptySceneResources = |
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. |
51 | getShader :: SceneResources -> String -> Maybe GLSLShader | 47 | getShader :: SceneResources -> String -> Maybe GLSLShader |
52 | getShader res key = M.lookup key $ shaders res | 48 | getShader 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. |
56 | getCustomProgram :: SceneResources -> String -> Maybe GLSLProgram | 51 | getCustomProgram :: SceneResources -> String -> Maybe GLSLProgram |
57 | getCustomProgram res key = M.lookup key $ customPrograms res | 52 | getCustomProgram 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. |
61 | getStaticProgram :: SceneResources -> String -> Maybe StaticProgram | 55 | getStaticProgram :: SceneResources -> String -> Maybe StaticProgram |
62 | getStaticProgram res key = M.lookup key $ staticPrograms res | 56 | getStaticProgram 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. |
66 | getAnimatedProgram :: SceneResources -> String -> Maybe AnimatedProgram | 59 | getAnimatedProgram :: SceneResources -> String -> Maybe AnimatedProgram |
67 | getAnimatedProgram res key = M.lookup key $ animatedPrograms res | 60 | getAnimatedProgram 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. |
71 | getTexture :: SceneResources -> String -> Maybe Texture | 63 | getTexture :: SceneResources -> String -> Maybe Texture |
72 | getTexture res key = M.lookup key $ textures res | 64 | getTexture 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. |
76 | getStaticModel :: SceneResources -> String -> Maybe StaticModelResource | 67 | getStaticModel :: SceneResources -> String -> Maybe StaticModelResource |
77 | getStaticModel res key = M.lookup key $ staticModels res | 68 | getStaticModel 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. |
81 | getAnimatedModel :: SceneResources -> String -> Maybe AnimatedModelResource | 71 | getAnimatedModel :: SceneResources -> String -> Maybe AnimatedModelResource |
82 | getAnimatedModel res key = M.lookup key $ animatedModels res | 72 | getAnimatedModel res key = M.lookup key $ animatedModels res |