    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.FramebufferObjects.Queries
    -- Copyright   :  (c) Sven Panne 2011-2019, Lars Corbijn 2011-2016
    -- License     :  BSD3
    --
    -- Maintainer  :  Sven Panne <svenpanne@gmail.com>
    -- Stability   :  stable
    -- Portability :  portable
    --
    -----------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.FramebufferObjects.Queries (
       AttachmentObjectType(..), attachmentObjectType, attachmentObject,
       attachmentTextureLayer, attachmentTextureLevel,
       attachmentTextureTextureTargetCubeMapFace,

       attachmentRedSize, attachmentBlueSize, attachmentGreenSize,
       attachmentAlphaSize, attachmentDepthSize, attachmentStencilSize,

       renderbufferWidth, renderbufferHeight,
       renderbufferInternalFormat, renderbufferSamples,

       renderbufferRedSize, renderbufferBlueSize, renderbufferGreenSize,
       renderbufferAlphaSize, renderbufferDepthSize, renderbufferStencilSize,
    ) where

    import Data.StateVar
    import Graphics.Rendering.OpenGL.GL.FramebufferObjects.FramebufferObjectAttachment
    import Graphics.Rendering.OpenGL.GL.FramebufferObjects.FramebufferTarget
    import Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferObject
    import Graphics.Rendering.OpenGL.GL.FramebufferObjects.RenderbufferTarget
    import Graphics.Rendering.OpenGL.GL.Texturing.PixelInternalFormat
    import Graphics.Rendering.OpenGL.GL.Texturing.Specification(Level)
    import Graphics.Rendering.OpenGL.GL.Texturing.TextureObject
    import Graphics.Rendering.OpenGL.GL.Texturing.TextureTarget
    import Graphics.GL

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

    data GetFramebufferAttachmentPName =
         AttachmentObjectType
       | AttachmentObjectName
       | AttachmentTextureLevel
       | AttachmentTextureCubeMapFace
       | AttachmentTextureLayer
       | AttachmentComponentType
       | AttachmentColorEncoding
       | AttachmentRedSize
       | AttachmentBlueSize
       | AttachmentGreenSize
       | AttachmentAlphaSize
       | AttachmentDepthSize
       | AttachmentStencilSize

    marshalGetFBAPName :: GetFramebufferAttachmentPName -> GLenum
    marshalGetFBAPName :: GetFramebufferAttachmentPName -> GLenum
    marshalGetFBAPName GetFramebufferAttachmentPName
    x = case GetFramebufferAttachmentPName
    x of
       GetFramebufferAttachmentPName
    AttachmentObjectType -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
       GetFramebufferAttachmentPName
    AttachmentObjectName -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
       GetFramebufferAttachmentPName
    AttachmentTextureLevel -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL
       GetFramebufferAttachmentPName
    AttachmentTextureCubeMapFace -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE
       GetFramebufferAttachmentPName
    AttachmentTextureLayer -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER
       GetFramebufferAttachmentPName
    AttachmentComponentType -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE -- TODO impement usefull function
       GetFramebufferAttachmentPName
    AttachmentColorEncoding -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING -- TODO impement usefull function
       GetFramebufferAttachmentPName
    AttachmentRedSize -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
       GetFramebufferAttachmentPName
    AttachmentBlueSize -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
       GetFramebufferAttachmentPName
    AttachmentGreenSize -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
       GetFramebufferAttachmentPName
    AttachmentAlphaSize -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
       GetFramebufferAttachmentPName
    AttachmentDepthSize -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
       GetFramebufferAttachmentPName
    AttachmentStencilSize -> GLenum
    GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE

    getFBAPName :: FramebufferAttachment fba => FramebufferTarget -> fba
        -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName :: forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba GLint -> a
    f GetFramebufferAttachmentPName
    p = FramebufferTarget -> fba -> (GLint -> a) -> GLenum -> IO a
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget -> fba -> (GLint -> a) -> GLenum -> IO a
    getFBAParameteriv FramebufferTarget
    fbt fba
    fba GLint -> a
    f (GetFramebufferAttachmentPName -> GLenum
    marshalGetFBAPName GetFramebufferAttachmentPName
    p)

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

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

    unmarshalAttachmentObjectType :: GLenum -> Maybe AttachmentObjectType
    unmarshalAttachmentObjectType :: GLenum -> Maybe AttachmentObjectType
    unmarshalAttachmentObjectType GLenum
    x
       | GLenum
    x GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_FRAMEBUFFER_DEFAULT = AttachmentObjectType -> Maybe AttachmentObjectType
    forall a. a -> Maybe a
    Just AttachmentObjectType
    DefaultFramebufferAttachment
       | GLenum
    x GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_TEXTURE = AttachmentObjectType -> Maybe AttachmentObjectType
    forall a. a -> Maybe a
    Just AttachmentObjectType
    TextureAttachment
       | GLenum
    x GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_RENDERBUFFER = AttachmentObjectType -> Maybe AttachmentObjectType
    forall a. a -> Maybe a
    Just AttachmentObjectType
    RenderbufferAttachment
       | GLenum
    x GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_NONE = Maybe AttachmentObjectType
    forall a. Maybe a
    Nothing
       | Bool
    otherwise = String -> Maybe AttachmentObjectType
    forall a. HasCallStack => String -> a
    error (String -> Maybe AttachmentObjectType)
    -> String -> Maybe AttachmentObjectType
    forall a b. (a -> b) -> a -> b
    $ String
    "unmarshalAttachmentObject: unknown value " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ GLenum -> String
    forall a. Show a => a -> String
    show GLenum
    x

    attachmentObjectType :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar (Maybe AttachmentObjectType)
    attachmentObjectType :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> GettableStateVar (Maybe AttachmentObjectType)
    attachmentObjectType FramebufferTarget
    fbt fba
    fba = GettableStateVar (Maybe AttachmentObjectType)
    -> GettableStateVar (Maybe AttachmentObjectType)
    forall a. IO a -> IO a
    makeGettableStateVar (GettableStateVar (Maybe AttachmentObjectType)
     -> GettableStateVar (Maybe AttachmentObjectType))
    -> GettableStateVar (Maybe AttachmentObjectType)
    -> GettableStateVar (Maybe AttachmentObjectType)
    forall a b. (a -> b) -> a -> b
    $ FramebufferTarget
    -> fba
    -> (GLint -> Maybe AttachmentObjectType)
    -> GetFramebufferAttachmentPName
    -> GettableStateVar (Maybe AttachmentObjectType)
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba
       (GLenum -> Maybe AttachmentObjectType
    unmarshalAttachmentObjectType (GLenum -> Maybe AttachmentObjectType)
    -> (GLint -> GLenum) -> GLint -> Maybe AttachmentObjectType
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLint -> GLenum
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) GetFramebufferAttachmentPName
    AttachmentObjectType

    -- | tries to retrieve the object that is bound to the attachment point of the
    -- given framebuffertarget. If the object type of it is None or the default, then
    -- `Nothing` is returned, otherwise the bound `RenderbufferObject` or `TextureObject`
    attachmentObject :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar (Maybe (Either RenderbufferObject TextureObject))
    attachmentObject :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    attachmentObject FramebufferTarget
    fbt fba
    fba = GettableStateVar (Maybe (Either RenderbufferObject TextureObject))
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    forall a. IO a -> IO a
    makeGettableStateVar GettableStateVar (Maybe (Either RenderbufferObject TextureObject))
    getter
       where getter :: GettableStateVar (Maybe (Either RenderbufferObject TextureObject))
    getter = do
                objT <- GettableStateVar (Maybe AttachmentObjectType)
    -> GettableStateVar (Maybe AttachmentObjectType)
    forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
    forall (m :: * -> *).
    MonadIO m =>
    GettableStateVar (Maybe AttachmentObjectType)
    -> m (Maybe AttachmentObjectType)
    get (GettableStateVar (Maybe AttachmentObjectType)
     -> GettableStateVar (Maybe AttachmentObjectType))
    -> GettableStateVar (Maybe AttachmentObjectType)
    -> GettableStateVar (Maybe AttachmentObjectType)
    forall a b. (a -> b) -> a -> b
    $ FramebufferTarget
    -> fba -> GettableStateVar (Maybe AttachmentObjectType)
    forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> GettableStateVar (Maybe AttachmentObjectType)
    attachmentObjectType FramebufferTarget
    fbt fba
    fba
                case objT of
                   Maybe AttachmentObjectType
    Nothing                             -> Maybe (Either RenderbufferObject TextureObject)
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe (Either RenderbufferObject TextureObject)
     -> GettableStateVar
          (Maybe (Either RenderbufferObject TextureObject)))
    -> Maybe (Either RenderbufferObject TextureObject)
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    forall a b. (a -> b) -> a -> b
    $ Maybe (Either RenderbufferObject TextureObject)
    forall a. Maybe a
    Nothing
                   (Just AttachmentObjectType
    DefaultFramebufferAttachment) -> Maybe (Either RenderbufferObject TextureObject)
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe (Either RenderbufferObject TextureObject)
     -> GettableStateVar
          (Maybe (Either RenderbufferObject TextureObject)))
    -> Maybe (Either RenderbufferObject TextureObject)
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    forall a b. (a -> b) -> a -> b
    $ Maybe (Either RenderbufferObject TextureObject)
    forall a. Maybe a
    Nothing
                   (Just AttachmentObjectType
    TextureAttachment)            -> (GLenum -> Either RenderbufferObject TextureObject)
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    forall n.
    Num n =>
    (n -> Either RenderbufferObject TextureObject)
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    getObjectName (TextureObject -> Either RenderbufferObject TextureObject
    forall a b. b -> Either a b
    Right (TextureObject -> Either RenderbufferObject TextureObject)
    -> (GLenum -> TextureObject)
    -> GLenum
    -> Either RenderbufferObject TextureObject
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLenum -> TextureObject
    TextureObject)
                   (Just AttachmentObjectType
    RenderbufferAttachment)       -> (GLenum -> Either RenderbufferObject TextureObject)
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    forall n.
    Num n =>
    (n -> Either RenderbufferObject TextureObject)
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    getObjectName (RenderbufferObject -> Either RenderbufferObject TextureObject
    forall a b. a -> Either a b
    Left (RenderbufferObject -> Either RenderbufferObject TextureObject)
    -> (GLenum -> RenderbufferObject)
    -> GLenum
    -> Either RenderbufferObject TextureObject
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLenum -> RenderbufferObject
    RenderbufferObject)
             getObjectName :: Num n => (n -> Either RenderbufferObject TextureObject) -> IO (Maybe (Either RenderbufferObject TextureObject))
             getObjectName :: forall n.
    Num n =>
    (n -> Either RenderbufferObject TextureObject)
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    getObjectName n -> Either RenderbufferObject TextureObject
    con = FramebufferTarget
    -> fba
    -> (GLint -> Maybe (Either RenderbufferObject TextureObject))
    -> GetFramebufferAttachmentPName
    -> GettableStateVar
         (Maybe (Either RenderbufferObject TextureObject))
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba (Either RenderbufferObject TextureObject
    -> Maybe (Either RenderbufferObject TextureObject)
    forall a. a -> Maybe a
    Just (Either RenderbufferObject TextureObject
     -> Maybe (Either RenderbufferObject TextureObject))
    -> (GLint -> Either RenderbufferObject TextureObject)
    -> GLint
    -> Maybe (Either RenderbufferObject TextureObject)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . n -> Either RenderbufferObject TextureObject
    con (n -> Either RenderbufferObject TextureObject)
    -> (GLint -> n) -> GLint -> Either RenderbufferObject TextureObject
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLint -> n
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) GetFramebufferAttachmentPName
    AttachmentObjectName

    attachmentTextureLayer :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar GLint
    attachmentTextureLayer :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget -> fba -> GettableStateVar GLint
    attachmentTextureLayer FramebufferTarget
    fbt fba
    fba = 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
    $
       FramebufferTarget
    -> fba
    -> (GLint -> GLint)
    -> GetFramebufferAttachmentPName
    -> GettableStateVar GLint
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba GLint -> GLint
    forall a. a -> a
    id GetFramebufferAttachmentPName
    AttachmentTextureLayer

    attachmentTextureLevel :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar Level
    attachmentTextureLevel :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget -> fba -> GettableStateVar GLint
    attachmentTextureLevel FramebufferTarget
    fbt fba
    fba = 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
    $
       FramebufferTarget
    -> fba
    -> (GLint -> GLint)
    -> GetFramebufferAttachmentPName
    -> GettableStateVar GLint
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba GLint -> GLint
    forall a. a -> a
    id GetFramebufferAttachmentPName
    AttachmentTextureLevel

    attachmentTextureTextureTargetCubeMapFace :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar TextureTargetCubeMapFace
    attachmentTextureTextureTargetCubeMapFace :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> GettableStateVar TextureTargetCubeMapFace
    attachmentTextureTextureTargetCubeMapFace FramebufferTarget
    fbt fba
    fba = GettableStateVar TextureTargetCubeMapFace
    -> GettableStateVar TextureTargetCubeMapFace
    forall a. IO a -> IO a
    makeGettableStateVar (GettableStateVar TextureTargetCubeMapFace
     -> GettableStateVar TextureTargetCubeMapFace)
    -> GettableStateVar TextureTargetCubeMapFace
    -> GettableStateVar TextureTargetCubeMapFace
    forall a b. (a -> b) -> a -> b
    $
       FramebufferTarget
    -> fba
    -> (GLint -> TextureTargetCubeMapFace)
    -> GetFramebufferAttachmentPName
    -> GettableStateVar TextureTargetCubeMapFace
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba (GLenum -> TextureTargetCubeMapFace
    unmarshalTextureTargetCubeMapFace (GLenum -> TextureTargetCubeMapFace)
    -> (GLint -> GLenum) -> GLint -> TextureTargetCubeMapFace
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLint -> GLenum
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) GetFramebufferAttachmentPName
    AttachmentTextureLevel

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

    attachmentRedSize :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar GLint
    attachmentRedSize :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget -> fba -> GettableStateVar GLint
    attachmentRedSize FramebufferTarget
    fbt fba
    fba = 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
    $ FramebufferTarget
    -> fba
    -> (GLint -> GLint)
    -> GetFramebufferAttachmentPName
    -> GettableStateVar GLint
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba
        GLint -> GLint
    forall a. a -> a
    id GetFramebufferAttachmentPName
    AttachmentRedSize

    attachmentGreenSize :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar GLint
    attachmentGreenSize :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget -> fba -> GettableStateVar GLint
    attachmentGreenSize FramebufferTarget
    fbt fba
    fba = 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
    $ FramebufferTarget
    -> fba
    -> (GLint -> GLint)
    -> GetFramebufferAttachmentPName
    -> GettableStateVar GLint
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba
        GLint -> GLint
    forall a. a -> a
    id GetFramebufferAttachmentPName
    AttachmentGreenSize

    attachmentBlueSize :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar GLint
    attachmentBlueSize :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget -> fba -> GettableStateVar GLint
    attachmentBlueSize FramebufferTarget
    fbt fba
    fba = 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
    $ FramebufferTarget
    -> fba
    -> (GLint -> GLint)
    -> GetFramebufferAttachmentPName
    -> GettableStateVar GLint
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba
        GLint -> GLint
    forall a. a -> a
    id GetFramebufferAttachmentPName
    AttachmentBlueSize

    attachmentAlphaSize :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar GLint
    attachmentAlphaSize :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget -> fba -> GettableStateVar GLint
    attachmentAlphaSize FramebufferTarget
    fbt fba
    fba = 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
    $ FramebufferTarget
    -> fba
    -> (GLint -> GLint)
    -> GetFramebufferAttachmentPName
    -> GettableStateVar GLint
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba
        GLint -> GLint
    forall a. a -> a
    id GetFramebufferAttachmentPName
    AttachmentAlphaSize

    attachmentDepthSize :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar GLint
    attachmentDepthSize :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget -> fba -> GettableStateVar GLint
    attachmentDepthSize FramebufferTarget
    fbt fba
    fba = 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
    $ FramebufferTarget
    -> fba
    -> (GLint -> GLint)
    -> GetFramebufferAttachmentPName
    -> GettableStateVar GLint
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba
        GLint -> GLint
    forall a. a -> a
    id GetFramebufferAttachmentPName
    AttachmentDepthSize

    attachmentStencilSize :: FramebufferAttachment fba => FramebufferTarget -> fba
       -> GettableStateVar GLint
    attachmentStencilSize :: forall fba.
    FramebufferAttachment fba =>
    FramebufferTarget -> fba -> GettableStateVar GLint
    attachmentStencilSize FramebufferTarget
    fbt fba
    fba = 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
    $ FramebufferTarget
    -> fba
    -> (GLint -> GLint)
    -> GetFramebufferAttachmentPName
    -> GettableStateVar GLint
    forall fba a.
    FramebufferAttachment fba =>
    FramebufferTarget
    -> fba -> (GLint -> a) -> GetFramebufferAttachmentPName -> IO a
    getFBAPName FramebufferTarget
    fbt fba
    fba
        GLint -> GLint
    forall a. a -> a
    id GetFramebufferAttachmentPName
    AttachmentStencilSize

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

    data GetRenderbufferPName =
         RenderbufferWidth
       | RenderbufferHeight
       | RenderbufferInternalFormat
       | RenderbufferSamples
       | RenderbufferRedSize
       | RenderbufferBlueSize
       | RenderbufferGreenSize
       | RenderbufferAlphaSize
       | RenderbufferDepthSize
       | RenderbufferStencilSize

    marshalGetRBPname :: GetRenderbufferPName -> GLenum
    marshalGetRBPname :: GetRenderbufferPName -> GLenum
    marshalGetRBPname GetRenderbufferPName
    x = case GetRenderbufferPName
    x of
        GetRenderbufferPName
    RenderbufferWidth -> GLenum
    GL_RENDERBUFFER_WIDTH
        GetRenderbufferPName
    RenderbufferHeight -> GLenum
    GL_RENDERBUFFER_HEIGHT
        GetRenderbufferPName
    RenderbufferInternalFormat -> GLenum
    GL_RENDERBUFFER_INTERNAL_FORMAT
        GetRenderbufferPName
    RenderbufferSamples -> GLenum
    GL_RENDERBUFFER_SAMPLES
        GetRenderbufferPName
    RenderbufferRedSize -> GLenum
    GL_RENDERBUFFER_RED_SIZE
        GetRenderbufferPName
    RenderbufferBlueSize -> GLenum
    GL_RENDERBUFFER_BLUE_SIZE
        GetRenderbufferPName
    RenderbufferGreenSize -> GLenum
    GL_RENDERBUFFER_GREEN_SIZE
        GetRenderbufferPName
    RenderbufferAlphaSize -> GLenum
    GL_RENDERBUFFER_ALPHA_SIZE
        GetRenderbufferPName
    RenderbufferDepthSize -> GLenum
    GL_RENDERBUFFER_DEPTH_SIZE
        GetRenderbufferPName
    RenderbufferStencilSize -> GLenum
    GL_RENDERBUFFER_STENCIL_SIZE

    getRBPName :: RenderbufferTarget -> (GLint -> a) ->
       GetRenderbufferPName -> IO a
    getRBPName :: forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt GLint -> a
    f = RenderbufferTarget -> (GLint -> a) -> GLenum -> IO a
    forall a. RenderbufferTarget -> (GLint -> a) -> GLenum -> IO a
    getRBParameteriv RenderbufferTarget
    rbt GLint -> a
    f (GLenum -> IO a)
    -> (GetRenderbufferPName -> GLenum) -> GetRenderbufferPName -> IO a
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GetRenderbufferPName -> GLenum
    marshalGetRBPname

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

    renderbufferWidth :: RenderbufferTarget -> GettableStateVar GLsizei
    renderbufferWidth :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferWidth RenderbufferTarget
    rbt = 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
    $
       RenderbufferTarget
    -> (GLint -> GLint)
    -> GetRenderbufferPName
    -> GettableStateVar GLint
    forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt GLint -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral GetRenderbufferPName
    RenderbufferWidth

    renderbufferHeight :: RenderbufferTarget -> GettableStateVar GLsizei
    renderbufferHeight :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferHeight RenderbufferTarget
    rbt = 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
    $
       RenderbufferTarget
    -> (GLint -> GLint)
    -> GetRenderbufferPName
    -> GettableStateVar GLint
    forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt GLint -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral GetRenderbufferPName
    RenderbufferHeight

    renderbufferInternalFormat :: RenderbufferTarget
       -> GettableStateVar PixelInternalFormat
    renderbufferInternalFormat :: RenderbufferTarget -> GettableStateVar PixelInternalFormat
    renderbufferInternalFormat RenderbufferTarget
    rbt = 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
    $
       RenderbufferTarget
    -> (GLint -> PixelInternalFormat)
    -> GetRenderbufferPName
    -> GettableStateVar PixelInternalFormat
    forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt GLint -> PixelInternalFormat
    unmarshalPixelInternalFormat GetRenderbufferPName
    RenderbufferInternalFormat

    renderbufferSamples :: RenderbufferTarget -> GettableStateVar Samples
    renderbufferSamples :: RenderbufferTarget -> GettableStateVar Samples
    renderbufferSamples RenderbufferTarget
    rbt = GettableStateVar Samples -> GettableStateVar Samples
    forall a. IO a -> IO a
    makeGettableStateVar (GettableStateVar Samples -> GettableStateVar Samples)
    -> GettableStateVar Samples -> GettableStateVar Samples
    forall a b. (a -> b) -> a -> b
    $
       RenderbufferTarget
    -> (GLint -> Samples)
    -> GetRenderbufferPName
    -> GettableStateVar Samples
    forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt (GLint -> Samples
    Samples (GLint -> Samples) -> (GLint -> GLint) -> GLint -> Samples
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . GLint -> GLint
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral) GetRenderbufferPName
    RenderbufferSamples

    renderbufferRedSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferRedSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferRedSize RenderbufferTarget
    rbt = 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
    $
       RenderbufferTarget
    -> (GLint -> GLint)
    -> GetRenderbufferPName
    -> GettableStateVar GLint
    forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt GLint -> GLint
    forall a. a -> a
    id GetRenderbufferPName
    RenderbufferRedSize

    renderbufferGreenSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferGreenSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferGreenSize RenderbufferTarget
    rbt = 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
    $
       RenderbufferTarget
    -> (GLint -> GLint)
    -> GetRenderbufferPName
    -> GettableStateVar GLint
    forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt GLint -> GLint
    forall a. a -> a
    id GetRenderbufferPName
    RenderbufferGreenSize

    renderbufferBlueSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferBlueSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferBlueSize RenderbufferTarget
    rbt = 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
    $
       RenderbufferTarget
    -> (GLint -> GLint)
    -> GetRenderbufferPName
    -> GettableStateVar GLint
    forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt GLint -> GLint
    forall a. a -> a
    id GetRenderbufferPName
    RenderbufferBlueSize

    renderbufferAlphaSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferAlphaSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferAlphaSize RenderbufferTarget
    rbt = 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
    $
       RenderbufferTarget
    -> (GLint -> GLint)
    -> GetRenderbufferPName
    -> GettableStateVar GLint
    forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt GLint -> GLint
    forall a. a -> a
    id GetRenderbufferPName
    RenderbufferAlphaSize

    renderbufferDepthSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferDepthSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferDepthSize RenderbufferTarget
    rbt = 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
    $
       RenderbufferTarget
    -> (GLint -> GLint)
    -> GetRenderbufferPName
    -> GettableStateVar GLint
    forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt GLint -> GLint
    forall a. a -> a
    id GetRenderbufferPName
    RenderbufferDepthSize

    renderbufferStencilSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferStencilSize :: RenderbufferTarget -> GettableStateVar GLint
    renderbufferStencilSize RenderbufferTarget
    rbt = 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
    $
       RenderbufferTarget
    -> (GLint -> GLint)
    -> GetRenderbufferPName
    -> GettableStateVar GLint
    forall a.
    RenderbufferTarget -> (GLint -> a) -> GetRenderbufferPName -> IO a
    getRBPName RenderbufferTarget
    rbt GLint -> GLint
    forall a. a -> a
    id GetRenderbufferPName
    RenderbufferStencilSize