packages feed

luminance 0.5 → 0.5.1

raw patch · 5 files changed

+191/−16 lines, 5 files

Files

CHANGELOG.md view
@@ -1,3 +1,14 @@+## 0.5.1++#### Minor changes++- Added several `Uniform` instances for [linear](http://hackage.haskell.org/package/linear).++#### Patch changes++- Fixed the indexed render.+- Fixed the vertex attributes being ignored.+ ### 0.5  #### Major changes
luminance.cabal view
@@ -1,21 +1,21 @@ name:                luminance-version:             0.5+version:             0.5.1 synopsis:            Type-safe, dependently-typed and stateless graphics framework description:         This package exposes several modules to work with /GPUs/ in a stateless and-                     type-safe way. Currently, it uses __OpenGL__ as backend hardware technology but-                     others will be added later on, such as __Vulkan__.+                     type-safe way. Currently, it uses OpenGL as backend hardware technology but+                     others will be added later on, such as Vulkan.                      .                      The initial unstable version is /0.1/. Consider everything in that version as                      part of an experiment, even though the library should be free of bugs. If you                      find any, please report an issue. If you think something could be enhanced,                      feel free to fill in an issue as well.                      .-                     One very important point is the fact that __luminance__ has nothing to do with+                     One very important point is the fact that luminance has nothing to do with                      /3D engines/ or /scene development kits/. Don’t expect to find /materials/,                      /lights/ or /mesh/ loaders. It’s just a graphics framework initiated to fix the-                     design choices of __OpenGL__. It won’t change in any other way.+                     design choices of OpenGL. It won’t change in any other way.                      .-                     __luminance__ is a small yet powerful graphics API. It was designed so that+                     luminance is a small yet powerful graphics API. It was designed so that                      people can quickly get their feet wet and start having fun with graphics in                      /Haskell/. The main idea is to unleash the graphical and visual properties of                      /GPUs/ in a stateless and type-safe way.
src/Graphics/Luminance/Core/Geometry.hs view
@@ -85,10 +85,11 @@     (vreg :: Region W v,vbo) <- createBuffer_ $ newRegion (fromIntegral vertNb)     writeWhole vreg vertices     liftIO $ glVertexArrayVertexBuffer vid vertexBindingIndex (bufferID vbo) 0 (fromIntegral $ sizeOf (undefined :: v))-    setFormatV vid 0 (Proxy :: Proxy v)+    _ <- setFormatV vid 0 0 (Proxy :: Proxy v)     -- element buffer, if required     case indices of       Just indices' -> do+        let ixNb = length indices'         (ireg :: Region W Word32,ibo) <- createBuffer_ $ newRegion (fromIntegral ixNb)         writeWhole ireg indices'         glVertexArrayElementBuffer vid (bufferID ibo)@@ -96,7 +97,6 @@       Nothing -> pure . DirectGeometry $ VertexArray vid mode' (fromIntegral vertNb)   where     vertNb = length vertices-    ixNb   = length indices     mode'  = fromGeometryMode mode  -- |/O (n log n)/
src/Graphics/Luminance/Core/Shader/Uniform.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE DataKinds #-}+ ----------------------------------------------------------------------------- -- | -- Copyright   : (C) 2015 Dimitri Sabadie@@ -13,10 +15,13 @@ import Data.Functor.Contravariant ( Contravariant(..) ) import Data.Functor.Contravariant.Divisible ( Decidable(..), Divisible(..) ) import Data.Int ( Int32 )+import Data.Foldable ( toList ) import Data.Semigroup ( Semigroup(..) ) import Data.Void ( absurd ) import Data.Word ( Word32 )+import Foreign.Marshal.Utils ( with ) import Foreign.Marshal.Array ( withArrayLen )+import Foreign.Ptr ( castPtr ) import Graphics.GL import Graphics.GL.Ext.ARB.BindlessTexture ( glProgramUniformHandleui64ARB ) import Graphics.Luminance.Core.Cubemap ( Cubemap(cubemapBase) )@@ -24,6 +29,8 @@ import Graphics.Luminance.Core.Texture1D ( Texture1D(texture1DBase) ) import Graphics.Luminance.Core.Texture2D ( Texture2D(texture2DBase) ) import Graphics.Luminance.Core.Texture3D ( Texture3D(texture3DBase) )+import Linear+import Linear.V ( V(V) )  -------------------------------------------------------------------------------- -- Uniform ---------------------------------------------------------------------@@ -87,14 +94,38 @@ instance Uniform (Int32,Int32) where   toU prog l = U $ \(x,y) -> glProgramUniform2i prog l x y +instance Uniform (V2 Int32) where+  toU prog l = U $ \(V2 x y) -> glProgramUniform2i prog l x y++instance Uniform (V 2 Int32) where+  toU prog l = U $ \(V v) -> case toList v of+    [x,y] -> glProgramUniform2i prog l x y+    _ -> pure ()+     -- D3 instance Uniform (Int32,Int32,Int32) where   toU prog l = U $ \(x,y,z) -> glProgramUniform3i prog l x y z +instance Uniform (V3 Int32) where+  toU prog l = U $ \(V3 x y z) -> glProgramUniform3i prog l x y z++instance Uniform (V 3 Int32) where+  toU prog l = U $ \(V v) -> case toList v of+    [x,y,z] -> glProgramUniform3i prog l x y z+    _ -> pure ()+ -- D4 instance Uniform (Int32,Int32,Int32,Int32) where   toU prog l = U $ \(x,y,z,w) -> glProgramUniform4i prog l x y z w +instance Uniform (V4 Int32) where+  toU prog l = U $ \(V4 x y z w) -> glProgramUniform4i prog l x y z w++instance Uniform (V 4 Int32) where+  toU prog l = U $ \(V v) -> case toList v of+    [x,y,z,w] -> glProgramUniform4i prog l x y z w+    _ -> pure ()+ -- scalar array instance Uniform [Int32] where   toU prog l = U $ \v -> withArrayLen v $ glProgramUniform1iv prog l . fromIntegral@@ -104,16 +135,40 @@   toU prog l = U $ \v -> withArrayLen (concatMap unPair v) $     glProgramUniform2iv prog l . fromIntegral +instance Uniform [V2 Int32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform2iv prog l (fromIntegral size) (castPtr p)++instance Uniform [V 2 Int32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform2iv prog l (fromIntegral size) (castPtr p)+ -- D3 array instance Uniform [(Int32,Int32,Int32)] where   toU prog l = U $ \v -> withArrayLen (concatMap unTriple v) $     glProgramUniform3iv prog l . fromIntegral +instance Uniform [V3 Int32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform3iv prog l (fromIntegral size) (castPtr p)++instance Uniform [V 3 Int32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform3iv prog l (fromIntegral size) (castPtr p)+ -- D4 array instance Uniform [(Int32,Int32,Int32,Int32)] where   toU prog l = U $ \v -> withArrayLen (concatMap unQuad v) $     glProgramUniform4iv prog l . fromIntegral +instance Uniform [V4 Int32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform4iv prog l (fromIntegral size) (castPtr p)++instance Uniform [V 4 Int32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform4iv prog l (fromIntegral size) (castPtr p)+ -------------------------------------------------------------------------------- -- Word32 instances ------------------------------------------------------------ @@ -125,14 +180,38 @@ instance Uniform (Word32,Word32) where   toU prog l = U $ \(x,y) -> glProgramUniform2ui prog l x y +instance Uniform (V2 Word32) where+  toU prog l = U $ \(V2 x y) -> glProgramUniform2ui prog l x y++instance Uniform (V 2 Word32) where+  toU prog l = U $ \(V v) -> case toList v of+    [x,y] -> glProgramUniform2ui prog l x y+    _ -> pure ()+ -- D3 instance Uniform (Word32,Word32,Word32) where   toU prog l = U $ \(x,y,z) -> glProgramUniform3ui prog l x y z +instance Uniform (V3 Word32) where+  toU prog l = U $ \(V3 x y z) -> glProgramUniform3ui prog l x y z++instance Uniform (V 3 Word32) where+  toU prog l = U $ \(V v) -> case toList v of+    [x,y,z] -> glProgramUniform3ui prog l x y z+    _ -> pure ()+ -- D4 instance Uniform (Word32,Word32,Word32,Word32) where   toU prog l = U $ \(x,y,z,w) -> glProgramUniform4ui prog l x y z w +instance Uniform (V4 Word32) where+  toU prog l = U $ \(V4 x y z w) -> glProgramUniform4ui prog l x y z w++instance Uniform (V 4 Word32) where+  toU prog l = U $ \(V v) -> case toList v of+    [x,y,z,w] -> glProgramUniform4ui prog l x y z w+    _ -> pure ()+ -- scalar array instance Uniform [Word32] where   toU prog l = U $ \v -> withArrayLen v $@@ -143,16 +222,40 @@   toU prog l = U $ \v -> withArrayLen (concatMap unPair v) $     glProgramUniform2uiv prog l . fromIntegral +instance Uniform [V2 Word32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform2uiv prog l (fromIntegral size) (castPtr p)++instance Uniform [V 2 Word32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform2uiv prog l (fromIntegral size) (castPtr p)+ -- D3 array instance Uniform [(Word32,Word32,Word32)] where   toU prog l = U $ \v -> withArrayLen (concatMap unTriple v) $     glProgramUniform3uiv prog l . fromIntegral +instance Uniform [V3 Word32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform3uiv prog l (fromIntegral size) (castPtr p)++instance Uniform [V 3 Word32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform3uiv prog l (fromIntegral size) (castPtr p)+ -- D4 array instance Uniform [(Word32,Word32,Word32,Word32)] where   toU prog l = U $ \v -> withArrayLen (concatMap unQuad v) $     glProgramUniform4uiv prog l . fromIntegral +instance Uniform [V4 Word32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform4uiv prog l (fromIntegral size) (castPtr p)++instance Uniform [V 4 Word32] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform4uiv prog l (fromIntegral size) (castPtr p)+ -------------------------------------------------------------------------------- -- Float instances ------------------------------------------------------------- @@ -164,14 +267,38 @@ instance Uniform (Float,Float) where   toU prog l = U $ \(x,y) -> glProgramUniform2f prog l x y +instance Uniform (V2 Float) where+  toU prog l = U $ \(V2 x y) -> glProgramUniform2f prog l x y++instance Uniform (V 2 Float) where+  toU prog l = U $ \(V v) -> case toList v of+    [x,y] -> glProgramUniform2f prog l x y+    _ -> pure ()+ -- D3 instance Uniform (Float,Float,Float) where   toU prog l = U $ \(x,y,z) -> glProgramUniform3f prog l x y z +instance Uniform (V3 Float) where+  toU prog l = U $ \(V3 x y z) -> glProgramUniform3f prog l x y z++instance Uniform (V 3 Float) where+  toU prog l = U $ \(V v) -> case toList v of+    [x,y,z] -> glProgramUniform3f prog l x y z+    _ -> pure ()+ -- D4 instance Uniform (Float,Float,Float,Float) where   toU prog l = U $ \(x,y,z,w) -> glProgramUniform4f prog l x y z w +instance Uniform (V4 Float) where+  toU prog l = U $ \(V4 x y z w) -> glProgramUniform4f prog l x y z w++instance Uniform (V 4 Float) where+  toU prog l = U $ \(V v) -> case toList v of+    [x,y,z,w] -> glProgramUniform4f prog l x y z w+    _ -> pure ()+ -- scalar array instance Uniform [Float] where   toU prog l = U $ \v -> withArrayLen v $@@ -182,15 +309,48 @@   toU prog l = U $ \v -> withArrayLen (concatMap unPair v) $     glProgramUniform2fv prog l . fromIntegral +instance Uniform [V2 Float] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform2fv prog l (fromIntegral size) (castPtr p)++instance Uniform [V 2 Float] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform2fv prog l (fromIntegral size) (castPtr p)+ -- D3 array instance Uniform [(Float,Float,Float)] where   toU prog l = U $ \v -> withArrayLen (concatMap unTriple v) $     glProgramUniform3fv prog l . fromIntegral +instance Uniform [V3 Float] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform3fv prog l (fromIntegral size) (castPtr p)++instance Uniform [V 3 Float] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform3fv prog l (fromIntegral size) (castPtr p)+ -- D4 array instance Uniform [(Float,Float,Float,Float)] where   toU prog l = U $ \v -> withArrayLen (concatMap unQuad v) $     glProgramUniform4fv prog l . fromIntegral++instance Uniform [V4 Float] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform4fv prog l (fromIntegral size) (castPtr p)++instance Uniform [V 4 Float] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniform4fv prog l (fromIntegral size) (castPtr p)++--------------------------------------------------------------------------------+-- Matrices --------------------------------------------------------------------+instance Uniform (M44 Float) where+  toU prog l = U $ \v -> with v $ glProgramUniformMatrix4fv prog l 1 GL_FALSE . castPtr++instance Uniform [M44 Float] where+  toU prog l = U $ \v -> withArrayLen v $ \size p ->+    glProgramUniformMatrix4fv prog l (fromIntegral size) GL_FALSE (castPtr p)  -------------------------------------------------------------------------------- -- Textures --------------------------------------------------------------------
src/Graphics/Luminance/Core/Vertex.hs view
@@ -24,7 +24,7 @@ import Data.Int ( Int32 ) import Data.Proxy ( Proxy(..) ) import Data.Word ( Word32 )-import Foreign.Storable ( Storable )+import Foreign.Storable ( Storable(sizeOf) ) import GHC.TypeLits ( KnownNat, natVal ) import Graphics.GL import Graphics.Luminance.Core.Tuple@@ -38,7 +38,7 @@ vec3 :: a -> a -> a -> V 3 a vec3 x y z = V [x,y,z] --- |Create a new @'V' 3@.+-- |Create a new @'V' 4@. vec4 :: a -> a -> a -> a -> V 4 a vec4 x y z w = V [x,y,z,w] @@ -60,18 +60,22 @@ -- you cannot add anymore instances. However, you shouldn’t need to since you can use the already -- provided types to build up your vertex type. class Vertex v where-  setFormatV :: (MonadIO m) => GLuint -> GLuint -> proxy v -> m ()+  -- @setFormatV vid index offset proxy@ sets the format of a vertex type. The returned value is the+  -- next index that can be used – and is used to chain index creation – along with the next offset+  -- to use.+  setFormatV :: (MonadIO m) => GLuint -> GLuint -> GLuint -> proxy v -> m (GLuint,GLuint)  instance (KnownNat n,Storable a,VertexAttribute a) => Vertex (V n a) where-  setFormatV vid index _ = do-    glVertexArrayAttribFormat vid index (fromIntegral $ natVal (Proxy :: Proxy n)) (vertexGLType (Proxy :: Proxy a)) GL_FALSE 0+  setFormatV vid index offset _ = do+    glVertexArrayAttribFormat vid index (fromIntegral $ natVal (Proxy :: Proxy n)) (vertexGLType (Proxy :: Proxy a)) GL_FALSE offset     glVertexArrayAttribBinding vid index vertexBindingIndex     glEnableVertexArrayAttrib vid index+    pure (succ index,offset + fromIntegral (sizeOf (undefined :: V n a)))  instance (Vertex a,Vertex b) => Vertex (a :. b) where-  setFormatV vid index _ = do-    setFormatV vid index (Proxy :: Proxy a)-    setFormatV vid index (Proxy :: Proxy b)+  setFormatV vid index offset _ = do+    (nextIndex,nextOffset) <- setFormatV vid index offset (Proxy :: Proxy a)+    setFormatV vid nextIndex nextOffset (Proxy :: Proxy b)  -- Used to connect vertex attribute to the vertex buffer binding point. Should be 0. vertexBindingIndex :: GLuint