OpenGL 3.0.0.2 → 3.0.1.0
raw patch · 5 files changed
+133/−69 lines, 5 filesdep ~OpenGLRawPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: OpenGLRaw
API changes (from Hackage documentation)
- Graphics.Rendering.OpenGL.GL.CoordTrans: instance Graphics.Rendering.OpenGL.GL.CoordTrans.MatrixComponent Graphics.GL.Types.GLdouble
- Graphics.Rendering.OpenGL.GL.CoordTrans: instance Graphics.Rendering.OpenGL.GL.CoordTrans.MatrixComponent Graphics.GL.Types.GLfloat
+ Graphics.Rendering.OpenGL.GL.Shaders.Uniform: instance Graphics.Rendering.OpenGL.GL.MatrixComponent.MatrixComponent a => Graphics.Rendering.OpenGL.GL.Shaders.Uniform.Uniform (Graphics.Rendering.OpenGL.GL.CoordTrans.GLmatrix a)
+ Graphics.Rendering.OpenGL.GL.Shaders.Uniform: instance Graphics.Rendering.OpenGL.GL.Shaders.Uniform.UniformComponent a => Graphics.Rendering.OpenGL.GL.Shaders.Uniform.Uniform (Graphics.Rendering.OpenGL.GL.Tensor.Vector1 a)
+ Graphics.Rendering.OpenGL.GL.Shaders.Uniform: instance Graphics.Rendering.OpenGL.GL.Shaders.Uniform.UniformComponent a => Graphics.Rendering.OpenGL.GL.Shaders.Uniform.Uniform (Graphics.Rendering.OpenGL.GL.Tensor.Vector2 a)
+ Graphics.Rendering.OpenGL.GL.Shaders.Uniform: instance Graphics.Rendering.OpenGL.GL.Shaders.Uniform.UniformComponent a => Graphics.Rendering.OpenGL.GL.Shaders.Uniform.Uniform (Graphics.Rendering.OpenGL.GL.Tensor.Vector3 a)
+ Graphics.Rendering.OpenGL.GL.Shaders.Uniform: instance Graphics.Rendering.OpenGL.GL.Shaders.Uniform.UniformComponent a => Graphics.Rendering.OpenGL.GL.Shaders.Uniform.Uniform (Graphics.Rendering.OpenGL.GL.Tensor.Vector4 a)
+ Graphics.Rendering.OpenGL.GL.Shaders.Uniform: instance Graphics.Rendering.OpenGL.GL.Shaders.Uniform.UniformComponent a => Graphics.Rendering.OpenGL.GL.Shaders.Uniform.Uniform (Graphics.Rendering.OpenGL.GL.Tensor.Vertex1 a)
Files
- CHANGELOG.md +6/−0
- OpenGL.cabal +3/−2
- src/Graphics/Rendering/OpenGL/GL/CoordTrans.hs +1/−35
- src/Graphics/Rendering/OpenGL/GL/MatrixComponent.hs +61/−0
- src/Graphics/Rendering/OpenGL/GL/Shaders/Uniform.hs +62/−32
CHANGELOG.md view
@@ -1,3 +1,9 @@+3.0.1.0+-------+* Added `Uniform` instances for `GLmatrix`, `Vertex1`, `Vector1`, `Vector2`, `Vector3`, and `Vector4`.+* Unbreak `Uniform` instances for `GLint`, `GLuint` and `Gldouble`.+* Relaxed upper version bound for `OpenGLRaw`.+ 3.0.0.2 ------- * Removed redundant constraints.
OpenGL.cabal view
@@ -1,5 +1,5 @@ name: OpenGL-version: 3.0.0.2+version: 3.0.1.0 synopsis: A binding for the OpenGL graphics system description: A Haskell binding for the OpenGL graphics system (GL, version 4.5) and its@@ -126,6 +126,7 @@ Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferTarget Graphics.Rendering.OpenGL.GL.GLboolean Graphics.Rendering.OpenGL.GL.IOState+ Graphics.Rendering.OpenGL.GL.MatrixComponent Graphics.Rendering.OpenGL.GL.PeekPoke Graphics.Rendering.OpenGL.GL.PixelData Graphics.Rendering.OpenGL.GL.PixelFormat@@ -162,7 +163,7 @@ transformers >= 0.2 && < 0.6, ObjectName >= 1.1 && < 1.2, StateVar >= 1.1 && < 1.2,- OpenGLRaw >= 3.0 && < 3.2,+ OpenGLRaw >= 3.0 && < 3.3, GLURaw >= 2.0 && < 2.1 default-language: Haskell2010 other-extensions:
src/Graphics/Rendering/OpenGL/GL/CoordTrans.hs view
@@ -13,8 +13,6 @@ -- -------------------------------------------------------------------------------- -{-# LANGUAGE TypeSynonymInstances #-}- module Graphics.Rendering.OpenGL.GL.CoordTrans ( -- * Controlling the Viewport depthRange,@@ -43,9 +41,9 @@ import Foreign.Marshal.Utils import Foreign.Ptr import Foreign.Storable-import Graphics.Rendering.OpenGL.GL.Tensor import Graphics.Rendering.OpenGL.GL.Capability import Graphics.Rendering.OpenGL.GL.Exception+import Graphics.Rendering.OpenGL.GL.MatrixComponent import Graphics.Rendering.OpenGL.GL.PeekPoke import Graphics.Rendering.OpenGL.GL.QueryUtils import Graphics.Rendering.OpenGL.GL.Texturing.TextureUnit@@ -177,38 +175,6 @@ data MatrixOrder = ColumnMajor | RowMajor deriving ( Eq, Ord, Show )------------------------------------------------------------------------------------class Storable c => MatrixComponent c where- getMatrix :: GetPNameMatrix p => p -> Ptr c -> IO ()- loadMatrix :: Ptr c -> IO ()- loadTransposeMatrix :: Ptr c -> IO ()- multMatrix_ :: Ptr c -> IO ()- multTransposeMatrix :: Ptr c -> IO ()- rotate :: c -> Vector3 c -> IO ()- translate :: Vector3 c -> IO ()- scale :: c -> c -> c -> IO ()--instance MatrixComponent GLfloat where- getMatrix = getMatrixf- loadMatrix = glLoadMatrixf- loadTransposeMatrix = glLoadTransposeMatrixf- multMatrix_ = glMultMatrixf- multTransposeMatrix = glMultTransposeMatrixf- rotate a (Vector3 x y z) = glRotatef a x y z- translate (Vector3 x y z) = glTranslatef x y z- scale = glScalef--instance MatrixComponent GLdouble where- getMatrix = getMatrixd- loadMatrix = glLoadMatrixd- loadTransposeMatrix = glLoadTransposeMatrixd- multMatrix_ = glMultMatrixd- multTransposeMatrix = glMultTransposeMatrixd- rotate a (Vector3 x y z) = glRotated a x y z- translate (Vector3 x y z) = glTranslated x y z- scale = glScaled --------------------------------------------------------------------------------
+ src/Graphics/Rendering/OpenGL/GL/MatrixComponent.hs view
@@ -0,0 +1,61 @@+{-# LANGUAGE TypeSynonymInstances #-}+{-# OPTIONS_HADDOCK hide #-}+--------------------------------------------------------------------------------+-- |+-- Module : Graphics.Rendering.OpenGL.GL.CoordTrans+-- Copyright : (c) Sven Panne 2002-2016+-- License : BSD3+--+-- Maintainer : Sven Panne <svenpanne@gmail.com>+-- Stability : stable+-- Portability : portable+--+-- This is a purely internal module for handling matrix components.+--+--------------------------------------------------------------------------------++module Graphics.Rendering.OpenGL.GL.MatrixComponent where++import Foreign.Ptr+import Foreign.Storable+import Graphics.Rendering.OpenGL.GL.QueryUtils+import Graphics.Rendering.OpenGL.GL.Tensor+import Graphics.GL++--------------------------------------------------------------------------------++class Storable c => MatrixComponent c where+ getMatrix :: GetPNameMatrix p => p -> Ptr c -> IO ()+ loadMatrix :: Ptr c -> IO ()+ loadTransposeMatrix :: Ptr c -> IO ()+ multMatrix_ :: Ptr c -> IO ()+ multTransposeMatrix :: Ptr c -> IO ()+ getUniformv :: GLuint -> GLint -> Ptr c -> IO ()+ uniformMatrix4v :: GLint -> GLsizei -> GLboolean -> Ptr c -> IO ()+ rotate :: c -> Vector3 c -> IO ()+ translate :: Vector3 c -> IO ()+ scale :: c -> c -> c -> IO ()++instance MatrixComponent GLfloat where+ getMatrix = getMatrixf+ loadMatrix = glLoadMatrixf+ loadTransposeMatrix = glLoadTransposeMatrixf+ multMatrix_ = glMultMatrixf+ multTransposeMatrix = glMultTransposeMatrixf+ getUniformv = glGetUniformfv+ uniformMatrix4v = glUniformMatrix4fv+ rotate a (Vector3 x y z) = glRotatef a x y z+ translate (Vector3 x y z) = glTranslatef x y z+ scale = glScalef++instance MatrixComponent GLdouble where+ getMatrix = getMatrixd+ loadMatrix = glLoadMatrixd+ loadTransposeMatrix = glLoadTransposeMatrixd+ multMatrix_ = glMultMatrixd+ multTransposeMatrix = glMultTransposeMatrixd+ getUniformv = glGetUniformdv+ uniformMatrix4v = glUniformMatrix4dv+ rotate a (Vector3 x y z) = glRotated a x y z+ translate (Vector3 x y z) = glTranslated x y z+ scale = glScaled
src/Graphics/Rendering/OpenGL/GL/Shaders/Uniform.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE TypeSynonymInstances #-} ----------------------------------------------------------------------------- -- | -- Module : Graphics.Rendering.OpenGL.GL.Shaders.Uniform@@ -13,8 +14,6 @@ -- ----------------------------------------------------------------------------- -{-# LANGUAGE TypeSynonymInstances #-}- module Graphics.Rendering.OpenGL.GL.Shaders.Uniform ( -- * Uniform variables UniformLocation(..), uniformLocation, activeUniforms, Uniform(..),@@ -29,6 +28,9 @@ import Foreign.Ptr import Foreign.Storable import Graphics.Rendering.OpenGL.GL.ByteString+import Graphics.Rendering.OpenGL.GL.CoordTrans+import Graphics.Rendering.OpenGL.GL.GLboolean+import Graphics.Rendering.OpenGL.GL.MatrixComponent import Graphics.Rendering.OpenGL.GL.Shaders.Program import Graphics.Rendering.OpenGL.GL.Shaders.ProgramObjects import Graphics.Rendering.OpenGL.GL.Shaders.Variables@@ -74,7 +76,7 @@ uniform3 :: UniformLocation -> a -> a -> a -> IO () uniform4 :: UniformLocation -> a -> a -> a -> a -> IO () - getUniform :: Storable (b a) => Program -> UniformLocation -> Ptr (b a) -> IO ()+ getUniform :: Storable (b a) => GLuint -> GLint -> Ptr (b a) -> IO () uniform1v :: UniformLocation -> GLsizei -> Ptr a -> IO () uniform2v :: UniformLocation -> GLsizei -> Ptr a -> IO ()@@ -87,7 +89,7 @@ uniform3 (UniformLocation ul) = glUniform3i ul uniform4 (UniformLocation ul) = glUniform4i ul - getUniform (Program p) (UniformLocation ul) = glGetUniformiv p ul . castPtr+ getUniform p ul = glGetUniformiv p ul . castPtr uniform1v (UniformLocation ul) = glUniform1iv ul uniform2v (UniformLocation ul) = glUniform2iv ul@@ -100,7 +102,7 @@ uniform3 (UniformLocation ul) = glUniform3ui ul uniform4 (UniformLocation ul) = glUniform4ui ul - getUniform (Program p) (UniformLocation ul) = glGetUniformuiv p ul . castPtr+ getUniform p ul = glGetUniformuiv p ul . castPtr uniform1v (UniformLocation ul) = glUniform1uiv ul uniform2v (UniformLocation ul) = glUniform2uiv ul@@ -113,7 +115,7 @@ uniform3 (UniformLocation ul) = glUniform3f ul uniform4 (UniformLocation ul) = glUniform4f ul - getUniform (Program p) (UniformLocation ul) = glGetUniformfv p ul . castPtr+ getUniform p ul = glGetUniformfv p ul . castPtr uniform1v (UniformLocation ul) = glUniform1fv ul uniform2v (UniformLocation ul) = glUniform2fv ul@@ -126,7 +128,7 @@ uniform3 (UniformLocation ul) = glUniform3d ul uniform4 (UniformLocation ul) = glUniform4d ul - getUniform (Program p) (UniformLocation ul) = glGetUniformdv p ul . castPtr+ getUniform p ul = glGetUniformdv p ul . castPtr uniform1v (UniformLocation ul) = glUniform1dv ul uniform2v (UniformLocation ul) = glUniform2dv ul@@ -152,38 +154,35 @@ => (UniformLocation -> b a -> IO ()) -> UniformLocation -> StateVar (b a) makeUniformVar setter location = makeStateVar getter (setter location)- where getter = do program <- fmap fromJust $ get currentProgram- allocaBytes maxUniformBufferSize $ \buf -> do- getUniform program location buf- peek buf--getSimpleUniform :: Program -> UniformLocation -> Ptr a -> IO ()-getSimpleUniform (Program p) (UniformLocation ul) = glGetUniformfv p ul . castPtr+ where getter = allocaBytes maxUniformBufferSize $ \buf -> do+ getUniformWith getUniform location buf+ peek buf -makeSimpleUniformVar :: (UniformComponent a)- => UniformLocation -> StateVar a-makeSimpleUniformVar location = makeStateVar getter (uniform1 location)- where getter = do program <- fmap fromJust $ get currentProgram- allocaBytes maxUniformBufferSize $ \buf -> do- getSimpleUniform program location buf- peek buf+single :: (UniformLocation -> StateVar (Vertex1 a))+ -> (UniformLocation -> StateVar a)+single var location = makeStateVar (do Vertex1 x <- get (var location); return x)+ (\x -> var location $= Vertex1 x) instance Uniform GLfloat where- uniform = makeSimpleUniformVar+ uniform = single uniform uniformv = uniform1v instance Uniform GLint where- uniform = makeSimpleUniformVar+ uniform = single uniform uniformv = uniform1v instance Uniform GLuint where- uniform = makeSimpleUniformVar+ uniform = single uniform uniformv = uniform1v instance Uniform GLdouble where- uniform = makeSimpleUniformVar+ uniform = single uniform uniformv = uniform1v +instance UniformComponent a => Uniform (Vertex1 a) where+ uniform = makeUniformVar $ \location (Vertex1 x) -> uniform1 location x+ uniformv location count = uniform1v location count . (castPtr :: Ptr (Vertex1 b) -> Ptr b)+ instance UniformComponent a => Uniform (Vertex2 a) where uniform = makeUniformVar $ \location (Vertex2 x y) -> uniform2 location x y uniformv location count = uniform2v location count . (castPtr :: Ptr (Vertex2 b) -> Ptr b)@@ -196,6 +195,22 @@ uniform = makeUniformVar $ \location (Vertex4 x y z w) -> uniform4 location x y z w uniformv location count = uniform4v location count . (castPtr :: Ptr (Vertex4 b) -> Ptr b) +instance UniformComponent a => Uniform (Vector1 a) where+ uniform = makeUniformVar $ \location (Vector1 x) -> uniform1 location x+ uniformv location count = uniform1v location count . (castPtr :: Ptr (Vector1 b) -> Ptr b)++instance UniformComponent a => Uniform (Vector2 a) where+ uniform = makeUniformVar $ \location (Vector2 x y) -> uniform2 location x y+ uniformv location count = uniform2v location count . (castPtr :: Ptr (Vector2 b) -> Ptr b)++instance UniformComponent a => Uniform (Vector3 a) where+ uniform = makeUniformVar $ \location (Vector3 x y z) -> uniform3 location x y z+ uniformv location count = uniform3v location count . (castPtr :: Ptr (Vector3 b) -> Ptr b)++instance UniformComponent a => Uniform (Vector4 a) where+ uniform = makeUniformVar $ \location (Vector4 x y z w) -> uniform4 location x y z w+ uniformv location count = uniform4v location count . (castPtr :: Ptr (Vector4 b) -> Ptr b)+ instance UniformComponent a => Uniform (TexCoord1 a) where uniform = makeUniformVar $ \location (TexCoord1 s) -> uniform1 location s uniformv location count = uniform1v location count . (castPtr :: Ptr (TexCoord1 b) -> Ptr b)@@ -236,13 +251,28 @@ -- getUniform. Even worse is that it requires the `GLint` uniforms while it is an enum or -- uint. instance Uniform TextureUnit where- uniform loc@(UniformLocation ul) = makeStateVar getter setter- where setter (TextureUnit tu) = uniform1 loc (fromIntegral tu :: GLint)- getter = do program <- fmap fromJust $ get currentProgram- allocaBytes (sizeOf (undefined :: GLint)) $ \buf -> do- glGetUniformiv (programID program) ul buf- tuID <- peek buf- return . TextureUnit $ fromIntegral tuID+ uniform loc = makeStateVar getter setter+ where getter = allocaBytes (sizeOf (undefined :: GLint)) $ \buf -> do+ getUniformWith glGetUniformiv loc buf+ fmap (TextureUnit . fromIntegral) $ peek buf+ setter (TextureUnit tu) = uniform1 loc (fromIntegral tu :: GLint) uniformv location count = uniform1v location count . (castPtr :: Ptr TextureUnit -> Ptr GLint)++-- | Note: 'uniformv' expects all matrices to be in 'ColumnMajor' form.+instance MatrixComponent a => Uniform (GLmatrix a) where+ uniform loc@(UniformLocation ul) = makeStateVar getter setter+ where getter = withNewMatrix ColumnMajor $ getUniformWith getUniformv loc+ setter m = withMatrix m $ uniformMatrix4v ul 1 . isRowMajor+ uniformv (UniformLocation ul) count buf =+ uniformMatrix4v ul count (marshalGLboolean False) (castPtr buf `asTypeOf` elemType buf)+ where elemType = undefined :: MatrixComponent c => Ptr (GLmatrix c) -> Ptr c++isRowMajor :: MatrixOrder -> GLboolean+isRowMajor = marshalGLboolean . (RowMajor ==)++getUniformWith :: (GLuint -> GLint -> Ptr a -> IO ()) -> UniformLocation -> Ptr a -> IO ()+getUniformWith getter (UniformLocation ul) buf = do+ program <- fmap (programID . fromJust) $ get currentProgram+ getter program ul buf --------------------------------------------------------------------------------