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

    module Graphics.Rendering.OpenGL.GL.Evaluators (
       -- * Evaluator-related Types
       Order, maxOrder, Domain, MapDescriptor(..), ControlPoint,

       -- * Defining Evaluator Maps
       -- ** One-dimensional Evaluator Maps
       Map1(..), GLmap1, map1,

       -- ** Two-dimensional Evaluator Maps
       Map2(..), GLmap2, map2,

       -- * Using Evaluator Maps

       -- ** Evaluating an Arbitrary Coordinate Value
       evalCoord1, evalCoord1v, evalCoord2, evalCoord2v,

       -- ** Using Evenly Spaced Coordinate Values

       -- *** Defining a Grid
       mapGrid1, mapGrid2,

       -- *** Evaluating a Whole Mesh
       evalMesh1, evalMesh2,

       -- *** Evaluating a Single Point on a Mesh
       evalPoint1, evalPoint2,

       -- * Normal Generation
       autoNormal
    ) where

    import Control.Monad
    import Data.List
    import Data.StateVar
    import Foreign.ForeignPtr
    import Foreign.Marshal.Array
    import Foreign.Marshal.Utils
    import Foreign.Ptr
    import Foreign.Storable
    import Graphics.Rendering.OpenGL.GL.Capability
    import Graphics.Rendering.OpenGL.GL.ControlPoint
    import Graphics.Rendering.OpenGL.GL.Domain
    import Graphics.Rendering.OpenGL.GL.PeekPoke
    import Graphics.Rendering.OpenGL.GL.PolygonMode
    import Graphics.Rendering.OpenGL.GL.QueryUtils
    import Graphics.Rendering.OpenGL.GL.VertexArrays
    import Graphics.GL

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

    type Order = GLint

    maxOrder :: GettableStateVar Order
    maxOrder :: GettableStateVar Order
    maxOrder = GettableStateVar Order -> GettableStateVar Order
    forall a. IO a -> IO a
    makeGettableStateVar ((Order -> Order) -> PName1I -> GettableStateVar Order
    forall p a. GetPName1I p => (Order -> a) -> p -> IO a
    forall a. (Order -> a) -> PName1I -> IO a
    getInteger1 Order -> Order
    forall a. a -> a
    id PName1I
    GetMaxEvalOrder)

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

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

    totalComponents1 :: MapDescriptor d -> Int
    totalComponents1 :: forall d. MapDescriptor d -> Int
    totalComponents1 (MapDescriptor (d, d)
    _ Order
    stride Order
    order Order
    numComp) =
       Order -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    stride Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * (Order -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    order Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Order -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    numComp

    totalComponents2 :: MapDescriptor d -> MapDescriptor d -> Int
    totalComponents2 :: forall d. MapDescriptor d -> MapDescriptor d -> Int
    totalComponents2 MapDescriptor d
    uDescriptor vDescriptor :: MapDescriptor d
    vDescriptor@(MapDescriptor (d, d)
    _ Order
    _ Order
    _ Order
    numComp) =
       MapDescriptor d -> Int
    forall d. MapDescriptor d -> Int
    totalComponents1 MapDescriptor d
    uDescriptor Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + MapDescriptor d -> Int
    forall d. MapDescriptor d -> Int
    totalComponents1 MapDescriptor d
    vDescriptor Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Order -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    numComp

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

    peekControlPoints1 ::
       (ControlPoint c, Domain d) => MapDescriptor d -> Ptr d -> IO [c d]
    peekControlPoints1 :: forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> Ptr d -> IO [c d]
    peekControlPoints1 MapDescriptor d
    descriptor Ptr d
    ptr =
       (Ptr (c d) -> IO (c d)) -> [Ptr (c d)] -> IO [c d]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM Ptr (c d) -> IO (c d)
    forall d. Domain d => Ptr (c d) -> IO (c d)
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    Ptr (c d) -> IO (c d)
    peekControlPoint (MapDescriptor d -> Ptr d -> [Ptr (c d)]
    forall d a. Domain d => MapDescriptor d -> Ptr d -> [Ptr a]
    controlPointPtrs1 MapDescriptor d
    descriptor Ptr d
    ptr)

    peekControlPoints2 ::
          (ControlPoint c, Domain d)
       => MapDescriptor d -> MapDescriptor d -> Ptr d -> IO [[c d]]
    peekControlPoints2 :: forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> MapDescriptor d -> Ptr d -> IO [[c d]]
    peekControlPoints2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d
    ptr =
       ([Ptr (c d)] -> IO [c d]) -> [[Ptr (c d)]] -> IO [[c d]]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM ((Ptr (c d) -> IO (c d)) -> [Ptr (c d)] -> IO [c d]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
    mapM Ptr (c d) -> IO (c d)
    forall d. Domain d => Ptr (c d) -> IO (c d)
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    Ptr (c d) -> IO (c d)
    peekControlPoint) (MapDescriptor d -> MapDescriptor d -> Ptr d -> [[Ptr (c d)]]
    forall d a.
    Domain d =>
    MapDescriptor d -> MapDescriptor d -> Ptr d -> [[Ptr a]]
    controlPointPtrs2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d
    ptr)

    pokeControlPoints1 ::
       (ControlPoint c, Domain d) => MapDescriptor d -> Ptr d -> [c d] -> IO ()
    pokeControlPoints1 :: forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> Ptr d -> [c d] -> IO ()
    pokeControlPoints1 MapDescriptor d
    descriptor Ptr d
    ptr =
       (Ptr (c d) -> c d -> IO ()) -> [Ptr (c d)] -> [c d] -> IO ()
    forall (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> m c) -> [a] -> [b] -> m ()
    zipWithM_ Ptr (c d) -> c d -> IO ()
    forall d. Domain d => Ptr (c d) -> c d -> IO ()
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    Ptr (c d) -> c d -> IO ()
    pokeControlPoint (MapDescriptor d -> Ptr d -> [Ptr (c d)]
    forall d a. Domain d => MapDescriptor d -> Ptr d -> [Ptr a]
    controlPointPtrs1 MapDescriptor d
    descriptor Ptr d
    ptr)

    pokeControlPoints2 ::
          (ControlPoint c, Domain d)
       => MapDescriptor d -> MapDescriptor d -> Ptr d -> [[c d]] -> IO ()
    pokeControlPoints2 :: forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> MapDescriptor d -> Ptr d -> [[c d]] -> IO ()
    pokeControlPoints2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d
    ptr =
       ([Ptr (c d)] -> [c d] -> IO ())
    -> [[Ptr (c d)]] -> [[c d]] -> IO ()
    forall (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> m c) -> [a] -> [b] -> m ()
    zipWithM_ ((Ptr (c d) -> c d -> IO ()) -> [Ptr (c d)] -> [c d] -> IO ()
    forall (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> m c) -> [a] -> [b] -> m ()
    zipWithM_ Ptr (c d) -> c d -> IO ()
    forall d. Domain d => Ptr (c d) -> c d -> IO ()
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    Ptr (c d) -> c d -> IO ()
    pokeControlPoint)
                 (MapDescriptor d -> MapDescriptor d -> Ptr d -> [[Ptr (c d)]]
    forall d a.
    Domain d =>
    MapDescriptor d -> MapDescriptor d -> Ptr d -> [[Ptr a]]
    controlPointPtrs2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d
    ptr)

    controlPointPtrs1 :: Domain d => MapDescriptor d -> Ptr d -> [Ptr a]
    controlPointPtrs1 :: forall d a. Domain d => MapDescriptor d -> Ptr d -> [Ptr a]
    controlPointPtrs1 (MapDescriptor (d, d)
    _ Order
    stride Order
    order Order
    _) Ptr d
    ptr =
       [ Ptr d
    ptr Ptr d -> Int -> Ptr a
    forall a b. Ptr a -> Int -> Ptr b
    `plusPtr` (Int
    o Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    s) | Int
    o <- [ Int
    0 .. Order -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    order Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1 ] ]
       where s :: Int
    s = Ptr d -> Int
    forall a. Storable a => Ptr a -> Int
    sizeOfPtr Ptr d
    ptr Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Order -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    stride

    controlPointPtrs2 ::
       Domain d => MapDescriptor d -> MapDescriptor d -> Ptr d -> [[Ptr a]]
    controlPointPtrs2 :: forall d a.
    Domain d =>
    MapDescriptor d -> MapDescriptor d -> Ptr d -> [[Ptr a]]
    controlPointPtrs2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d
    ptr =
       [ MapDescriptor d -> Ptr d -> [Ptr a]
    forall d a. Domain d => MapDescriptor d -> Ptr d -> [Ptr a]
    controlPointPtrs1 MapDescriptor d
    vDescriptor Ptr d
    p | Ptr d
    p <- MapDescriptor d -> Ptr d -> [Ptr d]
    forall d a. Domain d => MapDescriptor d -> Ptr d -> [Ptr a]
    controlPointPtrs1 MapDescriptor d
    uDescriptor Ptr d
    ptr ]

    sizeOfPtr :: Storable a => Ptr a -> Int
    sizeOfPtr :: forall a. Storable a => Ptr a -> Int
    sizeOfPtr = a -> Int
    forall a. Storable a => a -> Int
    sizeOf (a -> Int) -> (Ptr a -> a) -> Ptr a -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a -> Ptr a -> a
    forall a b. a -> b -> a
    const a
    forall a. HasCallStack => a
    undefined :: Ptr a -> a)

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

    class Map1 m where
       withNewMap1 :: (ControlPoint c, Domain d)
          => MapDescriptor d -> (Ptr d -> IO ()) -> IO (m c d)

       withMap1 :: (ControlPoint c, Domain d)
          => m c d -> (MapDescriptor d -> Ptr d -> IO a) -> IO a

       newMap1 :: (ControlPoint c, Domain d)
          => (d, d) -> [c d] -> IO (m c d)

       getMap1Components :: (ControlPoint c, Domain d)
          => m c d -> IO ((d, d), [c d])

       withNewMap1 descriptor :: MapDescriptor d
    descriptor@(MapDescriptor (d, d)
    domain Order
    _ Order
    _ Order
    _) Ptr d -> IO ()
    act = do
          Int -> (Ptr d -> IO (m c d)) -> IO (m c d)
    forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
    allocaArray (MapDescriptor d -> Int
    forall d. MapDescriptor d -> Int
    totalComponents1 MapDescriptor d
    descriptor) ((Ptr d -> IO (m c d)) -> IO (m c d))
    -> (Ptr d -> IO (m c d)) -> IO (m c d)
    forall a b. (a -> b) -> a -> b
    $ \Ptr d
    ptr -> do
             Ptr d -> IO ()
    act Ptr d
    ptr
             controlPoints <- MapDescriptor d -> Ptr d -> IO [c d]
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> Ptr d -> IO [c d]
    peekControlPoints1 MapDescriptor d
    descriptor Ptr d
    ptr
             newMap1 domain controlPoints

       withMap1 m c d
    m MapDescriptor d -> Ptr d -> IO a
    act = do
          (domain, controlPoints) <- m c d -> IO ((d, d), [c d])
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    m c d -> IO ((d, d), [c d])
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map1 m, ControlPoint c, Domain d) =>
    m c d -> IO ((d, d), [c d])
    getMap1Components m c d
    m
          let stride = c d -> Order
    forall d. Domain d => c d -> Order
    forall (c :: * -> *) d. (ControlPoint c, Domain d) => c d -> Order
    numComponents ([c d] -> c d
    forall a. HasCallStack => [a] -> a
    head [c d]
    controlPoints)
              order = [c d] -> Order
    forall i a. Num i => [a] -> i
    genericLength [c d]
    controlPoints
              descriptor = (d, d) -> Order -> Order -> Order -> MapDescriptor d
    forall d. (d, d) -> Order -> Order -> Order -> MapDescriptor d
    MapDescriptor (d, d)
    domain Order
    stride Order
    order (Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    stride)
          allocaArray (totalComponents1 descriptor) $ \Ptr d
    ptr -> do
             MapDescriptor d -> Ptr d -> [c d] -> IO ()
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> Ptr d -> [c d] -> IO ()
    pokeControlPoints1 MapDescriptor d
    descriptor Ptr d
    ptr [c d]
    controlPoints
             MapDescriptor d -> Ptr d -> IO a
    act MapDescriptor d
    descriptor Ptr d
    ptr

       newMap1 (d, d)
    domain [c d]
    controlPoints = do
          let stride :: Order
    stride = c d -> Order
    forall d. Domain d => c d -> Order
    forall (c :: * -> *) d. (ControlPoint c, Domain d) => c d -> Order
    numComponents ([c d] -> c d
    forall a. HasCallStack => [a] -> a
    head [c d]
    controlPoints)
              order :: Order
    order = [c d] -> Order
    forall i a. Num i => [a] -> i
    genericLength [c d]
    controlPoints
              descriptor :: MapDescriptor d
    descriptor = (d, d) -> Order -> Order -> Order -> MapDescriptor d
    forall d. (d, d) -> Order -> Order -> Order -> MapDescriptor d
    MapDescriptor (d, d)
    domain Order
    stride Order
    order (Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    stride)
          MapDescriptor d -> (Ptr d -> IO ()) -> IO (m c d)
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> (Ptr d -> IO ()) -> IO (m c d)
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map1 m, ControlPoint c, Domain d) =>
    MapDescriptor d -> (Ptr d -> IO ()) -> IO (m c d)
    withNewMap1 MapDescriptor d
    descriptor ((Ptr d -> IO ()) -> IO (m c d)) -> (Ptr d -> IO ()) -> IO (m c d)
    forall a b. (a -> b) -> a -> b
    $ \Ptr d
    ptr ->
             MapDescriptor d -> Ptr d -> [c d] -> IO ()
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> Ptr d -> [c d] -> IO ()
    pokeControlPoints1 MapDescriptor d
    descriptor Ptr d
    ptr [c d]
    controlPoints

       getMap1Components m c d
    m =
          m c d
    -> (MapDescriptor d -> Ptr d -> IO ((d, d), [c d]))
    -> IO ((d, d), [c d])
    forall (c :: * -> *) d a.
    (ControlPoint c, Domain d) =>
    m c d -> (MapDescriptor d -> Ptr d -> IO a) -> IO a
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d a.
    (Map1 m, ControlPoint c, Domain d) =>
    m c d -> (MapDescriptor d -> Ptr d -> IO a) -> IO a
    withMap1 m c d
    m ((MapDescriptor d -> Ptr d -> IO ((d, d), [c d]))
     -> IO ((d, d), [c d]))
    -> (MapDescriptor d -> Ptr d -> IO ((d, d), [c d]))
    -> IO ((d, d), [c d])
    forall a b. (a -> b) -> a -> b
    $ \descriptor :: MapDescriptor d
    descriptor@(MapDescriptor (d, d)
    domain Order
    _ Order
    _ Order
    _) Ptr d
    ptr -> do
             controlPoints <- MapDescriptor d -> Ptr d -> IO [c d]
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> Ptr d -> IO [c d]
    peekControlPoints1 MapDescriptor d
    descriptor Ptr d
    ptr
             return (domain, controlPoints)

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

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

    instance Map1 GLmap1 where
       withNewMap1 :: forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> (Ptr d -> IO ()) -> IO (GLmap1 c d)
    withNewMap1 MapDescriptor d
    descriptor Ptr d -> IO ()
    act = do
          fp <- Int -> IO (ForeignPtr d)
    forall a. Storable a => Int -> IO (ForeignPtr a)
    mallocForeignPtrArray (MapDescriptor d -> Int
    forall d. MapDescriptor d -> Int
    totalComponents1 MapDescriptor d
    descriptor)
          withForeignPtr fp act
          return $ GLmap1 descriptor fp

       withMap1 :: forall (c :: * -> *) d a.
    (ControlPoint c, Domain d) =>
    GLmap1 c d -> (MapDescriptor d -> Ptr d -> IO a) -> IO a
    withMap1 (GLmap1 MapDescriptor d
    descriptor ForeignPtr d
    fp) MapDescriptor d -> Ptr d -> IO a
    act =
          ForeignPtr d -> (Ptr d -> IO a) -> IO a
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr d
    fp ((Ptr d -> IO a) -> IO a) -> (Ptr d -> IO a) -> IO a
    forall a b. (a -> b) -> a -> b
    $ MapDescriptor d -> Ptr d -> IO a
    act MapDescriptor d
    descriptor

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

    map1 :: (Map1 m, ControlPoint c, Domain d) => StateVar (Maybe (m c d))
    map1 :: forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map1 m, ControlPoint c, Domain d) =>
    StateVar (Maybe (m c d))
    map1 = (c d -> EnableCap)
    -> (c d -> IO (m c d))
    -> (c d -> m c d -> IO ())
    -> StateVar (Maybe (m c d))
    forall (c :: * -> *) d (m :: (* -> *) -> * -> *).
    (c d -> EnableCap)
    -> (c d -> IO (m c d))
    -> (c d -> m c d -> IO ())
    -> StateVar (Maybe (m c d))
    makeMap1StateVar c d -> EnableCap
    forall d. Domain d => c d -> EnableCap
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    c d -> EnableCap
    enableCap1 c d -> IO (m c d)
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map1 m, ControlPoint c, Domain d) =>
    c d -> IO (m c d)
    getMap1 c d -> m c d -> IO ()
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map1 m, ControlPoint c, Domain d) =>
    c d -> m c d -> IO ()
    setMap1

    makeMap1StateVar ::
          (c d -> EnableCap) -> (c d -> IO (m c d)) -> (c d -> m c d -> IO ())
       -> StateVar (Maybe (m c d))
    makeMap1StateVar :: forall (c :: * -> *) d (m :: (* -> *) -> * -> *).
    (c d -> EnableCap)
    -> (c d -> IO (m c d))
    -> (c d -> m c d -> IO ())
    -> StateVar (Maybe (m c d))
    makeMap1StateVar c d -> EnableCap
    getCap c d -> IO (m c d)
    getAct c d -> m c d -> IO ()
    setAct =
       IO EnableCap
    -> IO (m c d) -> (m c d -> IO ()) -> StateVar (Maybe (m c d))
    forall a.
    IO EnableCap -> IO a -> (a -> IO ()) -> StateVar (Maybe a)
    makeStateVarMaybe
          (EnableCap -> IO EnableCap
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (c d -> EnableCap
    getCap c d
    forall a. HasCallStack => a
    undefined))
          (c d -> IO (m c d)
    getAct c d
    forall a. HasCallStack => a
    undefined)
          (c d -> m c d -> IO ()
    setAct c d
    forall a. HasCallStack => a
    undefined)

    getMap1 :: (Map1 m, ControlPoint c, Domain d) => c d -> IO (m c d)
    getMap1 :: forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map1 m, ControlPoint c, Domain d) =>
    c d -> IO (m c d)
    getMap1 c d
    dummyControlPoint = do
       let target :: GLenum
    target = c d -> GLenum
    forall d. Domain d => c d -> GLenum
    forall (c :: * -> *) d. (ControlPoint c, Domain d) => c d -> GLenum
    map1Target c d
    dummyControlPoint
           numComp :: Order
    numComp = Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (c d -> Order
    forall d. Domain d => c d -> Order
    forall (c :: * -> *) d. (ControlPoint c, Domain d) => c d -> Order
    numComponents c d
    dummyControlPoint)
       domain <- Int -> (Ptr d -> IO (d, d)) -> IO (d, d)
    forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
    allocaArray Int
    2 ((Ptr d -> IO (d, d)) -> IO (d, d))
    -> (Ptr d -> IO (d, d)) -> IO (d, d)
    forall a b. (a -> b) -> a -> b
    $ \Ptr d
    ptr -> do
          GLenum -> GLenum -> Ptr d -> IO ()
    forall d. Domain d => GLenum -> GLenum -> Ptr d -> IO ()
    glGetMapv GLenum
    target (GetMapQuery -> GLenum
    marshalGetMapQuery GetMapQuery
    Domain) Ptr d
    ptr
          (d -> d -> (d, d)) -> Ptr d -> IO (d, d)
    forall a b. Storable a => (a -> a -> b) -> Ptr a -> IO b
    peek2 (,) Ptr d
    ptr
       order <- with 0 $ \Ptr Order
    ptr -> do
          GLenum -> GLenum -> Ptr Order -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> Ptr Order -> m ()
    glGetMapiv GLenum
    target (GetMapQuery -> GLenum
    marshalGetMapQuery GetMapQuery
    Order) Ptr Order
    ptr
          (Order -> Order)
    -> GettableStateVar Order -> GettableStateVar Order
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (GettableStateVar Order -> GettableStateVar Order)
    -> GettableStateVar Order -> GettableStateVar Order
    forall a b. (a -> b) -> a -> b
    $ Ptr Order -> GettableStateVar Order
    forall a. Storable a => Ptr a -> IO a
    peek Ptr Order
    ptr
       withNewMap1 (MapDescriptor domain (numComponents dummyControlPoint) order numComp) $
          glGetMapv target (marshalGetMapQuery Coeff)

    setMap1 :: (Map1 m, ControlPoint c, Domain d) => c d -> m c d -> IO ()
    setMap1 :: forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map1 m, ControlPoint c, Domain d) =>
    c d -> m c d -> IO ()
    setMap1 c d
    dummyControlPoint m c d
    m =
       m c d -> (MapDescriptor d -> Ptr d -> IO ()) -> IO ()
    forall (c :: * -> *) d a.
    (ControlPoint c, Domain d) =>
    m c d -> (MapDescriptor d -> Ptr d -> IO a) -> IO a
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d a.
    (Map1 m, ControlPoint c, Domain d) =>
    m c d -> (MapDescriptor d -> Ptr d -> IO a) -> IO a
    withMap1 m c d
    m ((MapDescriptor d -> Ptr d -> IO ()) -> IO ())
    -> (MapDescriptor d -> Ptr d -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \(MapDescriptor (d
    u1, d
    u2) Order
    stride Order
    order Order
    _) ->
          GLenum -> d -> d -> Order -> Order -> Ptr d -> IO ()
    forall d.
    Domain d =>
    GLenum -> d -> d -> Order -> Order -> Ptr d -> IO ()
    glMap1 (c d -> GLenum
    forall d. Domain d => c d -> GLenum
    forall (c :: * -> *) d. (ControlPoint c, Domain d) => c d -> GLenum
    map1Target c d
    dummyControlPoint) d
    u1 d
    u2
                 (Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    stride) (Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    order)

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

    class Map2 m where
       withNewMap2 :: (ControlPoint c, Domain d)
          => MapDescriptor d -> MapDescriptor d -> (Ptr d -> IO ()) -> IO (m c d)

       withMap2 :: (ControlPoint c, Domain d)
          => m c d -> (MapDescriptor d -> MapDescriptor d -> Ptr d -> IO a) -> IO a

       newMap2 :: (ControlPoint c, Domain d)
          => (d, d) -> (d, d) -> [[c d]] -> IO (m c d)

       getMap2Components :: (ControlPoint c, Domain d)
          => m c d -> IO ((d, d), (d, d), [[c d]])

       withNewMap2 uDescriptor :: MapDescriptor d
    uDescriptor@(MapDescriptor (d, d)
    uDomain Order
    _ Order
    _ Order
    _)
                   vDescriptor :: MapDescriptor d
    vDescriptor@(MapDescriptor (d, d)
    vDomain Order
    _ Order
    _ Order
    _) Ptr d -> IO ()
    act =
          Int -> (Ptr d -> IO (m c d)) -> IO (m c d)
    forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
    allocaArray (MapDescriptor d -> MapDescriptor d -> Int
    forall d. MapDescriptor d -> MapDescriptor d -> Int
    totalComponents2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor) ((Ptr d -> IO (m c d)) -> IO (m c d))
    -> (Ptr d -> IO (m c d)) -> IO (m c d)
    forall a b. (a -> b) -> a -> b
    $ \Ptr d
    ptr -> do
             Ptr d -> IO ()
    act Ptr d
    ptr
             controlPoints <- MapDescriptor d -> MapDescriptor d -> Ptr d -> IO [[c d]]
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> MapDescriptor d -> Ptr d -> IO [[c d]]
    peekControlPoints2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d
    ptr
             newMap2 uDomain vDomain controlPoints

       withMap2 m c d
    m MapDescriptor d -> MapDescriptor d -> Ptr d -> IO a
    act = do
          (uDomain, vDomain, controlPoints) <- m c d -> IO ((d, d), (d, d), [[c d]])
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    m c d -> IO ((d, d), (d, d), [[c d]])
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map2 m, ControlPoint c, Domain d) =>
    m c d -> IO ((d, d), (d, d), [[c d]])
    getMap2Components m c d
    m
          let vStride = c d -> Order
    forall d. Domain d => c d -> Order
    forall (c :: * -> *) d. (ControlPoint c, Domain d) => c d -> Order
    numComponents ([c d] -> c d
    forall a. HasCallStack => [a] -> a
    head ([[c d]] -> [c d]
    forall a. HasCallStack => [a] -> a
    head [[c d]]
    controlPoints))
              vOrder = [c d] -> Order
    forall i a. Num i => [a] -> i
    genericLength ([[c d]] -> [c d]
    forall a. HasCallStack => [a] -> a
    head [[c d]]
    controlPoints)
              uStride = Order
    vStride Order -> Order -> Order
    forall a. Num a => a -> a -> a
    * Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    vOrder
              uOrder = [[c d]] -> Order
    forall i a. Num i => [a] -> i
    genericLength [[c d]]
    controlPoints
              numComp = Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    vStride
              uDescriptor = (d, d) -> Order -> Order -> Order -> MapDescriptor d
    forall d. (d, d) -> Order -> Order -> Order -> MapDescriptor d
    MapDescriptor (d, d)
    uDomain Order
    uStride Order
    uOrder Order
    numComp
              vDescriptor = (d, d) -> Order -> Order -> Order -> MapDescriptor d
    forall d. (d, d) -> Order -> Order -> Order -> MapDescriptor d
    MapDescriptor (d, d)
    vDomain Order
    vStride Order
    vOrder Order
    numComp
          allocaArray (totalComponents2 uDescriptor vDescriptor) $ \Ptr d
    ptr -> do
             MapDescriptor d -> MapDescriptor d -> Ptr d -> [[c d]] -> IO ()
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> MapDescriptor d -> Ptr d -> [[c d]] -> IO ()
    pokeControlPoints2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d
    ptr [[c d]]
    controlPoints
             MapDescriptor d -> MapDescriptor d -> Ptr d -> IO a
    act MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d
    ptr

       newMap2 (d, d)
    uDomain (d, d)
    vDomain [[c d]]
    controlPoints = do
          let vStride :: Order
    vStride = c d -> Order
    forall d. Domain d => c d -> Order
    forall (c :: * -> *) d. (ControlPoint c, Domain d) => c d -> Order
    numComponents ([c d] -> c d
    forall a. HasCallStack => [a] -> a
    head ([[c d]] -> [c d]
    forall a. HasCallStack => [a] -> a
    head [[c d]]
    controlPoints))
              vOrder :: Order
    vOrder = [c d] -> Order
    forall i a. Num i => [a] -> i
    genericLength ([[c d]] -> [c d]
    forall a. HasCallStack => [a] -> a
    head [[c d]]
    controlPoints)
              uStride :: Order
    uStride = Order
    vStride Order -> Order -> Order
    forall a. Num a => a -> a -> a
    * Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    vOrder
              uOrder :: Order
    uOrder = [[c d]] -> Order
    forall i a. Num i => [a] -> i
    genericLength [[c d]]
    controlPoints
              numComp :: Order
    numComp = Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    vStride
              uDescriptor :: MapDescriptor d
    uDescriptor = (d, d) -> Order -> Order -> Order -> MapDescriptor d
    forall d. (d, d) -> Order -> Order -> Order -> MapDescriptor d
    MapDescriptor (d, d)
    uDomain Order
    uStride Order
    uOrder Order
    numComp
              vDescriptor :: MapDescriptor d
    vDescriptor = (d, d) -> Order -> Order -> Order -> MapDescriptor d
    forall d. (d, d) -> Order -> Order -> Order -> MapDescriptor d
    MapDescriptor (d, d)
    vDomain Order
    vStride Order
    vOrder Order
    numComp
          MapDescriptor d
    -> MapDescriptor d -> (Ptr d -> IO ()) -> IO (m c d)
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d
    -> MapDescriptor d -> (Ptr d -> IO ()) -> IO (m c d)
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map2 m, ControlPoint c, Domain d) =>
    MapDescriptor d
    -> MapDescriptor d -> (Ptr d -> IO ()) -> IO (m c d)
    withNewMap2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor ((Ptr d -> IO ()) -> IO (m c d)) -> (Ptr d -> IO ()) -> IO (m c d)
    forall a b. (a -> b) -> a -> b
    $ \Ptr d
    ptr ->
             MapDescriptor d -> MapDescriptor d -> Ptr d -> [[c d]] -> IO ()
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> MapDescriptor d -> Ptr d -> [[c d]] -> IO ()
    pokeControlPoints2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d
    ptr [[c d]]
    controlPoints

       getMap2Components m c d
    m =
          m c d
    -> (MapDescriptor d
        -> MapDescriptor d -> Ptr d -> IO ((d, d), (d, d), [[c d]]))
    -> IO ((d, d), (d, d), [[c d]])
    forall (c :: * -> *) d a.
    (ControlPoint c, Domain d) =>
    m c d
    -> (MapDescriptor d -> MapDescriptor d -> Ptr d -> IO a) -> IO a
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d a.
    (Map2 m, ControlPoint c, Domain d) =>
    m c d
    -> (MapDescriptor d -> MapDescriptor d -> Ptr d -> IO a) -> IO a
    withMap2 m c d
    m ((MapDescriptor d
      -> MapDescriptor d -> Ptr d -> IO ((d, d), (d, d), [[c d]]))
     -> IO ((d, d), (d, d), [[c d]]))
    -> (MapDescriptor d
        -> MapDescriptor d -> Ptr d -> IO ((d, d), (d, d), [[c d]]))
    -> IO ((d, d), (d, d), [[c d]])
    forall a b. (a -> b) -> a -> b
    $ \uDescriptor :: MapDescriptor d
    uDescriptor@(MapDescriptor (d, d)
    uDomain Order
    _ Order
    _ Order
    _)
                        vDescriptor :: MapDescriptor d
    vDescriptor@(MapDescriptor (d, d)
    vDomain Order
    _ Order
    _ Order
    _) Ptr d
    ptr -> do
             controlPoints <- MapDescriptor d -> MapDescriptor d -> Ptr d -> IO [[c d]]
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d -> MapDescriptor d -> Ptr d -> IO [[c d]]
    peekControlPoints2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d
    ptr
             return (uDomain, vDomain, controlPoints)

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

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

    instance Map2 GLmap2 where
       withNewMap2 :: forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    MapDescriptor d
    -> MapDescriptor d -> (Ptr d -> IO ()) -> IO (GLmap2 c d)
    withNewMap2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor Ptr d -> IO ()
    act = do
          fp <- Int -> IO (ForeignPtr d)
    forall a. Storable a => Int -> IO (ForeignPtr a)
    mallocForeignPtrArray (MapDescriptor d -> MapDescriptor d -> Int
    forall d. MapDescriptor d -> MapDescriptor d -> Int
    totalComponents2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor)
          withForeignPtr fp act
          return $ GLmap2 uDescriptor vDescriptor fp

       withMap2 :: forall (c :: * -> *) d a.
    (ControlPoint c, Domain d) =>
    GLmap2 c d
    -> (MapDescriptor d -> MapDescriptor d -> Ptr d -> IO a) -> IO a
    withMap2 (GLmap2 MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor ForeignPtr d
    fp) MapDescriptor d -> MapDescriptor d -> Ptr d -> IO a
    act =
          ForeignPtr d -> (Ptr d -> IO a) -> IO a
    forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
    withForeignPtr ForeignPtr d
    fp ((Ptr d -> IO a) -> IO a) -> (Ptr d -> IO a) -> IO a
    forall a b. (a -> b) -> a -> b
    $ MapDescriptor d -> MapDescriptor d -> Ptr d -> IO a
    act MapDescriptor d
    uDescriptor MapDescriptor d
    vDescriptor

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

    map2 :: (Map2 m, ControlPoint c, Domain d) => StateVar (Maybe (m c d))
    map2 :: forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map2 m, ControlPoint c, Domain d) =>
    StateVar (Maybe (m c d))
    map2 = (c d -> EnableCap)
    -> (c d -> IO (m c d))
    -> (c d -> m c d -> IO ())
    -> StateVar (Maybe (m c d))
    forall (c :: * -> *) d (m :: (* -> *) -> * -> *).
    (c d -> EnableCap)
    -> (c d -> IO (m c d))
    -> (c d -> m c d -> IO ())
    -> StateVar (Maybe (m c d))
    makeMap2StateVar c d -> EnableCap
    forall d. Domain d => c d -> EnableCap
    forall (c :: * -> *) d.
    (ControlPoint c, Domain d) =>
    c d -> EnableCap
    enableCap2 c d -> IO (m c d)
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map2 m, ControlPoint c, Domain d) =>
    c d -> IO (m c d)
    getMap2 c d -> m c d -> IO ()
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map2 m, ControlPoint c, Domain d) =>
    c d -> m c d -> IO ()
    setMap2

    makeMap2StateVar ::
          (c d -> EnableCap) -> (c d -> IO (m c d)) -> (c d -> m c d -> IO ())
       -> StateVar (Maybe (m c d))
    makeMap2StateVar :: forall (c :: * -> *) d (m :: (* -> *) -> * -> *).
    (c d -> EnableCap)
    -> (c d -> IO (m c d))
    -> (c d -> m c d -> IO ())
    -> StateVar (Maybe (m c d))
    makeMap2StateVar c d -> EnableCap
    getCap c d -> IO (m c d)
    getAct c d -> m c d -> IO ()
    setAct =
       IO EnableCap
    -> IO (m c d) -> (m c d -> IO ()) -> StateVar (Maybe (m c d))
    forall a.
    IO EnableCap -> IO a -> (a -> IO ()) -> StateVar (Maybe a)
    makeStateVarMaybe
          (EnableCap -> IO EnableCap
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (c d -> EnableCap
    getCap c d
    forall a. HasCallStack => a
    undefined))
          (c d -> IO (m c d)
    getAct c d
    forall a. HasCallStack => a
    undefined)
          (c d -> m c d -> IO ()
    setAct c d
    forall a. HasCallStack => a
    undefined)

    getMap2 :: (Map2 m, ControlPoint c, Domain d) => c d -> IO (m c d)
    getMap2 :: forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map2 m, ControlPoint c, Domain d) =>
    c d -> IO (m c d)
    getMap2 c d
    dummyControlPoint = do
       let target :: GLenum
    target = c d -> GLenum
    forall d. Domain d => c d -> GLenum
    forall (c :: * -> *) d. (ControlPoint c, Domain d) => c d -> GLenum
    map2Target c d
    dummyControlPoint
       (uDomain, vDomain) <- Int -> (Ptr d -> IO ((d, d), (d, d))) -> IO ((d, d), (d, d))
    forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
    allocaArray Int
    4 ((Ptr d -> IO ((d, d), (d, d))) -> IO ((d, d), (d, d)))
    -> (Ptr d -> IO ((d, d), (d, d))) -> IO ((d, d), (d, d))
    forall a b. (a -> b) -> a -> b
    $ \Ptr d
    ptr -> do
          GLenum -> GLenum -> Ptr d -> IO ()
    forall d. Domain d => GLenum -> GLenum -> Ptr d -> IO ()
    glGetMapv GLenum
    target (GetMapQuery -> GLenum
    marshalGetMapQuery GetMapQuery
    Domain) Ptr d
    ptr
          (d -> d -> d -> d -> ((d, d), (d, d)))
    -> Ptr d -> IO ((d, d), (d, d))
    forall a b. Storable a => (a -> a -> a -> a -> b) -> Ptr a -> IO b
    peek4 (\d
    u1 d
    u2 d
    v1 d
    v2 -> ((d
    u1, d
    u2), (d
    v1, d
    v2))) Ptr d
    ptr
       (uOrder, vOrder) <- withArray [0,0] $ \Ptr Order
    ptr -> do
          GLenum -> GLenum -> Ptr Order -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> GLenum -> Ptr Order -> m ()
    glGetMapiv GLenum
    target (GetMapQuery -> GLenum
    marshalGetMapQuery GetMapQuery
    Order) Ptr Order
    ptr
          (Order -> Order -> (Order, Order))
    -> Ptr Order -> IO (Order, Order)
    forall a b. Storable a => (a -> a -> b) -> Ptr a -> IO b
    peek2 (,) Ptr Order
    ptr
       let vStride = c d -> Order
    forall d. Domain d => c d -> Order
    forall (c :: * -> *) d. (ControlPoint c, Domain d) => c d -> Order
    numComponents c d
    dummyControlPoint
           uStride = Order
    vStride Order -> Order -> Order
    forall a. Num a => a -> a -> a
    * Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    vOrder
       withNewMap2 (MapDescriptor uDomain uStride uOrder (fromIntegral vStride))
                   (MapDescriptor vDomain vStride vOrder (fromIntegral vStride)) $
          glGetMapv target (marshalGetMapQuery Coeff)

    setMap2 :: (Map2 m, ControlPoint c, Domain d) => c d -> m c d -> IO ()
    setMap2 :: forall (m :: (* -> *) -> * -> *) (c :: * -> *) d.
    (Map2 m, ControlPoint c, Domain d) =>
    c d -> m c d -> IO ()
    setMap2 c d
    dummyControlPoint m c d
    m =
       m c d
    -> (MapDescriptor d -> MapDescriptor d -> Ptr d -> IO ()) -> IO ()
    forall (c :: * -> *) d a.
    (ControlPoint c, Domain d) =>
    m c d
    -> (MapDescriptor d -> MapDescriptor d -> Ptr d -> IO a) -> IO a
    forall (m :: (* -> *) -> * -> *) (c :: * -> *) d a.
    (Map2 m, ControlPoint c, Domain d) =>
    m c d
    -> (MapDescriptor d -> MapDescriptor d -> Ptr d -> IO a) -> IO a
    withMap2 m c d
    m ((MapDescriptor d -> MapDescriptor d -> Ptr d -> IO ()) -> IO ())
    -> (MapDescriptor d -> MapDescriptor d -> Ptr d -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \(MapDescriptor (d
    u1, d
    u2) Order
    uStride Order
    uOrder Order
    _)
                     (MapDescriptor (d
    v1, d
    v2) Order
    vStride Order
    vOrder Order
    _) ->
          GLenum
    -> d
    -> d
    -> Order
    -> Order
    -> d
    -> d
    -> Order
    -> Order
    -> Ptr d
    -> IO ()
    forall d.
    Domain d =>
    GLenum
    -> d
    -> d
    -> Order
    -> Order
    -> d
    -> d
    -> Order
    -> Order
    -> Ptr d
    -> IO ()
    glMap2 (c d -> GLenum
    forall d. Domain d => c d -> GLenum
    forall (c :: * -> *) d. (ControlPoint c, Domain d) => c d -> GLenum
    map2Target c d
    dummyControlPoint)
                 d
    u1 d
    u2 (Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    uStride) (Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    uOrder)
                 d
    v1 d
    v2 (Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    vStride) (Order -> Order
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Order
    vOrder)

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

    data GetMapQuery =
         Coeff
       | Order
       | Domain

    marshalGetMapQuery :: GetMapQuery -> GLenum
    marshalGetMapQuery :: GetMapQuery -> GLenum
    marshalGetMapQuery GetMapQuery
    x = case GetMapQuery
    x of
       GetMapQuery
    Coeff -> GLenum
    GL_COEFF
       GetMapQuery
    Order -> GLenum
    GL_ORDER
       GetMapQuery
    Domain -> GLenum
    GL_DOMAIN

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

    mapGrid1 :: Domain d => StateVar (GLint, (d, d))
    mapGrid1 :: forall d. Domain d => StateVar (Order, (d, d))
    mapGrid1 =
       IO (Order, (d, d))
    -> ((Order, (d, d)) -> IO ()) -> StateVar (Order, (d, d))
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar
          (do n <- (Order -> Order) -> PName1I -> GettableStateVar Order
    forall p a. GetPName1I p => (Order -> a) -> p -> IO a
    forall a. (Order -> a) -> PName1I -> IO a
    getInteger1 Order -> Order
    forall a. a -> a
    id PName1I
    GetMap1GridSegments
              domain <- get2 (,) GetMap1GridDomain
              return (n, domain))
          (\(Order
    n, (d
    u1, d
    u2)) -> Order -> d -> d -> IO ()
    forall d. Domain d => Order -> d -> d -> IO ()
    glMapGrid1 Order
    n d
    u1 d
    u2)

    mapGrid2 :: Domain d => StateVar ((GLint, (d, d)), (GLint, (d, d)))
    mapGrid2 :: forall d. Domain d => StateVar ((Order, (d, d)), (Order, (d, d)))
    mapGrid2 =
       IO ((Order, (d, d)), (Order, (d, d)))
    -> (((Order, (d, d)), (Order, (d, d))) -> IO ())
    -> StateVar ((Order, (d, d)), (Order, (d, d)))
    forall a. IO a -> (a -> IO ()) -> StateVar a
    makeStateVar
          (do (un, vn) <- (Order -> Order -> (Order, Order)) -> PName2I -> IO (Order, Order)
    forall p a. GetPName2I p => (Order -> Order -> a) -> p -> IO a
    forall a. (Order -> Order -> a) -> PName2I -> IO a
    getInteger2 (,) PName2I
    GetMap2GridSegments
              (u1, u2, v1, v2) <- get4 (,,,) GetMap2GridDomain
              return ((un, (u1, u2)), (vn, (v1, v2))))
          (\((Order
    un, (d
    u1, d
    u2)), (Order
    vn, (d
    v1, d
    v2))) -> Order -> d -> d -> Order -> d -> d -> IO ()
    forall d. Domain d => Order -> d -> d -> Order -> d -> d -> IO ()
    glMapGrid2 Order
    un d
    u1 d
    u2 Order
    vn d
    v1 d
    v2)

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

    evalMesh1 :: PolygonMode -> (GLint, GLint) -> IO ()
    evalMesh1 :: PolygonMode -> (Order, Order) -> IO ()
    evalMesh1 PolygonMode
    m (Order
    p1, Order
    p2) = GLenum -> Order -> Order -> IO ()
    forall (m :: * -> *). MonadIO m => GLenum -> Order -> Order -> m ()
    glEvalMesh1 (PolygonMode -> GLenum
    marshalPolygonMode PolygonMode
    m) Order
    p1 Order
    p2

    evalMesh2 :: PolygonMode -> (GLint, GLint) -> (GLint, GLint) -> IO ()
    evalMesh2 :: PolygonMode -> (Order, Order) -> (Order, Order) -> IO ()
    evalMesh2 PolygonMode
    m (Order
    p1, Order
    p2) (Order
    q1, Order
    q2) = GLenum -> Order -> Order -> Order -> Order -> IO ()
    forall (m :: * -> *).
    MonadIO m =>
    GLenum -> Order -> Order -> Order -> Order -> m ()
    glEvalMesh2 (PolygonMode -> GLenum
    marshalPolygonMode PolygonMode
    m) Order
    p1 Order
    p2 Order
    q1 Order
    q2

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

    evalPoint1 :: GLint -> IO ()
    evalPoint1 :: Order -> IO ()
    evalPoint1 = Order -> IO ()
    forall (m :: * -> *). MonadIO m => Order -> m ()
    glEvalPoint1

    evalPoint2 :: (GLint, GLint) -> IO ()
    evalPoint2 :: (Order, Order) -> IO ()
    evalPoint2 = (Order -> Order -> IO ()) -> (Order, Order) -> IO ()
    forall a b c. (a -> b -> c) -> (a, b) -> c
    uncurry Order -> Order -> IO ()
    forall (m :: * -> *). MonadIO m => Order -> Order -> m ()
    glEvalPoint2

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

    autoNormal :: StateVar Capability
    autoNormal :: StateVar Capability
    autoNormal = EnableCap -> StateVar Capability
    makeCapability EnableCap
    CapAutoNormal