packages feed

Michelangelo 0.1.0.2 → 0.1.0.3

raw patch · 4 files changed

+68/−46 lines, 4 files

Files

Michelangelo.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes
 --                   | | +----- non-breaking API additions
 --                   | | | +--- code changes with no API change
-version:             0.1.0.2
+version:             0.1.0.3
 
 -- A short (one-line) description of the package.
 synopsis:            OpenGL for dummies
src/Graphics/Michelangelo/Mesh.hs view
@@ -57,19 +57,19 @@ -- renderMesh :: Mesh -> IO ()
 renderMesh :: Mesh -> IO ()
 renderMesh mesh = do
-	GLUtil.printErrorMsg "Entering renderMesh"
-	-- return $ (prepare mesh) <*> Just mesh
-	case prepare mesh of
-		Just action -> action mesh
-		_           -> return ()
-	GLUtil.printErrorMsg "Shader program set"
+  GLUtil.printErrorMsg "Entering renderMesh"
+  -- return $ (prepare mesh) <*> Just mesh
+  case prepare mesh of
+    Just action -> action mesh
+    _           -> return ()
+  GLUtil.printErrorMsg "Shader program set"
 
-	withAttributes mesh $ \ _ -> do
-		GLUtil.printErrorMsg "Entering withAttributes action"
-		Shade.setShaderUniforms (shader mesh) (Map.elems $ uniforms mesh) --
-		GLUtil.printErrorMsg "Uniforms set"
-		GL.drawArrays (primitive mesh) 0 (fromIntegral $ size mesh)       --
-		GLUtil.printErrorMsg "Arrays drawn"
+  withAttributes mesh $ \ _ -> do
+    GLUtil.printErrorMsg "Entering withAttributes action"
+    Shade.setShaderUniforms (shader mesh) (Map.elems $ uniforms mesh) --
+    GLUtil.printErrorMsg "Uniforms set"
+    GL.drawArrays (primitive mesh) 0 (fromIntegral $ size mesh)       --
+    GLUtil.printErrorMsg "Arrays drawn"
 
 
 -- |
@@ -81,42 +81,42 @@ -- TODO: Are there any attributes that are NOT buffers (?)
 bufferAttribute :: GL.BufferObject -> GL.AttribLocation -> Int -> IO ()
 bufferAttribute buffer loc count = do
-	GL.vertexAttribArray loc     $= GL.Enabled                                                                            --
-	GL.bindBuffer GL.ArrayBuffer $= Just buffer                                                                           --
-	GL.vertexAttribPointer loc   $= (GL.ToFloat, GL.VertexArrayDescriptor (fromIntegral count) GL.Float 0 GLUtil.offset0) --
+  GL.vertexAttribArray loc     $= GL.Enabled                                                                            --
+  GL.bindBuffer GL.ArrayBuffer $= Just buffer                                                                           --
+  GL.vertexAttribPointer loc   $= (GL.ToFloat, GL.VertexArrayDescriptor (fromIntegral count) GL.Float 0 GLUtil.offset0) --
 
 
 -- |
 attribute :: GL.Program -> String -> GL.BufferObject -> Int -> IO ()
 attribute program name buffer count = do
-	loc <- GL.get $ GL.attribLocation program name
-	bufferAttribute buffer loc count
+  loc <- GL.get $ GL.attribLocation program name
+  bufferAttribute buffer loc count
 
 
 -- |
 bindAttributes :: Mesh -> IO ()
 bindAttributes mesh = do
-	-- GLS.currentProgram $= Just (shader mesh)
-	Map.foldrWithKey reduce nothing (attributes mesh) -- TODO: Use Traversable instead (?)
-	where
-	   reduce key (loc, buff, count) acc = acc >> bufferAttribute buff loc count --
-	   nothing                           = return ()                             --
+  -- GLS.currentProgram $= Just (shader mesh)
+  Map.foldrWithKey reduce nothing (attributes mesh) -- TODO: Use Traversable instead (?)
+  where
+     reduce key (loc, buff, count) acc = acc >> bufferAttribute buff loc count --
+     nothing                           = return ()                             --
 
 
 -- |
 unbindAttributes :: Mesh -> IO ()
 unbindAttributes mesh = Map.foldrWithKey reduce nothing (attributes mesh)
-	where
-	   reduce key (loc, buff, count) acc = acc >> (GL.vertexAttribArray loc $= GL.Enabled) --
-	   nothing                           = return ()                                       --
+  where
+     reduce key (loc, buff, count) acc = acc >> (GL.vertexAttribArray loc $= GL.Enabled) --
+     nothing                           = return ()                                       --
 
 
 -- |
 withAttributes :: Mesh -> (Mesh -> IO ()) -> IO ()
 withAttributes mesh action = do
-	bindAttributes mesh
-	action mesh
-	unbindAttributes mesh
+  bindAttributes mesh
+  action mesh
+  unbindAttributes mesh
 
 
 -- |
@@ -127,10 +127,10 @@ {-
 prepareTextured :: state -> IO ()
 prepareTextured _ = do
-	maybe
-	  (return ())
-	  (\(tex, coords) -> do
-	  	GL.bindBuffer GL.ArrayBuffer $= Just coords
-	  	GL.vertexAttribPointer (texattrib) $= (GL.ToFloat, GL.VertexArrayDescriptor 2 GL.Float 0 GLUtil.offset0))
-	  (liftM2 (,) (texture mesh) (texcoords mesh))
+  maybe
+    (return ())
+    (\(tex, coords) -> do
+      GL.bindBuffer GL.ArrayBuffer $= Just coords
+      GL.vertexAttribPointer (texattrib) $= (GL.ToFloat, GL.VertexArrayDescriptor 2 GL.Float 0 GLUtil.offset0))
+    (liftM2 (,) (texture mesh) (texcoords mesh))
 -}
src/Graphics/Michelangelo/Shaders.hs view
@@ -150,14 +150,7 @@ --------------------------------------------------------------------------------------------------------------------------------------------
 -- Uniforms
 --------------------------------------------------------------------------------------------------------------------------------------------
--- |
--- TODO: Better naming conventions
--- TOOD: All uniform types (matrices, vectors, scalars, variable length)
-data UniformValue = UMatrix44 (M44 Float) |
-                    UVec3     (V3 Float)  |
-                    UFloat     Float      |
-                    UInt       Int
-                    deriving (Show)
+
 
 
 -- |
src/Graphics/Michelangelo/Types.hs view
@@ -1,5 +1,5 @@ -- |
--- Module      : Graphics.Michelangelo.Types.hs
+-- Module      : Graphics.Michelangelo.Types
 -- Description :
 -- Copyright   : (c) Jonatan H Sundqvist, 2015
 -- License     : MIT
@@ -21,24 +21,41 @@ --------------------------------------------------------------------------------------------------------------------------------------------
 -- GHC Pragmas
 --------------------------------------------------------------------------------------------------------------------------------------------
-
+{-# LANGUAGE TypeSynonymInstances #-} --
+{-# LANGUAGE FlexibleInstances    #-} --
 
 
 
 --------------------------------------------------------------------------------------------------------------------------------------------
 -- API
 --------------------------------------------------------------------------------------------------------------------------------------------
-module Graphics.Michelangelo.Types.hs where
+module Graphics.Michelangelo.Types where
 
 
 
 --------------------------------------------------------------------------------------------------------------------------------------------
 -- We'll need these
 --------------------------------------------------------------------------------------------------------------------------------------------
+import qualified Data.Map as Map
+import qualified Graphics.WaveFront.Parsers as WF
 
+import           Foreign.Storable                 (Storable)
+import           Foreign.Ptr                      (castPtr, Ptr())
+import qualified Foreign.Marshal.Utils as Marshal (with)
 
+import Linear.V3
+import Linear.Matrix
 
+import qualified Graphics.Rendering.OpenGL            as GL              --
+import           Graphics.Rendering.OpenGL            as GL              --
+import qualified Graphics.Rendering.OpenGL.GL.Shaders as GLS             --
+import qualified Graphics.Rendering.OpenGL.Raw        as GLRaw           --
+import qualified Graphics.Rendering.OpenGL.GL.Shaders.Uniform as Uniform --
+import           Graphics.Rendering.OpenGL.GL.Shaders.Uniform
+import           Graphics.GLUtil
 
+
+
 --------------------------------------------------------------------------------------------------------------------------------------------
 -- Types
 --------------------------------------------------------------------------------------------------------------------------------------------
@@ -78,6 +95,18 @@ -- type Uniform   = (GL.UniformLocation, UniformValue)         --
 type Attribute = (GL.AttribLocation,  GL.BufferObject, Int) -- TODO: Are there any non-buffer attribute types, separate type (?)
 
+-- Classes ---------------------------------------------------------------------------------------------------------------------------------
+
+-- |
+-- TODO: Better naming conventions
+-- TOOD: All uniform types (matrices, vectors, scalars, variable length)
+data UniformValue = UMatrix44 (M44 Float) |
+                    UVec3     (V3 Float)  |
+                    UFloat     Float      |
+                    UInt       Int
+                    deriving (Show)
+
+-- Instances -------------------------------------------------------------------------------------------------------------------------------
 
 -- |
 -- TODO: Make polymorphic (?)