summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/LambdaCube/GL/Backend.hs4
-rw-r--r--src/LambdaCube/GL/Util.hs22
-rw-r--r--testclient/TestData.hs33
-rw-r--r--testclient/client.hs10
4 files changed, 54 insertions, 15 deletions
diff --git a/src/LambdaCube/GL/Backend.hs b/src/LambdaCube/GL/Backend.hs
index 40abc6d..1d910a2 100644
--- a/src/LambdaCube/GL/Backend.hs
+++ b/src/LambdaCube/GL/Backend.hs
@@ -217,11 +217,11 @@ compileProgram p = do
217 --putStr " + setup shader output mapping: " >> printGLStatus 217 --putStr " + setup shader output mapping: " >> printGLStatus
218 218
219 glLinkProgram po 219 glLinkProgram po
220 printProgramLog po 220 log <- printProgramLog po
221 221
222 -- check link status 222 -- check link status
223 status <- glGetProgramiv1 GL_LINK_STATUS po 223 status <- glGetProgramiv1 GL_LINK_STATUS po
224 when (status /= fromIntegral GL_TRUE) $ fail "link program failed!" 224 when (status /= fromIntegral GL_TRUE) $ fail $ unlines ["link program failed:",log]
225 225
226 -- check program input 226 -- check program input
227 (uniforms,uniformsType) <- queryUniforms po 227 (uniforms,uniformsType) <- queryUniforms po
diff --git a/src/LambdaCube/GL/Util.hs b/src/LambdaCube/GL/Util.hs
index ab8350f..bbc4345 100644
--- a/src/LambdaCube/GL/Util.hs
+++ b/src/LambdaCube/GL/Util.hs
@@ -262,15 +262,18 @@ fromGLType (t,1)
262 | otherwise = error "Failed fromGLType" 262 | otherwise = error "Failed fromGLType"
263fromGLUniformType _ = error "Failed fromGLType" 263fromGLUniformType _ = error "Failed fromGLType"
264 264
265printShaderLog :: GLuint -> IO () 265printShaderLog :: GLuint -> IO String
266printShaderLog o = do 266printShaderLog o = do
267 i <- glGetShaderiv1 GL_INFO_LOG_LENGTH o 267 i <- glGetShaderiv1 GL_INFO_LOG_LENGTH o
268 when (i > 0) $ 268 case (i > 0) of
269 False -> return ""
270 True -> do
269 alloca $ \sizePtr -> allocaArray (fromIntegral i) $! \ps -> do 271 alloca $ \sizePtr -> allocaArray (fromIntegral i) $! \ps -> do
270 glGetShaderInfoLog o (fromIntegral i) sizePtr ps 272 glGetShaderInfoLog o (fromIntegral i) sizePtr ps
271 size <- peek sizePtr 273 size <- peek sizePtr
272 log <- peekCStringLen (castPtr ps, fromIntegral size) 274 log <- peekCStringLen (castPtr ps, fromIntegral size)
273 putStrLn log 275 putStrLn log
276 return log
274 277
275glGetShaderiv1 :: GLenum -> GLuint -> IO GLint 278glGetShaderiv1 :: GLenum -> GLuint -> IO GLint
276glGetShaderiv1 pname o = alloca $! \pi -> glGetShaderiv o pname pi >> peek pi 279glGetShaderiv1 pname o = alloca $! \pi -> glGetShaderiv o pname pi >> peek pi
@@ -278,23 +281,26 @@ glGetShaderiv1 pname o = alloca $! \pi -> glGetShaderiv o pname pi >> peek pi
278glGetProgramiv1 :: GLenum -> GLuint -> IO GLint 281glGetProgramiv1 :: GLenum -> GLuint -> IO GLint
279glGetProgramiv1 pname o = alloca $! \pi -> glGetProgramiv o pname pi >> peek pi 282glGetProgramiv1 pname o = alloca $! \pi -> glGetProgramiv o pname pi >> peek pi
280 283
281printProgramLog :: GLuint -> IO () 284printProgramLog :: GLuint -> IO String
282printProgramLog o = do 285printProgramLog o = do
283 i <- glGetProgramiv1 GL_INFO_LOG_LENGTH o 286 i <- glGetProgramiv1 GL_INFO_LOG_LENGTH o
284 when (i > 0) $ 287 case (i > 0) of
288 False -> return ""
289 True -> do
285 alloca $ \sizePtr -> allocaArray (fromIntegral i) $! \ps -> do 290 alloca $ \sizePtr -> allocaArray (fromIntegral i) $! \ps -> do
286 glGetProgramInfoLog o (fromIntegral i) sizePtr ps 291 glGetProgramInfoLog o (fromIntegral i) sizePtr ps
287 size <- peek sizePtr 292 size <- peek sizePtr
288 log <- peekCStringLen (castPtr ps, fromIntegral size) 293 log <- peekCStringLen (castPtr ps, fromIntegral size)
289 unless (null log) $ putStrLn log 294 unless (null log) $ putStrLn log
295 return log
290 296
291compileShader :: GLuint -> [String] -> IO () 297compileShader :: GLuint -> [String] -> IO ()
292compileShader o srcl = withMany withCString srcl $! \l -> withArray l $! \p -> do 298compileShader o srcl = withMany withCString srcl $! \l -> withArray l $! \p -> do
293 glShaderSource o (fromIntegral $! length srcl) (castPtr p) nullPtr 299 glShaderSource o (fromIntegral $! length srcl) (castPtr p) nullPtr
294 glCompileShader o 300 glCompileShader o
295 printShaderLog o 301 log <- printShaderLog o
296 status <- glGetShaderiv1 GL_COMPILE_STATUS o 302 status <- glGetShaderiv1 GL_COMPILE_STATUS o
297 when (status /= fromIntegral GL_TRUE) $ fail "compileShader failed!" 303 when (status /= fromIntegral GL_TRUE) $ fail $ unlines ["compileShader failed:",log]
298 304
299checkGL :: IO String 305checkGL :: IO String
300checkGL = do 306checkGL = do
diff --git a/testclient/TestData.hs b/testclient/TestData.hs
index a48dc42..d6d8e38 100644
--- a/testclient/TestData.hs
+++ b/testclient/TestData.hs
@@ -1,5 +1,5 @@
1-- generated file, do not modify! 1-- generated file, do not modify!
2-- 2016-01-28T13:15:31.27456Z 2-- 2016-02-12T16:05:13.383716000000Z
3 3
4{-# LANGUAGE OverloadedStrings, RecordWildCards #-} 4{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
5module TestData where 5module TestData where
@@ -46,13 +46,21 @@ data Scene
46 46
47 deriving (Show, Eq, Ord) 47 deriving (Show, Eq, Ord)
48 48
49data PipelineInfo
50 = PipelineInfo
51 { pipelineName :: String
52 , pipeline :: Pipeline
53 }
54
55 deriving (Show, Eq, Ord)
56
49data RenderJob 57data RenderJob
50 = RenderJob 58 = RenderJob
51 { meshes :: Vector Mesh 59 { meshes :: Vector Mesh
52 , textures :: Vector String 60 , textures :: Vector String
53 , schema :: PipelineSchema 61 , schema :: PipelineSchema
54 , scenes :: Vector Scene 62 , scenes :: Vector Scene
55 , pipelines :: Vector Pipeline 63 , pipelines :: Vector PipelineInfo
56 } 64 }
57 65
58 deriving (Show, Eq, Ord) 66 deriving (Show, Eq, Ord)
@@ -144,6 +152,27 @@ instance FromJSON Scene where
144 } 152 }
145 parseJSON _ = mzero 153 parseJSON _ = mzero
146 154
155instance ToJSON PipelineInfo where
156 toJSON v = case v of
157 PipelineInfo{..} -> object
158 [ "tag" .= ("PipelineInfo" :: Text)
159 , "pipelineName" .= pipelineName
160 , "pipeline" .= pipeline
161 ]
162
163instance FromJSON PipelineInfo where
164 parseJSON (Object obj) = do
165 tag <- obj .: "tag"
166 case tag :: Text of
167 "PipelineInfo" -> do
168 pipelineName <- obj .: "pipelineName"
169 pipeline <- obj .: "pipeline"
170 pure $ PipelineInfo
171 { pipelineName = pipelineName
172 , pipeline = pipeline
173 }
174 parseJSON _ = mzero
175
147instance ToJSON RenderJob where 176instance ToJSON RenderJob where
148 toJSON v = case v of 177 toJSON v = case v of
149 RenderJob{..} -> object 178 RenderJob{..} -> object
diff --git a/testclient/client.hs b/testclient/client.hs
index 236320c..62c197f 100644
--- a/testclient/client.hs
+++ b/testclient/client.hs
@@ -44,7 +44,10 @@ main = do
44 GLFW.pollEvents 44 GLFW.pollEvents
45 threadDelay 100000 45 threadDelay 100000
46 46
47setupConnection win = withSocketsDo $ WS.runClient "192.168.0.12" 9160 "/" $ \conn -> do 47setupConnection win = withSocketsDo $ WS.runClient "192.168.0.12" 9160 "/" $ \conn -> catchAll (execConnection win conn) $ \e -> do
48 WS.sendTextData conn . encode $ RenderJobError $ displayException e
49
50execConnection win conn = do
48 putStrLn "Connected!" 51 putStrLn "Connected!"
49 -- register backend 52 -- register backend
50 WS.sendTextData conn . encode $ ClientInfo 53 WS.sendTextData conn . encode $ ClientInfo
@@ -75,8 +78,9 @@ processRenderJob win conn renderJob@RenderJob{..} = do
75 putStrLn "got render job" 78 putStrLn "got render job"
76 gpuData@GPUData{..} <- allocateGPUData renderJob 79 gpuData@GPUData{..} <- allocateGPUData renderJob
77 -- foreach pipeline 80 -- foreach pipeline
78 doAfter (disposeGPUData gpuData) $ forM_ pipelines $ \pipelineDesc -> do 81 doAfter (disposeGPUData gpuData) $ forM_ pipelines $ \PipelineInfo{..} -> do
79 renderer <- allocRenderer pipelineDesc 82 putStrLn $ "use pipeline: " ++ pipelineName
83 renderer <- allocRenderer pipeline
80 -- foreach scene 84 -- foreach scene
81 doAfter (disposeRenderer renderer) $ forM_ scenes $ \Scene{..} -> do 85 doAfter (disposeRenderer renderer) $ forM_ scenes $ \Scene{..} -> do
82 storage <- allocStorage schema 86 storage <- allocStorage schema