summaryrefslogtreecommitdiff
path: root/testclient/TestData.hs
blob: d6d8e3817a571573ec691256aa24d2ca54733dc8 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
-- generated file, do not modify!
-- 2016-02-12T16:05:13.383716000000Z

{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
module TestData 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
import LambdaCube.Mesh
import LambdaCube.PipelineSchema

data ClientInfo
  = ClientInfo
  { clientName :: String
  , clientBackend :: Backend
  }

  deriving (Show, Eq, Ord)

data Frame
  = Frame
  { renderCount :: Int
  , frameUniforms :: Map String Value
  , frameTextures :: Map String Int
  }

  deriving (Show, Eq, Ord)

data Scene
  = Scene
  { objectArrays :: Map String (Vector Int)
  , renderTargetWidth :: Int
  , renderTargetHeight :: Int
  , frames :: Vector Frame
  }

  deriving (Show, Eq, Ord)

data PipelineInfo
  = PipelineInfo
  { pipelineName :: String
  , pipeline :: Pipeline
  }

  deriving (Show, Eq, Ord)

data RenderJob
  = RenderJob
  { meshes :: Vector Mesh
  , textures :: Vector String
  , schema :: PipelineSchema
  , scenes :: Vector Scene
  , pipelines :: Vector PipelineInfo
  }

  deriving (Show, Eq, Ord)

data FrameResult
  = FrameResult
  { frRenderTimes :: Vector Float
  , frImageWidth :: Int
  , frImageHeight :: Int
  }

  deriving (Show, Eq, Ord)

data RenderJobResult
  = RenderJobResult FrameResult
  | RenderJobError String
  deriving (Show, Eq, Ord)


instance ToJSON ClientInfo where
  toJSON v = case v of
    ClientInfo{..} -> object
      [ "tag" .= ("ClientInfo" :: Text)
      , "clientName" .= clientName
      , "clientBackend" .= clientBackend
      ]

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

instance ToJSON Frame where
  toJSON v = case v of
    Frame{..} -> object
      [ "tag" .= ("Frame" :: Text)
      , "renderCount" .= renderCount
      , "frameUniforms" .= frameUniforms
      , "frameTextures" .= frameTextures
      ]

instance FromJSON Frame where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "Frame" -> do
        renderCount <- obj .: "renderCount"
        frameUniforms <- obj .: "frameUniforms"
        frameTextures <- obj .: "frameTextures"
        pure $ Frame
          { renderCount = renderCount
          , frameUniforms = frameUniforms
          , frameTextures = frameTextures
          } 
  parseJSON _ = mzero

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

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

instance ToJSON PipelineInfo where
  toJSON v = case v of
    PipelineInfo{..} -> object
      [ "tag" .= ("PipelineInfo" :: Text)
      , "pipelineName" .= pipelineName
      , "pipeline" .= pipeline
      ]

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

instance ToJSON RenderJob where
  toJSON v = case v of
    RenderJob{..} -> object
      [ "tag" .= ("RenderJob" :: Text)
      , "meshes" .= meshes
      , "textures" .= textures
      , "schema" .= schema
      , "scenes" .= scenes
      , "pipelines" .= pipelines
      ]

instance FromJSON RenderJob where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "RenderJob" -> do
        meshes <- obj .: "meshes"
        textures <- obj .: "textures"
        schema <- obj .: "schema"
        scenes <- obj .: "scenes"
        pipelines <- obj .: "pipelines"
        pure $ RenderJob
          { meshes = meshes
          , textures = textures
          , schema = schema
          , scenes = scenes
          , pipelines = pipelines
          } 
  parseJSON _ = mzero

instance ToJSON FrameResult where
  toJSON v = case v of
    FrameResult{..} -> object
      [ "tag" .= ("FrameResult" :: Text)
      , "frRenderTimes" .= frRenderTimes
      , "frImageWidth" .= frImageWidth
      , "frImageHeight" .= frImageHeight
      ]

instance FromJSON FrameResult where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "FrameResult" -> do
        frRenderTimes <- obj .: "frRenderTimes"
        frImageWidth <- obj .: "frImageWidth"
        frImageHeight <- obj .: "frImageHeight"
        pure $ FrameResult
          { frRenderTimes = frRenderTimes
          , frImageWidth = frImageWidth
          , frImageHeight = frImageHeight
          } 
  parseJSON _ = mzero

instance ToJSON RenderJobResult where
  toJSON v = case v of
    RenderJobResult arg0 -> object [ "tag" .= ("RenderJobResult" :: Text), "arg0" .= arg0]
    RenderJobError arg0 -> object [ "tag" .= ("RenderJobError" :: Text), "arg0" .= arg0]

instance FromJSON RenderJobResult where
  parseJSON (Object obj) = do
    tag <- obj .: "tag"
    case tag :: Text of
      "RenderJobResult" -> RenderJobResult <$> obj .: "arg0"
      "RenderJobError" -> RenderJobError <$> obj .: "arg0"
  parseJSON _ = mzero