    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.Shaders.Attribs
    -- 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 attributes, corresponding
    -- to section 2.20.3 of the OpenGL 3.1 spec (Shader Variables).
    --
    -----------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.Shaders.Attribs (
       attribLocation, VariableType(..), activeAttribs,
    ) where

    import Data.StateVar
    import Graphics.Rendering.OpenGL.GL.ByteString
    import Graphics.Rendering.OpenGL.GL.QueryUtils
    import Graphics.Rendering.OpenGL.GL.Shaders.Program
    import Graphics.Rendering.OpenGL.GL.Shaders.Variables
    import Graphics.GL

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

    activeAttributes :: Program -> GettableStateVar GLuint
    activeAttributes :: Program -> GettableStateVar GLuint
    activeAttributes = (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
    ActiveAttributes

    activeAttributeMaxLength :: Program -> GettableStateVar GLsizei
    activeAttributeMaxLength :: Program -> GettableStateVar GLint
    activeAttributeMaxLength = (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
    ActiveAttributeMaxLength

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

    attribLocation :: Program -> String -> StateVar AttribLocation
    attribLocation :: Program -> String -> StateVar AttribLocation
    attribLocation Program
    program String
    name =
       IO AttribLocation
    -> (AttribLocation -> IO ()) -> StateVar AttribLocation
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar (Program -> String -> IO AttribLocation
    getAttribLocation Program
    program String
    name)
                    (\AttribLocation
    location -> Program -> AttribLocation -> String -> IO ()
    bindAttribLocation Program
    program AttribLocation
    location String
    name)

    getAttribLocation :: Program -> String -> IO AttribLocation
    getAttribLocation :: Program -> String -> IO AttribLocation
    getAttribLocation (Program GLuint
    program) String
    name =
       (GLint -> AttribLocation)
    -> GettableStateVar GLint -> IO AttribLocation
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (GLuint -> AttribLocation
    AttribLocation (GLuint -> AttribLocation)
    -> (GLint -> GLuint) -> GLint -> AttribLocation
    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 AttribLocation)
    -> GettableStateVar GLint -> IO AttribLocation
    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
    glGetAttribLocation GLuint
    program

    bindAttribLocation :: Program -> AttribLocation -> String -> IO ()
    bindAttribLocation :: Program -> AttribLocation -> String -> IO ()
    bindAttribLocation (Program GLuint
    program) (AttribLocation GLuint
    location) String
    name =
       String -> (Ptr GLchar -> IO ()) -> IO ()
    forall a. String -> (Ptr GLchar -> IO a) -> IO a
    withGLstring String
    name ((Ptr GLchar -> IO ()) -> IO ()) -> (Ptr GLchar -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $
          GLuint -> GLuint -> Ptr GLchar -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLuint -> GLuint -> Ptr GLchar -> m ()
    glBindAttribLocation GLuint
    program GLuint
    location

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

    activeAttribs :: Program -> GettableStateVar [(GLint,VariableType,String)]
    activeAttribs :: Program -> GettableStateVar [(GLint, VariableType, String)]
    activeAttribs =
       (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
    activeAttributes
          Program -> GettableStateVar GLint
    activeAttributeMaxLength
          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 ()
    glGetActiveAttrib
          GLuint -> VariableType
    unmarshalVariableType