{-# OPTIONS_HADDOCK hide #-}
--------------------------------------------------------------------------------
-- |
-- Module      :  Graphics.Rendering.OpenGL.GL.DataType
-- 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 (un-)marshaling DataType.
--
--------------------------------------------------------------------------------

module Graphics.Rendering.OpenGL.GL.DataType (
   DataType(..), marshalDataType, unmarshalDataType,
   DataRepresentation(..), unmarshalDataRepresentation
) where

import Graphics.GL

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

-- basically table 8.7 (pixel data type parameter) plus a few additions
data DataType =
     UnsignedByte
   | Byte
   | UnsignedShort
   | Short
   | UnsignedInt
   | Int
   | HalfFloat
   | Float
   | UnsignedByte332
   | UnsignedByte233Rev
   | UnsignedShort565
   | UnsignedShort565Rev
   | UnsignedShort4444
   | UnsignedShort4444Rev
   | UnsignedShort5551
   | UnsignedShort1555Rev
   | UnsignedInt8888
   | UnsignedInt8888Rev
   | UnsignedInt1010102
   | UnsignedInt2101010Rev
   | UnsignedInt248
   | UnsignedInt10f11f11fRev
   | UnsignedInt5999Rev
   | Float32UnsignedInt248Rev
   | Bitmap                    -- pixel data, deprecated in 3.1
   | UnsignedShort88           -- MESA_ycbcr_texture/APPLE_ycbcr_422
   | UnsignedShort88Rev        -- MESA_ycbcr_texture/APPLE_ycbcr_422
   | Double                    -- vertex arrays (EXT_vertex_array, now core)
   | TwoBytes                  -- CallLists
   | ThreeBytes                -- CallLists
   | FourBytes                 -- CallLists
   deriving ( DataType -> DataType -> Bool
(DataType -> DataType -> Bool)
-> (DataType -> DataType -> Bool) -> Eq DataType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DataType -> DataType -> Bool
$c/= :: DataType -> DataType -> Bool
== :: DataType -> DataType -> Bool
$c== :: DataType -> DataType -> Bool
Eq, Eq DataType
Eq DataType =>
(DataType -> DataType -> Ordering)
-> (DataType -> DataType -> Bool)
-> (DataType -> DataType -> Bool)
-> (DataType -> DataType -> Bool)
-> (DataType -> DataType -> Bool)
-> (DataType -> DataType -> DataType)
-> (DataType -> DataType -> DataType)
-> Ord DataType
DataType -> DataType -> Bool
DataType -> DataType -> Ordering
DataType -> DataType -> DataType
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 :: DataType -> DataType -> DataType
$cmin :: DataType -> DataType -> DataType
max :: DataType -> DataType -> DataType
$cmax :: DataType -> DataType -> DataType
>= :: DataType -> DataType -> Bool
$c>= :: DataType -> DataType -> Bool
> :: DataType -> DataType -> Bool
$c> :: DataType -> DataType -> Bool
<= :: DataType -> DataType -> Bool
$c<= :: DataType -> DataType -> Bool
< :: DataType -> DataType -> Bool
$c< :: DataType -> DataType -> Bool
compare :: DataType -> DataType -> Ordering
$ccompare :: DataType -> DataType -> Ordering
$cp1Ord :: Eq DataType
Ord, Int -> DataType -> ShowS
[DataType] -> ShowS
DataType -> String
(Int -> DataType -> ShowS)
-> (DataType -> String) -> ([DataType] -> ShowS) -> Show DataType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DataType] -> ShowS
$cshowList :: [DataType] -> ShowS
show :: DataType -> String
$cshow :: DataType -> String
showsPrec :: Int -> DataType -> ShowS
$cshowsPrec :: Int -> DataType -> ShowS
Show )

marshalDataType :: DataType -> GLenum
marshalDataType :: DataType -> GLenum
marshalDataType x :: DataType
x = case DataType
x of
   UnsignedByte -> GLenum
GL_UNSIGNED_BYTE
   Byte -> GLenum
GL_BYTE
   UnsignedShort -> GLenum
GL_UNSIGNED_SHORT
   Short -> GLenum
GL_SHORT
   UnsignedInt -> GLenum
GL_UNSIGNED_INT
   Int -> GLenum
GL_INT
   HalfFloat -> GLenum
GL_HALF_FLOAT
   Float -> GLenum
GL_FLOAT
   UnsignedByte332 -> GLenum
GL_UNSIGNED_BYTE_3_3_2
   UnsignedByte233Rev -> GLenum
GL_UNSIGNED_BYTE_2_3_3_REV
   UnsignedShort565 -> GLenum
GL_UNSIGNED_SHORT_5_6_5
   UnsignedShort565Rev -> GLenum
GL_UNSIGNED_SHORT_5_6_5_REV
   UnsignedShort4444 -> GLenum
GL_UNSIGNED_SHORT_4_4_4_4
   UnsignedShort4444Rev -> GLenum
GL_UNSIGNED_SHORT_4_4_4_4_REV
   UnsignedShort5551 -> GLenum
GL_UNSIGNED_SHORT_5_5_5_1
   UnsignedShort1555Rev -> GLenum
GL_UNSIGNED_SHORT_1_5_5_5_REV
   UnsignedInt8888 -> GLenum
GL_UNSIGNED_INT_8_8_8_8
   UnsignedInt8888Rev -> GLenum
GL_UNSIGNED_INT_8_8_8_8_REV
   UnsignedInt1010102 -> GLenum
GL_UNSIGNED_INT_10_10_10_2
   UnsignedInt2101010Rev -> GLenum
GL_UNSIGNED_INT_2_10_10_10_REV
   UnsignedInt248 -> GLenum
GL_UNSIGNED_INT_24_8
   UnsignedInt10f11f11fRev -> GLenum
GL_UNSIGNED_INT_10F_11F_11F_REV
   UnsignedInt5999Rev -> GLenum
GL_UNSIGNED_INT_5_9_9_9_REV
   Float32UnsignedInt248Rev -> GLenum
GL_FLOAT_32_UNSIGNED_INT_24_8_REV
   Bitmap -> GLenum
GL_BITMAP
   UnsignedShort88 -> GLenum
GL_UNSIGNED_SHORT_8_8_APPLE
   UnsignedShort88Rev -> GLenum
GL_UNSIGNED_SHORT_8_8_REV_APPLE
   Double -> GLenum
GL_DOUBLE
   TwoBytes -> GLenum
GL_2_BYTES
   ThreeBytes -> GLenum
GL_3_BYTES
   FourBytes -> GLenum
GL_4_BYTES

unmarshalDataType :: GLenum -> DataType
unmarshalDataType :: GLenum -> DataType
unmarshalDataType x :: GLenum
x
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_BYTE = DataType
UnsignedByte
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_BYTE = DataType
Byte
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_SHORT = DataType
UnsignedShort
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_SHORT = DataType
Short
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_INT = DataType
UnsignedInt
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_INT = DataType
Int
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_HALF_FLOAT = DataType
HalfFloat
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_FLOAT = DataType
Float
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_BYTE_3_3_2 = DataType
UnsignedByte332
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_BYTE_2_3_3_REV = DataType
UnsignedByte233Rev
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_SHORT_5_6_5 = DataType
UnsignedShort565
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_SHORT_5_6_5_REV = DataType
UnsignedShort565Rev
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_SHORT_4_4_4_4 = DataType
UnsignedShort4444
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_SHORT_4_4_4_4_REV = DataType
UnsignedShort4444Rev
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_SHORT_5_5_5_1 = DataType
UnsignedShort5551
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_SHORT_1_5_5_5_REV = DataType
UnsignedShort1555Rev
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_INT_8_8_8_8 = DataType
UnsignedInt8888
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_INT_8_8_8_8_REV = DataType
UnsignedInt8888Rev
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_INT_10_10_10_2 = DataType
UnsignedInt1010102
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_INT_2_10_10_10_REV = DataType
UnsignedInt2101010Rev
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_INT_24_8 = DataType
UnsignedInt248
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_INT_10F_11F_11F_REV = DataType
UnsignedInt10f11f11fRev
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_INT_5_9_9_9_REV = DataType
UnsignedInt5999Rev
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_FLOAT_32_UNSIGNED_INT_24_8_REV = DataType
Float32UnsignedInt248Rev
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_BITMAP = DataType
Bitmap
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_SHORT_8_8_APPLE = DataType
UnsignedShort88
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_SHORT_8_8_REV_APPLE = DataType
UnsignedShort88Rev
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_DOUBLE = DataType
Double
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_2_BYTES = DataType
TwoBytes
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_3_BYTES = DataType
ThreeBytes
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_4_BYTES = DataType
FourBytes
   | Bool
otherwise = String -> DataType
forall a. HasCallStack => String -> a
error ("unmarshalDataType: illegal value " String -> ShowS
forall a. [a] -> [a] -> [a]
++ GLenum -> String
forall a. Show a => a -> String
show GLenum
x)

data DataRepresentation
   = SignedNormalizedRepresentation
   | UnsignedNormalizedRepresentation
   | FloatRepresentation
   | IntRepresentation
   | UnsignedIntRepresentation
   deriving ( DataRepresentation -> DataRepresentation -> Bool
(DataRepresentation -> DataRepresentation -> Bool)
-> (DataRepresentation -> DataRepresentation -> Bool)
-> Eq DataRepresentation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DataRepresentation -> DataRepresentation -> Bool
$c/= :: DataRepresentation -> DataRepresentation -> Bool
== :: DataRepresentation -> DataRepresentation -> Bool
$c== :: DataRepresentation -> DataRepresentation -> Bool
Eq, Eq DataRepresentation
Eq DataRepresentation =>
(DataRepresentation -> DataRepresentation -> Ordering)
-> (DataRepresentation -> DataRepresentation -> Bool)
-> (DataRepresentation -> DataRepresentation -> Bool)
-> (DataRepresentation -> DataRepresentation -> Bool)
-> (DataRepresentation -> DataRepresentation -> Bool)
-> (DataRepresentation -> DataRepresentation -> DataRepresentation)
-> (DataRepresentation -> DataRepresentation -> DataRepresentation)
-> Ord DataRepresentation
DataRepresentation -> DataRepresentation -> Bool
DataRepresentation -> DataRepresentation -> Ordering
DataRepresentation -> DataRepresentation -> DataRepresentation
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 :: DataRepresentation -> DataRepresentation -> DataRepresentation
$cmin :: DataRepresentation -> DataRepresentation -> DataRepresentation
max :: DataRepresentation -> DataRepresentation -> DataRepresentation
$cmax :: DataRepresentation -> DataRepresentation -> DataRepresentation
>= :: DataRepresentation -> DataRepresentation -> Bool
$c>= :: DataRepresentation -> DataRepresentation -> Bool
> :: DataRepresentation -> DataRepresentation -> Bool
$c> :: DataRepresentation -> DataRepresentation -> Bool
<= :: DataRepresentation -> DataRepresentation -> Bool
$c<= :: DataRepresentation -> DataRepresentation -> Bool
< :: DataRepresentation -> DataRepresentation -> Bool
$c< :: DataRepresentation -> DataRepresentation -> Bool
compare :: DataRepresentation -> DataRepresentation -> Ordering
$ccompare :: DataRepresentation -> DataRepresentation -> Ordering
$cp1Ord :: Eq DataRepresentation
Ord, Int -> DataRepresentation -> ShowS
[DataRepresentation] -> ShowS
DataRepresentation -> String
(Int -> DataRepresentation -> ShowS)
-> (DataRepresentation -> String)
-> ([DataRepresentation] -> ShowS)
-> Show DataRepresentation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DataRepresentation] -> ShowS
$cshowList :: [DataRepresentation] -> ShowS
show :: DataRepresentation -> String
$cshow :: DataRepresentation -> String
showsPrec :: Int -> DataRepresentation -> ShowS
$cshowsPrec :: Int -> DataRepresentation -> ShowS
Show )

unmarshalDataRepresentation :: GLenum -> Maybe DataRepresentation
unmarshalDataRepresentation :: GLenum -> Maybe DataRepresentation
unmarshalDataRepresentation x :: GLenum
x
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_SIGNED_NORMALIZED = DataRepresentation -> Maybe DataRepresentation
forall a. a -> Maybe a
Just DataRepresentation
SignedNormalizedRepresentation
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_NORMALIZED = DataRepresentation -> Maybe DataRepresentation
forall a. a -> Maybe a
Just DataRepresentation
UnsignedNormalizedRepresentation
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_FLOAT = DataRepresentation -> Maybe DataRepresentation
forall a. a -> Maybe a
Just DataRepresentation
FloatRepresentation
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_INT = DataRepresentation -> Maybe DataRepresentation
forall a. a -> Maybe a
Just DataRepresentation
IntRepresentation
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_UNSIGNED_INT = DataRepresentation -> Maybe DataRepresentation
forall a. a -> Maybe a
Just DataRepresentation
UnsignedIntRepresentation
   | GLenum
x GLenum -> GLenum -> Bool
forall a. Eq a => a -> a -> Bool
== GLenum
GL_NONE = Maybe DataRepresentation
forall a. Maybe a
Nothing
   | Bool
otherwise = String -> Maybe DataRepresentation
forall a. HasCallStack => String -> a
error (String -> Maybe DataRepresentation)
-> String -> Maybe DataRepresentation
forall a b. (a -> b) -> a -> b
$ "unmarshalDataRepresentation: illegal value " String -> ShowS
forall a. [a] -> [a] -> [a]
++ GLenum -> String
forall a. Show a => a -> String
show GLenum
x