From 38cf114a03d0c7d5a9c154af9e095dfdb4c4c2f5 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Thu, 30 Aug 2012 20:11:07 +0200 Subject: Moved loadTextureImage to GLSL module --- Spear.cabal | 12 ++++++------ Spear.lkshs | 10 +++++----- Spear/GLSL.hs | 24 ++++++++++++++++++++++++ Spear/Render/Texture.hs | 34 ---------------------------------- Spear/Scene/Loader.hs | 5 +++-- Spear/Scene/SceneResources.hs | 1 - 6 files changed, 38 insertions(+), 48 deletions(-) delete mode 100644 Spear/Render/Texture.hs diff --git a/Spear.cabal b/Spear.cabal index a893ce3..ceb4ea7 100644 --- a/Spear.cabal +++ b/Spear.cabal @@ -25,12 +25,12 @@ library Spear.Math.Quaternion Spear.Math.Vector3 Spear.Math.Vector4 Spear.Physics Spear.Physics.Rigid Spear.Render.AnimatedModel Spear.Render.Material Spear.Render.Model Spear.Render.Program - Spear.Render.StaticModel Spear.Render.Texture Spear.Scene.Graph - Spear.Scene.Light Spear.Scene.Loader Spear.Scene.Scene - Spear.Scene.SceneResources Spear.Setup Spear.Sys.Timer - Spear.Sys.Store Spear.Sys.Store.ID Spear.Math.Vector2 - Spear.Math.Quad Spear.Math.Ray Spear.Math.Segment Spear.Math.Utils - Spear.Math.Spatial2 Spear.Math.Spatial3 + Spear.Render.StaticModel Spear.Scene.Graph Spear.Scene.Light + Spear.Scene.Loader Spear.Scene.Scene Spear.Scene.SceneResources + Spear.Setup Spear.Sys.Timer Spear.Sys.Store Spear.Sys.Store.ID + Spear.Math.Vector2 Spear.Math.Quad Spear.Math.Ray + Spear.Math.Segment Spear.Math.Utils Spear.Math.Spatial2 + Spear.Math.Spatial3 exposed: True buildable: True build-tools: hsc2hs -any diff --git a/Spear.lkshs b/Spear.lkshs index 1f6f16e..ee993af 100644 --- a/Spear.lkshs +++ b/Spear.lkshs @@ -1,18 +1,18 @@ Version of session file format: 1 Time of storage: - "Thu Aug 30 19:32:45 CEST 2012" -Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [("Browser",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 353) 140)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 653) 954 -Population: [(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Collision.hs" 3278)),[SplitP LeftP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 402)),[SplitP LeftP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/Loader.hs" 296)),[SplitP LeftP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Nothing,Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0]],[]), packageDExp = ([],[]), packageDExpNoBlack = ([],[]), workspaceExp = ([],[]), workspaceExpNoBlack = ([],[]), workspaceDExp = ([],[]), workspaceDExpNoBlack = ([],[]), systemExp = ([],[]), systemExpNoBlack = ([],[])}))),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Render/Program.hs" 248)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP])] + "Thu Aug 30 20:09:06 CEST 2012" +Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 3, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [("Browser",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 367) 146)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 678) 954 +Population: [(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/GLSL.hs" 1193)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 96)),[SplitP LeftP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/Loader.hs" 296)),[SplitP LeftP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Just (ModuleName ["Spear","Render","Texture"]),Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0,6],[0]],[]), packageDExp = ([],[]), packageDExpNoBlack = ([],[]), workspaceExp = ([],[]), workspaceExpNoBlack = ([],[]), workspaceDExp = ([],[]), workspaceDExpNoBlack = ([],[]), systemExp = ([],[]), systemExpNoBlack = ([],[])}))),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Render/Program.hs" 52)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP])] Window size: (1820,939) Completion size: (750,399) Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" -Active pane: Just "Collision.hs" +Active pane: Just "Modules" Toolbar visible: True FindbarState: (False,FindState {entryStr = "", entryHist = ["VAO","'VAO'","\170","\\","^","scale","Vector4.","asdad","translv","Vector3.","Vector.","copy_tr"], replaceStr = "V3.", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) Recently opened files: - ["/home/jeanne/programming/haskell/Spear/Spear/Math/QuadTree.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/Scene.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Types.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Collisioner.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Collision.hs","/home/jeanne/programming/haskell/Spear/Spear/Updatable.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Utils.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/Texture.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Player.hs","/home/jeanne/programming/haskell/Spear/Spear/GLSL.hs","/home/jeanne/programming/haskell/Spear/Spear/GLSL/VAO.hs"] + ["/home/jeanne/programming/haskell/Spear/Spear/Render/Texture.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/AnimatedModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/StaticModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/Program.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/QuadTree.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/Scene.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Types.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Collisioner.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Collision.hs","/home/jeanne/programming/haskell/Spear/Spear/Updatable.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/main.hs"] Recently opened workspaces: ["/home/jeanne/programming/haskell/hagen/hagen.lkshw","/home/jeanne/programming/haskell/foo/foo.lkshw","/home/jeanne/programming/haskell/Spear/Spear.lkshw","/home/jeanne/programming/haskell/nexus/nexus.lkshw","/home/jeanne/leksah.lkshw"] \ No newline at end of file diff --git a/Spear/GLSL.hs b/Spear/GLSL.hs index e0e1661..1d4d287 100644 --- a/Spear/GLSL.hs +++ b/Spear/GLSL.hs @@ -68,6 +68,7 @@ module Spear.GLSL , ($) -- ** Creation and destruction , newTexture +, loadTextureImage , releaseTexture -- ** Manipulation , bindTexture @@ -84,6 +85,7 @@ module Spear.GLSL where +import Spear.Assets.Image import Spear.Math.Matrix3 (Matrix3) import Spear.Math.Matrix4 (Matrix4) import Spear.Math.Vector3 as V3 @@ -625,6 +627,28 @@ deleteTexture tex = do with tex $ glDeleteTextures 1 +-- | Load the 'Texture' specified by the given file. +loadTextureImage :: FilePath + -> GLenum -- ^ Texture's min filter. + -> GLenum -- ^ Texture's mag filter. + -> Setup Texture +loadTextureImage file minFilter magFilter = do + image <- loadImage file + tex <- newTexture + setupIO $ do + let w = width image + h = height image + pix = pixels image + rgb = fromIntegral . fromEnum $ gl_RGB + + bindTexture tex + loadTextureData gl_TEXTURE_2D 0 rgb w h 0 gl_RGB gl_UNSIGNED_BYTE pix + texParami gl_TEXTURE_2D gl_TEXTURE_MIN_FILTER $= minFilter + texParami gl_TEXTURE_2D gl_TEXTURE_MAG_FILTER $= magFilter + + return tex + + -- | Bind the texture. bindTexture :: Texture -> IO () bindTexture = glBindTexture gl_TEXTURE_2D . getTex diff --git a/Spear/Render/Texture.hs b/Spear/Render/Texture.hs deleted file mode 100644 index 3311ce6..0000000 --- a/Spear/Render/Texture.hs +++ /dev/null @@ -1,34 +0,0 @@ -module Spear.Render.Texture -( - loadTextureImage -) -where - - -import Spear.Setup -import Spear.Assets.Image -import Spear.GLSL -import Data.StateVar (($=)) -import Graphics.Rendering.OpenGL.Raw.Core31 - - --- | Load the 'Texture' specified by the given file. -loadTextureImage :: FilePath - -> GLenum -- ^ Texture's min filter. - -> GLenum -- ^ Texture's mag filter. - -> Setup Texture -loadTextureImage file minFilter magFilter = do - image <- loadImage file - tex <- newTexture - setupIO $ do - let w = width image - h = height image - pix = pixels image - rgb = fromIntegral . fromEnum $ gl_RGB - - bindTexture tex - loadTextureData gl_TEXTURE_2D 0 rgb w h 0 gl_RGB gl_UNSIGNED_BYTE pix - texParami gl_TEXTURE_2D gl_TEXTURE_MIN_FILTER $= minFilter - texParami gl_TEXTURE_2D gl_TEXTURE_MAG_FILTER $= magFilter - - return tex diff --git a/Spear/Scene/Loader.hs b/Spear/Scene/Loader.hs index 820ad51..0ef5333 100644 --- a/Spear/Scene/Loader.hs +++ b/Spear/Scene/Loader.hs @@ -31,7 +31,6 @@ import Spear.Render.AnimatedModel as AM import Spear.Render.Material import Spear.Render.Program import Spear.Render.StaticModel as SM -import Spear.Render.Texture import Spear.Scene.GameObject as GO import Spear.Scene.Graph import Spear.Scene.Light @@ -227,7 +226,9 @@ rotateModel (Rotation x y z order) model = loadTexture :: FilePath -> Loader GLSL.Texture -loadTexture file = loadResource file textures addTexture $ loadTextureImage file gl_LINEAR gl_LINEAR +loadTexture file = + loadResource file textures addTexture $ + GLSL.loadTextureImage file gl_LINEAR gl_LINEAR newShaderProgram :: SceneGraph -> Loader () diff --git a/Spear/Scene/SceneResources.hs b/Spear/Scene/SceneResources.hs index e54f385..037e3aa 100644 --- a/Spear/Scene/SceneResources.hs +++ b/Spear/Scene/SceneResources.hs @@ -21,7 +21,6 @@ import Spear.Render.AnimatedModel import Spear.Render.Material import Spear.Render.Program import Spear.Render.StaticModel -import Spear.Render.Texture import Spear.Scene.Light import Data.Map as M -- cgit v1.2.3