    {-# OPTIONS_HADDOCK hide #-}
    --------------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.OpenGL.GL.ControlPoint
    -- Copyright   :  (c) Sven Panne 2002-2019
    -- License     :  BSD3
    --
    -- Maintainer  :  Sven Panne <svenpanne@gmail.com>
    -- Stability   :  stable
    -- Portability :  portable
    --
    -- This is a purely internal module for handling control points.
    --
    --------------------------------------------------------------------------------

    module Graphics.Rendering.OpenGL.GL.ControlPoint (
       ControlPoint(..)
    ) where

    import Foreign.Ptr
    import Foreign.Storable
    import Graphics.Rendering.OpenGL.GL.Tensor
    import Graphics.Rendering.OpenGL.GL.Capability
    import Graphics.Rendering.OpenGL.GL.Domain
    import Graphics.Rendering.OpenGL.GL.VertexArrays
    import Graphics.Rendering.OpenGL.GL.VertexSpec
    import Graphics.GL

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

    class ControlPoint c where
       map1Target       :: Domain d => c d -> GLenum
       map2Target       :: Domain d => c d -> GLenum
       enableCap1       :: Domain d => c d -> EnableCap
       enableCap2       :: Domain d => c d -> EnableCap
       numComponents    :: Domain d => c d -> Stride
       peekControlPoint :: Domain d => Ptr (c d) -> IO (c d)
       pokeControlPoint :: Domain d => Ptr (c d) -> (c d) -> IO ()

    instance ControlPoint Vertex3 where
       map1Target :: forall d. Domain d => Vertex3 d -> GLenum
    map1Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (Vertex3 d -> MapTarget) -> Vertex3 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> Vertex3 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map1Vertex3
       map2Target :: forall d. Domain d => Vertex3 d -> GLenum
    map2Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (Vertex3 d -> MapTarget) -> Vertex3 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> Vertex3 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map2Vertex3
       enableCap1 :: forall d. Domain d => Vertex3 d -> EnableCap
    enableCap1       = EnableCap -> Vertex3 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap1Vertex3
       enableCap2 :: forall d. Domain d => Vertex3 d -> EnableCap
    enableCap2       = EnableCap -> Vertex3 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap2Vertex3
       numComponents :: forall d. Domain d => Vertex3 d -> Stride
    numComponents    = Stride -> Vertex3 d -> Stride
    forall a b. a -> b -> a
    const Stride
    3
       peekControlPoint :: forall d. Domain d => Ptr (Vertex3 d) -> IO (Vertex3 d)
    peekControlPoint = Ptr (Vertex3 d) -> IO (Vertex3 d)
    forall a. Storable a => Ptr a -> IO a
    peek
       pokeControlPoint :: forall d. Domain d => Ptr (Vertex3 d) -> Vertex3 d -> IO ()
    pokeControlPoint = Ptr (Vertex3 d) -> Vertex3 d -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke

    instance ControlPoint Vertex4 where
       map1Target :: forall d. Domain d => Vertex4 d -> GLenum
    map1Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (Vertex4 d -> MapTarget) -> Vertex4 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> Vertex4 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map1Vertex4
       map2Target :: forall d. Domain d => Vertex4 d -> GLenum
    map2Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (Vertex4 d -> MapTarget) -> Vertex4 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> Vertex4 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map2Vertex4
       enableCap1 :: forall d. Domain d => Vertex4 d -> EnableCap
    enableCap1       = EnableCap -> Vertex4 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap1Vertex4
       enableCap2 :: forall d. Domain d => Vertex4 d -> EnableCap
    enableCap2       = EnableCap -> Vertex4 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap2Vertex4
       numComponents :: forall d. Domain d => Vertex4 d -> Stride
    numComponents    = Stride -> Vertex4 d -> Stride
    forall a b. a -> b -> a
    const Stride
    4
       peekControlPoint :: forall d. Domain d => Ptr (Vertex4 d) -> IO (Vertex4 d)
    peekControlPoint = Ptr (Vertex4 d) -> IO (Vertex4 d)
    forall a. Storable a => Ptr a -> IO a
    peek
       pokeControlPoint :: forall d. Domain d => Ptr (Vertex4 d) -> Vertex4 d -> IO ()
    pokeControlPoint = Ptr (Vertex4 d) -> Vertex4 d -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke

    instance ControlPoint Index1 where
       map1Target :: forall d. Domain d => Index1 d -> GLenum
    map1Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (Index1 d -> MapTarget) -> Index1 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> Index1 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map1Index
       map2Target :: forall d. Domain d => Index1 d -> GLenum
    map2Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (Index1 d -> MapTarget) -> Index1 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> Index1 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map2Index
       enableCap1 :: forall d. Domain d => Index1 d -> EnableCap
    enableCap1       = EnableCap -> Index1 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap1Index
       enableCap2 :: forall d. Domain d => Index1 d -> EnableCap
    enableCap2       = EnableCap -> Index1 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap2Index
       numComponents :: forall d. Domain d => Index1 d -> Stride
    numComponents    = Stride -> Index1 d -> Stride
    forall a b. a -> b -> a
    const Stride
    1
       peekControlPoint :: forall d. Domain d => Ptr (Index1 d) -> IO (Index1 d)
    peekControlPoint = Ptr (Index1 d) -> IO (Index1 d)
    forall a. Storable a => Ptr a -> IO a
    peek
       pokeControlPoint :: forall d. Domain d => Ptr (Index1 d) -> Index1 d -> IO ()
    pokeControlPoint = Ptr (Index1 d) -> Index1 d -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke

    instance ControlPoint Color4 where
       map1Target :: forall d. Domain d => Color4 d -> GLenum
    map1Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (Color4 d -> MapTarget) -> Color4 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> Color4 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map1Color4
       map2Target :: forall d. Domain d => Color4 d -> GLenum
    map2Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (Color4 d -> MapTarget) -> Color4 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> Color4 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map2Color4
       enableCap1 :: forall d. Domain d => Color4 d -> EnableCap
    enableCap1       = EnableCap -> Color4 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap1Color4
       enableCap2 :: forall d. Domain d => Color4 d -> EnableCap
    enableCap2       = EnableCap -> Color4 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap2Color4
       numComponents :: forall d. Domain d => Color4 d -> Stride
    numComponents    = Stride -> Color4 d -> Stride
    forall a b. a -> b -> a
    const Stride
    4
       peekControlPoint :: forall d. Domain d => Ptr (Color4 d) -> IO (Color4 d)
    peekControlPoint = Ptr (Color4 d) -> IO (Color4 d)
    forall a. Storable a => Ptr a -> IO a
    peek
       pokeControlPoint :: forall d. Domain d => Ptr (Color4 d) -> Color4 d -> IO ()
    pokeControlPoint = Ptr (Color4 d) -> Color4 d -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke

    instance ControlPoint Normal3 where
       map1Target :: forall d. Domain d => Normal3 d -> GLenum
    map1Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (Normal3 d -> MapTarget) -> Normal3 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> Normal3 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map1Normal
       map2Target :: forall d. Domain d => Normal3 d -> GLenum
    map2Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (Normal3 d -> MapTarget) -> Normal3 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> Normal3 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map2Normal
       enableCap1 :: forall d. Domain d => Normal3 d -> EnableCap
    enableCap1       = EnableCap -> Normal3 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap1Normal
       enableCap2 :: forall d. Domain d => Normal3 d -> EnableCap
    enableCap2       = EnableCap -> Normal3 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap2Normal
       numComponents :: forall d. Domain d => Normal3 d -> Stride
    numComponents    = Stride -> Normal3 d -> Stride
    forall a b. a -> b -> a
    const Stride
    3
       peekControlPoint :: forall d. Domain d => Ptr (Normal3 d) -> IO (Normal3 d)
    peekControlPoint = Ptr (Normal3 d) -> IO (Normal3 d)
    forall a. Storable a => Ptr a -> IO a
    peek
       pokeControlPoint :: forall d. Domain d => Ptr (Normal3 d) -> Normal3 d -> IO ()
    pokeControlPoint = Ptr (Normal3 d) -> Normal3 d -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke

    instance ControlPoint TexCoord1 where
       map1Target :: forall d. Domain d => TexCoord1 d -> GLenum
    map1Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (TexCoord1 d -> MapTarget) -> TexCoord1 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> TexCoord1 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map1TextureCoord1
       map2Target :: forall d. Domain d => TexCoord1 d -> GLenum
    map2Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (TexCoord1 d -> MapTarget) -> TexCoord1 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> TexCoord1 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map2TextureCoord1
       enableCap1 :: forall d. Domain d => TexCoord1 d -> EnableCap
    enableCap1       = EnableCap -> TexCoord1 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap1TextureCoord1
       enableCap2 :: forall d. Domain d => TexCoord1 d -> EnableCap
    enableCap2       = EnableCap -> TexCoord1 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap2TextureCoord1
       numComponents :: forall d. Domain d => TexCoord1 d -> Stride
    numComponents    = Stride -> TexCoord1 d -> Stride
    forall a b. a -> b -> a
    const Stride
    1
       peekControlPoint :: forall d. Domain d => Ptr (TexCoord1 d) -> IO (TexCoord1 d)
    peekControlPoint = Ptr (TexCoord1 d) -> IO (TexCoord1 d)
    forall a. Storable a => Ptr a -> IO a
    peek
       pokeControlPoint :: forall d. Domain d => Ptr (TexCoord1 d) -> TexCoord1 d -> IO ()
    pokeControlPoint = Ptr (TexCoord1 d) -> TexCoord1 d -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke

    instance ControlPoint TexCoord2 where
       map1Target :: forall d. Domain d => TexCoord2 d -> GLenum
    map1Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (TexCoord2 d -> MapTarget) -> TexCoord2 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> TexCoord2 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map1TextureCoord2
       map2Target :: forall d. Domain d => TexCoord2 d -> GLenum
    map2Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (TexCoord2 d -> MapTarget) -> TexCoord2 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> TexCoord2 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map2TextureCoord2
       enableCap1 :: forall d. Domain d => TexCoord2 d -> EnableCap
    enableCap1       = EnableCap -> TexCoord2 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap1TextureCoord2
       enableCap2 :: forall d. Domain d => TexCoord2 d -> EnableCap
    enableCap2       = EnableCap -> TexCoord2 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap2TextureCoord2
       numComponents :: forall d. Domain d => TexCoord2 d -> Stride
    numComponents    = Stride -> TexCoord2 d -> Stride
    forall a b. a -> b -> a
    const Stride
    2
       peekControlPoint :: forall d. Domain d => Ptr (TexCoord2 d) -> IO (TexCoord2 d)
    peekControlPoint = Ptr (TexCoord2 d) -> IO (TexCoord2 d)
    forall a. Storable a => Ptr a -> IO a
    peek
       pokeControlPoint :: forall d. Domain d => Ptr (TexCoord2 d) -> TexCoord2 d -> IO ()
    pokeControlPoint = Ptr (TexCoord2 d) -> TexCoord2 d -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke

    instance ControlPoint TexCoord3 where
       map1Target :: forall d. Domain d => TexCoord3 d -> GLenum
    map1Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (TexCoord3 d -> MapTarget) -> TexCoord3 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> TexCoord3 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map1TextureCoord3
       map2Target :: forall d. Domain d => TexCoord3 d -> GLenum
    map2Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (TexCoord3 d -> MapTarget) -> TexCoord3 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> TexCoord3 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map2TextureCoord3
       enableCap1 :: forall d. Domain d => TexCoord3 d -> EnableCap
    enableCap1       = EnableCap -> TexCoord3 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap1TextureCoord3
       enableCap2 :: forall d. Domain d => TexCoord3 d -> EnableCap
    enableCap2       = EnableCap -> TexCoord3 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap2TextureCoord3
       numComponents :: forall d. Domain d => TexCoord3 d -> Stride
    numComponents    = Stride -> TexCoord3 d -> Stride
    forall a b. a -> b -> a
    const Stride
    3
       peekControlPoint :: forall d. Domain d => Ptr (TexCoord3 d) -> IO (TexCoord3 d)
    peekControlPoint = Ptr (TexCoord3 d) -> IO (TexCoord3 d)
    forall a. Storable a => Ptr a -> IO a
    peek
       pokeControlPoint :: forall d. Domain d => Ptr (TexCoord3 d) -> TexCoord3 d -> IO ()
    pokeControlPoint = Ptr (TexCoord3 d) -> TexCoord3 d -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke

    instance ControlPoint TexCoord4 where
       map1Target :: forall d. Domain d => TexCoord4 d -> GLenum
    map1Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (TexCoord4 d -> MapTarget) -> TexCoord4 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> TexCoord4 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map1TextureCoord4
       map2Target :: forall d. Domain d => TexCoord4 d -> GLenum
    map2Target       = MapTarget -> GLenum
    marshalMapTarget (MapTarget -> GLenum)
    -> (TexCoord4 d -> MapTarget) -> TexCoord4 d -> GLenum
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . MapTarget -> TexCoord4 d -> MapTarget
    forall a b. a -> b -> a
    const MapTarget
    Map2TextureCoord4
       enableCap1 :: forall d. Domain d => TexCoord4 d -> EnableCap
    enableCap1       = EnableCap -> TexCoord4 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap1TextureCoord4
       enableCap2 :: forall d. Domain d => TexCoord4 d -> EnableCap
    enableCap2       = EnableCap -> TexCoord4 d -> EnableCap
    forall a b. a -> b -> a
    const EnableCap
    CapMap2TextureCoord4
       numComponents :: forall d. Domain d => TexCoord4 d -> Stride
    numComponents    = Stride -> TexCoord4 d -> Stride
    forall a b. a -> b -> a
    const Stride
    4
       peekControlPoint :: forall d. Domain d => Ptr (TexCoord4 d) -> IO (TexCoord4 d)
    peekControlPoint = Ptr (TexCoord4 d) -> IO (TexCoord4 d)
    forall a. Storable a => Ptr a -> IO a
    peek
       pokeControlPoint :: forall d. Domain d => Ptr (TexCoord4 d) -> TexCoord4 d -> IO ()
    pokeControlPoint = Ptr (TexCoord4 d) -> TexCoord4 d -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke

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

    data MapTarget =
         Map1Color4
       | Map1Index
       | Map1Normal
       | Map1TextureCoord1
       | Map1TextureCoord2
       | Map1TextureCoord3
       | Map1TextureCoord4
       | Map1Vertex3
       | Map1Vertex4
       | Map2Color4
       | Map2Index
       | Map2Normal
       | Map2TextureCoord1
       | Map2TextureCoord2
       | Map2TextureCoord3
       | Map2TextureCoord4
       | Map2Vertex3
       | Map2Vertex4

    marshalMapTarget :: MapTarget -> GLenum
    marshalMapTarget :: MapTarget -> GLenum
    marshalMapTarget MapTarget
    x = case MapTarget
    x of
       MapTarget
    Map1Color4 -> GLenum
    GL_MAP1_COLOR_4
       MapTarget
    Map1Index -> GLenum
    GL_MAP1_INDEX
       MapTarget
    Map1Normal -> GLenum
    GL_MAP1_NORMAL
       MapTarget
    Map1TextureCoord1 -> GLenum
    GL_MAP1_TEXTURE_COORD_1
       MapTarget
    Map1TextureCoord2 -> GLenum
    GL_MAP1_TEXTURE_COORD_2
       MapTarget
    Map1TextureCoord3 -> GLenum
    GL_MAP1_TEXTURE_COORD_3
       MapTarget
    Map1TextureCoord4 -> GLenum
    GL_MAP1_TEXTURE_COORD_4
       MapTarget
    Map1Vertex3 -> GLenum
    GL_MAP1_VERTEX_3
       MapTarget
    Map1Vertex4 -> GLenum
    GL_MAP1_VERTEX_4
       MapTarget
    Map2Color4 -> GLenum
    GL_MAP2_COLOR_4
       MapTarget
    Map2Index -> GLenum
    GL_MAP2_INDEX
       MapTarget
    Map2Normal -> GLenum
    GL_MAP2_NORMAL
       MapTarget
    Map2TextureCoord1 -> GLenum
    GL_MAP2_TEXTURE_COORD_1
       MapTarget
    Map2TextureCoord2 -> GLenum
    GL_MAP2_TEXTURE_COORD_2
       MapTarget
    Map2TextureCoord3 -> GLenum
    GL_MAP2_TEXTURE_COORD_3
       MapTarget
    Map2TextureCoord4 -> GLenum
    GL_MAP2_TEXTURE_COORD_4
       MapTarget
    Map2Vertex3 -> GLenum
    GL_MAP2_VERTEX_3
       MapTarget
    Map2Vertex4 -> GLenum
    GL_MAP2_VERTEX_4