Files
loop/src/Picture/Data.hs
T
2022-08-21 12:21:05 +01:00

101 lines
2.0 KiB
Haskell

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
module Picture.Data where
import TH.Derive
import Data.Store
import Data.Binary
import Flat
import LinearHelp ()
import Control.Lens
import Data.Aeson
import Data.Aeson.TH
import Geometry.Data
import Streaming
data Verx = Verx
{ _vxPos :: !Point3
, _vxCol :: !Point4
, _vxExt :: [Float]
, _vxLayer :: !Layer
, _vxShadNum :: !ShadNum
}
deriving (Eq, Ord, Show, Read, Generic, Flat)
data Layer
= BottomLayer
| MidLayer
| BloomLayer
| BloomNoZWrite
| DebugLayer
| FixedCoordLayer
deriving (Eq, Ord, Enum, Bounded, Show, Read, Generic, Flat)
layerNum :: Layer -> Int
layerNum = fromEnum
numLayers :: Int
numLayers = length [minBound :: Layer .. maxBound]
newtype ShadNum = ShadNum {_unShadNum :: Int}
deriving (Eq, Ord, Show, Read, Generic, Flat)
$($(derive [d| instance Deriving (Store ShadNum) |]))
polyNum, polyzNum, bezNum, textNum, arcNum, ellNum :: ShadNum
{-# INLINE polyNum #-}
{-# INLINE polyzNum #-}
{-# INLINE bezNum #-}
{-# INLINE textNum #-}
{-# INLINE arcNum #-}
{-# INLINE ellNum #-}
polyNum = ShadNum 0
polyzNum = ShadNum 1
bezNum = ShadNum 2
textNum = ShadNum 3
arcNum = ShadNum 4
ellNum = ShadNum 5
type Picture' = Stream (Of Verx) IO ()
type Picture = [Verx]
flatV2 :: V2 a -> [a]
flatV2 (V2 x y) = [x, y]
flatV3 :: V3 a -> [a]
flatV3 (V3 x y z) = [x, y, z]
flatV4 :: V4 a -> [a]
flatV4 (V4 x y z w) = [x, y, z, w]
{-# INLINE flatV2 #-}
{-# INLINE flatV3 #-}
{-# INLINE flatV4 #-}
tflat2 :: (a, a) -> [a]
tflat2 (x, y) = [x, y]
tflat3 :: (a, a, a) -> [a]
tflat3 (x, y, z) = [x, y, z]
tflat4 :: (a, a, a, a) -> [a]
tflat4 (x, y, z, w) = [x, y, z, w]
{-# INLINE tflat2 #-}
{-# INLINE tflat3 #-}
{-# INLINE tflat4 #-}
makeLenses ''Verx
deriveJSON defaultOptions ''Verx
deriveJSON defaultOptions ''Layer
deriveJSON defaultOptions ''ShadNum
$($(derive [d| instance Deriving (Store Verx ) |]))
$($(derive [d| instance Deriving (Store Layer) |]))