GLUtil 0.6.1.1 → 0.6.1.2
raw patch · 7 files changed
+36/−10 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- GLUtil.cabal +6/−6
- src/Graphics/GLUtil/JuicyTextures.hs +8/−1
- src/Graphics/GLUtil/Linear.hs +0/−1
- src/Graphics/GLUtil/ShaderProgram.hs +14/−1
- src/Graphics/GLUtil/TypeMapping.hs +3/−0
- src/Graphics/GLUtil/VertexArrayObjects.hs +0/−1
- src/Graphics/GLUtil/Viewport.hs +5/−0
GLUtil.cabal view
@@ -1,5 +1,5 @@ Name: GLUtil-Version: 0.6.1.1+Version: 0.6.1.2 Synopsis: Miscellaneous OpenGL utilities. License: BSD3 License-file: LICENSE@@ -20,6 +20,11 @@ examples/shaders/hello-gl.frag, examples/shaders/hello-gl.vert +source-repository this+ type: git+ tag: 0.6.1.2+ location: http://github.com/acowley/GLUtil.git+ Library Exposed-modules: Graphics.GLUtil, Graphics.GLUtil.GLError,@@ -45,8 +50,3 @@ Build-tools: cpphs GHC-Options: -Odph -Wall HS-Source-Dirs: src- -source-repository this- type: git- tag: 0.6.1- location: http://github.com/acowley/GLUtil.git
src/Graphics/GLUtil/JuicyTextures.hs view
@@ -1,10 +1,15 @@ {-# LANGUAGE RankNTypes #-}+-- | Uses the @JuicyPixels@ package to load images that are then used+-- to create OpenGL textuers. module Graphics.GLUtil.JuicyTextures where import Codec.Picture (readImage, DynamicImage(..), Image(..)) import Control.Applicative ((<$>)) import Graphics.GLUtil.Textures import Graphics.Rendering.OpenGL (TextureObject) +-- | Load a 'TexInfo' value from an image file, and supply it to a+-- user-provided function. Supported image formats include @png@,+-- @jpeg@, @bmp@, and @gif@. See 'readTexture' for most uses. readTexInfo :: FilePath -> (forall a. IsPixelData a => TexInfo a -> IO b) -> IO (Either String b)@@ -15,7 +20,9 @@ aux (ImageRGB8 (Image w h p)) = Right <$> k (texInfo w h TexRGB p) aux (ImageRGBF (Image w h p)) = Right <$> k (texInfo w h TexRGB p) aux (ImageRGBA8 (Image w h p)) = Right <$> k (texInfo w h TexRGBA p)- aux (ImageYCbCr8 _) = return $ Left "YCbCr format not supported"+ aux _ = return $ Left "Unsupported image format" +-- | Load a 'TextureObject' from an image file. Supported formats+-- include @png@, @jpeg@, @bmp@, and @gif@. readTexture :: FilePath -> IO (Either String TextureObject) readTexture f = readTexInfo f loadTexture
src/Graphics/GLUtil/Linear.hs view
@@ -6,7 +6,6 @@ import Foreign.Marshal.Array (withArray) import Foreign.Marshal.Utils (with) import Foreign.Ptr (Ptr, castPtr)-import Foreign.Storable (Storable) import Graphics.Rendering.OpenGL (UniformLocation) import Graphics.Rendering.OpenGL.Raw.Core31 import Linear
src/Graphics/GLUtil/ShaderProgram.hs view
@@ -86,8 +86,10 @@ throwError (attrs,unis) <- getActives p return $ ShaderProgram (fromList attrs) (fromList unis) p- +-- | Get all attributes and uniforms used by a program. Note that+-- unused parameters may be elided by the compiler, and so will not be+-- considered as active. getActives :: Program -> IO ( [(String, (AttribLocation, VariableType))] , [(String, (UniformLocation, VariableType))] )@@ -96,6 +98,8 @@ <*> (get (activeUniforms p) >>= mapM (aux (uniformLocation p))) where aux f (_,t,name) = get (f name) >>= \l -> return (name, (l, t)) +-- | Get the attribute and uniform locations associated with a list of+-- the names of each. getExplicits :: Program -> ([String], [String]) -> IO ( [(String, (AttribLocation, VariableType))] , [(String, (UniformLocation, VariableType))] )@@ -113,6 +117,8 @@ | otherwise = let Just i = findIndex isNothing xs in error $ "Missing GLSL variable: " ++ anames !! i +-- | Set a named uniform parameter associated with a particular shader+-- program. setUniform :: Uniform a => ShaderProgram -> String -> a -> IO () setUniform sp name = maybe (const (putStrLn warn >> return ())) (\(u,_) -> let u' = uniform u@@ -120,10 +126,14 @@ (lookup name $ uniforms sp) where warn = "WARNING: uniform "++name++" is not active" +-- | Get the 'UniformLocation' associated with a named uniform+-- parameter. getUniform :: ShaderProgram -> String -> UniformLocation getUniform sp n = maybe (error msg) fst . lookup n $ uniforms sp where msg = "Uniform "++show n++" is not active" +-- | Set a named vertex attribute's 'IntegerHandling' and+-- 'VertexArrayDescriptor'. setAttrib :: ShaderProgram -> String -> IntegerHandling -> VertexArrayDescriptor a -> IO () setAttrib sp name = maybe (\_ _ -> putStrLn warn >> return ())@@ -132,10 +142,13 @@ (lookup name $ attribs sp) where warn = "WARNING: attrib "++name++" is not active" +-- | Get the 'AttribLocation' associated with a named vertex+-- attribute. getAttrib :: ShaderProgram -> String -> AttribLocation getAttrib sp n = maybe (error msg) fst . lookup n $ attribs sp where msg = "Attrib "++show n++" is not active" +-- | Enable a named vertex attribute. enableAttrib :: ShaderProgram -> String -> IO () enableAttrib sp name = maybe (return ()) (($= Enabled) . vertexAttribArray . fst)
src/Graphics/GLUtil/TypeMapping.hs view
@@ -11,6 +11,9 @@ import Graphics.Rendering.OpenGL import Linear (V2, V3, V4, M22, M33, M44) +-- | A mapping from Haskell types to values of 'VariableType'. This+-- defines how Haskell values may be mapped to values that may be+-- bound to GLSL variables. class HasVariableType a where variableType :: a -> VariableType
src/Graphics/GLUtil/VertexArrayObjects.hs view
@@ -1,6 +1,5 @@ -- | A thin layer over OpenGL 3.1+ vertex array objects. module Graphics.GLUtil.VertexArrayObjects (makeVAO, withVAO, VAO) where-import Control.Applicative import Graphics.Rendering.OpenGL -- |Short alias for 'VertexArrayObject'.
src/Graphics/GLUtil/Viewport.hs view
@@ -1,6 +1,11 @@+-- | Helpers for working with OpenGL viewports. module Graphics.GLUtil.Viewport where import Graphics.Rendering.OpenGL +-- | @withViewport pos sz m@ runs the action @m@ after setting the+-- viewport with the given 'Position' and 'Size'. The viewport is+-- reset to its original state after the action is run, and the result+-- of the action is returned. withViewport :: Position -> Size -> IO a -> IO a withViewport p s m = do oldVP <- get viewport viewport $= (p,s)