    {-# OPTIONS_HADDOCK hide #-}
    --------------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.Texturing.TexParameter
    -- Copyright   :  (c) Sven Panne 2002-2019
    -- License     :  BSD3
    --
    -- Maintainer  :  Sven Panne <svenpanne@gmail.com>
    -- Stability   :  stable
    -- Portability :  portable
    --
    -- This is a purely internal module for getting\/setting texture parameters.
    --
    --------------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.Texturing.TexParameter (
       TexParameter(..), texParami, texParamf, texParamC4f, getTexParameteri
    ) where

    import Data.StateVar
    import Foreign.Marshal.Alloc
    import Foreign.Marshal.Utils
    import Foreign.Ptr
    import Foreign.Storable
    import Graphics.Rendering.OpenGL.GL.PeekPoke
    import Graphics.Rendering.OpenGL.GL.Texturing.TextureTarget
    import Graphics.Rendering.OpenGL.GL.VertexSpec
    import Graphics.GL

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

    data TexParameter =
         TextureMinFilter
       | TextureMagFilter
       | TextureWrapS
       | TextureWrapT
       | TextureWrapR
       | TextureBorderColor
       | TextureMinLOD
       | TextureMaxLOD
       | TextureBaseLevel
       | TextureMaxLevel
       | TexturePriority
       | TextureMaxAnisotropy
       | TextureCompare
       | TextureCompareOperator
       | TextureCompareFailValue
       | GenerateMipmap
       | TextureCompareMode
       | TextureCompareFunc
       | DepthTextureMode
       | TextureLODBias
       | TextureResident

    marshalTexParameter :: TexParameter -> GLenum
    marshalTexParameter :: TexParameter -> GLenum
    marshalTexParameter TexParameter
    x = case TexParameter
    x of
       TexParameter
    TextureMinFilter -> GLenum
    GL_TEXTURE_MIN_FILTER
       TexParameter
    TextureMagFilter -> GLenum
    GL_TEXTURE_MAG_FILTER
       TexParameter
    TextureWrapS -> GLenum
    GL_TEXTURE_WRAP_S
       TexParameter
    TextureWrapT -> GLenum
    GL_TEXTURE_WRAP_T
       TexParameter
    TextureWrapR -> GLenum
    GL_TEXTURE_WRAP_R
       TexParameter
    TextureBorderColor -> GLenum
    GL_TEXTURE_BORDER_COLOR
       TexParameter
    TextureMinLOD -> GLenum
    GL_TEXTURE_MIN_LOD
       TexParameter
    TextureMaxLOD -> GLenum
    GL_TEXTURE_MAX_LOD
       TexParameter
    TextureBaseLevel -> GLenum
    GL_TEXTURE_BASE_LEVEL
       TexParameter
    TextureMaxLevel -> GLenum
    GL_TEXTURE_MAX_LEVEL
       TexParameter
    TexturePriority -> GLenum
    GL_TEXTURE_PRIORITY
       TexParameter
    TextureMaxAnisotropy -> GLenum
    GL_TEXTURE_MAX_ANISOTROPY_EXT
       TexParameter
    TextureCompare -> GLenum
    GL_TEXTURE_COMPARE_SGIX
       TexParameter
    TextureCompareOperator -> GLenum
    GL_TEXTURE_COMPARE_OPERATOR_SGIX
       TexParameter
    TextureCompareFailValue -> GLenum
    GL_TEXTURE_COMPARE_FAIL_VALUE_ARB
       TexParameter
    GenerateMipmap -> GLenum
    GL_GENERATE_MIPMAP
       TexParameter
    TextureCompareMode -> GLenum
    GL_TEXTURE_COMPARE_MODE
       TexParameter
    TextureCompareFunc -> GLenum
    GL_TEXTURE_COMPARE_FUNC
       TexParameter
    DepthTextureMode -> GLenum
    GL_DEPTH_TEXTURE_MODE
       TexParameter
    TextureLODBias -> GLenum
    GL_TEXTURE_LOD_BIAS
       TexParameter
    TextureResident -> GLenum
    GL_TEXTURE_RESIDENT

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

    texParameter :: ParameterizedTextureTarget t
                 => (GLenum -> GLenum -> b -> IO ())
                 -> (a -> (b -> IO ()) -> IO ())
                 -> t -> TexParameter -> a -> IO ()
    texParameter :: forall t b a.
    ParameterizedTextureTarget t =>
    (GLenum -> GLenum -> b -> IO ())
    -> (a -> (b -> IO ()) -> IO ()) -> t -> TexParameter -> a -> IO ()
    texParameter GLenum -> GLenum -> b -> IO ()
    glTexParameter a -> (b -> IO ()) -> IO ()
    marshalAct t
    t TexParameter
    p a
    x =
       a -> (b -> IO ()) -> IO ()
    marshalAct a
    x ((b -> IO ()) -> IO ()) -> (b -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $
          GLenum -> GLenum -> b -> IO ()
    glTexParameter (t -> GLenum
    forall t. ParameterizedTextureTarget t => t -> GLenum
    marshalParameterizedTextureTarget t
    t) (TexParameter -> GLenum
    marshalTexParameter TexParameter
    p)

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

    getTexParameter :: (Storable b, ParameterizedTextureTarget t)
                    => (GLenum -> GLenum -> Ptr b -> IO ())
                    -> (b -> a)
                    -> t -> TexParameter -> IO a
    getTexParameter :: forall b t a.
    (Storable b, ParameterizedTextureTarget t) =>
    (GLenum -> GLenum -> Ptr b -> IO ())
    -> (b -> a) -> t -> TexParameter -> IO a
    getTexParameter GLenum -> GLenum -> Ptr b -> IO ()
    glGetTexParameter b -> a
    unmarshal t
    t TexParameter
    p =
       (Ptr b -> IO a) -> IO a
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr b -> IO a) -> IO a) -> (Ptr b -> IO a) -> IO a
    forall a b. (a -> b) -> a -> b
    $ \Ptr b
    buf -> do
         GLenum -> GLenum -> Ptr b -> IO ()
    glGetTexParameter (t -> GLenum
    forall t. ParameterizedTextureTarget t => t -> GLenum
    marshalParameterizedTextureTarget t
    t) (TexParameter -> GLenum
    marshalTexParameter TexParameter
    p) Ptr b
    buf
         (b -> a) -> Ptr b -> IO a
    forall a b. Storable a => (a -> b) -> Ptr a -> IO b
    peek1 b -> a
    unmarshal Ptr b
    buf

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

    m2a :: (a -> b) -> a -> (b -> IO ()) -> IO ()
    m2a :: forall a b. (a -> b) -> a -> (b -> IO ()) -> IO ()
    m2a a -> b
    marshal a
    x b -> IO ()
    act = b -> IO ()
    act (a -> b
    marshal a
    x)

    texParami :: ParameterizedTextureTarget t =>
       (GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
    texParami :: forall t a.
    ParameterizedTextureTarget t =>
    (GLint -> a) -> (a -> GLint) -> TexParameter -> t -> StateVar a
    texParami GLint -> a
    unmarshal a -> GLint
    marshal TexParameter
    p t
    t =
       IO a -> (a -> IO ()) -> StateVar a
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar
          ((GLenum -> GLenum -> Ptr GLint -> IO ())
    -> (GLint -> a) -> t -> TexParameter -> IO a
    forall b t a.
    (Storable b, ParameterizedTextureTarget t) =>
    (GLenum -> GLenum -> Ptr b -> IO ())
    -> (b -> a) -> t -> TexParameter -> IO a
    getTexParameter GLenum -> GLenum -> Ptr GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> Ptr GLint -> m ()
    glGetTexParameteriv GLint -> a
    unmarshal     t
    t TexParameter
    p)
          ((GLenum -> GLenum -> GLint -> IO ())
    -> (a -> (GLint -> IO ()) -> IO ())
    -> t
    -> TexParameter
    -> a
    -> IO ()
    forall t b a.
    ParameterizedTextureTarget t =>
    (GLenum -> GLenum -> b -> IO ())
    -> (a -> (b -> IO ()) -> IO ()) -> t -> TexParameter -> a -> IO ()
    texParameter    GLenum -> GLenum -> GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> GLint -> m ()
    glTexParameteri     ((a -> GLint) -> a -> (GLint -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> (b -> IO ()) -> IO ()
    m2a a -> GLint
    marshal) t
    t TexParameter
    p)

    texParamf :: ParameterizedTextureTarget t =>
       (GLfloat -> a) -> (a -> GLfloat) -> TexParameter -> t -> StateVar a
    texParamf :: forall t a.
    ParameterizedTextureTarget t =>
    (GLfloat -> a) -> (a -> GLfloat) -> TexParameter -> t -> StateVar a
    texParamf GLfloat -> a
    unmarshal a -> GLfloat
    marshal TexParameter
    p t
    t =
       IO a -> (a -> IO ()) -> StateVar a
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar
          ((GLenum -> GLenum -> Ptr GLfloat -> IO ())
    -> (GLfloat -> a) -> t -> TexParameter -> IO a
    forall b t a.
    (Storable b, ParameterizedTextureTarget t) =>
    (GLenum -> GLenum -> Ptr b -> IO ())
    -> (b -> a) -> t -> TexParameter -> IO a
    getTexParameter GLenum -> GLenum -> Ptr GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> Ptr GLfloat -> m ()
    glGetTexParameterfv GLfloat -> a
    unmarshal     t
    t TexParameter
    p)
          ((GLenum -> GLenum -> GLfloat -> IO ())
    -> (a -> (GLfloat -> IO ()) -> IO ())
    -> t
    -> TexParameter
    -> a
    -> IO ()
    forall t b a.
    ParameterizedTextureTarget t =>
    (GLenum -> GLenum -> b -> IO ())
    -> (a -> (b -> IO ()) -> IO ()) -> t -> TexParameter -> a -> IO ()
    texParameter    GLenum -> GLenum -> GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> GLfloat -> m ()
    glTexParameterf     ((a -> GLfloat) -> a -> (GLfloat -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> (b -> IO ()) -> IO ()
    m2a a -> GLfloat
    marshal) t
    t TexParameter
    p)

    texParamC4f :: ParameterizedTextureTarget t => TexParameter -> t -> StateVar (Color4 GLfloat)
    texParamC4f :: forall t.
    ParameterizedTextureTarget t =>
    TexParameter -> t -> StateVar (Color4 GLfloat)
    texParamC4f TexParameter
    p t
    t =
       IO (Color4 GLfloat)
    -> (Color4 GLfloat -> IO ()) -> StateVar (Color4 GLfloat)
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar
          ((GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ())
    -> (Color4 GLfloat -> Color4 GLfloat)
    -> t
    -> TexParameter
    -> IO (Color4 GLfloat)
    forall b t a.
    (Storable b, ParameterizedTextureTarget t) =>
    (GLenum -> GLenum -> Ptr b -> IO ())
    -> (b -> a) -> t -> TexParameter -> IO a
    getTexParameter GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ()
    glGetTexParameterC4f Color4 GLfloat -> Color4 GLfloat
    forall a. a -> a
    id   t
    t TexParameter
    p)
          ((GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ())
    -> (Color4 GLfloat -> (Ptr (Color4 GLfloat) -> IO ()) -> IO ())
    -> t
    -> TexParameter
    -> Color4 GLfloat
    -> IO ()
    forall t b a.
    ParameterizedTextureTarget t =>
    (GLenum -> GLenum -> b -> IO ())
    -> (a -> (b -> IO ()) -> IO ()) -> t -> TexParameter -> a -> IO ()
    texParameter    GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ()
    glTexParameterC4f    Color4 GLfloat -> (Ptr (Color4 GLfloat) -> IO ()) -> IO ()
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with t
    t TexParameter
    p)

    glTexParameterC4f :: GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ()
    glTexParameterC4f :: GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ()
    glTexParameterC4f GLenum
    target GLenum
    pname Ptr (Color4 GLfloat)
    ptr = GLenum -> GLenum -> Ptr GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> Ptr GLfloat -> m ()
    glTexParameterfv GLenum
    target GLenum
    pname (Ptr (Color4 GLfloat) -> Ptr GLfloat
    forall a b. Ptr a -> Ptr b
    castPtr Ptr (Color4 GLfloat)
    ptr)

    glGetTexParameterC4f :: GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ()
    glGetTexParameterC4f :: GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ()
    glGetTexParameterC4f GLenum
    target GLenum
    pname Ptr (Color4 GLfloat)
    ptr = GLenum -> GLenum -> Ptr GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> Ptr GLfloat -> m ()
    glGetTexParameterfv GLenum
    target GLenum
    pname (Ptr (Color4 GLfloat) -> Ptr GLfloat
    forall a b. Ptr a -> Ptr b
    castPtr Ptr (Color4 GLfloat)
    ptr)

    getTexParameteri :: ParameterizedTextureTarget t => (GLint -> a) -> t -> TexParameter -> IO a
    getTexParameteri :: forall t a.
    ParameterizedTextureTarget t =>
    (GLint -> a) -> t -> TexParameter -> IO a
    getTexParameteri = (GLenum -> GLenum -> Ptr GLint -> IO ())
    -> (GLint -> a) -> t -> TexParameter -> IO a
    forall b t a.
    (Storable b, ParameterizedTextureTarget t) =>
    (GLenum -> GLenum -> Ptr b -> IO ())
    -> (b -> a) -> t -> TexParameter -> IO a
    getTexParameter GLenum -> GLenum -> Ptr GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> Ptr GLint -> m ()
    glGetTexParameteriv