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

module Graphics.Rendering.OpenGL.GL.VertexArrays (
   -- * Describing Data for the Arrays
   NumComponents, DataType(..), Stride, VertexArrayDescriptor(..),

   -- * Specifying Data for the Arrays
   Capability(..),
   ClientArrayType(..), arrayPointer,
   InterleavedArrays(..), interleavedArrays,

   -- * Enabling Arrays
   clientState, clientActiveTexture,

   -- * Dereferencing and Rendering
   ArrayIndex, NumArrayIndices, NumIndexBlocks, NumInstances,
   BaseInstance, BaseVertex,
   arrayElement,

   drawArrays, drawArraysInstancedBaseInstance, drawArraysInstanced,
   multiDrawArrays,

   drawElements, drawElementsInstancedBaseInstance, drawElementsInstanced,
   multiDrawElements, drawRangeElements,

   drawElementsBaseVertex, drawRangeElementsBaseVertex,
   drawElementsInstancedBaseVertex, drawElementsInstancedBaseVertexBaseInstance,
   multiDrawElementsBaseVertex,

   maxElementsVertices, maxElementsIndices, lockArrays,
   primitiveRestartIndex, primitiveRestartIndexNV,

   -- * Generic Vertex Attribute Arrays
   vertexAttribPointer, vertexAttribArray,
) where

import Data.StateVar
import Foreign.Ptr ( Ptr, nullPtr )
import Graphics.Rendering.OpenGL.GL.Capability
import Graphics.Rendering.OpenGL.GL.DataType
import Graphics.Rendering.OpenGL.GL.GLboolean
import Graphics.Rendering.OpenGL.GL.PrimitiveMode
import Graphics.Rendering.OpenGL.GL.PrimitiveModeInternal
import Graphics.Rendering.OpenGL.GL.QueryUtils
import Graphics.Rendering.OpenGL.GL.Texturing.TextureUnit
import Graphics.Rendering.OpenGL.GL.VertexSpec
import Graphics.Rendering.OpenGL.GLU.ErrorsInternal
import Graphics.GL

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

type NumComponents = GLint

type Stride = GLsizei

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

noVertexArrayDescriptor :: VertexArrayDescriptor a
noVertexArrayDescriptor :: VertexArrayDescriptor a
noVertexArrayDescriptor = NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
forall a.
NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
VertexArrayDescriptor 0 DataType
Byte 0 Ptr a
forall a. Ptr a
nullPtr

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

data ClientArrayType =
     VertexArray
   | NormalArray
   | ColorArray
   | IndexArray
   | TextureCoordArray
   | EdgeFlagArray
   | FogCoordArray
   | SecondaryColorArray
   | MatrixIndexArray
   deriving ( ClientArrayType -> ClientArrayType -> Bool
(ClientArrayType -> ClientArrayType -> Bool)
-> (ClientArrayType -> ClientArrayType -> Bool)
-> Eq ClientArrayType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ClientArrayType -> ClientArrayType -> Bool
$c/= :: ClientArrayType -> ClientArrayType -> Bool
== :: ClientArrayType -> ClientArrayType -> Bool
$c== :: ClientArrayType -> ClientArrayType -> Bool
Eq, Eq ClientArrayType
Eq ClientArrayType =>
(ClientArrayType -> ClientArrayType -> Ordering)
-> (ClientArrayType -> ClientArrayType -> Bool)
-> (ClientArrayType -> ClientArrayType -> Bool)
-> (ClientArrayType -> ClientArrayType -> Bool)
-> (ClientArrayType -> ClientArrayType -> Bool)
-> (ClientArrayType -> ClientArrayType -> ClientArrayType)
-> (ClientArrayType -> ClientArrayType -> ClientArrayType)
-> Ord ClientArrayType
ClientArrayType -> ClientArrayType -> Bool
ClientArrayType -> ClientArrayType -> Ordering
ClientArrayType -> ClientArrayType -> ClientArrayType
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
min :: ClientArrayType -> ClientArrayType -> ClientArrayType
$cmin :: ClientArrayType -> ClientArrayType -> ClientArrayType
max :: ClientArrayType -> ClientArrayType -> ClientArrayType
$cmax :: ClientArrayType -> ClientArrayType -> ClientArrayType
>= :: ClientArrayType -> ClientArrayType -> Bool
$c>= :: ClientArrayType -> ClientArrayType -> Bool
> :: ClientArrayType -> ClientArrayType -> Bool
$c> :: ClientArrayType -> ClientArrayType -> Bool
<= :: ClientArrayType -> ClientArrayType -> Bool
$c<= :: ClientArrayType -> ClientArrayType -> Bool
< :: ClientArrayType -> ClientArrayType -> Bool
$c< :: ClientArrayType -> ClientArrayType -> Bool
compare :: ClientArrayType -> ClientArrayType -> Ordering
$ccompare :: ClientArrayType -> ClientArrayType -> Ordering
$cp1Ord :: Eq ClientArrayType
Ord, Int -> ClientArrayType -> ShowS
[ClientArrayType] -> ShowS
ClientArrayType -> String
(Int -> ClientArrayType -> ShowS)
-> (ClientArrayType -> String)
-> ([ClientArrayType] -> ShowS)
-> Show ClientArrayType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ClientArrayType] -> ShowS
$cshowList :: [ClientArrayType] -> ShowS
show :: ClientArrayType -> String
$cshow :: ClientArrayType -> String
showsPrec :: Int -> ClientArrayType -> ShowS
$cshowsPrec :: Int -> ClientArrayType -> ShowS
Show )

marshalClientArrayType :: ClientArrayType -> GLenum
marshalClientArrayType :: ClientArrayType -> GLenum
marshalClientArrayType x :: ClientArrayType
x = case ClientArrayType
x of
   VertexArray -> GLenum
GL_VERTEX_ARRAY
   NormalArray -> GLenum
GL_NORMAL_ARRAY
   ColorArray -> GLenum
GL_COLOR_ARRAY
   IndexArray -> GLenum
GL_INDEX_ARRAY
   TextureCoordArray -> GLenum
GL_TEXTURE_COORD_ARRAY
   EdgeFlagArray -> GLenum
GL_EDGE_FLAG_ARRAY
   FogCoordArray -> GLenum
GL_FOG_COORD_ARRAY
   SecondaryColorArray -> GLenum
GL_SECONDARY_COLOR_ARRAY
   MatrixIndexArray -> GLenum
GL_MATRIX_INDEX_ARRAY_ARB

-- Hmmm...
clientArrayTypeToEnableCap :: ClientArrayType -> EnableCap
clientArrayTypeToEnableCap :: ClientArrayType -> EnableCap
clientArrayTypeToEnableCap x :: ClientArrayType
x = case ClientArrayType
x of
   VertexArray -> EnableCap
CapVertexArray
   NormalArray -> EnableCap
CapNormalArray
   ColorArray -> EnableCap
CapColorArray
   IndexArray -> EnableCap
CapIndexArray
   TextureCoordArray -> EnableCap
CapTextureCoordArray
   EdgeFlagArray -> EnableCap
CapEdgeFlagArray
   FogCoordArray -> EnableCap
CapFogCoordArray
   SecondaryColorArray -> EnableCap
CapSecondaryColorArray
   MatrixIndexArray -> EnableCap
CapMatrixIndexArray

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

arrayPointer :: ClientArrayType -> StateVar (VertexArrayDescriptor a)
arrayPointer :: ClientArrayType -> StateVar (VertexArrayDescriptor a)
arrayPointer t :: ClientArrayType
t = case ClientArrayType
t of
   VertexArray -> StateVar (VertexArrayDescriptor a)
forall a. StateVar (VertexArrayDescriptor a)
vertexPointer
   NormalArray -> StateVar (VertexArrayDescriptor a)
forall a. StateVar (VertexArrayDescriptor a)
normalPointer
   ColorArray -> StateVar (VertexArrayDescriptor a)
forall a. StateVar (VertexArrayDescriptor a)
colorPointer
   IndexArray -> StateVar (VertexArrayDescriptor a)
forall a. StateVar (VertexArrayDescriptor a)
indexPointer
   TextureCoordArray -> StateVar (VertexArrayDescriptor a)
forall a. StateVar (VertexArrayDescriptor a)
texCoordPointer
   EdgeFlagArray -> StateVar (VertexArrayDescriptor a)
forall a. StateVar (VertexArrayDescriptor a)
edgeFlagPointer
   FogCoordArray -> StateVar (VertexArrayDescriptor a)
forall a. StateVar (VertexArrayDescriptor a)
fogCoordPointer
   SecondaryColorArray -> StateVar (VertexArrayDescriptor a)
forall a. StateVar (VertexArrayDescriptor a)
secondaryColorPointer
   MatrixIndexArray ->
      IO (VertexArrayDescriptor a)
-> (VertexArrayDescriptor a -> IO ())
-> StateVar (VertexArrayDescriptor a)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar
        (do IO ()
recordInvalidEnum ; VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall (m :: * -> *) a. Monad m => a -> m a
return VertexArrayDescriptor a
forall a. VertexArrayDescriptor a
noVertexArrayDescriptor)
        (IO () -> VertexArrayDescriptor a -> IO ()
forall a b. a -> b -> a
const IO ()
recordInvalidEnum)

check :: Bool -> IO () -> IO ()
check :: Bool -> IO () -> IO ()
check flag :: Bool
flag val :: IO ()
val = if Bool
flag then IO ()
val else IO ()
recordInvalidValue

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

vertexPointer :: StateVar (VertexArrayDescriptor a)
vertexPointer :: StateVar (VertexArrayDescriptor a)
vertexPointer = IO (VertexArrayDescriptor a)
-> (VertexArrayDescriptor a -> IO ())
-> StateVar (VertexArrayDescriptor a)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (VertexArrayDescriptor a)
forall a. IO (VertexArrayDescriptor a)
getVertexPointer VertexArrayDescriptor a -> IO ()
forall a. VertexArrayDescriptor a -> IO ()
setVertexPointer

getVertexPointer :: IO (VertexArrayDescriptor a)
getVertexPointer :: IO (VertexArrayDescriptor a)
getVertexPointer = do
   NumComponents
n <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a. a -> a
id PName1I
GetVertexArraySize
   DataType
d <- (GLenum -> DataType) -> PName1I -> IO DataType
forall p a. GetPName1I p => (GLenum -> a) -> p -> IO a
getEnum1 GLenum -> DataType
unmarshalDataType PName1I
GetVertexArrayType
   NumComponents
s <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral PName1I
GetVertexArrayStride
   Ptr a
p <- GetPointervPName -> IO (Ptr a)
forall a. GetPointervPName -> IO (Ptr a)
getPointer GetPointervPName
VertexArrayPointer
   VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall (m :: * -> *) a. Monad m => a -> m a
return (VertexArrayDescriptor a -> IO (VertexArrayDescriptor a))
-> VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall a b. (a -> b) -> a -> b
$ NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
forall a.
NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
VertexArrayDescriptor NumComponents
n DataType
d NumComponents
s Ptr a
p

setVertexPointer :: VertexArrayDescriptor a -> IO ()
setVertexPointer :: VertexArrayDescriptor a -> IO ()
setVertexPointer (VertexArrayDescriptor n :: NumComponents
n d :: DataType
d s :: NumComponents
s p :: Ptr a
p) =
   NumComponents -> GLenum -> NumComponents -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
NumComponents -> GLenum -> NumComponents -> Ptr a -> m ()
glVertexPointer NumComponents
n (DataType -> GLenum
marshalDataType DataType
d) NumComponents
s Ptr a
p

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

normalPointer :: StateVar (VertexArrayDescriptor a)
normalPointer :: StateVar (VertexArrayDescriptor a)
normalPointer = IO (VertexArrayDescriptor a)
-> (VertexArrayDescriptor a -> IO ())
-> StateVar (VertexArrayDescriptor a)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (VertexArrayDescriptor a)
forall a. IO (VertexArrayDescriptor a)
getNormalPointer VertexArrayDescriptor a -> IO ()
forall a. VertexArrayDescriptor a -> IO ()
setNormalPointer

getNormalPointer :: IO (VertexArrayDescriptor a)
getNormalPointer :: IO (VertexArrayDescriptor a)
getNormalPointer = do
   DataType
d <- (GLenum -> DataType) -> PName1I -> IO DataType
forall p a. GetPName1I p => (GLenum -> a) -> p -> IO a
getEnum1 GLenum -> DataType
unmarshalDataType PName1I
GetNormalArrayType
   NumComponents
s <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral PName1I
GetNormalArrayStride
   Ptr a
p <- GetPointervPName -> IO (Ptr a)
forall a. GetPointervPName -> IO (Ptr a)
getPointer GetPointervPName
NormalArrayPointer
   VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall (m :: * -> *) a. Monad m => a -> m a
return (VertexArrayDescriptor a -> IO (VertexArrayDescriptor a))
-> VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall a b. (a -> b) -> a -> b
$ NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
forall a.
NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
VertexArrayDescriptor 3 DataType
d NumComponents
s Ptr a
p

setNormalPointer :: VertexArrayDescriptor a -> IO ()
setNormalPointer :: VertexArrayDescriptor a -> IO ()
setNormalPointer (VertexArrayDescriptor n :: NumComponents
n d :: DataType
d s :: NumComponents
s p :: Ptr a
p) =
   Bool -> IO () -> IO ()
check (NumComponents
n NumComponents -> NumComponents -> Bool
forall a. Eq a => a -> a -> Bool
== 3) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ GLenum -> NumComponents -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum -> NumComponents -> Ptr a -> m ()
glNormalPointer (DataType -> GLenum
marshalDataType DataType
d) NumComponents
s Ptr a
p

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

colorPointer :: StateVar (VertexArrayDescriptor a)
colorPointer :: StateVar (VertexArrayDescriptor a)
colorPointer = IO (VertexArrayDescriptor a)
-> (VertexArrayDescriptor a -> IO ())
-> StateVar (VertexArrayDescriptor a)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (VertexArrayDescriptor a)
forall a. IO (VertexArrayDescriptor a)
getColorPointer VertexArrayDescriptor a -> IO ()
forall a. VertexArrayDescriptor a -> IO ()
setColorPointer

getColorPointer :: IO (VertexArrayDescriptor a)
getColorPointer :: IO (VertexArrayDescriptor a)
getColorPointer = do
   NumComponents
n <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a. a -> a
id PName1I
GetColorArraySize
   DataType
d <- (GLenum -> DataType) -> PName1I -> IO DataType
forall p a. GetPName1I p => (GLenum -> a) -> p -> IO a
getEnum1 GLenum -> DataType
unmarshalDataType PName1I
GetColorArrayType
   NumComponents
s <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral PName1I
GetColorArrayStride
   Ptr a
p <- GetPointervPName -> IO (Ptr a)
forall a. GetPointervPName -> IO (Ptr a)
getPointer GetPointervPName
ColorArrayPointer
   VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall (m :: * -> *) a. Monad m => a -> m a
return (VertexArrayDescriptor a -> IO (VertexArrayDescriptor a))
-> VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall a b. (a -> b) -> a -> b
$ NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
forall a.
NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
VertexArrayDescriptor NumComponents
n DataType
d NumComponents
s Ptr a
p

setColorPointer :: VertexArrayDescriptor a -> IO ()
setColorPointer :: VertexArrayDescriptor a -> IO ()
setColorPointer (VertexArrayDescriptor n :: NumComponents
n d :: DataType
d s :: NumComponents
s p :: Ptr a
p) =
   Bool -> IO () -> IO ()
check (NumComponents
n NumComponents -> NumComponents -> Bool
forall a. Eq a => a -> a -> Bool
== 3 Bool -> Bool -> Bool
|| NumComponents
n NumComponents -> NumComponents -> Bool
forall a. Eq a => a -> a -> Bool
== 4) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ NumComponents -> GLenum -> NumComponents -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
NumComponents -> GLenum -> NumComponents -> Ptr a -> m ()
glColorPointer NumComponents
n (DataType -> GLenum
marshalDataType DataType
d) NumComponents
s Ptr a
p

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

indexPointer :: StateVar (VertexArrayDescriptor a)
indexPointer :: StateVar (VertexArrayDescriptor a)
indexPointer = IO (VertexArrayDescriptor a)
-> (VertexArrayDescriptor a -> IO ())
-> StateVar (VertexArrayDescriptor a)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (VertexArrayDescriptor a)
forall a. IO (VertexArrayDescriptor a)
getIndexPointer VertexArrayDescriptor a -> IO ()
forall a. VertexArrayDescriptor a -> IO ()
setIndexPointer

getIndexPointer :: IO (VertexArrayDescriptor a)
getIndexPointer :: IO (VertexArrayDescriptor a)
getIndexPointer = do
   DataType
d <- (GLenum -> DataType) -> PName1I -> IO DataType
forall p a. GetPName1I p => (GLenum -> a) -> p -> IO a
getEnum1 GLenum -> DataType
unmarshalDataType PName1I
GetIndexArrayType
   NumComponents
s <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral PName1I
GetIndexArrayStride
   Ptr a
p <- GetPointervPName -> IO (Ptr a)
forall a. GetPointervPName -> IO (Ptr a)
getPointer GetPointervPName
IndexArrayPointer
   VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall (m :: * -> *) a. Monad m => a -> m a
return (VertexArrayDescriptor a -> IO (VertexArrayDescriptor a))
-> VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall a b. (a -> b) -> a -> b
$ NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
forall a.
NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
VertexArrayDescriptor 1 DataType
d NumComponents
s Ptr a
p

setIndexPointer :: VertexArrayDescriptor a -> IO ()
setIndexPointer :: VertexArrayDescriptor a -> IO ()
setIndexPointer (VertexArrayDescriptor n :: NumComponents
n d :: DataType
d s :: NumComponents
s p :: Ptr a
p) =
   Bool -> IO () -> IO ()
check (NumComponents
n NumComponents -> NumComponents -> Bool
forall a. Eq a => a -> a -> Bool
== 1) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ GLenum -> NumComponents -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum -> NumComponents -> Ptr a -> m ()
glIndexPointer (DataType -> GLenum
marshalDataType DataType
d) NumComponents
s Ptr a
p

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

texCoordPointer :: StateVar (VertexArrayDescriptor a)
texCoordPointer :: StateVar (VertexArrayDescriptor a)
texCoordPointer = IO (VertexArrayDescriptor a)
-> (VertexArrayDescriptor a -> IO ())
-> StateVar (VertexArrayDescriptor a)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (VertexArrayDescriptor a)
forall a. IO (VertexArrayDescriptor a)
getTexCoordPointer VertexArrayDescriptor a -> IO ()
forall a. VertexArrayDescriptor a -> IO ()
setTexCoordPointer

getTexCoordPointer :: IO (VertexArrayDescriptor a)
getTexCoordPointer :: IO (VertexArrayDescriptor a)
getTexCoordPointer = do
   NumComponents
n <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a. a -> a
id PName1I
GetTextureCoordArraySize
   DataType
d <- (GLenum -> DataType) -> PName1I -> IO DataType
forall p a. GetPName1I p => (GLenum -> a) -> p -> IO a
getEnum1 GLenum -> DataType
unmarshalDataType PName1I
GetTextureCoordArrayType
   NumComponents
s <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral PName1I
GetTextureCoordArrayStride
   Ptr a
p <- GetPointervPName -> IO (Ptr a)
forall a. GetPointervPName -> IO (Ptr a)
getPointer GetPointervPName
TextureCoordArrayPointer
   VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall (m :: * -> *) a. Monad m => a -> m a
return (VertexArrayDescriptor a -> IO (VertexArrayDescriptor a))
-> VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall a b. (a -> b) -> a -> b
$ NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
forall a.
NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
VertexArrayDescriptor NumComponents
n DataType
d NumComponents
s Ptr a
p

setTexCoordPointer :: VertexArrayDescriptor a -> IO ()
setTexCoordPointer :: VertexArrayDescriptor a -> IO ()
setTexCoordPointer (VertexArrayDescriptor n :: NumComponents
n d :: DataType
d s :: NumComponents
s p :: Ptr a
p) =
   NumComponents -> GLenum -> NumComponents -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
NumComponents -> GLenum -> NumComponents -> Ptr a -> m ()
glTexCoordPointer NumComponents
n (DataType -> GLenum
marshalDataType DataType
d) NumComponents
s Ptr a
p

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

edgeFlagPointer :: StateVar (VertexArrayDescriptor a)
edgeFlagPointer :: StateVar (VertexArrayDescriptor a)
edgeFlagPointer = IO (VertexArrayDescriptor a)
-> (VertexArrayDescriptor a -> IO ())
-> StateVar (VertexArrayDescriptor a)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (VertexArrayDescriptor a)
forall a. IO (VertexArrayDescriptor a)
getEdgeFlagPointer VertexArrayDescriptor a -> IO ()
forall a. VertexArrayDescriptor a -> IO ()
setEdgeFlagPointer

getEdgeFlagPointer :: IO (VertexArrayDescriptor a)
getEdgeFlagPointer :: IO (VertexArrayDescriptor a)
getEdgeFlagPointer = do
   NumComponents
s <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral PName1I
GetEdgeFlagArrayStride
   Ptr a
p <- GetPointervPName -> IO (Ptr a)
forall a. GetPointervPName -> IO (Ptr a)
getPointer GetPointervPName
EdgeFlagArrayPointer
   VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall (m :: * -> *) a. Monad m => a -> m a
return (VertexArrayDescriptor a -> IO (VertexArrayDescriptor a))
-> VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall a b. (a -> b) -> a -> b
$ NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
forall a.
NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
VertexArrayDescriptor 1 DataType
UnsignedByte NumComponents
s Ptr a
p

setEdgeFlagPointer :: VertexArrayDescriptor a -> IO ()
setEdgeFlagPointer :: VertexArrayDescriptor a -> IO ()
setEdgeFlagPointer (VertexArrayDescriptor n :: NumComponents
n d :: DataType
d s :: NumComponents
s p :: Ptr a
p) =
   Bool -> IO () -> IO ()
check (NumComponents
n NumComponents -> NumComponents -> Bool
forall a. Eq a => a -> a -> Bool
== 1 Bool -> Bool -> Bool
&& DataType
d DataType -> DataType -> Bool
forall a. Eq a => a -> a -> Bool
== DataType
UnsignedByte) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ NumComponents -> Ptr a -> IO ()
forall (m :: * -> *) a. MonadIO m => NumComponents -> Ptr a -> m ()
glEdgeFlagPointer NumComponents
s Ptr a
p

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

fogCoordPointer :: StateVar (VertexArrayDescriptor a)
fogCoordPointer :: StateVar (VertexArrayDescriptor a)
fogCoordPointer = IO (VertexArrayDescriptor a)
-> (VertexArrayDescriptor a -> IO ())
-> StateVar (VertexArrayDescriptor a)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (VertexArrayDescriptor a)
forall a. IO (VertexArrayDescriptor a)
getFogCoordPointer VertexArrayDescriptor a -> IO ()
forall a. VertexArrayDescriptor a -> IO ()
setFogCoordPointer

getFogCoordPointer :: IO (VertexArrayDescriptor a)
getFogCoordPointer :: IO (VertexArrayDescriptor a)
getFogCoordPointer = do
   DataType
d <- (GLenum -> DataType) -> PName1I -> IO DataType
forall p a. GetPName1I p => (GLenum -> a) -> p -> IO a
getEnum1 GLenum -> DataType
unmarshalDataType PName1I
GetFogCoordArrayType
   NumComponents
s <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral PName1I
GetFogCoordArrayStride
   Ptr a
p <- GetPointervPName -> IO (Ptr a)
forall a. GetPointervPName -> IO (Ptr a)
getPointer GetPointervPName
FogCoordArrayPointer
   VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall (m :: * -> *) a. Monad m => a -> m a
return (VertexArrayDescriptor a -> IO (VertexArrayDescriptor a))
-> VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall a b. (a -> b) -> a -> b
$ NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
forall a.
NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
VertexArrayDescriptor 1 DataType
d NumComponents
s Ptr a
p

setFogCoordPointer :: VertexArrayDescriptor a -> IO ()
setFogCoordPointer :: VertexArrayDescriptor a -> IO ()
setFogCoordPointer (VertexArrayDescriptor n :: NumComponents
n d :: DataType
d s :: NumComponents
s p :: Ptr a
p) =
   Bool -> IO () -> IO ()
check (NumComponents
n NumComponents -> NumComponents -> Bool
forall a. Eq a => a -> a -> Bool
== 1) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ GLenum -> NumComponents -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum -> NumComponents -> Ptr a -> m ()
glFogCoordPointer (DataType -> GLenum
marshalDataType DataType
d) NumComponents
s Ptr a
p

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

secondaryColorPointer :: StateVar (VertexArrayDescriptor a)
secondaryColorPointer :: StateVar (VertexArrayDescriptor a)
secondaryColorPointer =
   IO (VertexArrayDescriptor a)
-> (VertexArrayDescriptor a -> IO ())
-> StateVar (VertexArrayDescriptor a)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (VertexArrayDescriptor a)
forall a. IO (VertexArrayDescriptor a)
getSecondaryColorPointer VertexArrayDescriptor a -> IO ()
forall a. VertexArrayDescriptor a -> IO ()
setSecondaryColorPointer

getSecondaryColorPointer :: IO (VertexArrayDescriptor a)
getSecondaryColorPointer :: IO (VertexArrayDescriptor a)
getSecondaryColorPointer = do
   NumComponents
n <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a. a -> a
id PName1I
GetSecondaryColorArraySize
   DataType
d <- (GLenum -> DataType) -> PName1I -> IO DataType
forall p a. GetPName1I p => (GLenum -> a) -> p -> IO a
getEnum1 GLenum -> DataType
unmarshalDataType PName1I
GetSecondaryColorArrayType
   NumComponents
s <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral PName1I
GetSecondaryColorArrayStride
   Ptr a
p <- GetPointervPName -> IO (Ptr a)
forall a. GetPointervPName -> IO (Ptr a)
getPointer GetPointervPName
SecondaryColorArrayPointer
   VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall (m :: * -> *) a. Monad m => a -> m a
return (VertexArrayDescriptor a -> IO (VertexArrayDescriptor a))
-> VertexArrayDescriptor a -> IO (VertexArrayDescriptor a)
forall a b. (a -> b) -> a -> b
$ NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
forall a.
NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
VertexArrayDescriptor NumComponents
n DataType
d NumComponents
s Ptr a
p

setSecondaryColorPointer :: (VertexArrayDescriptor a) -> IO ()
setSecondaryColorPointer :: VertexArrayDescriptor a -> IO ()
setSecondaryColorPointer (VertexArrayDescriptor n :: NumComponents
n d :: DataType
d s :: NumComponents
s p :: Ptr a
p) =
   NumComponents -> GLenum -> NumComponents -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
NumComponents -> GLenum -> NumComponents -> Ptr a -> m ()
glSecondaryColorPointer NumComponents
n (DataType -> GLenum
marshalDataType DataType
d) NumComponents
s Ptr a
p

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

data InterleavedArrays =
     V2f
   | V3f
   | C4ubV2f
   | C4ubV3f
   | C3fV3f
   | N3fV3f
   | C4fN3fV3f
   | T2fV3f
   | T4fV4f
   | T2fC4ubV3f
   | T2fC3fV3f
   | T2fN3fV3f
   | T2fC4fN3fV3f
   | T4fC4fN3fV4f
   deriving ( InterleavedArrays -> InterleavedArrays -> Bool
(InterleavedArrays -> InterleavedArrays -> Bool)
-> (InterleavedArrays -> InterleavedArrays -> Bool)
-> Eq InterleavedArrays
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InterleavedArrays -> InterleavedArrays -> Bool
$c/= :: InterleavedArrays -> InterleavedArrays -> Bool
== :: InterleavedArrays -> InterleavedArrays -> Bool
$c== :: InterleavedArrays -> InterleavedArrays -> Bool
Eq, Eq InterleavedArrays
Eq InterleavedArrays =>
(InterleavedArrays -> InterleavedArrays -> Ordering)
-> (InterleavedArrays -> InterleavedArrays -> Bool)
-> (InterleavedArrays -> InterleavedArrays -> Bool)
-> (InterleavedArrays -> InterleavedArrays -> Bool)
-> (InterleavedArrays -> InterleavedArrays -> Bool)
-> (InterleavedArrays -> InterleavedArrays -> InterleavedArrays)
-> (InterleavedArrays -> InterleavedArrays -> InterleavedArrays)
-> Ord InterleavedArrays
InterleavedArrays -> InterleavedArrays -> Bool
InterleavedArrays -> InterleavedArrays -> Ordering
InterleavedArrays -> InterleavedArrays -> InterleavedArrays
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
min :: InterleavedArrays -> InterleavedArrays -> InterleavedArrays
$cmin :: InterleavedArrays -> InterleavedArrays -> InterleavedArrays
max :: InterleavedArrays -> InterleavedArrays -> InterleavedArrays
$cmax :: InterleavedArrays -> InterleavedArrays -> InterleavedArrays
>= :: InterleavedArrays -> InterleavedArrays -> Bool
$c>= :: InterleavedArrays -> InterleavedArrays -> Bool
> :: InterleavedArrays -> InterleavedArrays -> Bool
$c> :: InterleavedArrays -> InterleavedArrays -> Bool
<= :: InterleavedArrays -> InterleavedArrays -> Bool
$c<= :: InterleavedArrays -> InterleavedArrays -> Bool
< :: InterleavedArrays -> InterleavedArrays -> Bool
$c< :: InterleavedArrays -> InterleavedArrays -> Bool
compare :: InterleavedArrays -> InterleavedArrays -> Ordering
$ccompare :: InterleavedArrays -> InterleavedArrays -> Ordering
$cp1Ord :: Eq InterleavedArrays
Ord, Int -> InterleavedArrays -> ShowS
[InterleavedArrays] -> ShowS
InterleavedArrays -> String
(Int -> InterleavedArrays -> ShowS)
-> (InterleavedArrays -> String)
-> ([InterleavedArrays] -> ShowS)
-> Show InterleavedArrays
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InterleavedArrays] -> ShowS
$cshowList :: [InterleavedArrays] -> ShowS
show :: InterleavedArrays -> String
$cshow :: InterleavedArrays -> String
showsPrec :: Int -> InterleavedArrays -> ShowS
$cshowsPrec :: Int -> InterleavedArrays -> ShowS
Show )

marshalInterleavedArrays :: InterleavedArrays -> GLenum
marshalInterleavedArrays :: InterleavedArrays -> GLenum
marshalInterleavedArrays x :: InterleavedArrays
x = case InterleavedArrays
x of
   V2f -> GLenum
GL_V2F
   V3f -> GLenum
GL_V3F
   C4ubV2f -> GLenum
GL_C4UB_V2F
   C4ubV3f -> GLenum
GL_C4UB_V3F
   C3fV3f -> GLenum
GL_C3F_V3F
   N3fV3f -> GLenum
GL_N3F_V3F
   C4fN3fV3f -> GLenum
GL_C4F_N3F_V3F
   T2fV3f -> GLenum
GL_T2F_V3F
   T4fV4f -> GLenum
GL_T4F_V4F
   T2fC4ubV3f -> GLenum
GL_T2F_C4UB_V3F
   T2fC3fV3f -> GLenum
GL_T2F_C3F_V3F
   T2fN3fV3f -> GLenum
GL_T2F_N3F_V3F
   T2fC4fN3fV3f -> GLenum
GL_T2F_C4F_N3F_V3F
   T4fC4fN3fV4f -> GLenum
GL_T4F_C4F_N3F_V4F

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

interleavedArrays :: InterleavedArrays -> Stride -> Ptr a -> IO ()
interleavedArrays :: InterleavedArrays -> NumComponents -> Ptr a -> IO ()
interleavedArrays = GLenum -> NumComponents -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum -> NumComponents -> Ptr a -> m ()
glInterleavedArrays (GLenum -> NumComponents -> Ptr a -> IO ())
-> (InterleavedArrays -> GLenum)
-> InterleavedArrays
-> NumComponents
-> Ptr a
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InterleavedArrays -> GLenum
marshalInterleavedArrays

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

clientState :: ClientArrayType -> StateVar Capability
clientState :: ClientArrayType -> StateVar Capability
clientState arrayType :: ClientArrayType
arrayType =
   IO Capability -> (Capability -> IO ()) -> StateVar Capability
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar (ClientArrayType -> IO Capability
getClientState ClientArrayType
arrayType) (ClientArrayType -> Capability -> IO ()
setClientState ClientArrayType
arrayType)

getClientState :: ClientArrayType -> IO Capability
getClientState :: ClientArrayType -> IO Capability
getClientState arrayType :: ClientArrayType
arrayType = StateVar Capability -> IO Capability
forall t a (m :: * -> *). (HasGetter t a, MonadIO m) => t -> m a
get (StateVar Capability -> IO Capability)
-> (ClientArrayType -> StateVar Capability)
-> ClientArrayType
-> IO Capability
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EnableCap -> StateVar Capability
makeCapability (EnableCap -> StateVar Capability)
-> (ClientArrayType -> EnableCap)
-> ClientArrayType
-> StateVar Capability
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ClientArrayType -> EnableCap
clientArrayTypeToEnableCap (ClientArrayType -> IO Capability)
-> ClientArrayType -> IO Capability
forall a b. (a -> b) -> a -> b
$ ClientArrayType
arrayType

setClientState :: ClientArrayType -> Capability -> IO ()
setClientState :: ClientArrayType -> Capability -> IO ()
setClientState arrayType :: ClientArrayType
arrayType val :: Capability
val =
   (if Capability
val Capability -> Capability -> Bool
forall a. Eq a => a -> a -> Bool
== Capability
Enabled then GLenum -> IO ()
forall (m :: * -> *). MonadIO m => GLenum -> m ()
glEnableClientState else GLenum -> IO ()
forall (m :: * -> *). MonadIO m => GLenum -> m ()
glDisableClientState)
      (ClientArrayType -> GLenum
marshalClientArrayType ClientArrayType
arrayType)

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

clientActiveTexture :: StateVar TextureUnit
clientActiveTexture :: StateVar TextureUnit
clientActiveTexture =
   IO TextureUnit -> (TextureUnit -> IO ()) -> StateVar TextureUnit
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar ((GLenum -> TextureUnit) -> PName1I -> IO TextureUnit
forall p a. GetPName1I p => (GLenum -> a) -> p -> IO a
getEnum1 GLenum -> TextureUnit
unmarshalTextureUnit PName1I
GetClientActiveTexture)
                (GLenum -> IO ()
forall (m :: * -> *). MonadIO m => GLenum -> m ()
glClientActiveTexture (GLenum -> IO ())
-> (TextureUnit -> GLenum) -> TextureUnit -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextureUnit -> GLenum
marshalTextureUnit)

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

type ArrayIndex = GLint

type NumArrayIndices = GLsizei

type NumIndexBlocks = GLsizei

type NumInstances = GLsizei

type BaseInstance = GLuint

type BaseVertex = GLint

-- TODO: The ranges (ArrayIndex, ArrayIndex) below should actually use GLuint:
-- type RangeStart = GLuint
-- type RangeEnd = GLuint

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

arrayElement :: ArrayIndex -> IO ()
arrayElement :: NumComponents -> IO ()
arrayElement = NumComponents -> IO ()
forall (m :: * -> *). MonadIO m => NumComponents -> m ()
glArrayElement

drawArrays :: PrimitiveMode -> ArrayIndex -> NumArrayIndices -> IO ()
drawArrays :: PrimitiveMode -> NumComponents -> NumComponents -> IO ()
drawArrays = GLenum -> NumComponents -> NumComponents -> IO ()
forall (m :: * -> *).
MonadIO m =>
GLenum -> NumComponents -> NumComponents -> m ()
glDrawArrays (GLenum -> NumComponents -> NumComponents -> IO ())
-> (PrimitiveMode -> GLenum)
-> PrimitiveMode
-> NumComponents
-> NumComponents
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimitiveMode -> GLenum
marshalPrimitiveMode

drawArraysInstancedBaseInstance :: PrimitiveMode -> ArrayIndex -> NumArrayIndices -> NumInstances -> BaseInstance -> IO ()
drawArraysInstancedBaseInstance :: PrimitiveMode
-> NumComponents
-> NumComponents
-> NumComponents
-> GLenum
-> IO ()
drawArraysInstancedBaseInstance = GLenum
-> NumComponents
-> NumComponents
-> NumComponents
-> GLenum
-> IO ()
forall (m :: * -> *).
MonadIO m =>
GLenum
-> NumComponents
-> NumComponents
-> NumComponents
-> GLenum
-> m ()
glDrawArraysInstancedBaseInstance (GLenum
 -> NumComponents
 -> NumComponents
 -> NumComponents
 -> GLenum
 -> IO ())
-> (PrimitiveMode -> GLenum)
-> PrimitiveMode
-> NumComponents
-> NumComponents
-> NumComponents
-> GLenum
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimitiveMode -> GLenum
marshalPrimitiveMode

drawArraysInstanced :: PrimitiveMode -> ArrayIndex -> NumArrayIndices -> NumInstances -> IO ()
drawArraysInstanced :: PrimitiveMode
-> NumComponents -> NumComponents -> NumComponents -> IO ()
drawArraysInstanced = GLenum -> NumComponents -> NumComponents -> NumComponents -> IO ()
forall (m :: * -> *).
MonadIO m =>
GLenum -> NumComponents -> NumComponents -> NumComponents -> m ()
glDrawArraysInstanced (GLenum
 -> NumComponents -> NumComponents -> NumComponents -> IO ())
-> (PrimitiveMode -> GLenum)
-> PrimitiveMode
-> NumComponents
-> NumComponents
-> NumComponents
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimitiveMode -> GLenum
marshalPrimitiveMode

multiDrawArrays :: PrimitiveMode -> Ptr ArrayIndex -> Ptr NumArrayIndices -> NumIndexBlocks -> IO ()
multiDrawArrays :: PrimitiveMode
-> Ptr NumComponents -> Ptr NumComponents -> NumComponents -> IO ()
multiDrawArrays = GLenum
-> Ptr NumComponents -> Ptr NumComponents -> NumComponents -> IO ()
forall (m :: * -> *).
MonadIO m =>
GLenum
-> Ptr NumComponents -> Ptr NumComponents -> NumComponents -> m ()
glMultiDrawArrays (GLenum
 -> Ptr NumComponents
 -> Ptr NumComponents
 -> NumComponents
 -> IO ())
-> (PrimitiveMode -> GLenum)
-> PrimitiveMode
-> Ptr NumComponents
-> Ptr NumComponents
-> NumComponents
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PrimitiveMode -> GLenum
marshalPrimitiveMode

drawElements :: PrimitiveMode -> NumArrayIndices -> DataType -> Ptr a -> IO ()
drawElements :: PrimitiveMode -> NumComponents -> DataType -> Ptr a -> IO ()
drawElements m :: PrimitiveMode
m c :: NumComponents
c = GLenum -> NumComponents -> GLenum -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum -> NumComponents -> GLenum -> Ptr a -> m ()
glDrawElements (PrimitiveMode -> GLenum
marshalPrimitiveMode PrimitiveMode
m) NumComponents
c (GLenum -> Ptr a -> IO ())
-> (DataType -> GLenum) -> DataType -> Ptr a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> GLenum
marshalDataType

drawElementsInstancedBaseInstance :: PrimitiveMode -> NumArrayIndices -> DataType -> Ptr a -> NumInstances -> BaseInstance -> IO ()
drawElementsInstancedBaseInstance :: PrimitiveMode
-> NumComponents
-> DataType
-> Ptr a
-> NumComponents
-> GLenum
-> IO ()
drawElementsInstancedBaseInstance m :: PrimitiveMode
m c :: NumComponents
c = GLenum
-> NumComponents
-> GLenum
-> Ptr a
-> NumComponents
-> GLenum
-> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum
-> NumComponents
-> GLenum
-> Ptr a
-> NumComponents
-> GLenum
-> m ()
glDrawElementsInstancedBaseInstance (PrimitiveMode -> GLenum
marshalPrimitiveMode PrimitiveMode
m) NumComponents
c (GLenum -> Ptr a -> NumComponents -> GLenum -> IO ())
-> (DataType -> GLenum)
-> DataType
-> Ptr a
-> NumComponents
-> GLenum
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> GLenum
marshalDataType

drawElementsInstanced :: PrimitiveMode -> NumArrayIndices -> DataType -> Ptr a -> NumInstances -> IO ()
drawElementsInstanced :: PrimitiveMode
-> NumComponents -> DataType -> Ptr a -> NumComponents -> IO ()
drawElementsInstanced m :: PrimitiveMode
m c :: NumComponents
c = GLenum
-> NumComponents -> GLenum -> Ptr a -> NumComponents -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum -> NumComponents -> GLenum -> Ptr a -> NumComponents -> m ()
glDrawElementsInstanced (PrimitiveMode -> GLenum
marshalPrimitiveMode PrimitiveMode
m) NumComponents
c (GLenum -> Ptr a -> NumComponents -> IO ())
-> (DataType -> GLenum)
-> DataType
-> Ptr a
-> NumComponents
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> GLenum
marshalDataType

multiDrawElements :: PrimitiveMode -> Ptr NumArrayIndices -> DataType -> Ptr (Ptr a) -> NumIndexBlocks -> IO ()
multiDrawElements :: PrimitiveMode
-> Ptr NumComponents
-> DataType
-> Ptr (Ptr a)
-> NumComponents
-> IO ()
multiDrawElements m :: PrimitiveMode
m c :: Ptr NumComponents
c = GLenum
-> Ptr NumComponents
-> GLenum
-> Ptr (Ptr a)
-> NumComponents
-> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum
-> Ptr NumComponents
-> GLenum
-> Ptr (Ptr a)
-> NumComponents
-> m ()
glMultiDrawElements (PrimitiveMode -> GLenum
marshalPrimitiveMode PrimitiveMode
m) Ptr NumComponents
c (GLenum -> Ptr (Ptr a) -> NumComponents -> IO ())
-> (DataType -> GLenum)
-> DataType
-> Ptr (Ptr a)
-> NumComponents
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> GLenum
marshalDataType

drawRangeElements :: PrimitiveMode -> (ArrayIndex, ArrayIndex) -> NumArrayIndices -> DataType -> Ptr a -> IO ()
drawRangeElements :: PrimitiveMode
-> (NumComponents, NumComponents)
-> NumComponents
-> DataType
-> Ptr a
-> IO ()
drawRangeElements m :: PrimitiveMode
m (s :: NumComponents
s, e :: NumComponents
e) c :: NumComponents
c = GLenum
-> GLenum -> GLenum -> NumComponents -> GLenum -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum
-> GLenum -> GLenum -> NumComponents -> GLenum -> Ptr a -> m ()
glDrawRangeElements (PrimitiveMode -> GLenum
marshalPrimitiveMode PrimitiveMode
m) (NumComponents -> GLenum
forall a b. (Integral a, Num b) => a -> b
fromIntegral NumComponents
s) (NumComponents -> GLenum
forall a b. (Integral a, Num b) => a -> b
fromIntegral NumComponents
e) NumComponents
c (GLenum -> Ptr a -> IO ())
-> (DataType -> GLenum) -> DataType -> Ptr a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> GLenum
marshalDataType

drawElementsBaseVertex :: PrimitiveMode -> NumArrayIndices -> DataType -> Ptr a -> BaseVertex -> IO ()
drawElementsBaseVertex :: PrimitiveMode
-> NumComponents -> DataType -> Ptr a -> NumComponents -> IO ()
drawElementsBaseVertex m :: PrimitiveMode
m c :: NumComponents
c = GLenum
-> NumComponents -> GLenum -> Ptr a -> NumComponents -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum -> NumComponents -> GLenum -> Ptr a -> NumComponents -> m ()
glDrawElementsBaseVertex (PrimitiveMode -> GLenum
marshalPrimitiveMode PrimitiveMode
m) NumComponents
c (GLenum -> Ptr a -> NumComponents -> IO ())
-> (DataType -> GLenum)
-> DataType
-> Ptr a
-> NumComponents
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> GLenum
marshalDataType

drawRangeElementsBaseVertex :: PrimitiveMode -> (ArrayIndex, ArrayIndex) -> NumArrayIndices -> DataType -> Ptr a -> BaseVertex -> IO ()
drawRangeElementsBaseVertex :: PrimitiveMode
-> (NumComponents, NumComponents)
-> NumComponents
-> DataType
-> Ptr a
-> NumComponents
-> IO ()
drawRangeElementsBaseVertex m :: PrimitiveMode
m (s :: NumComponents
s, e :: NumComponents
e) c :: NumComponents
c = GLenum
-> GLenum
-> GLenum
-> NumComponents
-> GLenum
-> Ptr a
-> NumComponents
-> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum
-> GLenum
-> GLenum
-> NumComponents
-> GLenum
-> Ptr a
-> NumComponents
-> m ()
glDrawRangeElementsBaseVertex (PrimitiveMode -> GLenum
marshalPrimitiveMode PrimitiveMode
m) (NumComponents -> GLenum
forall a b. (Integral a, Num b) => a -> b
fromIntegral NumComponents
s) (NumComponents -> GLenum
forall a b. (Integral a, Num b) => a -> b
fromIntegral NumComponents
e) NumComponents
c (GLenum -> Ptr a -> NumComponents -> IO ())
-> (DataType -> GLenum)
-> DataType
-> Ptr a
-> NumComponents
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> GLenum
marshalDataType

drawElementsInstancedBaseVertex :: PrimitiveMode -> NumArrayIndices -> DataType -> Ptr a -> NumInstances -> BaseVertex -> IO ()
drawElementsInstancedBaseVertex :: PrimitiveMode
-> NumComponents
-> DataType
-> Ptr a
-> NumComponents
-> NumComponents
-> IO ()
drawElementsInstancedBaseVertex m :: PrimitiveMode
m c :: NumComponents
c = GLenum
-> NumComponents
-> GLenum
-> Ptr a
-> NumComponents
-> NumComponents
-> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum
-> NumComponents
-> GLenum
-> Ptr a
-> NumComponents
-> NumComponents
-> m ()
glDrawElementsInstancedBaseVertex (PrimitiveMode -> GLenum
marshalPrimitiveMode PrimitiveMode
m) NumComponents
c (GLenum -> Ptr a -> NumComponents -> NumComponents -> IO ())
-> (DataType -> GLenum)
-> DataType
-> Ptr a
-> NumComponents
-> NumComponents
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> GLenum
marshalDataType

drawElementsInstancedBaseVertexBaseInstance :: PrimitiveMode -> NumArrayIndices -> DataType -> Ptr a -> NumInstances -> BaseVertex -> BaseInstance -> IO ()
drawElementsInstancedBaseVertexBaseInstance :: PrimitiveMode
-> NumComponents
-> DataType
-> Ptr a
-> NumComponents
-> NumComponents
-> GLenum
-> IO ()
drawElementsInstancedBaseVertexBaseInstance m :: PrimitiveMode
m c :: NumComponents
c = GLenum
-> NumComponents
-> GLenum
-> Ptr a
-> NumComponents
-> NumComponents
-> GLenum
-> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum
-> NumComponents
-> GLenum
-> Ptr a
-> NumComponents
-> NumComponents
-> GLenum
-> m ()
glDrawElementsInstancedBaseVertexBaseInstance (PrimitiveMode -> GLenum
marshalPrimitiveMode PrimitiveMode
m) NumComponents
c (GLenum
 -> Ptr a -> NumComponents -> NumComponents -> GLenum -> IO ())
-> (DataType -> GLenum)
-> DataType
-> Ptr a
-> NumComponents
-> NumComponents
-> GLenum
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> GLenum
marshalDataType

multiDrawElementsBaseVertex :: PrimitiveMode -> Ptr NumArrayIndices -> DataType -> Ptr (Ptr a) -> NumIndexBlocks -> Ptr BaseVertex -> IO ()
multiDrawElementsBaseVertex :: PrimitiveMode
-> Ptr NumComponents
-> DataType
-> Ptr (Ptr a)
-> NumComponents
-> Ptr NumComponents
-> IO ()
multiDrawElementsBaseVertex m :: PrimitiveMode
m c :: Ptr NumComponents
c = GLenum
-> Ptr NumComponents
-> GLenum
-> Ptr (Ptr a)
-> NumComponents
-> Ptr NumComponents
-> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum
-> Ptr NumComponents
-> GLenum
-> Ptr (Ptr a)
-> NumComponents
-> Ptr NumComponents
-> m ()
glMultiDrawElementsBaseVertex (PrimitiveMode -> GLenum
marshalPrimitiveMode PrimitiveMode
m) Ptr NumComponents
c (GLenum
 -> Ptr (Ptr a) -> NumComponents -> Ptr NumComponents -> IO ())
-> (DataType -> GLenum)
-> DataType
-> Ptr (Ptr a)
-> NumComponents
-> Ptr NumComponents
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataType -> GLenum
marshalDataType

maxElementsVertices :: GettableStateVar NumArrayIndices
maxElementsVertices :: IO NumComponents
maxElementsVertices = IO NumComponents -> IO NumComponents
forall a. IO a -> IO a
makeGettableStateVar ((NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getSizei1 NumComponents -> NumComponents
forall a. a -> a
id PName1I
GetMaxElementsVertices)

maxElementsIndices :: GettableStateVar NumArrayIndices
maxElementsIndices :: IO NumComponents
maxElementsIndices = IO NumComponents -> IO NumComponents
forall a. IO a -> IO a
makeGettableStateVar ((NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getSizei1 NumComponents -> NumComponents
forall a. a -> a
id PName1I
GetMaxElementsIndices)

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

lockArrays :: StateVar (Maybe (ArrayIndex, NumArrayIndices))
lockArrays :: StateVar (Maybe (NumComponents, NumComponents))
lockArrays = IO (Maybe (NumComponents, NumComponents))
-> (Maybe (NumComponents, NumComponents) -> IO ())
-> StateVar (Maybe (NumComponents, NumComponents))
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe (NumComponents, NumComponents))
getLockArrays Maybe (NumComponents, NumComponents) -> IO ()
setLockArrays

getLockArrays :: IO (Maybe (ArrayIndex, NumArrayIndices))
getLockArrays :: IO (Maybe (NumComponents, NumComponents))
getLockArrays = do
   NumComponents
count <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral PName1I
GetArrayElementLockCount
   if NumComponents
count NumComponents -> NumComponents -> Bool
forall a. Ord a => a -> a -> Bool
> 0
      then do NumComponents
first <- (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a. a -> a
id PName1I
GetArrayElementLockFirst
              Maybe (NumComponents, NumComponents)
-> IO (Maybe (NumComponents, NumComponents))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (NumComponents, NumComponents)
 -> IO (Maybe (NumComponents, NumComponents)))
-> Maybe (NumComponents, NumComponents)
-> IO (Maybe (NumComponents, NumComponents))
forall a b. (a -> b) -> a -> b
$ (NumComponents, NumComponents)
-> Maybe (NumComponents, NumComponents)
forall a. a -> Maybe a
Just (NumComponents
first, NumComponents
count)
      else Maybe (NumComponents, NumComponents)
-> IO (Maybe (NumComponents, NumComponents))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (NumComponents, NumComponents)
forall a. Maybe a
Nothing

setLockArrays :: Maybe (ArrayIndex, NumArrayIndices) -> IO ()
setLockArrays :: Maybe (NumComponents, NumComponents) -> IO ()
setLockArrays = IO ()
-> ((NumComponents, NumComponents) -> IO ())
-> Maybe (NumComponents, NumComponents)
-> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IO ()
forall (m :: * -> *). MonadIO m => m ()
glUnlockArraysEXT ((NumComponents -> NumComponents -> IO ())
-> (NumComponents, NumComponents) -> IO ()
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry NumComponents -> NumComponents -> IO ()
forall (m :: * -> *).
MonadIO m =>
NumComponents -> NumComponents -> m ()
glLockArraysEXT)

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

primitiveRestartIndex :: StateVar (Maybe ArrayIndex)
primitiveRestartIndex :: StateVar (Maybe NumComponents)
primitiveRestartIndex =
   IO EnableCap
-> IO NumComponents
-> (NumComponents -> IO ())
-> StateVar (Maybe NumComponents)
forall a.
IO EnableCap -> IO a -> (a -> IO ()) -> StateVar (Maybe a)
makeStateVarMaybe
      (EnableCap -> IO EnableCap
forall (m :: * -> *) a. Monad m => a -> m a
return EnableCap
CapPrimitiveRestart)
      ((NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a. a -> a
id PName1I
GetPrimitiveRestartIndex)
      (GLenum -> IO ()
forall (m :: * -> *). MonadIO m => GLenum -> m ()
glPrimitiveRestartIndex (GLenum -> IO ())
-> (NumComponents -> GLenum) -> NumComponents -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NumComponents -> GLenum
forall a b. (Integral a, Num b) => a -> b
fromIntegral)

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

-- We almost could use makeStateVarMaybe below, but, alas, this is client state.

primitiveRestartIndexNV :: StateVar (Maybe ArrayIndex)
primitiveRestartIndexNV :: StateVar (Maybe NumComponents)
primitiveRestartIndexNV =
   IO (Maybe NumComponents)
-> (Maybe NumComponents -> IO ()) -> StateVar (Maybe NumComponents)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar IO (Maybe NumComponents)
getPrimitiveRestartIndexNV Maybe NumComponents -> IO ()
setPrimitiveRestartIndexNV

getPrimitiveRestartIndexNV :: IO (Maybe ArrayIndex)
getPrimitiveRestartIndexNV :: IO (Maybe NumComponents)
getPrimitiveRestartIndexNV = do
   Bool
on <- (GLboolean -> Bool) -> PName1I -> IO Bool
forall p a. GetPName1I p => (GLboolean -> a) -> p -> IO a
getBoolean1 GLboolean -> Bool
forall a. (Eq a, Num a) => a -> Bool
unmarshalGLboolean PName1I
GetPrimitiveRestartNV
   if Bool
on
      then (NumComponents -> Maybe NumComponents)
-> IO NumComponents -> IO (Maybe NumComponents)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NumComponents -> Maybe NumComponents
forall a. a -> Maybe a
Just (IO NumComponents -> IO (Maybe NumComponents))
-> IO NumComponents -> IO (Maybe NumComponents)
forall a b. (a -> b) -> a -> b
$ (NumComponents -> NumComponents) -> PName1I -> IO NumComponents
forall p a. GetPName1I p => (NumComponents -> a) -> p -> IO a
getInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral PName1I
GetPrimitiveRestartIndexNV
      else Maybe NumComponents -> IO (Maybe NumComponents)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe NumComponents
forall a. Maybe a
Nothing

setPrimitiveRestartIndexNV :: Maybe ArrayIndex -> IO ()
setPrimitiveRestartIndexNV :: Maybe NumComponents -> IO ()
setPrimitiveRestartIndexNV maybeIdx :: Maybe NumComponents
maybeIdx = case Maybe NumComponents
maybeIdx of
   Nothing  -> GLenum -> IO ()
forall (m :: * -> *). MonadIO m => GLenum -> m ()
glDisableClientState GLenum
GL_PRIMITIVE_RESTART_NV
   Just idx :: NumComponents
idx -> do GLenum -> IO ()
forall (m :: * -> *). MonadIO m => GLenum -> m ()
glEnableClientState GLenum
GL_PRIMITIVE_RESTART_NV
                  GLenum -> IO ()
forall (m :: * -> *). MonadIO m => GLenum -> m ()
glPrimitiveRestartIndexNV (NumComponents -> GLenum
forall a b. (Integral a, Num b) => a -> b
fromIntegral NumComponents
idx)

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

vertexAttribPointer :: AttribLocation -> StateVar (IntegerHandling, VertexArrayDescriptor a)
vertexAttribPointer :: AttribLocation
-> StateVar (IntegerHandling, VertexArrayDescriptor a)
vertexAttribPointer location :: AttribLocation
location =
   IO (IntegerHandling, VertexArrayDescriptor a)
-> ((IntegerHandling, VertexArrayDescriptor a) -> IO ())
-> StateVar (IntegerHandling, VertexArrayDescriptor a)
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar (AttribLocation -> IO (IntegerHandling, VertexArrayDescriptor a)
forall a.
AttribLocation -> IO (IntegerHandling, VertexArrayDescriptor a)
getVertexAttribPointer_ AttribLocation
location) (AttribLocation
-> (IntegerHandling, VertexArrayDescriptor a) -> IO ()
forall a.
AttribLocation
-> (IntegerHandling, VertexArrayDescriptor a) -> IO ()
setVertexAttribPointer AttribLocation
location)

getVertexAttribPointer_ :: AttribLocation -> IO (IntegerHandling, VertexArrayDescriptor a)
getVertexAttribPointer_ :: AttribLocation -> IO (IntegerHandling, VertexArrayDescriptor a)
getVertexAttribPointer_ location :: AttribLocation
location = do
   Bool
i <- (GLboolean -> Bool)
-> AttribLocation -> GetVertexAttribPName -> IO Bool
forall b.
(GLboolean -> b) -> AttribLocation -> GetVertexAttribPName -> IO b
getVertexAttribBoolean1 GLboolean -> Bool
forall a. (Eq a, Num a) => a -> Bool
unmarshalGLboolean AttribLocation
location GetVertexAttribPName
GetVertexAttribArrayInteger
   IntegerHandling
h <- if Bool
i
           then IntegerHandling -> IO IntegerHandling
forall (m :: * -> *) a. Monad m => a -> m a
return IntegerHandling
KeepIntegral
           else do Bool
f <- (GLboolean -> Bool)
-> AttribLocation -> GetVertexAttribPName -> IO Bool
forall b.
(GLboolean -> b) -> AttribLocation -> GetVertexAttribPName -> IO b
getVertexAttribBoolean1 GLboolean -> Bool
forall a. (Eq a, Num a) => a -> Bool
unmarshalGLboolean AttribLocation
location GetVertexAttribPName
GetVertexAttribArrayNormalized
                   IntegerHandling -> IO IntegerHandling
forall (m :: * -> *) a. Monad m => a -> m a
return (IntegerHandling -> IO IntegerHandling)
-> IntegerHandling -> IO IntegerHandling
forall a b. (a -> b) -> a -> b
$ if Bool
f then IntegerHandling
ToNormalizedFloat else IntegerHandling
ToFloat
   NumComponents
n <- (NumComponents -> NumComponents)
-> AttribLocation -> GetVertexAttribPName -> IO NumComponents
forall b.
(NumComponents -> b)
-> AttribLocation -> GetVertexAttribPName -> IO b
getVertexAttribInteger1 NumComponents -> NumComponents
forall a. a -> a
id AttribLocation
location GetVertexAttribPName
GetVertexAttribArraySize
   DataType
d <- (GLenum -> DataType)
-> AttribLocation -> GetVertexAttribPName -> IO DataType
forall b.
(GLenum -> b) -> AttribLocation -> GetVertexAttribPName -> IO b
getVertexAttribEnum1 GLenum -> DataType
unmarshalDataType AttribLocation
location GetVertexAttribPName
GetVertexAttribArrayType
   NumComponents
s <- (NumComponents -> NumComponents)
-> AttribLocation -> GetVertexAttribPName -> IO NumComponents
forall b.
(NumComponents -> b)
-> AttribLocation -> GetVertexAttribPName -> IO b
getVertexAttribInteger1 NumComponents -> NumComponents
forall a b. (Integral a, Num b) => a -> b
fromIntegral AttribLocation
location GetVertexAttribPName
GetVertexAttribArrayStride
   Ptr a
p <- AttribLocation -> GetVertexAttribPointerPName -> IO (Ptr a)
forall a.
AttribLocation -> GetVertexAttribPointerPName -> IO (Ptr a)
getVertexAttribPointer AttribLocation
location GetVertexAttribPointerPName
VertexAttribArrayPointer
   (IntegerHandling, VertexArrayDescriptor a)
-> IO (IntegerHandling, VertexArrayDescriptor a)
forall (m :: * -> *) a. Monad m => a -> m a
return (IntegerHandling
h, NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
forall a.
NumComponents
-> DataType -> NumComponents -> Ptr a -> VertexArrayDescriptor a
VertexArrayDescriptor NumComponents
n DataType
d NumComponents
s Ptr a
p)

setVertexAttribPointer :: AttribLocation -> (IntegerHandling, VertexArrayDescriptor a) -> IO ()
setVertexAttribPointer :: AttribLocation
-> (IntegerHandling, VertexArrayDescriptor a) -> IO ()
setVertexAttribPointer (AttribLocation location :: GLenum
location) (h :: IntegerHandling
h, VertexArrayDescriptor n :: NumComponents
n d :: DataType
d s :: NumComponents
s p :: Ptr a
p) = case IntegerHandling
h of
   ToFloat -> GLenum
-> NumComponents
-> GLenum
-> GLboolean
-> NumComponents
-> Ptr a
-> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum
-> NumComponents
-> GLenum
-> GLboolean
-> NumComponents
-> Ptr a
-> m ()
glVertexAttribPointer GLenum
location NumComponents
n GLenum
md (Bool -> GLboolean
forall a. Num a => Bool -> a
marshalGLboolean Bool
False) NumComponents
s Ptr a
p
   ToNormalizedFloat -> GLenum
-> NumComponents
-> GLenum
-> GLboolean
-> NumComponents
-> Ptr a
-> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum
-> NumComponents
-> GLenum
-> GLboolean
-> NumComponents
-> Ptr a
-> m ()
glVertexAttribPointer GLenum
location NumComponents
n GLenum
md (Bool -> GLboolean
forall a. Num a => Bool -> a
marshalGLboolean Bool
True) NumComponents
s Ptr a
p
   KeepIntegral -> GLenum
-> NumComponents -> GLenum -> NumComponents -> Ptr a -> IO ()
forall (m :: * -> *) a.
MonadIO m =>
GLenum -> NumComponents -> GLenum -> NumComponents -> Ptr a -> m ()
glVertexAttribIPointer GLenum
location NumComponents
n GLenum
md NumComponents
s Ptr a
p
  where md :: GLenum
md = DataType -> GLenum
marshalDataType DataType
d

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

vertexAttribArray :: AttribLocation -> StateVar Capability
vertexAttribArray :: AttribLocation -> StateVar Capability
vertexAttribArray location :: AttribLocation
location =
   IO Capability -> (Capability -> IO ()) -> StateVar Capability
forall a. IO a -> (a -> IO ()) -> StateVar a
makeStateVar (AttribLocation -> IO Capability
getVertexAttribArray AttribLocation
location) ((Capability -> AttribLocation -> IO ())
-> AttribLocation -> Capability -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Capability -> AttribLocation -> IO ()
setVertexAttribArray AttribLocation
location)

getVertexAttribArray :: AttribLocation -> IO Capability
getVertexAttribArray :: AttribLocation -> IO Capability
getVertexAttribArray location :: AttribLocation
location =
   (GLboolean -> Capability)
-> AttribLocation -> GetVertexAttribPName -> IO Capability
forall b.
(GLboolean -> b) -> AttribLocation -> GetVertexAttribPName -> IO b
getVertexAttribBoolean1 GLboolean -> Capability
unmarshalCapability AttribLocation
location GetVertexAttribPName
GetVertexAttribArrayEnabled

setVertexAttribArray :: Capability -> AttribLocation -> IO ()
setVertexAttribArray :: Capability -> AttribLocation -> IO ()
setVertexAttribArray Disabled (AttribLocation location :: GLenum
location) = GLenum -> IO ()
forall (m :: * -> *). MonadIO m => GLenum -> m ()
glDisableVertexAttribArray GLenum
location
setVertexAttribArray Enabled (AttribLocation location :: GLenum
location) = GLenum -> IO ()
forall (m :: * -> *). MonadIO m => GLenum -> m ()
glEnableVertexAttribArray GLenum
location