packages feed

GLUtil 0.7.5 → 0.8

raw patch · 5 files changed

+31/−10 lines, 5 files

Files

+ CHANGELOG.md view
@@ -0,0 +1,4 @@+0.8+---++* Generalized `setUniform` to work with any instance of `AsUniform`. Specifically, this enables the use of types from the `linear` package.
GLUtil.cabal view
@@ -1,5 +1,5 @@ Name:                GLUtil-Version:             0.7.5+Version:             0.8 Synopsis:            Miscellaneous OpenGL utilities. License:             BSD3 License-file:        LICENSE@@ -18,7 +18,8 @@                     examples/images/hello1.tga,                     examples/images/hello2.tga,                     examples/shaders/hello-gl.frag,-                    examples/shaders/hello-gl.vert+                    examples/shaders/hello-gl.vert,+                    CHANGELOG.md  -- source-repository this --   type:     git
src/Graphics/GLUtil/Linear.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE FlexibleInstances, FlexibleContexts, ScopedTypeVariables #-}+{-# LANGUAGE DefaultSignatures, FlexibleInstances, FlexibleContexts,+             ScopedTypeVariables #-} {-# OPTIONS_GHC -cpp -pgmPcpphs -optP--cpp -optP--hashes #-} -- |Support for writing "Linear" types to uniform locations in -- shader programs.@@ -6,15 +7,18 @@ import Foreign.Marshal.Array (withArray) import Foreign.Marshal.Utils (with) import Foreign.Ptr (Ptr, castPtr)-import Graphics.Rendering.OpenGL (UniformLocation)+import Graphics.Rendering.OpenGL import Graphics.Rendering.OpenGL.Raw.Core31 import Linear import Unsafe.Coerce (unsafeCoerce)  -- | A type class for things we can write to uniform locations in--- shader programs.+-- shader programs. We can provide instances of this class for types+-- from "Linear" without introducing orphan instances. class AsUniform t where   asUniform :: t -> UniformLocation -> IO ()+  default asUniform :: Uniform t => t -> UniformLocation -> IO ()+  asUniform x loc = uniform loc $= x  getUL :: UniformLocation -> GLint getUL = unsafeCoerce@@ -33,6 +37,20 @@  instance AsUniform GLfloat where   x `asUniform` loc = with x $ glUniform1fv (getUL loc) 1++instance AsUniform TextureUnit where+instance UniformComponent a => AsUniform (Index1 a) where+instance UniformComponent a => AsUniform (Color4 a) where+instance UniformComponent a => AsUniform (Color3 a) where+instance UniformComponent a => AsUniform (FogCoord1 a) where+instance UniformComponent a => AsUniform (Normal3 a) where+instance UniformComponent a => AsUniform (TexCoord4 a) where+instance UniformComponent a => AsUniform (TexCoord3 a) where+instance UniformComponent a => AsUniform (TexCoord2 a) where+instance UniformComponent a => AsUniform (TexCoord1 a) where+instance UniformComponent a => AsUniform (Vertex4 a) where+instance UniformComponent a => AsUniform (Vertex3 a) where+instance UniformComponent a => AsUniform (Vertex2 a) where  #define UNIFORMVEC_T(d,ht,glt) instance AsUniform (V ## d ht) where {v `asUniform` loc = with v $ glUniform##d##glt##v (getUL loc) 1 . castVecComponent} 
src/Graphics/GLUtil/ShaderProgram.hs view
@@ -18,6 +18,7 @@ import Data.List (find, findIndex, isSuffixOf) import Data.Map.Strict (Map, fromList, lookup) import Data.Maybe (isJust, isNothing, catMaybes)+import Graphics.GLUtil.Linear (AsUniform(..)) import Graphics.GLUtil.Shaders (loadShader, linkShaderProgram,                                 linkShaderProgramWith, loadShaderBS) import Graphics.GLUtil.GLError (throwError)@@ -153,10 +154,9 @@  -- | Set a named uniform parameter associated with a particular shader -- program.-setUniform :: Uniform a => ShaderProgram -> String -> a -> IO ()+setUniform :: AsUniform a => ShaderProgram -> String -> a -> IO () setUniform sp name = maybe (const (putStrLn warn >> return ()))-                           (\(u,_) -> let u' = uniform u-                                      in \x -> u' $= x)+                           (flip asUniform . fst)                            (lookup name $ uniforms sp)   where warn = "WARNING: uniform "++name++" is not active" 
src/Graphics/GLUtil/Textures.hs view
@@ -5,8 +5,6 @@ import Control.Monad (forM_) import Graphics.Rendering.OpenGL import qualified Graphics.Rendering.OpenGL.GL.VertexArrays as GL-import Graphics.Rendering.OpenGL.Raw.Core31 (glGenerateMipmap,-                                             gl_TEXTURE_2D, gl_TEXTURE_CUBE_MAP) import Data.Array.Storable (StorableArray, withStorableArray) import Data.ByteString.Internal (ByteString, toForeignPtr) import Data.Vector.Storable (Vector, unsafeWith)