summaryrefslogtreecommitdiff
path: root/lc
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-02-05 22:04:46 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-02-05 22:13:59 +0100
commit45f6f1c72feffb4e80430395511788ccf576f29e (patch)
tree7d3a35fb3d980004232fd3a3226cca30b3b2f35d /lc
parentbf1e53a0fe348bd41f07ea21802b9bb77b3ecb18 (diff)
refactor Builtins.lc
Diffstat (limited to 'lc')
-rw-r--r--lc/Builtins.lc82
1 files changed, 39 insertions, 43 deletions
diff --git a/lc/Builtins.lc b/lc/Builtins.lc
index 271b636e..77027a39 100644
--- a/lc/Builtins.lc
+++ b/lc/Builtins.lc
@@ -14,8 +14,6 @@ class AttributeTuple a
14instance AttributeTuple a -- TODO 14instance AttributeTuple a -- TODO
15class ValidOutput a 15class ValidOutput a
16instance ValidOutput a -- TODO 16instance ValidOutput a -- TODO
17class ValidFrameBuffer a
18instance ValidFrameBuffer a -- TODO
19 17
20data VecS (a :: Type) :: Nat -> Type where 18data VecS (a :: Type) :: Nat -> Type where
21 V2 :: a -> a -> VecS a 2 19 V2 :: a -> a -> VecS a 2
@@ -237,10 +235,7 @@ data PointSpriteCoordOrigin
237 = LowerLeft 235 = LowerLeft
238 | UpperLeft 236 | UpperLeft
239 237
240 238data ImageSemantics = Depth Type | Stencil Type | Color Type
241data Depth a where
242data Stencil a where
243data Color a where
244 239
245data PrimitiveType 240data PrimitiveType
246 = Triangle 241 = Triangle
@@ -282,25 +277,18 @@ data StencilTests
282data StencilOps 277data StencilOps
283data Int32 278data Int32
284 279
285data FragmentOperation :: Type -> Type where 280data FragmentOperation :: ImageSemantics -> Type where
286 ColorOp :: (mask ~ VecScalar d Bool, color ~ VecScalar d c, Num c) => Blending c -> mask 281 ColorOp :: (mask ~ VecScalar d Bool, color ~ VecScalar d c, Num c) => Blending c -> mask
287 -> FragmentOperation (Color color) 282 -> FragmentOperation (Color color)
288 DepthOp :: ComparisonFunction -> Bool -> FragmentOperation (Depth Float) 283 DepthOp :: ComparisonFunction -> Bool -> FragmentOperation (Depth Float)
289 StencilOp :: StencilTests -> StencilOps -> StencilOps -> FragmentOperation (Stencil Int32) 284 StencilOp :: StencilTests -> StencilOps -> StencilOps -> FragmentOperation (Stencil Int32)
290{- 285
291type family FragOps a where 286type family FragOps (a :: [ImageSemantics]) where
292 FragOps (FragmentOperation t) = t 287 FragOps '[t] = (FragmentOperation t)
293 FragOps (FragmentOperation t1, FragmentOperation t2) = (t1, t2) 288 FragOps '[t1, t2] = (FragmentOperation t1, FragmentOperation t2)
294 FragOps (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3) = (t1, t2, t3) 289 FragOps '[t1, t2, t3] = (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3)
295 FragOps (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3, FragmentOperation t4) = (t1, t2, t3, t4) 290 FragOps '[t1, t2, t3, t4] = (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3, FragmentOperation t4)
296 FragOps (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3, FragmentOperation t4, FragmentOperation t5) = (t1, t2, t3, t4, t5) 291 FragOps '[t1, t2, t3, t4, t5] = (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3, FragmentOperation t4, FragmentOperation t5)
297-}
298type family FragOps a where
299 FragOps (t1, t2) = (FragmentOperation t1, FragmentOperation t2)
300 FragOps (t1, t2, t3) = (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3)
301 FragOps (t1, t2, t3, t4) = (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3, FragmentOperation t4)
302 FragOps (t1, t2, t3, t4, t5) = (FragmentOperation t1, FragmentOperation t2, FragmentOperation t3, FragmentOperation t4, FragmentOperation t5)
303 FragOps t = (FragmentOperation t)
304 292
305[] ++ ys = ys 293[] ++ ys = ys
306x:xs ++ ys = x : xs ++ ys 294x:xs ++ ys = x : xs ++ ys
@@ -339,18 +327,22 @@ mapPrimitives f = map (mapPrimitive f)
339fetch s a t = fetch_ @a s t 327fetch s a t = fetch_ @a s t
340fetchArrays a t = fetchArrays_ @a t 328fetchArrays a t = fetchArrays_ @a t
341 329
342type family RemSemantics a where 330remSemantics :: ImageSemantics -> Type
343 RemSemantics () = () 331remSemantics (Color a) = a
344 RemSemantics (Color a) = a 332remSemantics (Depth a) = a
345 RemSemantics (Color a, Color b) = (a, b) 333remSemantics (Stencil a) = a
346 RemSemantics (Color a, Color b, Color c) = (a, b, c) 334
347 RemSemantics (Color a, Color b, Color c, Color d) = (a, b, c, d) 335remSemantics_ :: [ImageSemantics] -> Type
348 RemSemantics (Color a, Color b, Color c, Color d, Color e) = (a, b, c, d, e) 336remSemantics_ [] = '()
349 RemSemantics (Depth Float) = () 337remSemantics_ [a] = remSemantics a
350 RemSemantics (Depth Float, Color a) = a 338remSemantics_ [a, b] = '(remSemantics a, remSemantics b)
351 RemSemantics (Depth Float, Color a, Color b) = (a, b) 339remSemantics_ [a, b, c] = '(remSemantics a, remSemantics b, remSemantics c)
352 RemSemantics (Depth Float, Color a, Color b, Color c) = (a, b, c) 340remSemantics_ [a, b, c, d] = '(remSemantics a, remSemantics b, remSemantics c, remSemantics d)
353 RemSemantics (Depth Float, Color a, Color b, Color c, Color d) = (a, b, c, d) 341remSemantics_ [a, b, c, d, e] = '(remSemantics a, remSemantics b, remSemantics c, remSemantics d, remSemantics e)
342
343remSemantics' :: [ImageSemantics] -> Type
344remSemantics' (Depth _: x) = remSemantics_ x
345remSemantics' x = remSemantics_ x
354 346
355------------------- 347-------------------
356 348
@@ -407,7 +399,7 @@ rasterizePrimitive
407 399
408rasterizePrimitives ctx is s = concat (map (rasterizePrimitive is ctx) s) 400rasterizePrimitives ctx is s = concat (map (rasterizePrimitive is ctx) s)
409 401
410data Image :: Nat -> Type -> Type 402data Image (n :: Nat) (t :: ImageSemantics) -- = Vector n [[t]]
411 403
412ColorImage :: forall a d t color . (Num t, color ~ VecScalar d t) 404ColorImage :: forall a d t color . (Num t, color ~ VecScalar d t)
413 => color -> Image a (Color color) 405 => color -> Image a (Color color)
@@ -418,23 +410,27 @@ type family SameLayerCounts a where
418 SameLayerCounts (Image n1 t1) = Unit 410 SameLayerCounts (Image n1 t1) = Unit
419 SameLayerCounts (Image n1 t1, Image n2 t2) = EqCT Nat n1 n2 411 SameLayerCounts (Image n1 t1, Image n2 t2) = EqCT Nat n1 n2
420 SameLayerCounts (Image n1 t1, Image n2 t2, Image n3 t3) = T2 (EqCT Nat n1 n2) (EqCT Nat n1 n3) 412 SameLayerCounts (Image n1 t1, Image n2 t2, Image n3 t3) = T2 (EqCT Nat n1 n2) (EqCT Nat n1 n3)
421 413{-
422class DefaultFragOp a where defaultFragOp :: FragmentOperation a 414class DefaultFragOp a where defaultFragOp :: FragmentOperation a
423instance DefaultFragOp (Color (VecS Float 4)) where defaultFragOp = ColorOp NoBlending (V4 True True True True) 415instance DefaultFragOp (Color (VecS Float 4)) where defaultFragOp = ColorOp NoBlending (V4 True True True True)
424instance DefaultFragOp (Depth Float) where defaultFragOp = DepthOp Less True 416instance DefaultFragOp (Depth Float) where defaultFragOp = DepthOp Less True
425{- 417
426class DefaultFragOps a where defaultFragOps :: a 418class DefaultFragOps a where defaultFragOps :: a
427instance (DefaultFragOp a, DefaultFragOp b) => DefaultFragOps (FragmentOperation a, FragmentOperation b) where 419instance (DefaultFragOp a, DefaultFragOp b) => DefaultFragOps (FragmentOperation a, FragmentOperation b) where
428 defaultFragOps = -- (undefined @(), undefined) 420 defaultFragOps = -- (undefined @(), undefined)
429 (defaultFragOp @a @_, defaultFragOp @b @_) 421 (defaultFragOp @a @_, defaultFragOp @b @_)
430-} 422-}
431data FrameBuffer (n :: Nat) t 423data FrameBuffer (n :: Nat) (t :: [ImageSemantics])
432Accumulate :: FragOps b -> FragmentStream n (RemSemantics b) -> FrameBuffer n b -> FrameBuffer n b 424
425Accumulate :: FragOps b -> FragmentStream n (remSemantics' b) -> FrameBuffer n b -> FrameBuffer n b
433 426
434type family TFFrameBuffer a where 427type family TFFrameBuffer a where
435 TFFrameBuffer (Image n1 t1) = FrameBuffer n1 t1 428 TFFrameBuffer (Image n1 t1) = FrameBuffer n1 '[t1]
436 TFFrameBuffer (Image n1 t1, Image n2 t2) = FrameBuffer n1 (t1, t2) 429 TFFrameBuffer (Image n1 t1, Image n2 t2) = FrameBuffer n1 '[t1, t2]
437 TFFrameBuffer (Image n1 t1, Image n2 t2, Image n3 t3) = FrameBuffer n1 (t1, t2, t3) 430 TFFrameBuffer (Image n1 t1, Image n2 t2, Image n3 t3) = FrameBuffer n1 '[t1, t2, t3]
431
432class ValidFrameBuffer (a :: [ImageSemantics])
433instance ValidFrameBuffer a -- TODO
438 434
439FrameBuffer :: (ValidFrameBuffer b, SameLayerCounts a, FrameBuffer n b ~ TFFrameBuffer a) => a -> FrameBuffer n b 435FrameBuffer :: (ValidFrameBuffer b, SameLayerCounts a, FrameBuffer n b ~ TFFrameBuffer a) => a -> FrameBuffer n b
440 436
@@ -443,8 +439,8 @@ accumulate ctx fshader fstr fb = Accumulate ctx (mapFragments fshader fstr) fb
443accumulationContext x = x 439accumulationContext x = x
444 440
445-- texture support 441-- texture support
446PrjImage :: FrameBuffer 1 a -> Image 1 a 442PrjImage :: FrameBuffer 1 '[a] -> Image 1 a
447PrjImageColor :: FrameBuffer 1 (Depth Float, Color (Vec 4 Float)) -> Image 1 (Color (Vec 4 Float)) 443PrjImageColor :: FrameBuffer 1 '[Depth 'Float, Color '(Vec 4 Float)] -> Image 1 (Color (Vec 4 Float))
448 444
449data Output where 445data Output where
450 ScreenOut :: FrameBuffer a b -> Output 446 ScreenOut :: FrameBuffer a b -> Output