module Codec.GlTF.BufferView
  ( BufferViewIx(..)
  , BufferView(..)
  , BufferViewTarget(..)
  , pattern ARRAY_BUFFER
  , pattern ELEMENT_ARRAY_BUFFER
  ) where

import Codec.GlTF.Prelude

import Codec.GlTF.Buffer (BufferIx)

newtype BufferViewIx = BufferViewIx { BufferViewIx -> Int
unBufferViewIx :: Int }
  deriving (BufferViewIx -> BufferViewIx -> Bool
(BufferViewIx -> BufferViewIx -> Bool)
-> (BufferViewIx -> BufferViewIx -> Bool) -> Eq BufferViewIx
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BufferViewIx -> BufferViewIx -> Bool
$c/= :: BufferViewIx -> BufferViewIx -> Bool
== :: BufferViewIx -> BufferViewIx -> Bool
$c== :: BufferViewIx -> BufferViewIx -> Bool
Eq, Eq BufferViewIx
Eq BufferViewIx
-> (BufferViewIx -> BufferViewIx -> Ordering)
-> (BufferViewIx -> BufferViewIx -> Bool)
-> (BufferViewIx -> BufferViewIx -> Bool)
-> (BufferViewIx -> BufferViewIx -> Bool)
-> (BufferViewIx -> BufferViewIx -> Bool)
-> (BufferViewIx -> BufferViewIx -> BufferViewIx)
-> (BufferViewIx -> BufferViewIx -> BufferViewIx)
-> Ord BufferViewIx
BufferViewIx -> BufferViewIx -> Bool
BufferViewIx -> BufferViewIx -> Ordering
BufferViewIx -> BufferViewIx -> BufferViewIx
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 :: BufferViewIx -> BufferViewIx -> BufferViewIx
$cmin :: BufferViewIx -> BufferViewIx -> BufferViewIx
max :: BufferViewIx -> BufferViewIx -> BufferViewIx
$cmax :: BufferViewIx -> BufferViewIx -> BufferViewIx
>= :: BufferViewIx -> BufferViewIx -> Bool
$c>= :: BufferViewIx -> BufferViewIx -> Bool
> :: BufferViewIx -> BufferViewIx -> Bool
$c> :: BufferViewIx -> BufferViewIx -> Bool
<= :: BufferViewIx -> BufferViewIx -> Bool
$c<= :: BufferViewIx -> BufferViewIx -> Bool
< :: BufferViewIx -> BufferViewIx -> Bool
$c< :: BufferViewIx -> BufferViewIx -> Bool
compare :: BufferViewIx -> BufferViewIx -> Ordering
$ccompare :: BufferViewIx -> BufferViewIx -> Ordering
$cp1Ord :: Eq BufferViewIx
Ord, Int -> BufferViewIx -> ShowS
[BufferViewIx] -> ShowS
BufferViewIx -> String
(Int -> BufferViewIx -> ShowS)
-> (BufferViewIx -> String)
-> ([BufferViewIx] -> ShowS)
-> Show BufferViewIx
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BufferViewIx] -> ShowS
$cshowList :: [BufferViewIx] -> ShowS
show :: BufferViewIx -> String
$cshow :: BufferViewIx -> String
showsPrec :: Int -> BufferViewIx -> ShowS
$cshowsPrec :: Int -> BufferViewIx -> ShowS
Show, Value -> Parser [BufferViewIx]
Value -> Parser BufferViewIx
(Value -> Parser BufferViewIx)
-> (Value -> Parser [BufferViewIx]) -> FromJSON BufferViewIx
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [BufferViewIx]
$cparseJSONList :: Value -> Parser [BufferViewIx]
parseJSON :: Value -> Parser BufferViewIx
$cparseJSON :: Value -> Parser BufferViewIx
FromJSON, [BufferViewIx] -> Encoding
[BufferViewIx] -> Value
BufferViewIx -> Encoding
BufferViewIx -> Value
(BufferViewIx -> Value)
-> (BufferViewIx -> Encoding)
-> ([BufferViewIx] -> Value)
-> ([BufferViewIx] -> Encoding)
-> ToJSON BufferViewIx
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [BufferViewIx] -> Encoding
$ctoEncodingList :: [BufferViewIx] -> Encoding
toJSONList :: [BufferViewIx] -> Value
$ctoJSONList :: [BufferViewIx] -> Value
toEncoding :: BufferViewIx -> Encoding
$ctoEncoding :: BufferViewIx -> Encoding
toJSON :: BufferViewIx -> Value
$ctoJSON :: BufferViewIx -> Value
ToJSON, (forall x. BufferViewIx -> Rep BufferViewIx x)
-> (forall x. Rep BufferViewIx x -> BufferViewIx)
-> Generic BufferViewIx
forall x. Rep BufferViewIx x -> BufferViewIx
forall x. BufferViewIx -> Rep BufferViewIx x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BufferViewIx x -> BufferViewIx
$cfrom :: forall x. BufferViewIx -> Rep BufferViewIx x
Generic)

-- | A view into a buffer generally representing a subset of the buffer.
data BufferView = BufferView
  { BufferView -> BufferIx
buffer     :: BufferIx
  , BufferView -> Int
byteOffset :: Size
  , BufferView -> Int
byteLength :: Size
  , BufferView -> Maybe Int
byteStride :: Maybe Size -- [4-252]
    -- ^ The stride, in bytes, between vertex attributes.
    -- When this is not defined, data is tightly packed.
    -- When two or more accessors use the same bufferView, this field must be defined.
  , BufferView -> Maybe BufferViewTarget
target     :: Maybe BufferViewTarget
    -- ^ The target that the GPU buffer should be bound to.
  , BufferView -> Maybe Text
name       :: Maybe Text
  , BufferView -> Maybe Object
extensions :: Maybe Object
  , BufferView -> Maybe Value
extras     :: Maybe Value
  } deriving (BufferView -> BufferView -> Bool
(BufferView -> BufferView -> Bool)
-> (BufferView -> BufferView -> Bool) -> Eq BufferView
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BufferView -> BufferView -> Bool
$c/= :: BufferView -> BufferView -> Bool
== :: BufferView -> BufferView -> Bool
$c== :: BufferView -> BufferView -> Bool
Eq, Int -> BufferView -> ShowS
[BufferView] -> ShowS
BufferView -> String
(Int -> BufferView -> ShowS)
-> (BufferView -> String)
-> ([BufferView] -> ShowS)
-> Show BufferView
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BufferView] -> ShowS
$cshowList :: [BufferView] -> ShowS
show :: BufferView -> String
$cshow :: BufferView -> String
showsPrec :: Int -> BufferView -> ShowS
$cshowsPrec :: Int -> BufferView -> ShowS
Show, (forall x. BufferView -> Rep BufferView x)
-> (forall x. Rep BufferView x -> BufferView) -> Generic BufferView
forall x. Rep BufferView x -> BufferView
forall x. BufferView -> Rep BufferView x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BufferView x -> BufferView
$cfrom :: forall x. BufferView -> Rep BufferView x
Generic)

instance FromJSON BufferView where
  parseJSON :: Value -> Parser BufferView
parseJSON = String
-> (Object -> Parser BufferView) -> Value -> Parser BufferView
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"BufferView" \Object
o -> do
    BufferIx
buffer     <- Object
o Object -> Key -> Parser BufferIx
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"buffer"
    Int
byteOffset <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"byteOffset" Parser (Maybe Int) -> Int -> Parser Int
forall a. Parser (Maybe a) -> a -> Parser a
.!= Int
0
    Int
byteLength <- Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"byteLength"
    Maybe Int
byteStride <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"byteStride"
    Maybe BufferViewTarget
target     <- Object
o Object -> Key -> Parser (Maybe BufferViewTarget)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"target"
    Maybe Text
name       <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"name"
    Maybe Object
extensions <- Object
o Object -> Key -> Parser (Maybe Object)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"extensions"
    Maybe Value
extras     <- Object
o Object -> Key -> Parser (Maybe Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"extras"
    pure BufferView :: BufferIx
-> Int
-> Int
-> Maybe Int
-> Maybe BufferViewTarget
-> Maybe Text
-> Maybe Object
-> Maybe Value
-> BufferView
BufferView{Int
Maybe Int
Maybe Text
Maybe Value
Maybe Object
Maybe BufferViewTarget
BufferIx
extras :: Maybe Value
extensions :: Maybe Object
name :: Maybe Text
target :: Maybe BufferViewTarget
byteStride :: Maybe Int
byteLength :: Int
byteOffset :: Int
buffer :: BufferIx
$sel:extras:BufferView :: Maybe Value
$sel:extensions:BufferView :: Maybe Object
$sel:name:BufferView :: Maybe Text
$sel:target:BufferView :: Maybe BufferViewTarget
$sel:byteStride:BufferView :: Maybe Int
$sel:byteLength:BufferView :: Int
$sel:byteOffset:BufferView :: Int
$sel:buffer:BufferView :: BufferIx
..}

instance ToJSON BufferView

newtype BufferViewTarget = BufferViewTarget { BufferViewTarget -> Int
unBufferViewTarget :: Int }
  deriving (BufferViewTarget -> BufferViewTarget -> Bool
(BufferViewTarget -> BufferViewTarget -> Bool)
-> (BufferViewTarget -> BufferViewTarget -> Bool)
-> Eq BufferViewTarget
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BufferViewTarget -> BufferViewTarget -> Bool
$c/= :: BufferViewTarget -> BufferViewTarget -> Bool
== :: BufferViewTarget -> BufferViewTarget -> Bool
$c== :: BufferViewTarget -> BufferViewTarget -> Bool
Eq, Eq BufferViewTarget
Eq BufferViewTarget
-> (BufferViewTarget -> BufferViewTarget -> Ordering)
-> (BufferViewTarget -> BufferViewTarget -> Bool)
-> (BufferViewTarget -> BufferViewTarget -> Bool)
-> (BufferViewTarget -> BufferViewTarget -> Bool)
-> (BufferViewTarget -> BufferViewTarget -> Bool)
-> (BufferViewTarget -> BufferViewTarget -> BufferViewTarget)
-> (BufferViewTarget -> BufferViewTarget -> BufferViewTarget)
-> Ord BufferViewTarget
BufferViewTarget -> BufferViewTarget -> Bool
BufferViewTarget -> BufferViewTarget -> Ordering
BufferViewTarget -> BufferViewTarget -> BufferViewTarget
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 :: BufferViewTarget -> BufferViewTarget -> BufferViewTarget
$cmin :: BufferViewTarget -> BufferViewTarget -> BufferViewTarget
max :: BufferViewTarget -> BufferViewTarget -> BufferViewTarget
$cmax :: BufferViewTarget -> BufferViewTarget -> BufferViewTarget
>= :: BufferViewTarget -> BufferViewTarget -> Bool
$c>= :: BufferViewTarget -> BufferViewTarget -> Bool
> :: BufferViewTarget -> BufferViewTarget -> Bool
$c> :: BufferViewTarget -> BufferViewTarget -> Bool
<= :: BufferViewTarget -> BufferViewTarget -> Bool
$c<= :: BufferViewTarget -> BufferViewTarget -> Bool
< :: BufferViewTarget -> BufferViewTarget -> Bool
$c< :: BufferViewTarget -> BufferViewTarget -> Bool
compare :: BufferViewTarget -> BufferViewTarget -> Ordering
$ccompare :: BufferViewTarget -> BufferViewTarget -> Ordering
$cp1Ord :: Eq BufferViewTarget
Ord, Int -> BufferViewTarget -> ShowS
[BufferViewTarget] -> ShowS
BufferViewTarget -> String
(Int -> BufferViewTarget -> ShowS)
-> (BufferViewTarget -> String)
-> ([BufferViewTarget] -> ShowS)
-> Show BufferViewTarget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BufferViewTarget] -> ShowS
$cshowList :: [BufferViewTarget] -> ShowS
show :: BufferViewTarget -> String
$cshow :: BufferViewTarget -> String
showsPrec :: Int -> BufferViewTarget -> ShowS
$cshowsPrec :: Int -> BufferViewTarget -> ShowS
Show, Value -> Parser [BufferViewTarget]
Value -> Parser BufferViewTarget
(Value -> Parser BufferViewTarget)
-> (Value -> Parser [BufferViewTarget])
-> FromJSON BufferViewTarget
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [BufferViewTarget]
$cparseJSONList :: Value -> Parser [BufferViewTarget]
parseJSON :: Value -> Parser BufferViewTarget
$cparseJSON :: Value -> Parser BufferViewTarget
FromJSON, [BufferViewTarget] -> Encoding
[BufferViewTarget] -> Value
BufferViewTarget -> Encoding
BufferViewTarget -> Value
(BufferViewTarget -> Value)
-> (BufferViewTarget -> Encoding)
-> ([BufferViewTarget] -> Value)
-> ([BufferViewTarget] -> Encoding)
-> ToJSON BufferViewTarget
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [BufferViewTarget] -> Encoding
$ctoEncodingList :: [BufferViewTarget] -> Encoding
toJSONList :: [BufferViewTarget] -> Value
$ctoJSONList :: [BufferViewTarget] -> Value
toEncoding :: BufferViewTarget -> Encoding
$ctoEncoding :: BufferViewTarget -> Encoding
toJSON :: BufferViewTarget -> Value
$ctoJSON :: BufferViewTarget -> Value
ToJSON, (forall x. BufferViewTarget -> Rep BufferViewTarget x)
-> (forall x. Rep BufferViewTarget x -> BufferViewTarget)
-> Generic BufferViewTarget
forall x. Rep BufferViewTarget x -> BufferViewTarget
forall x. BufferViewTarget -> Rep BufferViewTarget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BufferViewTarget x -> BufferViewTarget
$cfrom :: forall x. BufferViewTarget -> Rep BufferViewTarget x
Generic)

pattern ARRAY_BUFFER :: BufferViewTarget
pattern $bARRAY_BUFFER :: BufferViewTarget
$mARRAY_BUFFER :: forall r. BufferViewTarget -> (Void# -> r) -> (Void# -> r) -> r
ARRAY_BUFFER = BufferViewTarget 34962

pattern ELEMENT_ARRAY_BUFFER :: BufferViewTarget
pattern $bELEMENT_ARRAY_BUFFER :: BufferViewTarget
$mELEMENT_ARRAY_BUFFER :: forall r. BufferViewTarget -> (Void# -> r) -> (Void# -> r) -> r
ELEMENT_ARRAY_BUFFER = BufferViewTarget 34963