summaryrefslogtreecommitdiff
path: root/ddl/out/LambdaCube.PipelineSchema.hs
blob: a573d27c10db42c31b251f6f53a4c7d858e7c6c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
-- generated file, do not modify!
-- 2016-02-12T16:05:13.310528000000Z

{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module LambdaCube.PipelineSchema where

import Data.Int
import Data.Word
import Data.Map
import Data.Vector (Vector(..))
import LambdaCube.Linear

import Data.Text
import Data.Aeson hiding (Value,Bool)
import Data.Aeson.Types hiding (Value,Bool)
import Control.Monad

import LambdaCube.IR

data StreamType
  = Attribute_Word
  | Attribute_V2U
  | Attribute_V3U
  | Attribute_V4U
  | Attribute_Int
  | Attribute_V2I
  | Attribute_V3I
  | Attribute_V4I
  | Attribute_Float
  | Attribute_V2F
  | Attribute_V3F
  | Attribute_V4F
  | Attribute_M22F
  | Attribute_M23F
  | Attribute_M24F
  | Attribute_M32F
  | Attribute_M33F
  | Attribute_M34F
  | Attribute_M42F
  | Attribute_M43F
  | Attribute_M44F
  deriving (Show, Eq, Ord)

data ObjectArraySchema
  = ObjectArraySchema
  { primitive :: FetchPrimitive
  , attributes :: Map String StreamType
  }

  deriving (Show, Eq, Ord)

data PipelineSchema
  = PipelineSchema
  { objectArrays :: Map String ObjectArraySchema
  , uniforms :: Map String InputType
  }

  deriving (Show, Eq, Ord)


instance ToJSON StreamType where
  toJSON v = case v of
    Attribute_Word -> object [ "tag" .= ("Attribute_Word" :: Text)]
    Attribute_V2U -> object [ "tag" .= ("Attribute_V2U" :: Text)]
    Attribute_V3U -> object [ "tag" .= ("Attribute_V3U" :: Text)]
    Attribute_V4U -> object [ "tag" .= ("Attribute_V4U" :: Text)]
    Attribute_Int -> object [ "tag" .= ("Attribute_Int" :: Text)]
    Attribute_V2I -> object [ "tag" .= ("Attribute_V2I" :: Text)]
    Attribute_V3I -> object [ "tag" .= ("Attribute_V3I" :: Text)]
    Attribute_V4I -> object [ "tag" .= ("Attribute_V4I" :: Text)]
    Attribute_Float -> object [ "tag" .= ("Attribute_Float" :: Text)]
    Attribute_V2F -> object [ "tag" .= ("Attribute_V2F" :: Text)]
    Attribute_V3F -> object [ "tag" .= ("Attribute_V3F" :: Text)]
    Attribute_V4F -> object [ "tag" .= ("Attribute_V4F" :: Text)]
    Attribute_M22F -> object [ "tag" .= ("Attribute_M22F" :: Text)]
    Attribute_M23F -> object [ "tag" .= ("Attribute_M23F" :: Text)]
    Attribute_M24F -> object [ "tag" .= ("Attribute_M24F" :: Text)]
    Attribute_M32F -> object [ "tag" .= ("Attribute_M32F" :: Text)]
    Attribute_M33F -> object [ "tag" .= ("Attribute_M33F" :: Text)]
    Attribute_M34F -> object [ "tag" .= ("Attribute_M34F" :: Text)]
    Attribute_M42F -> object [ "tag" .= ("Attribute_M42F" :: Text)]
    Attribute_M43F -> object [ "tag" .= ("Attribute_M43F" :: Text)]
    Attribute_M44F -> object [ "tag" .= ("Attribute_M44F" :: Text)]

instance FromJSON StreamType where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "Attribute_Word" -> pure Attribute_Word
      "Attribute_V2U" -> pure Attribute_V2U
      "Attribute_V3U" -> pure Attribute_V3U
      "Attribute_V4U" -> pure Attribute_V4U
      "Attribute_Int" -> pure Attribute_Int
      "Attribute_V2I" -> pure Attribute_V2I
      "Attribute_V3I" -> pure Attribute_V3I
      "Attribute_V4I" -> pure Attribute_V4I
      "Attribute_Float" -> pure Attribute_Float
      "Attribute_V2F" -> pure Attribute_V2F
      "Attribute_V3F" -> pure Attribute_V3F
      "Attribute_V4F" -> pure Attribute_V4F
      "Attribute_M22F" -> pure Attribute_M22F
      "Attribute_M23F" -> pure Attribute_M23F
      "Attribute_M24F" -> pure Attribute_M24F
      "Attribute_M32F" -> pure Attribute_M32F
      "Attribute_M33F" -> pure Attribute_M33F
      "Attribute_M34F" -> pure Attribute_M34F
      "Attribute_M42F" -> pure Attribute_M42F
      "Attribute_M43F" -> pure Attribute_M43F
      "Attribute_M44F" -> pure Attribute_M44F
  parseJSON _ = mzero

instance ToJSON ObjectArraySchema where
  toJSON v = case v of
    ObjectArraySchema{..} -> object
      [ "tag" .= ("ObjectArraySchema" :: Text)
      , "primitive" .= primitive
      , "attributes" .= attributes
      ]

instance FromJSON ObjectArraySchema where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "ObjectArraySchema" -> do
        primitive <- obj .: "primitive"
        attributes <- obj .: "attributes"
        pure $ ObjectArraySchema
          { primitive = primitive
          , attributes = attributes
          } 
  parseJSON _ = mzero

instance ToJSON PipelineSchema where
  toJSON v = case v of
    PipelineSchema{..} -> object
      [ "tag" .= ("PipelineSchema" :: Text)
      , "objectArrays" .= objectArrays
      , "uniforms" .= uniforms
      ]

instance FromJSON PipelineSchema where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "PipelineSchema" -> do
        objectArrays <- obj .: "objectArrays"
        uniforms <- obj .: "uniforms"
        pure $ PipelineSchema
          { objectArrays = objectArrays
          , uniforms = uniforms
          } 
  parseJSON _ = mzero