    {-# LANGUAGE TypeSynonymInstances #-}
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.Shaders.Uniform
    -- Copyright   :  (c) Sven Panne 2006-2019
    -- License     :  BSD3
    --
    -- Maintainer  :  Sven Panne <svenpanne@gmail.com>
    -- Stability   :  stable
    -- Portability :  portable
    --
    -- This module contains functions related to shader uniforms, this corresponds
    -- to section 2.20.3 of the OpenGL 3.1 spec (Shader Variables).
    --
    -----------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.Shaders.Uniform (
       -- * Uniform variables
       UniformLocation(..), uniformLocation, activeUniforms, Uniform(..),
       UniformComponent,

       -- TODO: glGetUniformSubroutineuiv
    ) 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 = (GLint -> GLuint)
    -> GetProgramPName -> Program -> GettableStateVar GLuint
    forall a.
    (GLint -> a) -> GetProgramPName -> Program -> GettableStateVar a
    programVar1 GLint -> GLuint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral GetProgramPName
    ActiveUniforms

    activeUniformMaxLength :: Program -> GettableStateVar GLsizei
    activeUniformMaxLength :: Program -> GettableStateVar GLint
    activeUniformMaxLength = (GLint -> GLint)
    -> GetProgramPName -> Program -> GettableStateVar GLint
    forall a.
    (GLint -> a) -> GetProgramPName -> Program -> GettableStateVar a
    programVar1 GLint -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral GetProgramPName
    ActiveUniformMaxLength

    --------------------------------------------------------------------------------

    newtype UniformLocation = UniformLocation GLint
       deriving ( UniformLocation -> UniformLocation -> Bool
    (UniformLocation -> UniformLocation -> Bool)
    -> (UniformLocation -> UniformLocation -> Bool)
    -> Eq UniformLocation
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: UniformLocation -> UniformLocation -> Bool
    == :: UniformLocation -> UniformLocation -> Bool
    $c/= :: UniformLocation -> UniformLocation -> Bool
    /= :: UniformLocation -> UniformLocation -> Bool
    Eq, Eq UniformLocation
    Eq UniformLocation =>
    (UniformLocation -> UniformLocation -> Ordering)
    -> (UniformLocation -> UniformLocation -> Bool)
    -> (UniformLocation -> UniformLocation -> Bool)
    -> (UniformLocation -> UniformLocation -> Bool)
    -> (UniformLocation -> UniformLocation -> Bool)
    -> (UniformLocation -> UniformLocation -> UniformLocation)
    -> (UniformLocation -> UniformLocation -> UniformLocation)
    -> Ord 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
    $ccompare :: UniformLocation -> UniformLocation -> Ordering
    compare :: UniformLocation -> UniformLocation -> Ordering
    $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
    >= :: UniformLocation -> UniformLocation -> Bool
    $cmax :: UniformLocation -> UniformLocation -> UniformLocation
    max :: UniformLocation -> UniformLocation -> UniformLocation
    $cmin :: UniformLocation -> UniformLocation -> UniformLocation
    min :: UniformLocation -> UniformLocation -> UniformLocation
    Ord, Int -> UniformLocation -> ShowS
    [UniformLocation] -> ShowS
    UniformLocation -> String
    (Int -> UniformLocation -> ShowS)
    -> (UniformLocation -> String)
    -> ([UniformLocation] -> ShowS)
    -> Show UniformLocation
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> UniformLocation -> ShowS
    showsPrec :: Int -> UniformLocation -> ShowS
    $cshow :: UniformLocation -> String
    show :: UniformLocation -> String
    $cshowList :: [UniformLocation] -> ShowS
    showList :: [UniformLocation] -> ShowS
    Show )

    uniformLocation :: Program -> String -> GettableStateVar UniformLocation
    uniformLocation :: Program -> String -> GettableStateVar UniformLocation
    uniformLocation (Program GLuint
    program) String
    name =
       GettableStateVar UniformLocation
    -> GettableStateVar UniformLocation
    forall a. IO a -> IO a
    makeGettableStateVar (GettableStateVar UniformLocation
     -> GettableStateVar UniformLocation)
    -> GettableStateVar UniformLocation
    -> GettableStateVar UniformLocation
    forall a b. (a -> b) -> a -> b
    $
          (GLint -> UniformLocation)
    -> GettableStateVar GLint -> GettableStateVar UniformLocation
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap GLint -> UniformLocation
    UniformLocation (GettableStateVar GLint -> GettableStateVar UniformLocation)
    -> GettableStateVar GLint -> GettableStateVar UniformLocation
    forall a b. (a -> b) -> a -> b
    $
             String
    -> (Ptr GLchar -> GettableStateVar GLint) -> GettableStateVar GLint
    forall a. String -> (Ptr GLchar -> IO a) -> IO a
    withGLstring String
    name ((Ptr GLchar -> GettableStateVar GLint) -> GettableStateVar GLint)
    -> (Ptr GLchar -> GettableStateVar GLint) -> GettableStateVar GLint
    forall a b. (a -> b) -> a -> b
    $
                GLuint -> Ptr GLchar -> GettableStateVar GLint
    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 =
       (Program -> GettableStateVar GLuint)
    -> (Program -> GettableStateVar GLint)
    -> (GLuint
        -> GLuint
        -> GLint
        -> Ptr GLint
        -> Ptr GLint
        -> Ptr GLuint
        -> Ptr GLchar
        -> IO ())
    -> (GLuint -> VariableType)
    -> Program
    -> GettableStateVar [(GLint, VariableType, String)]
    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
          GLuint
    -> GLuint
    -> GLint
    -> Ptr GLint
    -> Ptr GLint
    -> Ptr GLuint
    -> Ptr GLchar
    -> IO ()
    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) = GLint -> GLint -> IO ()
    forall (m :: * -> *). MonadIO m => GLint -> GLint -> m ()
    glUniform1i GLint
    ul
       uniform2 :: UniformLocation -> GLint -> GLint -> IO ()
    uniform2 (UniformLocation GLint
    ul) = GLint -> GLint -> GLint -> IO ()
    forall (m :: * -> *). MonadIO m => GLint -> GLint -> GLint -> m ()
    glUniform2i GLint
    ul
       uniform3 :: UniformLocation -> GLint -> GLint -> GLint -> IO ()
    uniform3 (UniformLocation GLint
    ul) = GLint -> GLint -> GLint -> GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> GLint -> GLint -> m ()
    glUniform3i GLint
    ul
       uniform4 :: UniformLocation -> GLint -> GLint -> GLint -> GLint -> IO ()
    uniform4 (UniformLocation GLint
    ul) = GLint -> GLint -> GLint -> GLint -> GLint -> IO ()
    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 = GLuint -> GLint -> Ptr GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLuint -> GLint -> Ptr GLint -> m ()
    glGetUniformiv GLuint
    p GLint
    ul (Ptr GLint -> IO ())
    -> (Ptr (b GLint) -> Ptr GLint) -> Ptr (b GLint) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr (b GLint) -> Ptr GLint
    forall a b. Ptr a -> Ptr b
    castPtr

       uniform1v :: UniformLocation -> GLint -> Ptr GLint -> IO ()
    uniform1v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLint -> m ()
    glUniform1iv GLint
    ul
       uniform2v :: UniformLocation -> GLint -> Ptr GLint -> IO ()
    uniform2v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLint -> m ()
    glUniform2iv GLint
    ul
       uniform3v :: UniformLocation -> GLint -> Ptr GLint -> IO ()
    uniform3v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLint -> m ()
    glUniform3iv GLint
    ul
       uniform4v :: UniformLocation -> GLint -> Ptr GLint -> IO ()
    uniform4v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLint -> m ()
    glUniform4iv GLint
    ul

    instance UniformComponent GLuint where
       uniform1 :: UniformLocation -> GLuint -> IO ()
    uniform1 (UniformLocation GLint
    ul) = GLint -> GLuint -> IO ()
    forall (m :: * -> *). MonadIO m => GLint -> GLuint -> m ()
    glUniform1ui GLint
    ul
       uniform2 :: UniformLocation -> GLuint -> GLuint -> IO ()
    uniform2 (UniformLocation GLint
    ul) = GLint -> GLuint -> GLuint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLuint -> GLuint -> m ()
    glUniform2ui GLint
    ul
       uniform3 :: UniformLocation -> GLuint -> GLuint -> GLuint -> IO ()
    uniform3 (UniformLocation GLint
    ul) = GLint -> GLuint -> GLuint -> GLuint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLuint -> GLuint -> GLuint -> m ()
    glUniform3ui GLint
    ul
       uniform4 :: UniformLocation -> GLuint -> GLuint -> GLuint -> GLuint -> IO ()
    uniform4 (UniformLocation GLint
    ul) = GLint -> GLuint -> GLuint -> GLuint -> GLuint -> IO ()
    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 = GLuint -> GLint -> Ptr GLuint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLuint -> GLint -> Ptr GLuint -> m ()
    glGetUniformuiv GLuint
    p GLint
    ul (Ptr GLuint -> IO ())
    -> (Ptr (b GLuint) -> Ptr GLuint) -> Ptr (b GLuint) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr (b GLuint) -> Ptr GLuint
    forall a b. Ptr a -> Ptr b
    castPtr

       uniform1v :: UniformLocation -> GLint -> Ptr GLuint -> IO ()
    uniform1v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLuint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLuint -> m ()
    glUniform1uiv GLint
    ul
       uniform2v :: UniformLocation -> GLint -> Ptr GLuint -> IO ()
    uniform2v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLuint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLuint -> m ()
    glUniform2uiv GLint
    ul
       uniform3v :: UniformLocation -> GLint -> Ptr GLuint -> IO ()
    uniform3v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLuint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLuint -> m ()
    glUniform3uiv GLint
    ul
       uniform4v :: UniformLocation -> GLint -> Ptr GLuint -> IO ()
    uniform4v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLuint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLuint -> m ()
    glUniform4uiv GLint
    ul

    instance UniformComponent GLfloat where
       uniform1 :: UniformLocation -> GLfloat -> IO ()
    uniform1 (UniformLocation GLint
    ul) = GLint -> GLfloat -> IO ()
    forall (m :: * -> *). MonadIO m => GLint -> GLfloat -> m ()
    glUniform1f GLint
    ul
       uniform2 :: UniformLocation -> GLfloat -> GLfloat -> IO ()
    uniform2 (UniformLocation GLint
    ul) = GLint -> GLfloat -> GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLfloat -> GLfloat -> m ()
    glUniform2f GLint
    ul
       uniform3 :: UniformLocation -> GLfloat -> GLfloat -> GLfloat -> IO ()
    uniform3 (UniformLocation GLint
    ul) = GLint -> GLfloat -> GLfloat -> GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLfloat -> GLfloat -> GLfloat -> m ()
    glUniform3f GLint
    ul
       uniform4 :: UniformLocation
    -> GLfloat -> GLfloat -> GLfloat -> GLfloat -> IO ()
    uniform4 (UniformLocation GLint
    ul) = GLint -> GLfloat -> GLfloat -> GLfloat -> GLfloat -> IO ()
    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 = GLuint -> GLint -> Ptr GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLuint -> GLint -> Ptr GLfloat -> m ()
    glGetUniformfv GLuint
    p GLint
    ul (Ptr GLfloat -> IO ())
    -> (Ptr (b GLfloat) -> Ptr GLfloat) -> Ptr (b GLfloat) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr (b GLfloat) -> Ptr GLfloat
    forall a b. Ptr a -> Ptr b
    castPtr

       uniform1v :: UniformLocation -> GLint -> Ptr GLfloat -> IO ()
    uniform1v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLfloat -> m ()
    glUniform1fv GLint
    ul
       uniform2v :: UniformLocation -> GLint -> Ptr GLfloat -> IO ()
    uniform2v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLfloat -> m ()
    glUniform2fv GLint
    ul
       uniform3v :: UniformLocation -> GLint -> Ptr GLfloat -> IO ()
    uniform3v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLfloat -> m ()
    glUniform3fv GLint
    ul
       uniform4v :: UniformLocation -> GLint -> Ptr GLfloat -> IO ()
    uniform4v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLfloat -> m ()
    glUniform4fv GLint
    ul

    instance UniformComponent GLdouble where
       uniform1 :: UniformLocation -> GLdouble -> IO ()
    uniform1 (UniformLocation GLint
    ul) = GLint -> GLdouble -> IO ()
    forall (m :: * -> *). MonadIO m => GLint -> GLdouble -> m ()
    glUniform1d GLint
    ul
       uniform2 :: UniformLocation -> GLdouble -> GLdouble -> IO ()
    uniform2 (UniformLocation GLint
    ul) = GLint -> GLdouble -> GLdouble -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLdouble -> GLdouble -> m ()
    glUniform2d GLint
    ul
       uniform3 :: UniformLocation -> GLdouble -> GLdouble -> GLdouble -> IO ()
    uniform3 (UniformLocation GLint
    ul) = GLint -> GLdouble -> GLdouble -> GLdouble -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLdouble -> GLdouble -> GLdouble -> m ()
    glUniform3d GLint
    ul
       uniform4 :: UniformLocation
    -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> IO ()
    uniform4 (UniformLocation GLint
    ul) = GLint -> GLdouble -> GLdouble -> GLdouble -> GLdouble -> IO ()
    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 = GLuint -> GLint -> Ptr GLdouble -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLuint -> GLint -> Ptr GLdouble -> m ()
    glGetUniformdv GLuint
    p GLint
    ul (Ptr GLdouble -> IO ())
    -> (Ptr (b GLdouble) -> Ptr GLdouble) -> Ptr (b GLdouble) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Ptr (b GLdouble) -> Ptr GLdouble
    forall a b. Ptr a -> Ptr b
    castPtr

       uniform1v :: UniformLocation -> GLint -> Ptr GLdouble -> IO ()
    uniform1v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLdouble -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLdouble -> m ()
    glUniform1dv GLint
    ul
       uniform2v :: UniformLocation -> GLint -> Ptr GLdouble -> IO ()
    uniform2v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLdouble -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLdouble -> m ()
    glUniform2dv GLint
    ul
       uniform3v :: UniformLocation -> GLint -> Ptr GLdouble -> IO ()
    uniform3v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLdouble -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLint -> GLint -> Ptr GLdouble -> m ()
    glUniform3dv GLint
    ul
       uniform4v :: UniformLocation -> GLint -> Ptr GLdouble -> IO ()
    uniform4v (UniformLocation GLint
    ul) = GLint -> GLint -> Ptr GLdouble -> IO ()
    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 = GLint -> Int
    forall a. Storable a => a -> Int
    sizeOf (GLint
    forall a. HasCallStack => a
    undefined :: GLint) Int -> Int -> Int
    forall a. Ord a => a -> a -> a
    `max` GLfloat -> Int
    forall a. Storable a => a -> Int
    sizeOf (GLfloat
    forall a. HasCallStack => a
    undefined :: GLfloat)

    maxNumComponents :: Int
    maxNumComponents :: Int
    maxNumComponents = Int
    16

    maxUniformBufferSize :: Int
    maxUniformBufferSize :: Int
    maxUniformBufferSize = Int
    maxComponentSize Int -> Int -> Int
    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 = IO (b a) -> (b a -> IO ()) -> StateVar (b a)
    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 = Int -> (Ptr (b a) -> IO (b a)) -> IO (b a)
    forall a b. Int -> (Ptr a -> IO b) -> IO b
    allocaBytes Int
    maxUniformBufferSize ((Ptr (b a) -> IO (b a)) -> IO (b a))
    -> (Ptr (b a) -> IO (b a)) -> IO (b a)
    forall a b. (a -> b) -> a -> b
    $ \Ptr (b a)
    buf -> do
                         (GLuint -> GLint -> Ptr (b a) -> IO ())
    -> UniformLocation -> Ptr (b a) -> IO ()
    forall a.
    (GLuint -> GLint -> Ptr a -> IO ())
    -> UniformLocation -> Ptr a -> IO ()
    getUniformWith GLuint -> GLint -> Ptr (b a) -> IO ()
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    GLuint -> GLint -> Ptr (b a) -> IO ()
    forall (b :: * -> *).
    Storable (b a) =>
    GLuint -> GLint -> Ptr (b a) -> IO ()
    getUniform UniformLocation
    location Ptr (b a)
    buf
                         Ptr (b a) -> IO (b a)
    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 = IO a -> (a -> IO ()) -> StateVar a
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar (do Vertex1 x <- StateVar (Vertex1 a) -> IO (Vertex1 a)
    forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
    forall (m :: * -> *).
    MonadIO m =>
    StateVar (Vertex1 a) -> m (Vertex1 a)
    get (UniformLocation -> StateVar (Vertex1 a)
    var UniformLocation
    location); return x)
                                       (\a
    x -> UniformLocation -> StateVar (Vertex1 a)
    var UniformLocation
    location StateVar (Vertex1 a) -> Vertex1 a -> IO ()
    forall t a (m :: * -> *).
    (HasSetter t a, MonadIO m) =>
    t -> a -> m ()
    forall (m :: * -> *).
    MonadIO m =>
    StateVar (Vertex1 a) -> Vertex1 a -> m ()
    $= a -> Vertex1 a
    forall a. a -> Vertex1 a
    Vertex1 a
    x)

    instance Uniform GLfloat where
       uniform :: UniformLocation -> StateVar GLfloat
    uniform = (UniformLocation -> StateVar (Vertex1 GLfloat))
    -> UniformLocation -> StateVar GLfloat
    forall a.
    (UniformLocation -> StateVar (Vertex1 a))
    -> UniformLocation -> StateVar a
    single UniformLocation -> StateVar (Vertex1 GLfloat)
    forall a. Uniform a => UniformLocation -> StateVar a
    uniform
       uniformv :: UniformLocation -> GLint -> Ptr GLfloat -> IO ()
    uniformv = UniformLocation -> GLint -> Ptr GLfloat -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform1v

    instance Uniform GLint where
       uniform :: UniformLocation -> StateVar GLint
    uniform = (UniformLocation -> StateVar (Vertex1 GLint))
    -> UniformLocation -> StateVar GLint
    forall a.
    (UniformLocation -> StateVar (Vertex1 a))
    -> UniformLocation -> StateVar a
    single UniformLocation -> StateVar (Vertex1 GLint)
    forall a. Uniform a => UniformLocation -> StateVar a
    uniform
       uniformv :: UniformLocation -> GLint -> Ptr GLint -> IO ()
    uniformv = UniformLocation -> GLint -> Ptr GLint -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform1v

    instance Uniform GLuint where
       uniform :: UniformLocation -> StateVar GLuint
    uniform = (UniformLocation -> StateVar (Vertex1 GLuint))
    -> UniformLocation -> StateVar GLuint
    forall a.
    (UniformLocation -> StateVar (Vertex1 a))
    -> UniformLocation -> StateVar a
    single UniformLocation -> StateVar (Vertex1 GLuint)
    forall a. Uniform a => UniformLocation -> StateVar a
    uniform
       uniformv :: UniformLocation -> GLint -> Ptr GLuint -> IO ()
    uniformv = UniformLocation -> GLint -> Ptr GLuint -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform1v

    instance Uniform GLdouble where
       uniform :: UniformLocation -> StateVar GLdouble
    uniform = (UniformLocation -> StateVar (Vertex1 GLdouble))
    -> UniformLocation -> StateVar GLdouble
    forall a.
    (UniformLocation -> StateVar (Vertex1 a))
    -> UniformLocation -> StateVar a
    single UniformLocation -> StateVar (Vertex1 GLdouble)
    forall a. Uniform a => UniformLocation -> StateVar a
    uniform
       uniformv :: UniformLocation -> GLint -> Ptr GLdouble -> IO ()
    uniformv = UniformLocation -> GLint -> Ptr GLdouble -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform1v

    instance UniformComponent a => Uniform (Vertex1 a) where
       uniform :: UniformLocation -> StateVar (Vertex1 a)
    uniform = (UniformLocation -> Vertex1 a -> IO ())
    -> UniformLocation -> StateVar (Vertex1 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Vertex1 a -> IO ())
     -> UniformLocation -> StateVar (Vertex1 a))
    -> (UniformLocation -> Vertex1 a -> IO ())
    -> UniformLocation
    -> StateVar (Vertex1 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Vertex1 a
    x) -> UniformLocation -> a -> IO ()
    forall a. UniformComponent a => UniformLocation -> a -> IO ()
    uniform1 UniformLocation
    location a
    x
       uniformv :: UniformLocation -> GLint -> Ptr (Vertex1 a) -> IO ()
    uniformv UniformLocation
    location GLint
    count = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform1v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Vertex1 a) -> Ptr a) -> Ptr (Vertex1 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Vertex1 b) -> Ptr b
    forall {b}. Ptr (Vertex1 b) -> Ptr b
    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 = (UniformLocation -> Vertex2 a -> IO ())
    -> UniformLocation -> StateVar (Vertex2 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Vertex2 a -> IO ())
     -> UniformLocation -> StateVar (Vertex2 a))
    -> (UniformLocation -> Vertex2 a -> IO ())
    -> UniformLocation
    -> StateVar (Vertex2 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Vertex2 a
    x a
    y) -> UniformLocation -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform2v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Vertex2 a) -> Ptr a) -> Ptr (Vertex2 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Vertex2 b) -> Ptr b
    forall {b}. Ptr (Vertex2 b) -> Ptr b
    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 = (UniformLocation -> Vertex3 a -> IO ())
    -> UniformLocation -> StateVar (Vertex3 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Vertex3 a -> IO ())
     -> UniformLocation -> StateVar (Vertex3 a))
    -> (UniformLocation -> Vertex3 a -> IO ())
    -> UniformLocation
    -> StateVar (Vertex3 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Vertex3 a
    x a
    y a
    z) -> UniformLocation -> a -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform3v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Vertex3 a) -> Ptr a) -> Ptr (Vertex3 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Vertex3 b) -> Ptr b
    forall {b}. Ptr (Vertex3 b) -> Ptr b
    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 = (UniformLocation -> Vertex4 a -> IO ())
    -> UniformLocation -> StateVar (Vertex4 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Vertex4 a -> IO ())
     -> UniformLocation -> StateVar (Vertex4 a))
    -> (UniformLocation -> Vertex4 a -> IO ())
    -> UniformLocation
    -> StateVar (Vertex4 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Vertex4 a
    x a
    y a
    z a
    w) -> UniformLocation -> a -> a -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform4v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Vertex4 a) -> Ptr a) -> Ptr (Vertex4 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Vertex4 b) -> Ptr b
    forall {b}. Ptr (Vertex4 b) -> Ptr b
    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 = (UniformLocation -> Vector1 a -> IO ())
    -> UniformLocation -> StateVar (Vector1 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Vector1 a -> IO ())
     -> UniformLocation -> StateVar (Vector1 a))
    -> (UniformLocation -> Vector1 a -> IO ())
    -> UniformLocation
    -> StateVar (Vector1 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Vector1 a
    x) -> UniformLocation -> a -> IO ()
    forall a. UniformComponent a => UniformLocation -> a -> IO ()
    uniform1 UniformLocation
    location a
    x
       uniformv :: UniformLocation -> GLint -> Ptr (Vector1 a) -> IO ()
    uniformv UniformLocation
    location GLint
    count = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform1v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Vector1 a) -> Ptr a) -> Ptr (Vector1 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Vector1 b) -> Ptr b
    forall {b}. Ptr (Vector1 b) -> Ptr b
    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 = (UniformLocation -> Vector2 a -> IO ())
    -> UniformLocation -> StateVar (Vector2 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Vector2 a -> IO ())
     -> UniformLocation -> StateVar (Vector2 a))
    -> (UniformLocation -> Vector2 a -> IO ())
    -> UniformLocation
    -> StateVar (Vector2 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Vector2 a
    x a
    y) -> UniformLocation -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform2v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Vector2 a) -> Ptr a) -> Ptr (Vector2 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Vector2 b) -> Ptr b
    forall {b}. Ptr (Vector2 b) -> Ptr b
    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 = (UniformLocation -> Vector3 a -> IO ())
    -> UniformLocation -> StateVar (Vector3 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Vector3 a -> IO ())
     -> UniformLocation -> StateVar (Vector3 a))
    -> (UniformLocation -> Vector3 a -> IO ())
    -> UniformLocation
    -> StateVar (Vector3 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Vector3 a
    x a
    y a
    z) -> UniformLocation -> a -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform3v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Vector3 a) -> Ptr a) -> Ptr (Vector3 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Vector3 b) -> Ptr b
    forall {b}. Ptr (Vector3 b) -> Ptr b
    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 = (UniformLocation -> Vector4 a -> IO ())
    -> UniformLocation -> StateVar (Vector4 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Vector4 a -> IO ())
     -> UniformLocation -> StateVar (Vector4 a))
    -> (UniformLocation -> Vector4 a -> IO ())
    -> UniformLocation
    -> StateVar (Vector4 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Vector4 a
    x a
    y a
    z a
    w) -> UniformLocation -> a -> a -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform4v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Vector4 a) -> Ptr a) -> Ptr (Vector4 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Vector4 b) -> Ptr b
    forall {b}. Ptr (Vector4 b) -> Ptr b
    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 = (UniformLocation -> TexCoord1 a -> IO ())
    -> UniformLocation -> StateVar (TexCoord1 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> TexCoord1 a -> IO ())
     -> UniformLocation -> StateVar (TexCoord1 a))
    -> (UniformLocation -> TexCoord1 a -> IO ())
    -> UniformLocation
    -> StateVar (TexCoord1 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (TexCoord1 a
    s) -> UniformLocation -> a -> IO ()
    forall a. UniformComponent a => UniformLocation -> a -> IO ()
    uniform1 UniformLocation
    location a
    s
       uniformv :: UniformLocation -> GLint -> Ptr (TexCoord1 a) -> IO ()
    uniformv UniformLocation
    location GLint
    count = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform1v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (TexCoord1 a) -> Ptr a) -> Ptr (TexCoord1 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (TexCoord1 b) -> Ptr b
    forall {b}. Ptr (TexCoord1 b) -> Ptr b
    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 = (UniformLocation -> TexCoord2 a -> IO ())
    -> UniformLocation -> StateVar (TexCoord2 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> TexCoord2 a -> IO ())
     -> UniformLocation -> StateVar (TexCoord2 a))
    -> (UniformLocation -> TexCoord2 a -> IO ())
    -> UniformLocation
    -> StateVar (TexCoord2 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (TexCoord2 a
    s a
    t) -> UniformLocation -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform2v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (TexCoord2 a) -> Ptr a) -> Ptr (TexCoord2 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (TexCoord2 b) -> Ptr b
    forall {b}. Ptr (TexCoord2 b) -> Ptr b
    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 = (UniformLocation -> TexCoord3 a -> IO ())
    -> UniformLocation -> StateVar (TexCoord3 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> TexCoord3 a -> IO ())
     -> UniformLocation -> StateVar (TexCoord3 a))
    -> (UniformLocation -> TexCoord3 a -> IO ())
    -> UniformLocation
    -> StateVar (TexCoord3 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (TexCoord3 a
    s a
    t a
    r) -> UniformLocation -> a -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform3v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (TexCoord3 a) -> Ptr a) -> Ptr (TexCoord3 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (TexCoord3 b) -> Ptr b
    forall {b}. Ptr (TexCoord3 b) -> Ptr b
    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 = (UniformLocation -> TexCoord4 a -> IO ())
    -> UniformLocation -> StateVar (TexCoord4 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> TexCoord4 a -> IO ())
     -> UniformLocation -> StateVar (TexCoord4 a))
    -> (UniformLocation -> TexCoord4 a -> IO ())
    -> UniformLocation
    -> StateVar (TexCoord4 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (TexCoord4 a
    s a
    t a
    r a
    q) -> UniformLocation -> a -> a -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform4v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (TexCoord4 a) -> Ptr a) -> Ptr (TexCoord4 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (TexCoord4 b) -> Ptr b
    forall {b}. Ptr (TexCoord4 b) -> Ptr b
    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 = (UniformLocation -> Normal3 a -> IO ())
    -> UniformLocation -> StateVar (Normal3 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Normal3 a -> IO ())
     -> UniformLocation -> StateVar (Normal3 a))
    -> (UniformLocation -> Normal3 a -> IO ())
    -> UniformLocation
    -> StateVar (Normal3 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Normal3 a
    x a
    y a
    z) -> UniformLocation -> a -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform3v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Normal3 a) -> Ptr a) -> Ptr (Normal3 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Normal3 b) -> Ptr b
    forall {b}. Ptr (Normal3 b) -> Ptr b
    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 = (UniformLocation -> FogCoord1 a -> IO ())
    -> UniformLocation -> StateVar (FogCoord1 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> FogCoord1 a -> IO ())
     -> UniformLocation -> StateVar (FogCoord1 a))
    -> (UniformLocation -> FogCoord1 a -> IO ())
    -> UniformLocation
    -> StateVar (FogCoord1 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (FogCoord1 a
    c) -> UniformLocation -> a -> IO ()
    forall a. UniformComponent a => UniformLocation -> a -> IO ()
    uniform1 UniformLocation
    location a
    c
       uniformv :: UniformLocation -> GLint -> Ptr (FogCoord1 a) -> IO ()
    uniformv UniformLocation
    location GLint
    count = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform1v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (FogCoord1 a) -> Ptr a) -> Ptr (FogCoord1 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (FogCoord1 b) -> Ptr b
    forall {b}. Ptr (FogCoord1 b) -> Ptr b
    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 = (UniformLocation -> Color3 a -> IO ())
    -> UniformLocation -> StateVar (Color3 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Color3 a -> IO ())
     -> UniformLocation -> StateVar (Color3 a))
    -> (UniformLocation -> Color3 a -> IO ())
    -> UniformLocation
    -> StateVar (Color3 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Color3 a
    r a
    g a
    b) -> UniformLocation -> a -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform3v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Color3 a) -> Ptr a) -> Ptr (Color3 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Color3 b) -> Ptr b
    forall {b}. Ptr (Color3 b) -> Ptr b
    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 = (UniformLocation -> Color4 a -> IO ())
    -> UniformLocation -> StateVar (Color4 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Color4 a -> IO ())
     -> UniformLocation -> StateVar (Color4 a))
    -> (UniformLocation -> Color4 a -> IO ())
    -> UniformLocation
    -> StateVar (Color4 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Color4 a
    r a
    g a
    b a
    a) -> UniformLocation -> a -> a -> a -> a -> IO ()
    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 = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform4v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Color4 a) -> Ptr a) -> Ptr (Color4 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Color4 b) -> Ptr b
    forall {b}. Ptr (Color4 b) -> Ptr b
    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 = (UniformLocation -> Index1 a -> IO ())
    -> UniformLocation -> StateVar (Index1 a)
    forall a (b :: * -> *).
    (UniformComponent a, Storable (b a)) =>
    (UniformLocation -> b a -> IO ())
    -> UniformLocation -> StateVar (b a)
    makeUniformVar ((UniformLocation -> Index1 a -> IO ())
     -> UniformLocation -> StateVar (Index1 a))
    -> (UniformLocation -> Index1 a -> IO ())
    -> UniformLocation
    -> StateVar (Index1 a)
    forall a b. (a -> b) -> a -> b
    $ \UniformLocation
    location (Index1 a
    i) -> UniformLocation -> a -> IO ()
    forall a. UniformComponent a => UniformLocation -> a -> IO ()
    uniform1 UniformLocation
    location a
    i
       uniformv :: UniformLocation -> GLint -> Ptr (Index1 a) -> IO ()
    uniformv UniformLocation
    location GLint
    count = UniformLocation -> GLint -> Ptr a -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform1v UniformLocation
    location GLint
    count (Ptr a -> IO ())
    -> (Ptr (Index1 a) -> Ptr a) -> Ptr (Index1 a) -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr (Index1 b) -> Ptr b
    forall {b}. Ptr (Index1 b) -> Ptr b
    forall a b. Ptr a -> Ptr b
    castPtr :: Ptr (Index1 b) -> Ptr b)

    -- Nasty instance declaration as TextureUnit is not of the form Storable (b a) as required for
    -- getUniform. Even worse is that it requires the `GLint` uniforms while it is an enum or
    -- uint.
    instance Uniform TextureUnit where
        uniform :: UniformLocation -> StateVar TextureUnit
    uniform UniformLocation
    loc = IO TextureUnit -> (TextureUnit -> IO ()) -> StateVar TextureUnit
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar IO TextureUnit
    getter TextureUnit -> IO ()
    setter
            where getter :: IO TextureUnit
    getter = Int -> (Ptr GLint -> IO TextureUnit) -> IO TextureUnit
    forall a b. Int -> (Ptr a -> IO b) -> IO b
    allocaBytes (GLint -> Int
    forall a. Storable a => a -> Int
    sizeOf (GLint
    forall a. HasCallStack => a
    undefined :: GLint))  ((Ptr GLint -> IO TextureUnit) -> IO TextureUnit)
    -> (Ptr GLint -> IO TextureUnit) -> IO TextureUnit
    forall a b. (a -> b) -> a -> b
    $ \Ptr GLint
    buf -> do
                              (GLuint -> GLint -> Ptr GLint -> IO ())
    -> UniformLocation -> Ptr GLint -> IO ()
    forall a.
    (GLuint -> GLint -> Ptr a -> IO ())
    -> UniformLocation -> Ptr a -> IO ()
    getUniformWith GLuint -> GLint -> Ptr GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLuint -> GLint -> Ptr GLint -> m ()
    glGetUniformiv UniformLocation
    loc Ptr GLint
    buf
                              (GLint -> TextureUnit) -> GettableStateVar GLint -> IO TextureUnit
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (GLuint -> TextureUnit
    TextureUnit (GLuint -> TextureUnit)
    -> (GLint -> GLuint) -> GLint -> TextureUnit
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLint -> GLuint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) (GettableStateVar GLint -> IO TextureUnit)
    -> GettableStateVar GLint -> IO TextureUnit
    forall a b. (a -> b) -> a -> b
    $ Ptr GLint -> GettableStateVar GLint
    forall a. Storable a => Ptr a -> IO a
    peek Ptr GLint
    buf
                  setter :: TextureUnit -> IO ()
    setter (TextureUnit GLuint
    tu) = UniformLocation -> GLint -> IO ()
    forall a. UniformComponent a => UniformLocation -> a -> IO ()
    uniform1 UniformLocation
    loc (GLuint -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral GLuint
    tu :: GLint)
        uniformv :: UniformLocation -> GLint -> Ptr TextureUnit -> IO ()
    uniformv UniformLocation
    location GLint
    count = UniformLocation -> GLint -> Ptr GLint -> IO ()
    forall a.
    UniformComponent a =>
    UniformLocation -> GLint -> Ptr a -> IO ()
    uniform1v UniformLocation
    location GLint
    count (Ptr GLint -> IO ())
    -> (Ptr TextureUnit -> Ptr GLint) -> Ptr TextureUnit -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Ptr TextureUnit -> Ptr GLint
    forall a b. Ptr a -> Ptr b
    castPtr :: Ptr TextureUnit -> Ptr GLint)

    -- | Note: 'uniformv' expects all matrices to be in 'ColumnMajor' form.
    instance MatrixComponent a => Uniform (GLmatrix a) where
       uniform :: UniformLocation -> StateVar (GLmatrix a)
    uniform loc :: UniformLocation
    loc@(UniformLocation GLint
    ul) = IO (GLmatrix a) -> (GLmatrix a -> IO ()) -> StateVar (GLmatrix a)
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar IO (GLmatrix a)
    getter GLmatrix a -> IO ()
    forall {m :: * -> *} {c}.
    (Matrix m, MatrixComponent c) =>
    m c -> IO ()
    setter
          where getter :: IO (GLmatrix a)
    getter = MatrixOrder -> (Ptr a -> IO ()) -> IO (GLmatrix a)
    forall c.
    MatrixComponent c =>
    MatrixOrder -> (Ptr c -> IO ()) -> IO (GLmatrix c)
    forall (m :: * -> *) c.
    (Matrix m, MatrixComponent c) =>
    MatrixOrder -> (Ptr c -> IO ()) -> IO (m c)
    withNewMatrix MatrixOrder
    ColumnMajor ((Ptr a -> IO ()) -> IO (GLmatrix a))
    -> (Ptr a -> IO ()) -> IO (GLmatrix a)
    forall a b. (a -> b) -> a -> b
    $ (GLuint -> GLint -> Ptr a -> IO ())
    -> UniformLocation -> Ptr a -> IO ()
    forall a.
    (GLuint -> GLint -> Ptr a -> IO ())
    -> UniformLocation -> Ptr a -> IO ()
    getUniformWith GLuint -> GLint -> Ptr a -> IO ()
    forall c. MatrixComponent c => GLuint -> GLint -> Ptr c -> IO ()
    getUniformv UniformLocation
    loc
                setter :: m c -> IO ()
    setter m c
    m = m c -> (MatrixOrder -> Ptr c -> IO ()) -> IO ()
    forall c a.
    MatrixComponent c =>
    m c -> (MatrixOrder -> Ptr c -> IO a) -> IO a
    forall (m :: * -> *) c a.
    (Matrix m, MatrixComponent c) =>
    m c -> (MatrixOrder -> Ptr c -> IO a) -> IO a
    withMatrix m c
    m ((MatrixOrder -> Ptr c -> IO ()) -> IO ())
    -> (MatrixOrder -> Ptr c -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ GLint -> GLint -> GLboolean -> Ptr c -> IO ()
    forall c.
    MatrixComponent c =>
    GLint -> GLint -> GLboolean -> Ptr c -> IO ()
    uniformMatrix4v GLint
    ul GLint
    1 (GLboolean -> Ptr c -> IO ())
    -> (MatrixOrder -> GLboolean) -> MatrixOrder -> Ptr c -> IO ()
    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 =
          GLint -> GLint -> GLboolean -> Ptr a -> IO ()
    forall c.
    MatrixComponent c =>
    GLint -> GLint -> GLboolean -> Ptr c -> IO ()
    uniformMatrix4v GLint
    ul GLint
    count (Bool -> GLboolean
    forall a. Num a => Bool -> a
    marshalGLboolean Bool
    False) (Ptr (GLmatrix a) -> Ptr a
    forall a b. Ptr a -> Ptr b
    castPtr Ptr (GLmatrix a)
    buf Ptr a -> Ptr a -> Ptr a
    forall a. a -> a -> a
    `asTypeOf` Ptr (GLmatrix a) -> Ptr a
    elemType Ptr (GLmatrix a)
    buf)
          where elemType :: Ptr (GLmatrix a) -> Ptr a
    elemType = Ptr (GLmatrix c) -> Ptr c
    forall {c}. MatrixComponent c => Ptr (GLmatrix c) -> Ptr c
    forall a. HasCallStack => a
    undefined :: MatrixComponent c => Ptr (GLmatrix c) -> Ptr c

    isRowMajor :: MatrixOrder -> GLboolean
    isRowMajor :: MatrixOrder -> GLboolean
    isRowMajor = Bool -> GLboolean
    forall a. Num a => Bool -> a
    marshalGLboolean (Bool -> GLboolean)
    -> (MatrixOrder -> Bool) -> MatrixOrder -> GLboolean
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (MatrixOrder
    RowMajor MatrixOrder -> MatrixOrder -> Bool
    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
       program <- (Maybe Program -> GLuint)
    -> IO (Maybe Program) -> GettableStateVar GLuint
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (Program -> GLuint
    programID (Program -> GLuint)
    -> (Maybe Program -> Program) -> Maybe Program -> GLuint
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Maybe Program -> Program
    forall a. HasCallStack => Maybe a -> a
    fromJust) (IO (Maybe Program) -> GettableStateVar GLuint)
    -> IO (Maybe Program) -> GettableStateVar GLuint
    forall a b. (a -> b) -> a -> b
    $ StateVar (Maybe Program) -> IO (Maybe Program)
    forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
    forall (m :: * -> *).
    MonadIO m =>
    StateVar (Maybe Program) -> m (Maybe Program)
    get StateVar (Maybe Program)
    currentProgram
       getter program ul buf

    --------------------------------------------------------------------------------