    {-# OPTIONS_HADDOCK hide #-}
    --------------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.Capability
    -- 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 handling OpenGL capabilities, i.e.
    -- boolean state variables.
    --
    --------------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.Capability (
       Capability(..), marshalCapability, unmarshalCapability,
       EnableCap(..), makeCapability, makeStateVarMaybe,

       IndexedEnableCap(..), makeIndexedCapability,
    ) where

    import Data.StateVar
    import Graphics.Rendering.OpenGL.GL.GLboolean
    import Graphics.Rendering.OpenGL.GL.QueryUtils
    import Graphics.Rendering.OpenGL.GLU.ErrorsInternal
    import Graphics.GL

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

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

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

    marshalCapability :: Capability -> GLboolean
    marshalCapability :: Capability -> GLboolean
    marshalCapability = Bool -> GLboolean
    forall a. Num a => Bool -> a
    marshalGLboolean (Bool -> GLboolean)
    -> (Capability -> Bool) -> Capability -> GLboolean
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Capability
    Enabled Capability -> Capability -> Bool
    forall a. Eq a => a -> a -> Bool
    ==)

    unmarshalCapability :: GLboolean -> Capability
    unmarshalCapability :: GLboolean -> Capability
    unmarshalCapability GLboolean
    x = if GLboolean -> Bool
    forall a. (Eq a, Num a) => a -> Bool
    unmarshalGLboolean GLboolean
    x then Capability
    Enabled else Capability
    Disabled

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

    data EnableCap =
         CapFog
       | CapLighting
       | CapTexture1D
       | CapTexture2D
       | CapTexture2DMultisample
       | CapTexture1DArray
       | CapTextureRectangle
       | CapTextureCubeMap
       | CapTexture3D
       | CapTexture2DArray
       | CapTexture2DMultisampleArray
       | CapTextureCubeMapArray
       | CapLineStipple
       | CapPolygonStipple
       | CapCullFace
       | CapAlphaTest
       | CapBlend
       | CapIndexLogicOp
       | CapColorLogicOp
       | CapDither
       | CapStencilTest
       | CapDepthTest
       | CapClipPlane GLsizei
       | CapLight GLsizei
       | CapTextureGenS
       | CapTextureGenT
       | CapTextureGenR
       | CapTextureGenQ
       | CapMap1Vertex3
       | CapMap1Vertex4
       | CapMap1Color4
       | CapMap1Index
       | CapMap1Normal
       | CapMap1TextureCoord1
       | CapMap1TextureCoord2
       | CapMap1TextureCoord3
       | CapMap1TextureCoord4
       | CapMap2Vertex3
       | CapMap2Vertex4
       | CapMap2Color4
       | CapMap2Index
       | CapMap2Normal
       | CapMap2TextureCoord1
       | CapMap2TextureCoord2
       | CapMap2TextureCoord3
       | CapMap2TextureCoord4
       | CapPointSmooth
       | CapLineSmooth
       | CapPolygonSmooth
       | CapScissorTest
       | CapColorMaterial
       | CapNormalize
       | CapAutoNormal
       | CapPolygonOffsetPoint
       | CapPolygonOffsetLine
       | CapPolygonOffsetFill
       | CapVertexArray
       | CapNormalArray
       | CapColorArray
       | CapIndexArray
       | CapTextureCoordArray
       | CapEdgeFlagArray
       | CapFogCoordArray
       | CapSecondaryColorArray
       | CapMatrixIndexArray
       | CapConvolution1D
       | CapConvolution2D
       | CapSeparable2D
       | CapHistogram
       | CapMinmax
       | CapRescaleNormal
       | CapSharedTexturePalette
       | CapMultisample
       | CapSampleAlphaToCoverage
       | CapSampleAlphaToOne
       | CapSampleCoverage
       | CapColorTable
       | CapPostConvolutionColorTable
       | CapPostColorMatrixColorTable
       | CapColorSum
       | CapWeightSumUnity
       | CapVertexBlend
       | CapWeightArray
       | CapMatrixPalette
       | CapDepthClamp
       | CapDepthBoundsTest
       | CapPrimitiveRestart
       | CapPointSprite
       | CapStencilTestTwoSide
       | CapRasterPositionUnclipped
       | CapRasterizerDiscard
       | CapTextureColorTable
       | CapVertexProgramPointSize
       | CapVertexProgramTwoSide
       | CapDebugOutput
       | CapDebugOutputSynchronous

    marshalEnableCap :: EnableCap -> Maybe GLenum
    marshalEnableCap :: EnableCap -> Maybe GLenum
    marshalEnableCap EnableCap
    x = case EnableCap
    x of
       EnableCap
    CapFog -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_FOG
       EnableCap
    CapLighting -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_LIGHTING
       EnableCap
    CapTexture1D -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_1D
       EnableCap
    CapTexture2D -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_2D
       EnableCap
    CapTexture2DMultisample -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_2D_MULTISAMPLE
       EnableCap
    CapTexture1DArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_1D_ARRAY
       EnableCap
    CapTextureRectangle -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_RECTANGLE
       EnableCap
    CapTextureCubeMap -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_CUBE_MAP
       EnableCap
    CapTexture3D -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_3D
       EnableCap
    CapTexture2DArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_2D_ARRAY
       EnableCap
    CapTexture2DMultisampleArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_2D_MULTISAMPLE_ARRAY
       EnableCap
    CapTextureCubeMapArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_CUBE_MAP_ARRAY
       EnableCap
    CapLineStipple -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_LINE_STIPPLE
       EnableCap
    CapPolygonStipple -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_POLYGON_STIPPLE
       EnableCap
    CapCullFace -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_CULL_FACE
       EnableCap
    CapAlphaTest -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_ALPHA_TEST
       EnableCap
    CapBlend -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_BLEND
       EnableCap
    CapIndexLogicOp -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_INDEX_LOGIC_OP
       EnableCap
    CapColorLogicOp -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_COLOR_LOGIC_OP
       EnableCap
    CapDither -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_DITHER
       EnableCap
    CapStencilTest -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_STENCIL_TEST
       EnableCap
    CapDepthTest -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_DEPTH_TEST
       CapClipPlane GLsizei
    i -> GLsizei -> Maybe GLenum
    clipPlaneIndexToEnum GLsizei
    i
       CapLight GLsizei
    i -> GLsizei -> Maybe GLenum
    lightIndexToEnum GLsizei
    i
       EnableCap
    CapTextureGenS -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_GEN_S
       EnableCap
    CapTextureGenT -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_GEN_T
       EnableCap
    CapTextureGenR -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_GEN_R
       EnableCap
    CapTextureGenQ -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_GEN_Q
       EnableCap
    CapMap1Vertex3 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP1_VERTEX_3
       EnableCap
    CapMap1Vertex4 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP1_VERTEX_4
       EnableCap
    CapMap1Color4 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP1_COLOR_4
       EnableCap
    CapMap1Index -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP1_INDEX
       EnableCap
    CapMap1Normal -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP1_NORMAL
       EnableCap
    CapMap1TextureCoord1 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP1_TEXTURE_COORD_1
       EnableCap
    CapMap1TextureCoord2 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP1_TEXTURE_COORD_2
       EnableCap
    CapMap1TextureCoord3 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP1_TEXTURE_COORD_3
       EnableCap
    CapMap1TextureCoord4 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP1_TEXTURE_COORD_4
       EnableCap
    CapMap2Vertex3 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP2_VERTEX_3
       EnableCap
    CapMap2Vertex4 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP2_VERTEX_4
       EnableCap
    CapMap2Color4 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP2_COLOR_4
       EnableCap
    CapMap2Index -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP2_INDEX
       EnableCap
    CapMap2Normal -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP2_NORMAL
       EnableCap
    CapMap2TextureCoord1 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP2_TEXTURE_COORD_1
       EnableCap
    CapMap2TextureCoord2 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP2_TEXTURE_COORD_2
       EnableCap
    CapMap2TextureCoord3 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP2_TEXTURE_COORD_3
       EnableCap
    CapMap2TextureCoord4 -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MAP2_TEXTURE_COORD_4
       EnableCap
    CapPointSmooth -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_POINT_SMOOTH
       EnableCap
    CapLineSmooth -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_LINE_SMOOTH
       EnableCap
    CapPolygonSmooth -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_POLYGON_SMOOTH
       EnableCap
    CapScissorTest -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_SCISSOR_TEST
       EnableCap
    CapColorMaterial -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_COLOR_MATERIAL
       EnableCap
    CapNormalize -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_NORMALIZE
       EnableCap
    CapAutoNormal -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_AUTO_NORMAL
       EnableCap
    CapPolygonOffsetPoint -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_POLYGON_OFFSET_POINT
       EnableCap
    CapPolygonOffsetLine -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_POLYGON_OFFSET_LINE
       EnableCap
    CapPolygonOffsetFill -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_POLYGON_OFFSET_FILL
       EnableCap
    CapVertexArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_VERTEX_ARRAY
       EnableCap
    CapNormalArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_NORMAL_ARRAY
       EnableCap
    CapColorArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_COLOR_ARRAY
       EnableCap
    CapIndexArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_INDEX_ARRAY
       EnableCap
    CapTextureCoordArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_COORD_ARRAY
       EnableCap
    CapEdgeFlagArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_EDGE_FLAG_ARRAY
       EnableCap
    CapFogCoordArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_FOG_COORD_ARRAY
       EnableCap
    CapSecondaryColorArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_SECONDARY_COLOR_ARRAY
       EnableCap
    CapMatrixIndexArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MATRIX_INDEX_ARRAY_ARB
       EnableCap
    CapConvolution1D -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_CONVOLUTION_1D
       EnableCap
    CapConvolution2D -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_CONVOLUTION_2D
       EnableCap
    CapSeparable2D -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_SEPARABLE_2D
       EnableCap
    CapHistogram -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_HISTOGRAM
       EnableCap
    CapMinmax -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MINMAX
       EnableCap
    CapRescaleNormal -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_RESCALE_NORMAL
       EnableCap
    CapSharedTexturePalette -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_SHARED_TEXTURE_PALETTE_EXT
       EnableCap
    CapMultisample -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MULTISAMPLE
       EnableCap
    CapSampleAlphaToCoverage -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_SAMPLE_ALPHA_TO_COVERAGE
       EnableCap
    CapSampleAlphaToOne -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_SAMPLE_ALPHA_TO_ONE
       EnableCap
    CapSampleCoverage -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_SAMPLE_COVERAGE
       EnableCap
    CapColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_COLOR_TABLE
       EnableCap
    CapPostConvolutionColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_POST_CONVOLUTION_COLOR_TABLE
       EnableCap
    CapPostColorMatrixColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_POST_COLOR_MATRIX_COLOR_TABLE
       EnableCap
    CapColorSum -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_COLOR_SUM
       EnableCap
    CapWeightSumUnity -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_WEIGHT_SUM_UNITY_ARB
       EnableCap
    CapVertexBlend -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_VERTEX_BLEND_ARB
       EnableCap
    CapWeightArray -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_WEIGHT_ARRAY_ARB
       EnableCap
    CapMatrixPalette -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_MATRIX_PALETTE_ARB
       EnableCap
    CapDepthClamp -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_DEPTH_CLAMP
       EnableCap
    CapDepthBoundsTest -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_DEPTH_BOUNDS_TEST_EXT
       EnableCap
    CapPrimitiveRestart -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_PRIMITIVE_RESTART
       EnableCap
    CapPointSprite -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_POINT_SPRITE
       EnableCap
    CapStencilTestTwoSide -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_STENCIL_TEST_TWO_SIDE_EXT
       EnableCap
    CapRasterPositionUnclipped -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_RASTER_POSITION_UNCLIPPED_IBM
       EnableCap
    CapRasterizerDiscard -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_RASTERIZER_DISCARD
       EnableCap
    CapTextureColorTable -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_TEXTURE_COLOR_TABLE_SGI
       EnableCap
    CapVertexProgramPointSize -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_VERTEX_PROGRAM_POINT_SIZE
       EnableCap
    CapVertexProgramTwoSide -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_VERTEX_PROGRAM_TWO_SIDE
       EnableCap
    CapDebugOutput -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_DEBUG_OUTPUT
       EnableCap
    CapDebugOutputSynchronous -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_DEBUG_OUTPUT_SYNCHRONOUS

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

    makeCapability :: EnableCap -> StateVar Capability
    makeCapability :: EnableCap -> StateVar Capability
    makeCapability EnableCap
    cap = IO Capability -> (Capability -> IO ()) -> StateVar Capability
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar (EnableCap -> IO Capability
    isEnabled EnableCap
    cap) (EnableCap -> Capability -> IO ()
    enable EnableCap
    cap)

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

    isEnabled :: EnableCap -> IO Capability
    isEnabled :: EnableCap -> IO Capability
    isEnabled =
       IO Capability
    -> (GLenum -> IO Capability) -> Maybe GLenum -> IO Capability
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (do IO ()
    recordInvalidEnum; Capability -> IO Capability
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Capability
    Disabled)
             ((GLboolean -> Capability) -> IO GLboolean -> IO Capability
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap GLboolean -> Capability
    unmarshalCapability (IO GLboolean -> IO Capability)
    -> (GLenum -> IO GLboolean) -> GLenum -> IO Capability
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLenum -> IO GLboolean
    forall (m :: * -> *). MonadIO m => GLenum -> m GLboolean
    glIsEnabled) (Maybe GLenum -> IO Capability)
    -> (EnableCap -> Maybe GLenum) -> EnableCap -> IO Capability
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
       EnableCap -> Maybe GLenum
    marshalEnableCap

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

    enable :: EnableCap -> Capability -> IO ()
    enable :: EnableCap -> Capability -> IO ()
    enable EnableCap
    cap Capability
    state = IO () -> (GLenum -> IO ()) -> Maybe GLenum -> IO ()
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe IO ()
    recordInvalidEnum (Capability -> GLenum -> IO ()
    forall {m :: * -> *}. MonadIO m => Capability -> GLenum -> m ()
    f Capability
    state) (EnableCap -> Maybe GLenum
    marshalEnableCap EnableCap
    cap)
       where f :: Capability -> GLenum -> m ()
    f Capability
    Disabled = GLenum -> m ()
    forall (m :: * -> *). MonadIO m => GLenum -> m ()
    glDisable
             f Capability
    Enabled  = GLenum -> m ()
    forall (m :: * -> *). MonadIO m => GLenum -> m ()
    glEnable

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

    makeStateVarMaybe :: IO EnableCap -> IO a -> (a -> IO ()) -> StateVar (Maybe a)
    makeStateVarMaybe :: forall a.
    IO EnableCap -> IO a -> (a -> IO ()) -> StateVar (Maybe a)
    makeStateVarMaybe IO EnableCap
    getCap IO a
    getAct a -> IO ()
    setAct =
       IO (Maybe a) -> (Maybe a -> IO ()) -> StateVar (Maybe a)
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar
          (IO EnableCap -> IO a -> IO (Maybe a)
    forall a. IO EnableCap -> IO a -> IO (Maybe a)
    getStateVarMaybe IO EnableCap
    getCap IO a
    getAct)
          (IO EnableCap -> (a -> IO ()) -> Maybe a -> IO ()
    forall a. IO EnableCap -> (a -> IO ()) -> Maybe a -> IO ()
    setStateVarMaybe IO EnableCap
    getCap a -> IO ()
    setAct)

    getStateVarMaybe :: IO EnableCap -> IO a -> IO (Maybe a)
    getStateVarMaybe :: forall a. IO EnableCap -> IO a -> IO (Maybe a)
    getStateVarMaybe IO EnableCap
    getCap IO a
    act = do
       capability <- (EnableCap -> StateVar Capability)
    -> IO EnableCap -> IO (StateVar Capability)
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap EnableCap -> StateVar Capability
    makeCapability IO EnableCap
    getCap
       state <- get capability
       if state == Enabled
          then fmap Just act
          else return Nothing

    setStateVarMaybe :: IO EnableCap -> (a -> IO ()) -> Maybe a -> IO ()
    setStateVarMaybe :: forall a. IO EnableCap -> (a -> IO ()) -> Maybe a -> IO ()
    setStateVarMaybe IO EnableCap
    getCap a -> IO ()
    act Maybe a
    val = do
       capability <- (EnableCap -> StateVar Capability)
    -> IO EnableCap -> IO (StateVar Capability)
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap EnableCap -> StateVar Capability
    makeCapability IO EnableCap
    getCap
       maybe (capability $= Disabled) (\a
    x -> a -> IO ()
    act a
    x IO () -> IO () -> IO ()
    forall a b. IO a -> IO b -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> StateVar Capability
    capability StateVar Capability -> Capability -> IO ()
    forall t a (m :: * -> *).
    (HasSetter t a, MonadIO m) =>
    t -> a -> m ()
    forall (m :: * -> *).
    MonadIO m =>
    StateVar Capability -> Capability -> m ()
    $= Capability
    Enabled) val

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

    data IndexedEnableCap =
       BlendI

    marshalIndexedEnableCap :: IndexedEnableCap -> Maybe GLenum
    marshalIndexedEnableCap :: IndexedEnableCap -> Maybe GLenum
    marshalIndexedEnableCap IndexedEnableCap
    x = case IndexedEnableCap
    x of
       IndexedEnableCap
    BlendI -> GLenum -> Maybe GLenum
    forall a. a -> Maybe a
    Just GLenum
    GL_BLEND

    makeIndexedCapability ::(a -> GLuint) -> IndexedEnableCap ->  a
       -> StateVar Capability
    makeIndexedCapability :: forall a.
    (a -> GLenum) -> IndexedEnableCap -> a -> StateVar Capability
    makeIndexedCapability a -> GLenum
    f IndexedEnableCap
    cap a
    val = IO Capability -> (Capability -> IO ()) -> StateVar Capability
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar
       (GLenum -> IndexedEnableCap -> IO Capability
    isIndexedEnabled (a -> GLenum
    f a
    val) IndexedEnableCap
    cap)
       (\Capability
    state -> GLenum -> IndexedEnableCap -> Capability -> IO ()
    enableIndexed (a -> GLenum
    f a
    val) IndexedEnableCap
    cap Capability
    state)

    isIndexedEnabled :: GLuint -> IndexedEnableCap -> IO Capability
    isIndexedEnabled :: GLenum -> IndexedEnableCap -> IO Capability
    isIndexedEnabled GLenum
    i =
       IO Capability
    -> (GLenum -> IO Capability) -> Maybe GLenum -> IO Capability
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe (do IO ()
    recordInvalidEnum; Capability -> IO Capability
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Capability
    Disabled)
             (\GLenum
    cap -> (GLboolean -> Capability) -> IO GLboolean -> IO Capability
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap GLboolean -> Capability
    unmarshalCapability (IO GLboolean -> IO Capability) -> IO GLboolean -> IO Capability
    forall a b. (a -> b) -> a -> b
    $ GLenum -> GLenum -> IO GLboolean
    forall (m :: * -> *). MonadIO m => GLenum -> GLenum -> m GLboolean
    glIsEnabledi GLenum
    cap GLenum
    i) (Maybe GLenum -> IO Capability)
    -> (IndexedEnableCap -> Maybe GLenum)
    -> IndexedEnableCap
    -> IO Capability
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .
       IndexedEnableCap -> Maybe GLenum
    marshalIndexedEnableCap

    enableIndexed :: GLuint -> IndexedEnableCap -> Capability -> IO ()
    enableIndexed :: GLenum -> IndexedEnableCap -> Capability -> IO ()
    enableIndexed GLenum
    i IndexedEnableCap
    cap Capability
    state =
       IO () -> (GLenum -> IO ()) -> Maybe GLenum -> IO ()
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe IO ()
    recordInvalidEnum (Capability -> GLenum -> IO ()
    forall {m :: * -> *}. MonadIO m => Capability -> GLenum -> m ()
    f Capability
    state) (IndexedEnableCap -> Maybe GLenum
    marshalIndexedEnableCap IndexedEnableCap
    cap)
          where f :: Capability -> GLenum -> m ()
    f Capability
    Enabled  = \GLenum
    c -> GLenum -> GLenum -> m ()
    forall (m :: * -> *). MonadIO m => GLenum -> GLenum -> m ()
    glEnablei GLenum
    c GLenum
    i
                f Capability
    Disabled = \GLenum
    c -> GLenum -> GLenum -> m ()
    forall (m :: * -> *). MonadIO m => GLenum -> GLenum -> m ()
    glDisablei GLenum
    c GLenum
    i