{-# LANGUAGE TypeSynonymInstances #-}
module Graphics.Rendering.OpenGL.GL.Shaders.Uniform (
UniformLocation(..), uniformLocation, activeUniforms, Uniform(..),
UniformComponent,
) where
import Data.Maybe
import Data.StateVar
import Foreign.Marshal.Alloc
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
import Graphics.Rendering.OpenGL.GL.Tensor
import Graphics.Rendering.OpenGL.GL.VertexSpec
import Graphics.GL
numActiveUniforms :: Program -> GettableStateVar GLuint
numActiveUniforms :: Program -> GettableStateVar GLuint
numActiveUniforms = forall a.
(GLint -> a) -> GetProgramPName -> Program -> GettableStateVar a
programVar1 forall a b. (Integral a, Num b) => a -> b
fromIntegral GetProgramPName
ActiveUniforms
activeUniformMaxLength :: Program -> GettableStateVar GLsizei
activeUniformMaxLength :: Program -> GettableStateVar GLint
activeUniformMaxLength = forall a.
(GLint -> a) -> GetProgramPName -> Program -> GettableStateVar a
programVar1 forall a b. (Integral a, Num b) => a -> b
fromIntegral GetProgramPName
ActiveUniformMaxLength
newtype UniformLocation = UniformLocation GLint
deriving ( UniformLocation -> UniformLocation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UniformLocation -> UniformLocation -> Bool
$c/= :: UniformLocation -> UniformLocation -> Bool
== :: UniformLocation -> UniformLocation -> Bool
$c== :: UniformLocation -> UniformLocation -> Bool
Eq, Eq UniformLocation
UniformLocation -> UniformLocation -> Bool
UniformLocation -> UniformLocation -> Ordering
UniformLocation -> UniformLocation -> UniformLocation
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: UniformLocation -> UniformLocation -> UniformLocation
$cmin :: UniformLocation -> UniformLocation -> UniformLocation
max :: UniformLocation -> UniformLocation -> UniformLocation
$cmax :: UniformLocation -> UniformLocation -> UniformLocation
>= :: UniformLocation -> UniformLocation -> Bool
$c>= :: UniformLocation -> UniformLocation -> Bool
> :: UniformLocation -> UniformLocation -> Bool
$c> :: UniformLocation -> UniformLocation -> Bool
<= :: UniformLocation -> UniformLocation -> Bool
$c<= :: UniformLocation -> UniformLocation -> Bool
< :: UniformLocation -> UniformLocation -> Bool
$c< :: UniformLocation -> UniformLocation -> Bool
compare :: UniformLocation -> UniformLocation -> Ordering
$ccompare :: UniformLocation -> UniformLocation -> Ordering
Ord, Int -> UniformLocation -> ShowS
[UniformLocation] -> ShowS
UniformLocation -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UniformLocation] -> ShowS
$cshowList :: [UniformLocation] -> ShowS
show :: UniformLocation -> String
$cshow :: UniformLocation -> String
showsPrec :: Int -> UniformLocation -> ShowS
$cshowsPrec :: Int -> UniformLocation -> ShowS
Show )
uniformLocation :: Program -> String -> GettableStateVar UniformLocation
uniformLocation :: Program -> String -> GettableStateVar UniformLocation
uniformLocation (Program GLuint
program) String
name =
forall a. IO a -> IO a
makeGettableStateVar forall a b. (a -> b) -> a -> b
$
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GLint -> UniformLocation
UniformLocation forall a b. (a -> b) -> a -> b
$
forall a. String -> (Ptr GLchar -> IO a) -> IO a
withGLstring String
name forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). MonadIO m => GLuint -> Ptr GLchar -> m GLint
glGetUniformLocation GLuint
program
activeUniforms :: Program -> GettableStateVar [(GLint,VariableType,String)]
activeUniforms :: Program -> GettableStateVar [(GLint, VariableType, String)]
activeUniforms =
forall a.
(Program -> GettableStateVar GLuint)
-> (Program -> GettableStateVar GLint)
-> (GLuint
-> GLuint
-> GLint
-> Ptr GLint
-> Ptr GLint
-> Ptr GLuint
-> Ptr GLchar
-> IO ())
-> (GLuint -> a)
-> Program
-> GettableStateVar [(GLint, a, String)]
activeVars
Program -> GettableStateVar GLuint
numActiveUniforms
Program -> GettableStateVar GLint
activeUniformMaxLength
forall (m :: * -> *).
MonadIO m =>
GLuint
-> GLuint
-> GLint
-> Ptr GLint
-> Ptr GLint
-> Ptr GLuint
-> Ptr GLchar
-> m ()
glGetActiveUniform
GLuint -> VariableType
unmarshalVariableType
class Storable a => UniformComponent a where
uniform1 :: UniformLocation -> a -> IO ()
uniform2 :: UniformLocation -> a -> a -> IO ()
uniform3 :: UniformLocation -> a -> a -> a -> IO ()
uniform4 :: UniformLocation -> a -> a -> a -> a -> IO ()
getUniform :: Storable (b a) => GLuint -> GLint -> Ptr (b a) -> IO ()
uniform1v :: UniformLocation -> GLsizei -> Ptr a -> IO ()
uniform2v :: UniformLocation -> GLsizei -> Ptr a -> IO ()
uniform3v :: UniformLocation -> GLsizei -> Ptr a -> IO ()
uniform4v :: UniformLocation -> GLsizei -> Ptr a -> IO ()
instance UniformComponent GLint where
uniform1 :: UniformLocation -> GLint -> IO ()
uniform1 (UniformLocation GLint
ul) = forall (m :: * -> *). MonadIO m => GLint -> GLint -> m ()
glUniform1i GLint
ul
uniform2 :: UniformLocation -> GLint -> GLint -> IO ()
uniform2 (UniformLocation GLint
ul) = forall (m :: * -> *). MonadIO m => GLint -> GLint -> GLint -> m ()
glUniform2i GLint
ul
uniform3 :: UniformLocation -> GLint -> GLint -> GLint -> IO ()
uniform3 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> GLint -> GLint -> m ()
glUniform3i GLint
ul
uniform4 :: UniformLocation -> GLint -> GLint -> GLint -> GLint -> IO ()
uniform4 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> GLint -> GLint -> GLint -> m ()
glUniform4i GLint
ul
getUniform :: forall (b :: * -> *).
Storable (b GLint) =>
GLuint -> GLint -> Ptr (b GLint) -> IO ()
getUniform GLuint
p GLint
ul = forall (m :: * -> *).
MonadIO m =>
GLuint -> GLint -> Ptr GLint -> m ()
glGetUniformiv GLuint
p GLint
ul forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Ptr a -> Ptr b
castPtr
uniform1v :: UniformLocation -> GLint -> Ptr GLint -> IO ()
uniform1v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLint -> m ()
glUniform1iv GLint
ul
uniform2v :: UniformLocation -> GLint -> Ptr GLint -> IO ()
uniform2v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLint -> m ()
glUniform2iv GLint
ul
uniform3v :: UniformLocation -> GLint -> Ptr GLint -> IO ()
uniform3v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLint -> m ()
glUniform3iv GLint
ul
uniform4v :: UniformLocation -> GLint -> Ptr GLint -> IO ()
uniform4v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLint -> m ()
glUniform4iv GLint
ul
instance UniformComponent GLuint where
uniform1 :: UniformLocation -> GLuint -> IO ()
uniform1 (UniformLocation GLint
ul) = forall (m :: * -> *). MonadIO m => GLint -> GLuint -> m ()
glUniform1ui GLint
ul
uniform2 :: UniformLocation -> GLuint -> GLuint -> IO ()
uniform2 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLuint -> GLuint -> m ()
glUniform2ui GLint
ul
uniform3 :: UniformLocation -> GLuint -> GLuint -> GLuint -> IO ()
uniform3 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLuint -> GLuint -> GLuint -> m ()
glUniform3ui GLint
ul
uniform4 :: UniformLocation -> GLuint -> GLuint -> GLuint -> GLuint -> IO ()
uniform4 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLuint -> GLuint -> GLuint -> GLuint -> m ()
glUniform4ui GLint
ul
getUniform :: forall (b :: * -> *).
Storable (b GLuint) =>
GLuint -> GLint -> Ptr (b GLuint) -> IO ()
getUniform GLuint
p GLint
ul = forall (m :: * -> *).
MonadIO m =>
GLuint -> GLint -> Ptr GLuint -> m ()
glGetUniformuiv GLuint
p GLint
ul forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Ptr a -> Ptr b
castPtr
uniform1v :: UniformLocation -> GLint -> Ptr GLuint -> IO ()
uniform1v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLuint -> m ()
glUniform1uiv GLint
ul
uniform2v :: UniformLocation -> GLint -> Ptr GLuint -> IO ()
uniform2v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLuint -> m ()
glUniform2uiv GLint
ul
uniform3v :: UniformLocation -> GLint -> Ptr GLuint -> IO ()
uniform3v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLuint -> m ()
glUniform3uiv GLint
ul
uniform4v :: UniformLocation -> GLint -> Ptr GLuint -> IO ()
uniform4v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLuint -> m ()
glUniform4uiv GLint
ul
instance UniformComponent GLfloat where
uniform1 :: UniformLocation -> GLfloat -> IO ()
uniform1 (UniformLocation GLint
ul) = forall (m :: * -> *). MonadIO m => GLint -> GLfloat -> m ()
glUniform1f GLint
ul
uniform2 :: UniformLocation -> GLfloat -> GLfloat -> IO ()
uniform2 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLfloat -> GLfloat -> m ()
glUniform2f GLint
ul
uniform3 :: UniformLocation -> GLfloat -> GLfloat -> GLfloat -> IO ()
uniform3 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLfloat -> GLfloat -> GLfloat -> m ()
glUniform3f GLint
ul
uniform4 :: UniformLocation
-> GLfloat -> GLfloat -> GLfloat -> GLfloat -> IO ()
uniform4 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLfloat -> GLfloat -> GLfloat -> GLfloat -> m ()
glUniform4f GLint
ul
getUniform :: forall (b :: * -> *).
Storable (b GLfloat) =>
GLuint -> GLint -> Ptr (b GLfloat) -> IO ()
getUniform GLuint
p GLint
ul = forall (m :: * -> *).
MonadIO m =>
GLuint -> GLint -> Ptr GLfloat -> m ()
glGetUniformfv GLuint
p GLint
ul forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Ptr a -> Ptr b
castPtr
uniform1v :: UniformLocation -> GLint -> Ptr GLfloat -> IO ()
uniform1v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLfloat -> m ()
glUniform1fv GLint
ul
uniform2v :: UniformLocation -> GLint -> Ptr GLfloat -> IO ()
uniform2v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLfloat -> m ()
glUniform2fv GLint
ul
uniform3v :: UniformLocation -> GLint -> Ptr GLfloat -> IO ()
uniform3v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLfloat -> m ()
glUniform3fv GLint
ul
uniform4v :: UniformLocation -> GLint -> Ptr GLfloat -> IO ()
uniform4v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLfloat -> m ()
glUniform4fv GLint
ul
instance UniformComponent GLdouble where
uniform1 :: UniformLocation -> GLdouble -> IO ()
uniform1 (UniformLocation GLint
ul) = forall (m :: * -> *). MonadIO m => GLint -> GLdouble -> m ()
glUniform1d GLint
ul
uniform2 :: UniformLocation -> GLdouble -> GLdouble -> IO ()
uniform2 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLdouble -> GLdouble -> m ()
glUniform2d GLint
ul
uniform3 :: UniformLocation -> GLdouble -> GLdouble -> GLdouble -> IO ()
uniform3 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLdouble -> GLdouble -> GLdouble -> m ()
glUniform3d GLint
ul
uniform4 :: UniformLocation
-> GLdouble -> GLdouble -> GLdouble -> GLdouble -> IO ()
uniform4 (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> m ()
glUniform4d GLint
ul
getUniform :: forall (b :: * -> *).
Storable (b GLdouble) =>
GLuint -> GLint -> Ptr (b GLdouble) -> IO ()
getUniform GLuint
p GLint
ul = forall (m :: * -> *).
MonadIO m =>
GLuint -> GLint -> Ptr GLdouble -> m ()
glGetUniformdv GLuint
p GLint
ul forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. Ptr a -> Ptr b
castPtr
uniform1v :: UniformLocation -> GLint -> Ptr GLdouble -> IO ()
uniform1v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLdouble -> m ()
glUniform1dv GLint
ul
uniform2v :: UniformLocation -> GLint -> Ptr GLdouble -> IO ()
uniform2v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLdouble -> m ()
glUniform2dv GLint
ul
uniform3v :: UniformLocation -> GLint -> Ptr GLdouble -> IO ()
uniform3v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLdouble -> m ()
glUniform3dv GLint
ul
uniform4v :: UniformLocation -> GLint -> Ptr GLdouble -> IO ()
uniform4v (UniformLocation GLint
ul) = forall (m :: * -> *).
MonadIO m =>
GLint -> GLint -> Ptr GLdouble -> m ()
glUniform4dv GLint
ul
class Uniform a where
uniform :: UniformLocation -> StateVar a
uniformv :: UniformLocation -> GLsizei -> Ptr a -> IO ()
maxComponentSize :: Int
maxComponentSize :: Int
maxComponentSize = forall a. Storable a => a -> Int
sizeOf (forall a. HasCallStack => a
undefined :: GLint) forall a. Ord a => a -> a -> a
`max` forall a. Storable a => a -> Int
sizeOf (forall a. HasCallStack => a
undefined :: GLfloat)
maxNumComponents :: Int
maxNumComponents :: Int
maxNumComponents = Int
16
maxUniformBufferSize :: Int
maxUniformBufferSize :: Int
maxUniformBufferSize = Int
maxComponentSize forall a. Num a => a -> a -> a
* Int
maxNumComponents
makeUniformVar :: (UniformComponent a, Storable (b a))
=> (UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar :: forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar UniformLocation -> b a -> IO ()
setter UniformLocation
location = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (b a)
getter (UniformLocation -> b a -> IO ()
setter UniformLocation
location)
where getter :: IO (b a)
getter = forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes Int
maxUniformBufferSize forall a b. (a -> b) -> a -> b
$ \Ptr (b a)
buf -> do
forall a.
(GLuint -> GLint -> Ptr a -> IO ())
-> UniformLocation -> Ptr a -> IO ()
getUniformWith forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
GLuint -> GLint -> Ptr (b a) -> IO ()
getUniform UniformLocation
location Ptr (b a)
buf
forall a. Storable a => Ptr a -> IO a
peek Ptr (b a)
buf
single :: (UniformLocation -> StateVar (Vertex1 a))
-> (UniformLocation -> StateVar a)
single :: forall a.
(UniformLocation -> StateVar (Vertex1 a))
-> UniformLocation -> StateVar a
single UniformLocation -> StateVar (Vertex1 a)
var UniformLocation
location = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar (do Vertex1 a
x <- forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get (UniformLocation -> StateVar (Vertex1 a)
var UniformLocation
location); forall (m :: * -> *) a. Monad m => a -> m a
return a
x)
(\a
x -> UniformLocation -> StateVar (Vertex1 a)
var UniformLocation
location forall t a (m :: * -> *).
(HasSetter t a, MonadIO m) =>
t -> a -> m ()
$= forall a. a -> Vertex1 a
Vertex1 a
x)
instance Uniform GLfloat where
uniform :: UniformLocation -> StateVar GLfloat
uniform = forall a.
(UniformLocation -> StateVar (Vertex1 a))
-> UniformLocation -> StateVar a
single forall a. Uniform a => UniformLocation -> StateVar a
uniform
uniformv :: UniformLocation -> GLint -> Ptr GLfloat -> IO ()
uniformv = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform1v
instance Uniform GLint where
uniform :: UniformLocation -> StateVar GLint
uniform = forall a.
(UniformLocation -> StateVar (Vertex1 a))
-> UniformLocation -> StateVar a
single forall a. Uniform a => UniformLocation -> StateVar a
uniform
uniformv :: UniformLocation -> GLint -> Ptr GLint -> IO ()
uniformv = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform1v
instance Uniform GLuint where
uniform :: UniformLocation -> StateVar GLuint
uniform = forall a.
(UniformLocation -> StateVar (Vertex1 a))
-> UniformLocation -> StateVar a
single forall a. Uniform a => UniformLocation -> StateVar a
uniform
uniformv :: UniformLocation -> GLint -> Ptr GLuint -> IO ()
uniformv = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform1v
instance Uniform GLdouble where
uniform :: UniformLocation -> StateVar GLdouble
uniform = forall a.
(UniformLocation -> StateVar (Vertex1 a))
-> UniformLocation -> StateVar a
single forall a. Uniform a => UniformLocation -> StateVar a
uniform
uniformv :: UniformLocation -> GLint -> Ptr GLdouble -> IO ()
uniformv = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform1v
instance UniformComponent a => Uniform (Vertex1 a) where
uniform :: UniformLocation -> StateVar (Vertex1 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Vertex1 a
x) -> forall a. UniformComponent a => UniformLocation -> a -> IO ()
uniform1 UniformLocation
location a
x
uniformv :: UniformLocation -> GLint -> Ptr (Vertex1 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform1v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Vertex1 b) -> Ptr b)
instance UniformComponent a => Uniform (Vertex2 a) where
uniform :: UniformLocation -> StateVar (Vertex2 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Vertex2 a
x a
y) -> forall a. UniformComponent a => UniformLocation -> a -> a -> IO ()
uniform2 UniformLocation
location a
x a
y
uniformv :: UniformLocation -> GLint -> Ptr (Vertex2 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform2v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Vertex2 b) -> Ptr b)
instance UniformComponent a => Uniform (Vertex3 a) where
uniform :: UniformLocation -> StateVar (Vertex3 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Vertex3 a
x a
y a
z) -> forall a.
UniformComponent a =>
UniformLocation -> a -> a -> a -> IO ()
uniform3 UniformLocation
location a
x a
y a
z
uniformv :: UniformLocation -> GLint -> Ptr (Vertex3 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform3v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Vertex3 b) -> Ptr b)
instance UniformComponent a => Uniform (Vertex4 a) where
uniform :: UniformLocation -> StateVar (Vertex4 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Vertex4 a
x a
y a
z a
w) -> forall a.
UniformComponent a =>
UniformLocation -> a -> a -> a -> a -> IO ()
uniform4 UniformLocation
location a
x a
y a
z a
w
uniformv :: UniformLocation -> GLint -> Ptr (Vertex4 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform4v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Vertex4 b) -> Ptr b)
instance UniformComponent a => Uniform (Vector1 a) where
uniform :: UniformLocation -> StateVar (Vector1 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Vector1 a
x) -> forall a. UniformComponent a => UniformLocation -> a -> IO ()
uniform1 UniformLocation
location a
x
uniformv :: UniformLocation -> GLint -> Ptr (Vector1 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform1v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Vector1 b) -> Ptr b)
instance UniformComponent a => Uniform (Vector2 a) where
uniform :: UniformLocation -> StateVar (Vector2 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Vector2 a
x a
y) -> forall a. UniformComponent a => UniformLocation -> a -> a -> IO ()
uniform2 UniformLocation
location a
x a
y
uniformv :: UniformLocation -> GLint -> Ptr (Vector2 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform2v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Vector2 b) -> Ptr b)
instance UniformComponent a => Uniform (Vector3 a) where
uniform :: UniformLocation -> StateVar (Vector3 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Vector3 a
x a
y a
z) -> forall a.
UniformComponent a =>
UniformLocation -> a -> a -> a -> IO ()
uniform3 UniformLocation
location a
x a
y a
z
uniformv :: UniformLocation -> GLint -> Ptr (Vector3 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform3v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Vector3 b) -> Ptr b)
instance UniformComponent a => Uniform (Vector4 a) where
uniform :: UniformLocation -> StateVar (Vector4 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Vector4 a
x a
y a
z a
w) -> forall a.
UniformComponent a =>
UniformLocation -> a -> a -> a -> a -> IO ()
uniform4 UniformLocation
location a
x a
y a
z a
w
uniformv :: UniformLocation -> GLint -> Ptr (Vector4 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform4v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Vector4 b) -> Ptr b)
instance UniformComponent a => Uniform (TexCoord1 a) where
uniform :: UniformLocation -> StateVar (TexCoord1 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (TexCoord1 a
s) -> forall a. UniformComponent a => UniformLocation -> a -> IO ()
uniform1 UniformLocation
location a
s
uniformv :: UniformLocation -> GLint -> Ptr (TexCoord1 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform1v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (TexCoord1 b) -> Ptr b)
instance UniformComponent a => Uniform (TexCoord2 a) where
uniform :: UniformLocation -> StateVar (TexCoord2 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (TexCoord2 a
s a
t) -> forall a. UniformComponent a => UniformLocation -> a -> a -> IO ()
uniform2 UniformLocation
location a
s a
t
uniformv :: UniformLocation -> GLint -> Ptr (TexCoord2 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform2v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (TexCoord2 b) -> Ptr b)
instance UniformComponent a => Uniform (TexCoord3 a) where
uniform :: UniformLocation -> StateVar (TexCoord3 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (TexCoord3 a
s a
t a
r) -> forall a.
UniformComponent a =>
UniformLocation -> a -> a -> a -> IO ()
uniform3 UniformLocation
location a
s a
t a
r
uniformv :: UniformLocation -> GLint -> Ptr (TexCoord3 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform3v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (TexCoord3 b) -> Ptr b)
instance UniformComponent a => Uniform (TexCoord4 a) where
uniform :: UniformLocation -> StateVar (TexCoord4 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (TexCoord4 a
s a
t a
r a
q) -> forall a.
UniformComponent a =>
UniformLocation -> a -> a -> a -> a -> IO ()
uniform4 UniformLocation
location a
s a
t a
r a
q
uniformv :: UniformLocation -> GLint -> Ptr (TexCoord4 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform4v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (TexCoord4 b) -> Ptr b)
instance UniformComponent a => Uniform (Normal3 a) where
uniform :: UniformLocation -> StateVar (Normal3 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Normal3 a
x a
y a
z) -> forall a.
UniformComponent a =>
UniformLocation -> a -> a -> a -> IO ()
uniform3 UniformLocation
location a
x a
y a
z
uniformv :: UniformLocation -> GLint -> Ptr (Normal3 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform3v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Normal3 b) -> Ptr b)
instance UniformComponent a => Uniform (FogCoord1 a) where
uniform :: UniformLocation -> StateVar (FogCoord1 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (FogCoord1 a
c) -> forall a. UniformComponent a => UniformLocation -> a -> IO ()
uniform1 UniformLocation
location a
c
uniformv :: UniformLocation -> GLint -> Ptr (FogCoord1 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform1v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (FogCoord1 b) -> Ptr b)
instance UniformComponent a => Uniform (Color3 a) where
uniform :: UniformLocation -> StateVar (Color3 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Color3 a
r a
g a
b) -> forall a.
UniformComponent a =>
UniformLocation -> a -> a -> a -> IO ()
uniform3 UniformLocation
location a
r a
g a
b
uniformv :: UniformLocation -> GLint -> Ptr (Color3 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform3v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Color3 b) -> Ptr b)
instance UniformComponent a => Uniform (Color4 a) where
uniform :: UniformLocation -> StateVar (Color4 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Color4 a
r a
g a
b a
a) -> forall a.
UniformComponent a =>
UniformLocation -> a -> a -> a -> a -> IO ()
uniform4 UniformLocation
location a
r a
g a
b a
a
uniformv :: UniformLocation -> GLint -> Ptr (Color4 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform4v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Color4 b) -> Ptr b)
instance UniformComponent a => Uniform (Index1 a) where
uniform :: UniformLocation -> StateVar (Index1 a)
uniform = forall a (b :: * -> *).
(UniformComponent a, Storable (b a)) =>
(UniformLocation -> b a -> IO ())
-> UniformLocation -> StateVar (b a)
makeUniformVar forall a b. (a -> b) -> a -> b
$ \UniformLocation
location (Index1 a
i) -> forall a. UniformComponent a => UniformLocation -> a -> IO ()
uniform1 UniformLocation
location a
i
uniformv :: UniformLocation -> GLint -> Ptr (Index1 a) -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform1v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr (Index1 b) -> Ptr b)
instance Uniform TextureUnit where
uniform :: UniformLocation -> StateVar TextureUnit
uniform UniformLocation
loc = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO TextureUnit
getter TextureUnit -> IO ()
setter
where getter :: IO TextureUnit
getter = forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes (forall a. Storable a => a -> Int
sizeOf (forall a. HasCallStack => a
undefined :: GLint)) forall a b. (a -> b) -> a -> b
$ \Ptr GLint
buf -> do
forall a.
(GLuint -> GLint -> Ptr a -> IO ())
-> UniformLocation -> Ptr a -> IO ()
getUniformWith forall (m :: * -> *).
MonadIO m =>
GLuint -> GLint -> Ptr GLint -> m ()
glGetUniformiv UniformLocation
loc Ptr GLint
buf
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (GLuint -> TextureUnit
TextureUnit forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral) forall a b. (a -> b) -> a -> b
$ forall a. Storable a => Ptr a -> IO a
peek Ptr GLint
buf
setter :: TextureUnit -> IO ()
setter (TextureUnit GLuint
tu) = forall a. UniformComponent a => UniformLocation -> a -> IO ()
uniform1 UniformLocation
loc (forall a b. (Integral a, Num b) => a -> b
fromIntegral GLuint
tu :: GLint)
uniformv :: UniformLocation -> GLint -> Ptr TextureUnit -> IO ()
uniformv UniformLocation
location GLint
count = forall a.
UniformComponent a =>
UniformLocation -> GLint -> Ptr a -> IO ()
uniform1v UniformLocation
location GLint
count forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b. Ptr a -> Ptr b
castPtr :: Ptr TextureUnit -> Ptr GLint)
instance MatrixComponent a => Uniform (GLmatrix a) where
uniform :: UniformLocation -> StateVar (GLmatrix a)
uniform loc :: UniformLocation
loc@(UniformLocation GLint
ul) = forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (GLmatrix a)
getter forall {m :: * -> *} {c}.
(Matrix m, MatrixComponent c) =>
m c -> IO ()
setter
where getter :: IO (GLmatrix a)
getter = forall (m :: * -> *) c.
(Matrix m, MatrixComponent c) =>
MatrixOrder -> (Ptr c -> IO ()) -> IO (m c)
withNewMatrix MatrixOrder
ColumnMajor forall a b. (a -> b) -> a -> b
$ forall a.
(GLuint -> GLint -> Ptr a -> IO ())
-> UniformLocation -> Ptr a -> IO ()
getUniformWith forall c. MatrixComponent c => GLuint -> GLint -> Ptr c -> IO ()
getUniformv UniformLocation
loc
setter :: m c -> IO ()
setter m c
m = forall (m :: * -> *) c a.
(Matrix m, MatrixComponent c) =>
m c -> (MatrixOrder -> Ptr c -> IO a) -> IO a
withMatrix m c
m forall a b. (a -> b) -> a -> b
$ forall c.
MatrixComponent c =>
GLint -> GLint -> GLboolean -> Ptr c -> IO ()
uniformMatrix4v GLint
ul GLint
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. MatrixOrder -> GLboolean
isRowMajor
uniformv :: UniformLocation -> GLint -> Ptr (GLmatrix a) -> IO ()
uniformv (UniformLocation GLint
ul) GLint
count Ptr (GLmatrix a)
buf =
forall c.
MatrixComponent c =>
GLint -> GLint -> GLboolean -> Ptr c -> IO ()
uniformMatrix4v GLint
ul GLint
count (forall a. Num a => Bool -> a
marshalGLboolean Bool
False) (forall a b. Ptr a -> Ptr b
castPtr Ptr (GLmatrix a)
buf forall a. a -> a -> a
`asTypeOf` Ptr (GLmatrix a) -> Ptr a
elemType Ptr (GLmatrix a)
buf)
where elemType :: Ptr (GLmatrix a) -> Ptr a
elemType = forall a. HasCallStack => a
undefined :: MatrixComponent c => Ptr (GLmatrix c) -> Ptr c
isRowMajor :: MatrixOrder -> GLboolean
isRowMajor :: MatrixOrder -> GLboolean
isRowMajor = forall a. Num a => Bool -> a
marshalGLboolean forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MatrixOrder
RowMajor forall a. Eq a => a -> a -> Bool
==)
getUniformWith :: (GLuint -> GLint -> Ptr a -> IO ()) -> UniformLocation -> Ptr a -> IO ()
getUniformWith :: forall a.
(GLuint -> GLint -> Ptr a -> IO ())
-> UniformLocation -> Ptr a -> IO ()
getUniformWith GLuint -> GLint -> Ptr a -> IO ()
getter (UniformLocation GLint
ul) Ptr a
buf = do
GLuint
program <- forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Program -> GLuint
programID forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. HasCallStack => Maybe a -> a
fromJust) forall a b. (a -> b) -> a -> b
$ forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get StateVar (Maybe Program)
currentProgram
GLuint -> GLint -> Ptr a -> IO ()
getter GLuint
program GLint
ul Ptr a
buf