    --------------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.PixelRectangles.ColorTable
    -- 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.ColorTable (
       ColorTableStage(..), colorTableStage,
       Proxy(..), ColorTable(..), PixelInternalFormat(..),
       colorTable, getColorTable, copyColorTable, colorSubTable, copyColorSubTable,
       colorTableScale, colorTableBias, colorTableFormat, colorTableWidth,
       colorTableRGBASizes, colorTableLuminanceSize, colorTableIntesitySize,
    ) 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 ColorTableStage =
         ColorTableStage
       | PostConvolutionColorTableStage
       | PostColorMatrixColorTableStage
       | TextureColorTableStage
       deriving ( ColorTableStage -> ColorTableStage -> Bool
    (ColorTableStage -> ColorTableStage -> Bool)
    -> (ColorTableStage -> ColorTableStage -> Bool)
    -> Eq ColorTableStage
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ColorTableStage -> ColorTableStage -> Bool
    == :: ColorTableStage -> ColorTableStage -> Bool
    $c/= :: ColorTableStage -> ColorTableStage -> Bool
    /= :: ColorTableStage -> ColorTableStage -> Bool
    Eq, Eq ColorTableStage
    Eq ColorTableStage =>
    (ColorTableStage -> ColorTableStage -> Ordering)
    -> (ColorTableStage -> ColorTableStage -> Bool)
    -> (ColorTableStage -> ColorTableStage -> Bool)
    -> (ColorTableStage -> ColorTableStage -> Bool)
    -> (ColorTableStage -> ColorTableStage -> Bool)
    -> (ColorTableStage -> ColorTableStage -> ColorTableStage)
    -> (ColorTableStage -> ColorTableStage -> ColorTableStage)
    -> Ord ColorTableStage
    ColorTableStage -> ColorTableStage -> Bool
    ColorTableStage -> ColorTableStage -> Ordering
    ColorTableStage -> ColorTableStage -> ColorTableStage
    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 :: ColorTableStage -> ColorTableStage -> Ordering
    compare :: ColorTableStage -> ColorTableStage -> Ordering
    $c< :: ColorTableStage -> ColorTableStage -> Bool
    < :: ColorTableStage -> ColorTableStage -> Bool
    $c<= :: ColorTableStage -> ColorTableStage -> Bool
    <= :: ColorTableStage -> ColorTableStage -> Bool
    $c> :: ColorTableStage -> ColorTableStage -> Bool
    > :: ColorTableStage -> ColorTableStage -> Bool
    $c>= :: ColorTableStage -> ColorTableStage -> Bool
    >= :: ColorTableStage -> ColorTableStage -> Bool
    $cmax :: ColorTableStage -> ColorTableStage -> ColorTableStage
    max :: ColorTableStage -> ColorTableStage -> ColorTableStage
    $cmin :: ColorTableStage -> ColorTableStage -> ColorTableStage
    min :: ColorTableStage -> ColorTableStage -> ColorTableStage
    Ord, Int -> ColorTableStage -> ShowS
    [ColorTableStage] -> ShowS
    ColorTableStage -> String
    (Int -> ColorTableStage -> ShowS)
    -> (ColorTableStage -> String)
    -> ([ColorTableStage] -> ShowS)
    -> Show ColorTableStage
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ColorTableStage -> ShowS
    showsPrec :: Int -> ColorTableStage -> ShowS
    $cshow :: ColorTableStage -> String
    show :: ColorTableStage -> String
    $cshowList :: [ColorTableStage] -> ShowS
    showList :: [ColorTableStage] -> ShowS
    Show )

    colorTableStageToColorTable :: ColorTableStage -> ColorTable
    colorTableStageToColorTable :: ColorTableStage -> ColorTable
    colorTableStageToColorTable ColorTableStage
    x = case ColorTableStage
    x of
       ColorTableStage
    ColorTableStage -> ColorTable
    ColorTable
       ColorTableStage
    PostConvolutionColorTableStage -> ColorTable
    PostConvolutionColorTable
       ColorTableStage
    PostColorMatrixColorTableStage -> ColorTable
    PostColorMatrixColorTable
       ColorTableStage
    TextureColorTableStage -> ColorTable
    TextureColorTable

    colorTableStageToEnableCap :: ColorTableStage -> EnableCap
    colorTableStageToEnableCap :: ColorTableStage -> EnableCap
    colorTableStageToEnableCap ColorTableStage
    x = case ColorTableStage
    x of
       ColorTableStage
    ColorTableStage -> EnableCap
    CapColorTable
       ColorTableStage
    PostConvolutionColorTableStage -> EnableCap
    CapPostConvolutionColorTable
       ColorTableStage
    PostColorMatrixColorTableStage -> EnableCap
    CapPostColorMatrixColorTable
       ColorTableStage
    TextureColorTableStage -> EnableCap
    CapTextureColorTable

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

    colorTableStage :: ColorTableStage -> StateVar Capability
    colorTableStage :: ColorTableStage -> StateVar Capability
    colorTableStage = EnableCap -> StateVar Capability
    makeCapability (EnableCap -> StateVar Capability)
    -> (ColorTableStage -> EnableCap)
    -> ColorTableStage
    -> StateVar Capability
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ColorTableStage -> EnableCap
    colorTableStageToEnableCap

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

    data ColorTable =
         ColorTable
       | PostConvolutionColorTable
       | PostColorMatrixColorTable
       | Texture1DColorTable
       | Texture2DColorTable
       | Texture3DColorTable
       | TextureCubeMapColorTable
       | TextureColorTable
       | SharedTexturePalette
       deriving ( ColorTable -> ColorTable -> Bool
    (ColorTable -> ColorTable -> Bool)
    -> (ColorTable -> ColorTable -> Bool) -> Eq ColorTable
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ColorTable -> ColorTable -> Bool
    == :: ColorTable -> ColorTable -> Bool
    $c/= :: ColorTable -> ColorTable -> Bool
    /= :: ColorTable -> ColorTable -> Bool
    Eq, Eq ColorTable
    Eq ColorTable =>
    (ColorTable -> ColorTable -> Ordering)
    -> (ColorTable -> ColorTable -> Bool)
    -> (ColorTable -> ColorTable -> Bool)
    -> (ColorTable -> ColorTable -> Bool)
    -> (ColorTable -> ColorTable -> Bool)
    -> (ColorTable -> ColorTable -> ColorTable)
    -> (ColorTable -> ColorTable -> ColorTable)
    -> Ord ColorTable
    ColorTable -> ColorTable -> Bool
    ColorTable -> ColorTable -> Ordering
    ColorTable -> ColorTable -> ColorTable
    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 :: ColorTable -> ColorTable -> Ordering
    compare :: ColorTable -> ColorTable -> Ordering
    $c< :: ColorTable -> ColorTable -> Bool
    < :: ColorTable -> ColorTable -> Bool
    $c<= :: ColorTable -> ColorTable -> Bool
    <= :: ColorTable -> ColorTable -> Bool
    $c> :: ColorTable -> ColorTable -> Bool
    > :: ColorTable -> ColorTable -> Bool
    $c>= :: ColorTable -> ColorTable -> Bool
    >= :: ColorTable -> ColorTable -> Bool
    $cmax :: ColorTable -> ColorTable -> ColorTable
    max :: ColorTable -> ColorTable -> ColorTable
    $cmin :: ColorTable -> ColorTable -> ColorTable
    min :: ColorTable -> ColorTable -> ColorTable
    Ord, Int -> ColorTable -> ShowS
    [ColorTable] -> ShowS
    ColorTable -> String
    (Int -> ColorTable -> ShowS)
    -> (ColorTable -> String)
    -> ([ColorTable] -> ShowS)
    -> Show ColorTable
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ColorTable -> ShowS
    showsPrec :: Int -> ColorTable -> ShowS
    $cshow :: ColorTable -> String
    show :: ColorTable -> String
    $cshowList :: [ColorTable] -> ShowS
    showList :: [ColorTable] -> ShowS
    Show )

    marshalColorTable :: ColorTable -> GLenum
    marshalColorTable :: ColorTable -> GLenum
    marshalColorTable ColorTable
    x = case ColorTable
    x of
       ColorTable
    ColorTable -> GLenum
    GL_COLOR_TABLE
       ColorTable
    PostConvolutionColorTable -> GLenum
    GL_POST_CONVOLUTION_COLOR_TABLE
       ColorTable
    PostColorMatrixColorTable -> GLenum
    GL_POST_COLOR_MATRIX_COLOR_TABLE
       ColorTable
    Texture1DColorTable -> GLenum
    GL_TEXTURE_1D
       ColorTable
    Texture2DColorTable -> GLenum
    GL_TEXTURE_2D
       ColorTable
    Texture3DColorTable -> GLenum
    GL_TEXTURE_3D
       ColorTable
    TextureCubeMapColorTable -> GLenum
    GL_TEXTURE_CUBE_MAP
       ColorTable
    TextureColorTable -> GLenum
    GL_TEXTURE_COLOR_TABLE_SGI
       ColorTable
    SharedTexturePalette -> GLenum
    GL_SHARED_TEXTURE_PALETTE_EXT

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

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

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

    marshalProxyColorTable :: Proxy -> ColorTable -> Maybe GLenum
    marshalProxyColorTable :: Proxy -> ColorTable -> Maybe GLenum
    marshalProxyColorTable Proxy
    NoProxy ColorTable
    x = GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just (ColorTable -> GLenum
    marshalColorTable ColorTable
    x)
    marshalProxyColorTable Proxy
    Proxy   ColorTable
    x = case ColorTable
    x of
       ColorTable
    ColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_PROXY_COLOR_TABLE
       ColorTable
    PostConvolutionColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
       ColorTable
    PostColorMatrixColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
       ColorTable
    Texture1DColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_PROXY_TEXTURE_1D
       ColorTable
    Texture2DColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_PROXY_TEXTURE_2D
       ColorTable
    Texture3DColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_PROXY_TEXTURE_3D
       ColorTable
    TextureCubeMapColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_PROXY_TEXTURE_CUBE_MAP
       ColorTable
    TextureColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_COLOR_TABLE_SGI
       ColorTable
    SharedTexturePalette -> Maybe GLenum
    forall a. Maybe a
    Nothing

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

    colorTable ::
       Proxy -> ColorTable -> PixelInternalFormat -> GLsizei -> PixelData a -> IO ()
    colorTable :: forall a.
    Proxy
    -> ColorTable
    -> PixelInternalFormat
    -> GLint
    -> PixelData a
    -> IO ()
    colorTable Proxy
    proxy ColorTable
    ct PixelInternalFormat
    int GLint
    w PixelData a
    pd =
       IO () -> (GLenum -> IO ()) -> Maybe GLenum -> IO ()
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe IO ()
    recordInvalidEnum
             (\GLenum
    target -> 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 ()
    glColorTable GLenum
    target (PixelInternalFormat -> GLenum
    marshalPixelInternalFormat' PixelInternalFormat
    int) GLint
    w)
             (Proxy -> ColorTable -> Maybe GLenum
    marshalProxyColorTable Proxy
    proxy ColorTable
    ct)

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

    getColorTable :: ColorTable -> PixelData a -> IO ()
    getColorTable :: forall a. ColorTable -> PixelData a -> IO ()
    getColorTable ColorTable
    ct 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 ()
    glGetColorTable (ColorTable -> GLenum
    marshalColorTable ColorTable
    ct)

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

    copyColorTable :: ColorTable -> PixelInternalFormat -> Position -> GLsizei -> IO ()
    copyColorTable :: ColorTable -> PixelInternalFormat -> Position -> GLint -> IO ()
    copyColorTable ColorTable
    ct PixelInternalFormat
    int (Position GLint
    x GLint
    y) =
       GLenum -> GLenum -> GLint -> GLint -> GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> GLint -> GLint -> GLint -> m ()
    glCopyColorTable (ColorTable -> GLenum
    marshalColorTable ColorTable
    ct) (PixelInternalFormat -> GLenum
    marshalPixelInternalFormat' PixelInternalFormat
    int) GLint
    x GLint
    y

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

    colorSubTable :: ColorTable -> GLsizei -> GLsizei -> PixelData a -> IO ()
    colorSubTable :: forall a. ColorTable -> GLint -> GLint -> PixelData a -> IO ()
    colorSubTable ColorTable
    ct GLint
    start GLint
    count 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 -> GLint -> GLint -> GLenum -> GLenum -> Ptr a -> IO ()
    forall (m :: * -> *) a.
    MonadIO m =>
    GLenum -> GLint -> GLint -> GLenum -> GLenum -> Ptr a -> m ()
    glColorSubTable (ColorTable -> GLenum
    marshalColorTable ColorTable
    ct) GLint
    start GLint
    count

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

    copyColorSubTable :: ColorTable -> GLsizei -> Position -> GLsizei -> IO ()
    copyColorSubTable :: ColorTable -> GLint -> Position -> GLint -> IO ()
    copyColorSubTable ColorTable
    ct GLint
    start (Position GLint
    x GLint
    y) =
       GLenum -> GLint -> GLint -> GLint -> GLint -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLint -> GLint -> GLint -> GLint -> m ()
    glCopyColorSubTable (ColorTable -> GLenum
    marshalColorTable ColorTable
    ct) GLint
    start GLint
    x GLint
    y

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

    data ColorTablePName =
         ColorTableScale
       | ColorTableBias
       | ColorTableFormat
       | ColorTableWidth
       | ColorTableRedSize
       | ColorTableGreenSize
       | ColorTableBlueSize
       | ColorTableAlphaSize
       | ColorTableLuminanceSize
       | ColorTableIntensitySize

    marshalColorTablePName :: ColorTablePName -> GLenum
    marshalColorTablePName :: ColorTablePName -> GLenum
    marshalColorTablePName ColorTablePName
    x = case ColorTablePName
    x of
       ColorTablePName
    ColorTableScale -> GLenum
    GL_COLOR_TABLE_SCALE
       ColorTablePName
    ColorTableBias -> GLenum
    GL_COLOR_TABLE_BIAS
       ColorTablePName
    ColorTableFormat -> GLenum
    GL_COLOR_TABLE_FORMAT
       ColorTablePName
    ColorTableWidth -> GLenum
    GL_COLOR_TABLE_WIDTH
       ColorTablePName
    ColorTableRedSize -> GLenum
    GL_COLOR_TABLE_RED_SIZE
       ColorTablePName
    ColorTableGreenSize -> GLenum
    GL_COLOR_TABLE_GREEN_SIZE
       ColorTablePName
    ColorTableBlueSize -> GLenum
    GL_COLOR_TABLE_BLUE_SIZE
       ColorTablePName
    ColorTableAlphaSize -> GLenum
    GL_COLOR_TABLE_ALPHA_SIZE
       ColorTablePName
    ColorTableLuminanceSize -> GLenum
    GL_COLOR_TABLE_LUMINANCE_SIZE
       ColorTablePName
    ColorTableIntensitySize -> GLenum
    GL_COLOR_TABLE_INTENSITY_SIZE

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

    colorTableScale :: ColorTableStage -> StateVar (Color4 GLfloat)
    colorTableScale :: ColorTableStage -> StateVar (Color4 GLfloat)
    colorTableScale = ColorTablePName -> ColorTableStage -> StateVar (Color4 GLfloat)
    colorTableScaleBias ColorTablePName
    ColorTableScale

    colorTableBias :: ColorTableStage -> StateVar (Color4 GLfloat)
    colorTableBias :: ColorTableStage -> StateVar (Color4 GLfloat)
    colorTableBias = ColorTablePName -> ColorTableStage -> StateVar (Color4 GLfloat)
    colorTableScaleBias ColorTablePName
    ColorTableBias

    colorTableScaleBias ::
       ColorTablePName -> ColorTableStage -> StateVar (Color4 GLfloat)
    colorTableScaleBias :: ColorTablePName -> ColorTableStage -> StateVar (Color4 GLfloat)
    colorTableScaleBias ColorTablePName
    p ColorTableStage
    s =
       IO (Color4 GLfloat)
    -> (Color4 GLfloat -> IO ()) -> StateVar (Color4 GLfloat)
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar (ColorTable -> ColorTablePName -> IO (Color4 GLfloat)
    getColorTableParameterC4f ColorTable
    ct ColorTablePName
    p) (ColorTable -> ColorTablePName -> Color4 GLfloat -> IO ()
    colorTableParameterC4f ColorTable
    ct ColorTablePName
    p)
       where ct :: ColorTable
    ct = ColorTableStage -> ColorTable
    colorTableStageToColorTable ColorTableStage
    s

    getColorTableParameterC4f ::
       ColorTable -> ColorTablePName -> IO (Color4 GLfloat)
    getColorTableParameterC4f :: ColorTable -> ColorTablePName -> IO (Color4 GLfloat)
    getColorTableParameterC4f ColorTable
    ct ColorTablePName
    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 ()
    glGetColorTableParameterfv
             (ColorTable -> GLenum
    marshalColorTable ColorTable
    ct)
             (ColorTablePName -> GLenum
    marshalColorTablePName ColorTablePName
    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

    colorTableParameterC4f ::
       ColorTable -> ColorTablePName -> Color4 GLfloat -> IO ()
    colorTableParameterC4f :: ColorTable -> ColorTablePName -> Color4 GLfloat -> IO ()
    colorTableParameterC4f ColorTable
    ct ColorTablePName
    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 ()
    glColorTableParameterfv (ColorTable -> GLenum
    marshalColorTable ColorTable
    ct) (ColorTablePName -> GLenum
    marshalColorTablePName ColorTablePName
    p) (Ptr (Color4 GLfloat) -> Ptr GLfloat
    forall a b. Ptr a -> Ptr b
    castPtr Ptr (Color4 GLfloat)
    ptr)

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

    colorTableFormat :: ColorTable -> GettableStateVar PixelInternalFormat
    colorTableFormat :: ColorTable -> GettableStateVar PixelInternalFormat
    colorTableFormat ColorTable
    ct =
       GettableStateVar PixelInternalFormat
    -> GettableStateVar PixelInternalFormat
    forall a. IO a -> IO a
    makeGettableStateVar (GettableStateVar PixelInternalFormat
     -> GettableStateVar PixelInternalFormat)
    -> GettableStateVar PixelInternalFormat
    -> GettableStateVar PixelInternalFormat
    forall a b. (a -> b) -> a -> b
    $
          (GLint -> PixelInternalFormat)
    -> ColorTable
    -> ColorTablePName
    -> GettableStateVar PixelInternalFormat
    forall a. (GLint -> a) -> ColorTable -> ColorTablePName -> IO a
    getColorTableParameteri GLint -> PixelInternalFormat
    unmarshalPixelInternalFormat ColorTable
    ct ColorTablePName
    ColorTableFormat

    getColorTableParameteri :: (GLint -> a) -> ColorTable -> ColorTablePName -> IO a
    getColorTableParameteri :: forall a. (GLint -> a) -> ColorTable -> ColorTablePName -> IO a
    getColorTableParameteri GLint -> a
    f ColorTable
    ct ColorTablePName
    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 ()
    glGetColorTableParameteriv
             (ColorTable -> GLenum
    marshalColorTable ColorTable
    ct)
             (ColorTablePName -> GLenum
    marshalColorTablePName ColorTablePName
    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

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

    colorTableWidth :: ColorTable -> GettableStateVar GLsizei
    colorTableWidth :: ColorTable -> GettableStateVar GLint
    colorTableWidth ColorTable
    ct =
       GettableStateVar GLint -> GettableStateVar GLint
    forall a. IO a -> IO a
    makeGettableStateVar (GettableStateVar GLint -> GettableStateVar GLint)
    -> GettableStateVar GLint -> GettableStateVar GLint
    forall a b. (a -> b) -> a -> b
    $
          (GLint -> GLint)
    -> ColorTable -> ColorTablePName -> GettableStateVar GLint
    forall a. (GLint -> a) -> ColorTable -> ColorTablePName -> IO a
    getColorTableParameteri GLint -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral ColorTable
    ct ColorTablePName
    ColorTableWidth

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

    colorTableRGBASizes :: ColorTable -> GettableStateVar (Color4 GLsizei)
    colorTableRGBASizes :: ColorTable -> GettableStateVar (Color4 GLint)
    colorTableRGBASizes ColorTable
    ct =
       GettableStateVar (Color4 GLint) -> GettableStateVar (Color4 GLint)
    forall a. IO a -> IO a
    makeGettableStateVar (GettableStateVar (Color4 GLint)
     -> GettableStateVar (Color4 GLint))
    -> GettableStateVar (Color4 GLint)
    -> GettableStateVar (Color4 GLint)
    forall a b. (a -> b) -> a -> b
    $ do
          r <- (GLint -> GLint)
    -> ColorTable -> ColorTablePName -> GettableStateVar GLint
    forall a. (GLint -> a) -> ColorTable -> ColorTablePName -> IO a
    getColorTableParameteri GLint -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral ColorTable
    ct ColorTablePName
    ColorTableRedSize
          g <- getColorTableParameteri fromIntegral ct ColorTableGreenSize
          b <- getColorTableParameteri fromIntegral ct ColorTableBlueSize
          a <- getColorTableParameteri fromIntegral ct ColorTableAlphaSize
          return $ Color4 r g b a

    colorTableLuminanceSize :: ColorTable -> GettableStateVar GLsizei
    colorTableLuminanceSize :: ColorTable -> GettableStateVar GLint
    colorTableLuminanceSize ColorTable
    ct =
       GettableStateVar GLint -> GettableStateVar GLint
    forall a. IO a -> IO a
    makeGettableStateVar (GettableStateVar GLint -> GettableStateVar GLint)
    -> GettableStateVar GLint -> GettableStateVar GLint
    forall a b. (a -> b) -> a -> b
    $
          (GLint -> GLint)
    -> ColorTable -> ColorTablePName -> GettableStateVar GLint
    forall a. (GLint -> a) -> ColorTable -> ColorTablePName -> IO a
    getColorTableParameteri GLint -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral ColorTable
    ct ColorTablePName
    ColorTableLuminanceSize

    colorTableIntesitySize :: ColorTable -> GettableStateVar GLsizei
    colorTableIntesitySize :: ColorTable -> GettableStateVar GLint
    colorTableIntesitySize ColorTable
    ct =
       GettableStateVar GLint -> GettableStateVar GLint
    forall a. IO a -> IO a
    makeGettableStateVar (GettableStateVar GLint -> GettableStateVar GLint)
    -> GettableStateVar GLint -> GettableStateVar GLint
    forall a b. (a -> b) -> a -> b
    $
          (GLint -> GLint)
    -> ColorTable -> ColorTablePName -> GettableStateVar GLint
    forall a. (GLint -> a) -> ColorTable -> ColorTablePName -> IO a
    getColorTableParameteri GLint -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral ColorTable
    ct ColorTablePName
    ColorTableIntensitySize