    --------------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.Hints
    -- Copyright   :  (c) Sven Panne 2002-2019
    -- License     :  BSD3
    --
    -- Maintainer  :  Sven Panne <svenpanne@gmail.com>
    -- Stability   :  stable
    -- Portability :  portable
    --
    -- This module corresponds to section 5.6 (Hints) of the OpenGL 2.1 specs.
    --
    --------------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.Hints (
       HintTarget(..), HintMode(..), hint
    ) where

    import Data.StateVar
    import Graphics.Rendering.OpenGL.GL.QueryUtils
    import Graphics.GL

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

    data HintTarget =
         PerspectiveCorrection
       | PointSmooth
       | LineSmooth
       | PolygonSmooth
       | Fog
       | GenerateMipmap
       | TextureCompression
       | PackCMYK
       | UnpackCMYK
       deriving ( HintTarget -> HintTarget -> Bool
    (HintTarget -> HintTarget -> Bool)
    -> (HintTarget -> HintTarget -> Bool) -> Eq HintTarget
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: HintTarget -> HintTarget -> Bool
    == :: HintTarget -> HintTarget -> Bool
    $c/= :: HintTarget -> HintTarget -> Bool
    /= :: HintTarget -> HintTarget -> Bool
    Eq, Eq HintTarget
    Eq HintTarget =>
    (HintTarget -> HintTarget -> Ordering)
    -> (HintTarget -> HintTarget -> Bool)
    -> (HintTarget -> HintTarget -> Bool)
    -> (HintTarget -> HintTarget -> Bool)
    -> (HintTarget -> HintTarget -> Bool)
    -> (HintTarget -> HintTarget -> HintTarget)
    -> (HintTarget -> HintTarget -> HintTarget)
    -> Ord HintTarget
    HintTarget -> HintTarget -> Bool
    HintTarget -> HintTarget -> Ordering
    HintTarget -> HintTarget -> HintTarget
    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 :: HintTarget -> HintTarget -> Ordering
    compare :: HintTarget -> HintTarget -> Ordering
    $c< :: HintTarget -> HintTarget -> Bool
    < :: HintTarget -> HintTarget -> Bool
    $c<= :: HintTarget -> HintTarget -> Bool
    <= :: HintTarget -> HintTarget -> Bool
    $c> :: HintTarget -> HintTarget -> Bool
    > :: HintTarget -> HintTarget -> Bool
    $c>= :: HintTarget -> HintTarget -> Bool
    >= :: HintTarget -> HintTarget -> Bool
    $cmax :: HintTarget -> HintTarget -> HintTarget
    max :: HintTarget -> HintTarget -> HintTarget
    $cmin :: HintTarget -> HintTarget -> HintTarget
    min :: HintTarget -> HintTarget -> HintTarget
    Ord, Int -> HintTarget -> ShowS
    [HintTarget] -> ShowS
    HintTarget -> String
    (Int -> HintTarget -> ShowS)
    -> (HintTarget -> String)
    -> ([HintTarget] -> ShowS)
    -> Show HintTarget
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> HintTarget -> ShowS
    showsPrec :: Int -> HintTarget -> ShowS
    $cshow :: HintTarget -> String
    show :: HintTarget -> String
    $cshowList :: [HintTarget] -> ShowS
    showList :: [HintTarget] -> ShowS
    Show )

    marshalHintTarget :: HintTarget -> GLenum
    marshalHintTarget :: HintTarget -> GLenum
    marshalHintTarget HintTarget
    x = case HintTarget
    x of
       HintTarget
    PerspectiveCorrection -> GLenum
    GL_PERSPECTIVE_CORRECTION_HINT
       HintTarget
    PointSmooth -> GLenum
    GL_POINT_SMOOTH_HINT
       HintTarget
    LineSmooth -> GLenum
    GL_LINE_SMOOTH_HINT
       HintTarget
    PolygonSmooth -> GLenum
    GL_POLYGON_SMOOTH_HINT
       HintTarget
    Fog -> GLenum
    GL_FOG_HINT
       HintTarget
    GenerateMipmap -> GLenum
    GL_GENERATE_MIPMAP_HINT
       HintTarget
    TextureCompression -> GLenum
    GL_TEXTURE_COMPRESSION_HINT
       HintTarget
    PackCMYK -> GLenum
    GL_PACK_CMYK_HINT_EXT
       HintTarget
    UnpackCMYK -> GLenum
    GL_UNPACK_CMYK_HINT_EXT

    hintTargetToGetPName :: HintTarget -> PName1I
    hintTargetToGetPName :: HintTarget -> PName1I
    hintTargetToGetPName HintTarget
    x = case HintTarget
    x of
       HintTarget
    PerspectiveCorrection -> PName1I
    GetPerspectiveCorrectionHint
       HintTarget
    PointSmooth -> PName1I
    GetPointSmoothHint
       HintTarget
    LineSmooth -> PName1I
    GetLineSmoothHint
       HintTarget
    PolygonSmooth -> PName1I
    GetPolygonSmoothHint
       HintTarget
    Fog -> PName1I
    GetFogHint
       HintTarget
    GenerateMipmap -> PName1I
    GetGenerateMipmapHint
       HintTarget
    TextureCompression -> PName1I
    GetTextureCompressionHint
       HintTarget
    PackCMYK -> PName1I
    GetPackCMYKHint
       HintTarget
    UnpackCMYK -> PName1I
    GetUnpackCMYKHint

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

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

    marshalHintMode :: HintMode -> GLenum
    marshalHintMode :: HintMode -> GLenum
    marshalHintMode HintMode
    x = case HintMode
    x of
       HintMode
    DontCare -> GLenum
    GL_DONT_CARE
       HintMode
    Fastest -> GLenum
    GL_FASTEST
       HintMode
    Nicest -> GLenum
    GL_NICEST

    unmarshalHintMode :: GLenum -> HintMode
    unmarshalHintMode :: GLenum -> HintMode
    unmarshalHintMode GLenum
    x
       | GLenum
    x GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_DONT_CARE = HintMode
    DontCare
       | GLenum
    x GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_FASTEST = HintMode
    Fastest
       | GLenum
    x GLenum -> GLenum -> Bool
    forall a. Eq a => a -> a -> Bool
    == GLenum
    GL_NICEST = HintMode
    Nicest
       | Bool
    otherwise = String -> HintMode
    forall a. HasCallStack => String -> a
    error (String
    "unmarshalHintMode: illegal value " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ GLenum -> String
    forall a. Show a => a -> String
    show GLenum
    x)

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

    hint ::  HintTarget -> StateVar HintMode
    hint :: HintTarget -> StateVar HintMode
    hint HintTarget
    t =
       IO HintMode -> (HintMode -> IO ()) -> StateVar HintMode
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar
          ((GLenum -> HintMode) -> PName1I -> IO HintMode
    forall p a. GetPName1I p => (GLenum -> a) -> p -> IO a
    forall a. (GLenum -> a) -> PName1I -> IO a
    getEnum1 GLenum -> HintMode
    unmarshalHintMode (HintTarget -> PName1I
    hintTargetToGetPName HintTarget
    t))
          (GLenum -> GLenum -> IO ()
    forall (m :: * -> *). MonadIO m => GLenum -> GLenum -> m ()
    glHint (HintTarget -> GLenum
    marshalHintTarget HintTarget
    t) (GLenum -> IO ()) -> (HintMode -> GLenum) -> HintMode -> IO ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . HintMode -> GLenum
    marshalHintMode)