    --------------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.PixelRectangles.Convolution
    -- Copyright   :  (c) Sven Panne 2002-2019
    -- License     :  BSD3
    --
    -- Maintainer  :  Sven Panne <svenpanne@gmail.com>
    -- Stability   :  stable
    -- Portability :  portable
    --
    -- This module corresponds to a part of section 3.6.1 (Pixel Storage Modes) of
    -- the OpenGL 2.1 specs.
    --
    --------------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.PixelRectangles.Convolution (
       ConvolutionTarget(..), convolution,
       convolutionFilter1D, getConvolutionFilter1D,
       convolutionFilter2D, getConvolutionFilter2D,
       separableFilter2D, getSeparableFilter2D,
       copyConvolutionFilter1D, copyConvolutionFilter2D,
       convolutionWidth, convolutionHeight,
       maxConvolutionWidth, maxConvolutionHeight,
       ConvolutionBorderMode(..), convolutionBorderMode,
       convolutionFilterScale, convolutionFilterBias,
    ) where

    import Data.StateVar
    import Foreign.Marshal.Alloc
    import Foreign.Marshal.Utils
    import Foreign.Ptr
    import Foreign.Storable
    import Graphics.Rendering.OpenGL.GL.Capability
    import Graphics.Rendering.OpenGL.GL.CoordTrans
    import Graphics.Rendering.OpenGL.GL.PeekPoke
    import Graphics.Rendering.OpenGL.GL.PixelData
    import Graphics.Rendering.OpenGL.GL.Texturing.PixelInternalFormat
    import Graphics.Rendering.OpenGL.GL.VertexSpec
    import Graphics.Rendering.OpenGL.GLU.ErrorsInternal
    import Graphics.GL

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

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

    marshalConvolutionTarget :: ConvolutionTarget -> GLenum
    marshalConvolutionTarget :: ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    x = case ConvolutionTarget
    x of
       ConvolutionTarget
    Convolution1D -> GLenum
    GL_CONVOLUTION_1D
       ConvolutionTarget
    Convolution2D -> GLenum
    GL_CONVOLUTION_2D
       ConvolutionTarget
    Separable2D -> GLenum
    GL_SEPARABLE_2D

    convolutionTargetToEnableCap :: ConvolutionTarget -> EnableCap
    convolutionTargetToEnableCap :: ConvolutionTarget -> EnableCap
    convolutionTargetToEnableCap ConvolutionTarget
    x = case ConvolutionTarget
    x of
       ConvolutionTarget
    Convolution1D -> EnableCap
    CapConvolution1D
       ConvolutionTarget
    Convolution2D -> EnableCap
    CapConvolution2D
       ConvolutionTarget
    Separable2D -> EnableCap
    CapSeparable2D

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

    convolution :: ConvolutionTarget -> StateVar Capability
    convolution :: ConvolutionTarget -> StateVar Capability
    convolution = EnableCap -> StateVar Capability
    makeCapability (EnableCap -> StateVar Capability)
    -> (ConvolutionTarget -> EnableCap)
    -> ConvolutionTarget
    -> StateVar Capability
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ConvolutionTarget -> EnableCap
    convolutionTargetToEnableCap

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

    convolutionFilter1D :: PixelInternalFormat -> GLsizei -> PixelData a -> IO ()
    convolutionFilter1D :: forall a. PixelInternalFormat -> GLint -> PixelData a -> IO ()
    convolutionFilter1D PixelInternalFormat
    int GLint
    w PixelData a
    pd =
       PixelData a -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. PixelData a -> (GLenum -> GLenum -> Ptr a -> b) -> b
    withPixelData PixelData a
    pd ((GLenum -> GLenum -> Ptr a -> IO ()) -> IO ())
    -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $
          GLenum -> GLenum -> GLint -> GLenum -> GLenum -> Ptr a -> IO ()
    forall (m :: * -> *) a.
    MonadIO m =>
    GLenum -> GLenum -> GLint -> GLenum -> GLenum -> Ptr a -> m ()
    glConvolutionFilter1D
             (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    Convolution1D)
             (PixelInternalFormat -> GLenum
    marshalPixelInternalFormat' PixelInternalFormat
    int) GLint
    w

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

    getConvolutionFilter1D :: PixelData a -> IO ()
    getConvolutionFilter1D :: forall a. PixelData a -> IO ()
    getConvolutionFilter1D = ConvolutionTarget -> PixelData a -> IO ()
    forall a. ConvolutionTarget -> PixelData a -> IO ()
    getConvolutionFilter ConvolutionTarget
    Convolution1D

    getConvolutionFilter :: ConvolutionTarget -> PixelData a -> IO ()
    getConvolutionFilter :: forall a. ConvolutionTarget -> PixelData a -> IO ()
    getConvolutionFilter ConvolutionTarget
    t PixelData a
    pd =
       PixelData a -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. PixelData a -> (GLenum -> GLenum -> Ptr a -> b) -> b
    withPixelData PixelData a
    pd ((GLenum -> GLenum -> Ptr a -> IO ()) -> IO ())
    -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ GLenum -> GLenum -> GLenum -> Ptr a -> IO ()
    forall (m :: * -> *) a.
    MonadIO m =>
    GLenum -> GLenum -> GLenum -> Ptr a -> m ()
    glGetConvolutionFilter (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    t)

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

    convolutionFilter2D :: PixelInternalFormat -> Size -> PixelData a -> IO ()
    convolutionFilter2D :: forall a. PixelInternalFormat -> Size -> PixelData a -> IO ()
    convolutionFilter2D PixelInternalFormat
    int (Size GLint
    w GLint
    h) PixelData a
    pd =
       PixelData a -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. PixelData a -> (GLenum -> GLenum -> Ptr a -> b) -> b
    withPixelData PixelData a
    pd ((GLenum -> GLenum -> Ptr a -> IO ()) -> IO ())
    -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $
          GLenum
    -> GLenum -> GLint -> GLint -> GLenum -> GLenum -> Ptr a -> IO ()
    forall (m :: * -> *) a.
    MonadIO m =>
    GLenum
    -> GLenum -> GLint -> GLint -> GLenum -> GLenum -> Ptr a -> m ()
    glConvolutionFilter2D
             (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    Convolution2D)
             (PixelInternalFormat -> GLenum
    marshalPixelInternalFormat' PixelInternalFormat
    int) GLint
    w GLint
    h

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

    getConvolutionFilter2D :: PixelData a -> IO ()
    getConvolutionFilter2D :: forall a. PixelData a -> IO ()
    getConvolutionFilter2D = ConvolutionTarget -> PixelData a -> IO ()
    forall a. ConvolutionTarget -> PixelData a -> IO ()
    getConvolutionFilter ConvolutionTarget
    Convolution2D

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

    separableFilter2D ::
       PixelInternalFormat -> Size -> PixelData a -> PixelData a -> IO ()
    separableFilter2D :: forall a.
    PixelInternalFormat -> Size -> PixelData a -> PixelData a -> IO ()
    separableFilter2D PixelInternalFormat
    int (Size GLint
    w GLint
    h) PixelData a
    pdRow PixelData a
    pdCol =
       PixelData a -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. PixelData a -> (GLenum -> GLenum -> Ptr a -> b) -> b
    withPixelData PixelData a
    pdRow ((GLenum -> GLenum -> Ptr a -> IO ()) -> IO ())
    -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \GLenum
    f1 GLenum
    d1 Ptr a
    p1 ->
          PixelData a -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. PixelData a -> (GLenum -> GLenum -> Ptr a -> b) -> b
    withPixelData PixelData a
    pdCol ((GLenum -> GLenum -> Ptr a -> IO ()) -> IO ())
    -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \GLenum
    f2 GLenum
    d2 Ptr a
    p2 ->
             if GLenum
    f1 GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    f2 Bool -> Bool -> Bool
    && GLenum
    d1 GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    d2
                then GLenum
    -> GLenum
    -> GLint
    -> GLint
    -> GLenum
    -> GLenum
    -> Ptr a
    -> Ptr a
    -> IO ()
    forall (m :: * -> *) a b.
    MonadIO m =>
    GLenum
    -> GLenum
    -> GLint
    -> GLint
    -> GLenum
    -> GLenum
    -> Ptr a
    -> Ptr b
    -> m ()
    glSeparableFilter2D
                        (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    Separable2D)
                        (PixelInternalFormat -> GLenum
    marshalPixelInternalFormat' PixelInternalFormat
    int) GLint
    w GLint
    h GLenum
    f1 GLenum
    d1 Ptr a
    p1 Ptr a
    p2
                else IO ()
    recordInvalidValue

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

    getSeparableFilter2D :: PixelData a -> PixelData a -> IO ()
    getSeparableFilter2D :: forall a. PixelData a -> PixelData a -> IO ()
    getSeparableFilter2D PixelData a
    pdRow PixelData a
    pdCol =
       PixelData a -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. PixelData a -> (GLenum -> GLenum -> Ptr a -> b) -> b
    withPixelData PixelData a
    pdRow ((GLenum -> GLenum -> Ptr a -> IO ()) -> IO ())
    -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \GLenum
    f1 GLenum
    d1 Ptr a
    p1 ->
          PixelData a -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. PixelData a -> (GLenum -> GLenum -> Ptr a -> b) -> b
    withPixelData PixelData a
    pdCol ((GLenum -> GLenum -> Ptr a -> IO ()) -> IO ())
    -> (GLenum -> GLenum -> Ptr a -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \GLenum
    f2 GLenum
    d2 Ptr a
    p2 ->
             if GLenum
    f1 GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    f2 Bool -> Bool -> Bool
    && GLenum
    d1 GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    d2
                then GLenum
    -> GLenum -> GLenum -> Ptr a -> Ptr a -> Ptr (ZonkAny 0) -> IO ()
    forall (m :: * -> *) a b c.
    MonadIO m =>
    GLenum -> GLenum -> GLenum -> Ptr a -> Ptr b -> Ptr c -> m ()
    glGetSeparableFilter
                        (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    Separable2D) GLenum
    f1 GLenum
    d1 Ptr a
    p1 Ptr a
    p2 Ptr (ZonkAny 0)
    forall a. Ptr a
    nullPtr
                else IO ()
    recordInvalidValue

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

    copyConvolutionFilter1D :: PixelInternalFormat -> Position -> GLsizei -> IO ()
    copyConvolutionFilter1D :: PixelInternalFormat -> Position -> GLint -> IO ()
    copyConvolutionFilter1D PixelInternalFormat
    int (Position GLint
    x GLint
    y) =
       GLenum -> GLenum -> GLint -> GLint -> GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> GLint -> GLint -> GLint -> m ()
    glCopyConvolutionFilter1D
          (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    Convolution1D) (PixelInternalFormat -> GLenum
    marshalPixelInternalFormat' PixelInternalFormat
    int)
          GLint
    x GLint
    y

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

    copyConvolutionFilter2D :: PixelInternalFormat -> Position -> Size -> IO ()
    copyConvolutionFilter2D :: PixelInternalFormat -> Position -> Size -> IO ()
    copyConvolutionFilter2D PixelInternalFormat
    int (Position GLint
    x GLint
    y) (Size GLint
    w GLint
    h) =
       GLenum -> GLenum -> GLint -> GLint -> GLint -> GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> GLint -> GLint -> GLint -> GLint -> m ()
    glCopyConvolutionFilter2D
          (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    Convolution2D) (PixelInternalFormat -> GLenum
    marshalPixelInternalFormat' PixelInternalFormat
    int)
          GLint
    x GLint
    y GLint
    w GLint
    h

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

    data ConvolutionParameter =
         ConvolutionBorderColor
       | ConvolutionBorderMode
       | ConvolutionFilterScale
       | ConvolutionFilterBias
       | ConvolutionFormat
       | ConvolutionWidth
       | ConvolutionHeight
       | MaxConvolutionWidth
       | MaxConvolutionHeight
       deriving ( ConvolutionParameter -> ConvolutionParameter -> Bool
    (ConvolutionParameter -> ConvolutionParameter -> Bool)
    -> (ConvolutionParameter -> ConvolutionParameter -> Bool)
    -> Eq ConvolutionParameter
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ConvolutionParameter -> ConvolutionParameter -> Bool
    == :: ConvolutionParameter -> ConvolutionParameter -> Bool
    $c/= :: ConvolutionParameter -> ConvolutionParameter -> Bool
    /= :: ConvolutionParameter -> ConvolutionParameter -> Bool
    Eq, Eq ConvolutionParameter
    Eq ConvolutionParameter =>
    (ConvolutionParameter -> ConvolutionParameter -> Ordering)
    -> (ConvolutionParameter -> ConvolutionParameter -> Bool)
    -> (ConvolutionParameter -> ConvolutionParameter -> Bool)
    -> (ConvolutionParameter -> ConvolutionParameter -> Bool)
    -> (ConvolutionParameter -> ConvolutionParameter -> Bool)
    -> (ConvolutionParameter
        -> ConvolutionParameter -> ConvolutionParameter)
    -> (ConvolutionParameter
        -> ConvolutionParameter -> ConvolutionParameter)
    -> Ord ConvolutionParameter
    ConvolutionParameter -> ConvolutionParameter -> Bool
    ConvolutionParameter -> ConvolutionParameter -> Ordering
    ConvolutionParameter
    -> ConvolutionParameter -> ConvolutionParameter
    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 :: ConvolutionParameter -> ConvolutionParameter -> Ordering
    compare :: ConvolutionParameter -> ConvolutionParameter -> Ordering
    $c< :: ConvolutionParameter -> ConvolutionParameter -> Bool
    < :: ConvolutionParameter -> ConvolutionParameter -> Bool
    $c<= :: ConvolutionParameter -> ConvolutionParameter -> Bool
    <= :: ConvolutionParameter -> ConvolutionParameter -> Bool
    $c> :: ConvolutionParameter -> ConvolutionParameter -> Bool
    > :: ConvolutionParameter -> ConvolutionParameter -> Bool
    $c>= :: ConvolutionParameter -> ConvolutionParameter -> Bool
    >= :: ConvolutionParameter -> ConvolutionParameter -> Bool
    $cmax :: ConvolutionParameter
    -> ConvolutionParameter -> ConvolutionParameter
    max :: ConvolutionParameter
    -> ConvolutionParameter -> ConvolutionParameter
    $cmin :: ConvolutionParameter
    -> ConvolutionParameter -> ConvolutionParameter
    min :: ConvolutionParameter
    -> ConvolutionParameter -> ConvolutionParameter
    Ord, Int -> ConvolutionParameter -> ShowS
    [ConvolutionParameter] -> ShowS
    ConvolutionParameter -> String
    (Int -> ConvolutionParameter -> ShowS)
    -> (ConvolutionParameter -> String)
    -> ([ConvolutionParameter] -> ShowS)
    -> Show ConvolutionParameter
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ConvolutionParameter -> ShowS
    showsPrec :: Int -> ConvolutionParameter -> ShowS
    $cshow :: ConvolutionParameter -> String
    show :: ConvolutionParameter -> String
    $cshowList :: [ConvolutionParameter] -> ShowS
    showList :: [ConvolutionParameter] -> ShowS
    Show )

    marshalConvolutionParameter :: ConvolutionParameter -> GLenum
    marshalConvolutionParameter :: ConvolutionParameter -> GLenum
    marshalConvolutionParameter ConvolutionParameter
    x = case ConvolutionParameter
    x of
       ConvolutionParameter
    ConvolutionBorderColor -> GLenum
    GL_CONVOLUTION_BORDER_COLOR
       ConvolutionParameter
    ConvolutionBorderMode -> GLenum
    GL_CONVOLUTION_BORDER_MODE
       ConvolutionParameter
    ConvolutionFilterScale -> GLenum
    GL_CONVOLUTION_FILTER_SCALE
       ConvolutionParameter
    ConvolutionFilterBias -> GLenum
    GL_CONVOLUTION_FILTER_BIAS
       ConvolutionParameter
    ConvolutionFormat -> GLenum
    GL_CONVOLUTION_FORMAT
       ConvolutionParameter
    ConvolutionWidth -> GLenum
    GL_CONVOLUTION_WIDTH
       ConvolutionParameter
    ConvolutionHeight -> GLenum
    GL_CONVOLUTION_HEIGHT
       ConvolutionParameter
    MaxConvolutionWidth -> GLenum
    GL_MAX_CONVOLUTION_WIDTH
       ConvolutionParameter
    MaxConvolutionHeight -> GLenum
    GL_MAX_CONVOLUTION_HEIGHT

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

    convolutionWidth :: ConvolutionTarget -> GettableStateVar GLsizei
    convolutionWidth :: ConvolutionTarget -> GettableStateVar GLint
    convolutionWidth ConvolutionTarget
    t = ConvolutionTarget -> ConvolutionParameter -> GettableStateVar GLint
    convolutionParameteri ConvolutionTarget
    t ConvolutionParameter
    ConvolutionWidth

    convolutionHeight :: ConvolutionTarget -> GettableStateVar GLsizei
    convolutionHeight :: ConvolutionTarget -> GettableStateVar GLint
    convolutionHeight ConvolutionTarget
    t = ConvolutionTarget -> ConvolutionParameter -> GettableStateVar GLint
    convolutionParameteri ConvolutionTarget
    t ConvolutionParameter
    ConvolutionHeight

    maxConvolutionWidth :: ConvolutionTarget -> GettableStateVar GLsizei
    maxConvolutionWidth :: ConvolutionTarget -> GettableStateVar GLint
    maxConvolutionWidth ConvolutionTarget
    t = ConvolutionTarget -> ConvolutionParameter -> GettableStateVar GLint
    convolutionParameteri ConvolutionTarget
    t ConvolutionParameter
    MaxConvolutionWidth

    maxConvolutionHeight :: ConvolutionTarget -> GettableStateVar GLsizei
    maxConvolutionHeight :: ConvolutionTarget -> GettableStateVar GLint
    maxConvolutionHeight ConvolutionTarget
    t = ConvolutionTarget -> ConvolutionParameter -> GettableStateVar GLint
    convolutionParameteri ConvolutionTarget
    t ConvolutionParameter
    MaxConvolutionHeight

    convolutionParameteri ::
       ConvolutionTarget -> ConvolutionParameter -> GettableStateVar GLsizei
    convolutionParameteri :: ConvolutionTarget -> ConvolutionParameter -> GettableStateVar GLint
    convolutionParameteri ConvolutionTarget
    t ConvolutionParameter
    p =
       GettableStateVar GLint -> GettableStateVar GLint
    forall a. IO a -> IO a
    makeGettableStateVar ((GLint -> GLint)
    -> ConvolutionTarget
    -> ConvolutionParameter
    -> GettableStateVar GLint
    forall a.
    (GLint -> a) -> ConvolutionTarget -> ConvolutionParameter -> IO a
    getConvolutionParameteri GLint -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral ConvolutionTarget
    t ConvolutionParameter
    p)

    getConvolutionParameteri ::
       (GLint -> a) -> ConvolutionTarget -> ConvolutionParameter -> IO a
    getConvolutionParameteri :: forall a.
    (GLint -> a) -> ConvolutionTarget -> ConvolutionParameter -> IO a
    getConvolutionParameteri GLint -> a
    f ConvolutionTarget
    t ConvolutionParameter
    p =
       GLint -> (Ptr GLint -> IO a) -> IO a
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with GLint
    0 ((Ptr GLint -> IO a) -> IO a) -> (Ptr GLint -> IO a) -> IO a
    forall a b. (a -> b) -> a -> b
    $ \Ptr GLint
    buf -> do
          GLenum -> GLenum -> Ptr GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> Ptr GLint -> m ()
    glGetConvolutionParameteriv
             (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    t) (ConvolutionParameter -> GLenum
    marshalConvolutionParameter ConvolutionParameter
    p) Ptr GLint
    buf
          (GLint -> a) -> Ptr GLint -> IO a
    forall a b. Storable a => (a -> b) -> Ptr a -> IO b
    peek1 GLint -> a
    f Ptr GLint
    buf

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

    data ConvolutionBorderMode' =
         Reduce'
       | ConstantBorder'
       | ReplicateBorder'

    marshalConvolutionBorderMode' :: ConvolutionBorderMode' -> GLint
    marshalConvolutionBorderMode' :: ConvolutionBorderMode' -> GLint
    marshalConvolutionBorderMode' ConvolutionBorderMode'
    x = GLenum -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (GLenum -> GLint) -> GLenum -> GLint
    forall a b. (a -> b) -> a -> b
    $ case ConvolutionBorderMode'
    x of
       ConvolutionBorderMode'
    Reduce' -> GLenum
    GL_REDUCE
       ConvolutionBorderMode'
    ConstantBorder' -> GLenum
    GL_CONSTANT_BORDER
       ConvolutionBorderMode'
    ReplicateBorder' -> GLenum
    GL_REPLICATE_BORDER

    unmarshalConvolutionBorderMode' :: GLint -> ConvolutionBorderMode'
    unmarshalConvolutionBorderMode' :: GLint -> ConvolutionBorderMode'
    unmarshalConvolutionBorderMode' GLint
    x
       | GLenum
    y GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_REDUCE = ConvolutionBorderMode'
    Reduce'
       | GLenum
    y GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_CONSTANT_BORDER = ConvolutionBorderMode'
    ConstantBorder'
       | GLenum
    y GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_REPLICATE_BORDER = ConvolutionBorderMode'
    ReplicateBorder'
       | Bool
    otherwise = String -> ConvolutionBorderMode'
    forall a. HasCallStack => String -> a
    error (String
    "unmarshalConvolutionBorderMode': illegal value " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ GLint -> String
    forall a. Show a => a -> String
    show GLint
    x)
       where y :: GLenum
    y = GLint -> GLenum
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral GLint
    x

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

    data ConvolutionBorderMode =
         Reduce
       | ConstantBorder (Color4 GLfloat)
       | ReplicateBorder
       deriving ( ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    (ConvolutionBorderMode -> ConvolutionBorderMode -> Bool)
    -> (ConvolutionBorderMode -> ConvolutionBorderMode -> Bool)
    -> Eq ConvolutionBorderMode
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    == :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    $c/= :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    /= :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    Eq, Eq ConvolutionBorderMode
    Eq ConvolutionBorderMode =>
    (ConvolutionBorderMode -> ConvolutionBorderMode -> Ordering)
    -> (ConvolutionBorderMode -> ConvolutionBorderMode -> Bool)
    -> (ConvolutionBorderMode -> ConvolutionBorderMode -> Bool)
    -> (ConvolutionBorderMode -> ConvolutionBorderMode -> Bool)
    -> (ConvolutionBorderMode -> ConvolutionBorderMode -> Bool)
    -> (ConvolutionBorderMode
        -> ConvolutionBorderMode -> ConvolutionBorderMode)
    -> (ConvolutionBorderMode
        -> ConvolutionBorderMode -> ConvolutionBorderMode)
    -> Ord ConvolutionBorderMode
    ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    ConvolutionBorderMode -> ConvolutionBorderMode -> Ordering
    ConvolutionBorderMode
    -> ConvolutionBorderMode -> ConvolutionBorderMode
    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 :: ConvolutionBorderMode -> ConvolutionBorderMode -> Ordering
    compare :: ConvolutionBorderMode -> ConvolutionBorderMode -> Ordering
    $c< :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    < :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    $c<= :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    <= :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    $c> :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    > :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    $c>= :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    >= :: ConvolutionBorderMode -> ConvolutionBorderMode -> Bool
    $cmax :: ConvolutionBorderMode
    -> ConvolutionBorderMode -> ConvolutionBorderMode
    max :: ConvolutionBorderMode
    -> ConvolutionBorderMode -> ConvolutionBorderMode
    $cmin :: ConvolutionBorderMode
    -> ConvolutionBorderMode -> ConvolutionBorderMode
    min :: ConvolutionBorderMode
    -> ConvolutionBorderMode -> ConvolutionBorderMode
    Ord, Int -> ConvolutionBorderMode -> ShowS
    [ConvolutionBorderMode] -> ShowS
    ConvolutionBorderMode -> String
    (Int -> ConvolutionBorderMode -> ShowS)
    -> (ConvolutionBorderMode -> String)
    -> ([ConvolutionBorderMode] -> ShowS)
    -> Show ConvolutionBorderMode
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ConvolutionBorderMode -> ShowS
    showsPrec :: Int -> ConvolutionBorderMode -> ShowS
    $cshow :: ConvolutionBorderMode -> String
    show :: ConvolutionBorderMode -> String
    $cshowList :: [ConvolutionBorderMode] -> ShowS
    showList :: [ConvolutionBorderMode] -> ShowS
    Show )

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

    convolutionBorderMode :: ConvolutionTarget -> StateVar ConvolutionBorderMode
    convolutionBorderMode :: ConvolutionTarget -> StateVar ConvolutionBorderMode
    convolutionBorderMode ConvolutionTarget
    t =
       IO ConvolutionBorderMode
    -> (ConvolutionBorderMode -> IO ())
    -> StateVar ConvolutionBorderMode
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar (ConvolutionTarget -> IO ConvolutionBorderMode
    getConvolutionBorderMode ConvolutionTarget
    t) (ConvolutionTarget -> ConvolutionBorderMode -> IO ()
    setConvolutionBorderMode ConvolutionTarget
    t)

    getConvolutionBorderMode :: ConvolutionTarget -> IO ConvolutionBorderMode
    getConvolutionBorderMode :: ConvolutionTarget -> IO ConvolutionBorderMode
    getConvolutionBorderMode ConvolutionTarget
    t = do
       mode <- (GLint -> ConvolutionBorderMode')
    -> ConvolutionTarget
    -> ConvolutionParameter
    -> IO ConvolutionBorderMode'
    forall a.
    (GLint -> a) -> ConvolutionTarget -> ConvolutionParameter -> IO a
    getConvolutionParameteri
                  GLint -> ConvolutionBorderMode'
    unmarshalConvolutionBorderMode' ConvolutionTarget
    t ConvolutionParameter
    ConvolutionBorderMode
       case mode of
          ConvolutionBorderMode'
    Reduce' -> ConvolutionBorderMode -> IO ConvolutionBorderMode
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ConvolutionBorderMode
    Reduce
          ConvolutionBorderMode'
    ConstantBorder' -> do
             c <- ConvolutionTarget -> ConvolutionParameter -> IO (Color4 GLfloat)
    getConvolutionParameterC4f ConvolutionTarget
    t ConvolutionParameter
    ConvolutionBorderColor
             return $ ConstantBorder c
          ConvolutionBorderMode'
    ReplicateBorder' -> ConvolutionBorderMode -> IO ConvolutionBorderMode
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ConvolutionBorderMode
    ReplicateBorder

    setConvolutionBorderMode :: ConvolutionTarget -> ConvolutionBorderMode -> IO ()
    setConvolutionBorderMode :: ConvolutionTarget -> ConvolutionBorderMode -> IO ()
    setConvolutionBorderMode ConvolutionTarget
    t ConvolutionBorderMode
    mode = do
       let setBM :: ConvolutionBorderMode' -> IO ()
    setBM = (ConvolutionBorderMode' -> GLint)
    -> ConvolutionTarget
    -> ConvolutionParameter
    -> ConvolutionBorderMode'
    -> IO ()
    forall a.
    (a -> GLint)
    -> ConvolutionTarget -> ConvolutionParameter -> a -> IO ()
    setConvolutionParameteri
                      ConvolutionBorderMode' -> GLint
    marshalConvolutionBorderMode' ConvolutionTarget
    t ConvolutionParameter
    ConvolutionBorderMode
       case ConvolutionBorderMode
    mode of
          ConvolutionBorderMode
    Reduce -> ConvolutionBorderMode' -> IO ()
    setBM ConvolutionBorderMode'
    Reduce'
          ConstantBorder Color4 GLfloat
    c -> do
             ConvolutionBorderMode' -> IO ()
    setBM ConvolutionBorderMode'
    ConstantBorder'
             ConvolutionTarget
    -> ConvolutionParameter -> Color4 GLfloat -> IO ()
    convolutionParameterC4f ConvolutionTarget
    t ConvolutionParameter
    ConvolutionBorderColor Color4 GLfloat
    c
          ConvolutionBorderMode
    ReplicateBorder -> ConvolutionBorderMode' -> IO ()
    setBM ConvolutionBorderMode'
    ReplicateBorder'

    setConvolutionParameteri ::
       (a -> GLint) -> ConvolutionTarget -> ConvolutionParameter -> a -> IO ()
    setConvolutionParameteri :: forall a.
    (a -> GLint)
    -> ConvolutionTarget -> ConvolutionParameter -> a -> IO ()
    setConvolutionParameteri a -> GLint
    f ConvolutionTarget
    t ConvolutionParameter
    p a
    x =
       GLenum -> GLenum -> GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> GLint -> m ()
    glConvolutionParameteri
          (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    t) (ConvolutionParameter -> GLenum
    marshalConvolutionParameter ConvolutionParameter
    p) (a -> GLint
    f a
    x)

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

    convolutionFilterScale :: ConvolutionTarget -> StateVar (Color4 GLfloat)
    convolutionFilterScale :: ConvolutionTarget -> StateVar (Color4 GLfloat)
    convolutionFilterScale = ConvolutionParameter
    -> ConvolutionTarget -> StateVar (Color4 GLfloat)
    convolutionC4f ConvolutionParameter
    ConvolutionFilterScale

    convolutionFilterBias :: ConvolutionTarget -> StateVar (Color4 GLfloat)
    convolutionFilterBias :: ConvolutionTarget -> StateVar (Color4 GLfloat)
    convolutionFilterBias = ConvolutionParameter
    -> ConvolutionTarget -> StateVar (Color4 GLfloat)
    convolutionC4f ConvolutionParameter
    ConvolutionFilterBias

    convolutionC4f ::
       ConvolutionParameter -> ConvolutionTarget -> StateVar (Color4 GLfloat)
    convolutionC4f :: ConvolutionParameter
    -> ConvolutionTarget -> StateVar (Color4 GLfloat)
    convolutionC4f ConvolutionParameter
    p ConvolutionTarget
    t =
       IO (Color4 GLfloat)
    -> (Color4 GLfloat -> IO ()) -> StateVar (Color4 GLfloat)
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar (ConvolutionTarget -> ConvolutionParameter -> IO (Color4 GLfloat)
    getConvolutionParameterC4f ConvolutionTarget
    t ConvolutionParameter
    p) (ConvolutionTarget
    -> ConvolutionParameter -> Color4 GLfloat -> IO ()
    convolutionParameterC4f ConvolutionTarget
    t ConvolutionParameter
    p)

    getConvolutionParameterC4f ::
       ConvolutionTarget -> ConvolutionParameter -> IO (Color4 GLfloat)
    getConvolutionParameterC4f :: ConvolutionTarget -> ConvolutionParameter -> IO (Color4 GLfloat)
    getConvolutionParameterC4f ConvolutionTarget
    t ConvolutionParameter
    p =
       (Ptr (Color4 GLfloat) -> IO (Color4 GLfloat))
    -> IO (Color4 GLfloat)
    forall a b. Storable a => (Ptr a -> IO b) -> IO b
    alloca ((Ptr (Color4 GLfloat) -> IO (Color4 GLfloat))
     -> IO (Color4 GLfloat))
    -> (Ptr (Color4 GLfloat) -> IO (Color4 GLfloat))
    -> IO (Color4 GLfloat)
    forall a b. (a -> b) -> a -> b
    $ \Ptr (Color4 GLfloat)
    buf -> do
          GLenum -> GLenum -> Ptr GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> Ptr GLfloat -> m ()
    glGetConvolutionParameterfv
             (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    t) (ConvolutionParameter -> GLenum
    marshalConvolutionParameter ConvolutionParameter
    p) (Ptr (Color4 GLfloat) -> Ptr GLfloat
    forall a b. Ptr a -> Ptr b
    castPtr Ptr (Color4 GLfloat)
    buf)
          Ptr (Color4 GLfloat) -> IO (Color4 GLfloat)
    forall a. Storable a => Ptr a -> IO a
    peek Ptr (Color4 GLfloat)
    buf

    convolutionParameterC4f ::
       ConvolutionTarget -> ConvolutionParameter -> Color4 GLfloat -> IO ()
    convolutionParameterC4f :: ConvolutionTarget
    -> ConvolutionParameter -> Color4 GLfloat -> IO ()
    convolutionParameterC4f ConvolutionTarget
    t ConvolutionParameter
    p Color4 GLfloat
    c =
       Color4 GLfloat -> (Ptr (Color4 GLfloat) -> IO ()) -> IO ()
    forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
    with Color4 GLfloat
    c ((Ptr (Color4 GLfloat) -> IO ()) -> IO ())
    -> (Ptr (Color4 GLfloat) -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr (Color4 GLfloat)
    ptr ->
          GLenum -> GLenum -> Ptr GLfloat -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> Ptr GLfloat -> m ()
    glConvolutionParameterfv
             (ConvolutionTarget -> GLenum
    marshalConvolutionTarget ConvolutionTarget
    t) (ConvolutionParameter -> GLenum
    marshalConvolutionParameter ConvolutionParameter
    p) (Ptr (Color4 GLfloat) -> Ptr GLfloat
    forall a b. Ptr a -> Ptr b
    castPtr Ptr (Color4 GLfloat)
    ptr)