diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-02-05 22:04:46 +0100 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-02-05 22:13:59 +0100 |
commit | 45f6f1c72feffb4e80430395511788ccf576f29e (patch) | |
tree | 7d3a35fb3d980004232fd3a3226cca30b3b2f35d /lc | |
parent | bf1e53a0fe348bd41f07ea21802b9bb77b3ecb18 (diff) |
refactor Builtins.lc
Diffstat (limited to 'lc')
-rw-r--r-- | lc/Builtins.lc | 82 |
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 | |||
14 | instance AttributeTuple a -- TODO | 14 | instance AttributeTuple a -- TODO |
15 | class ValidOutput a | 15 | class ValidOutput a |
16 | instance ValidOutput a -- TODO | 16 | instance ValidOutput a -- TODO |
17 | class ValidFrameBuffer a | ||
18 | instance ValidFrameBuffer a -- TODO | ||
19 | 17 | ||
20 | data VecS (a :: Type) :: Nat -> Type where | 18 | data 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 | 238 | data ImageSemantics = Depth Type | Stencil Type | Color Type | |
241 | data Depth a where | ||
242 | data Stencil a where | ||
243 | data Color a where | ||
244 | 239 | ||
245 | data PrimitiveType | 240 | data PrimitiveType |
246 | = Triangle | 241 | = Triangle |
@@ -282,25 +277,18 @@ data StencilTests | |||
282 | data StencilOps | 277 | data StencilOps |
283 | data Int32 | 278 | data Int32 |
284 | 279 | ||
285 | data FragmentOperation :: Type -> Type where | 280 | data 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 | |
291 | type family FragOps a where | 286 | type 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 | -} | ||
298 | type 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 |
306 | x:xs ++ ys = x : xs ++ ys | 294 | x:xs ++ ys = x : xs ++ ys |
@@ -339,18 +327,22 @@ mapPrimitives f = map (mapPrimitive f) | |||
339 | fetch s a t = fetch_ @a s t | 327 | fetch s a t = fetch_ @a s t |
340 | fetchArrays a t = fetchArrays_ @a t | 328 | fetchArrays a t = fetchArrays_ @a t |
341 | 329 | ||
342 | type family RemSemantics a where | 330 | remSemantics :: ImageSemantics -> Type |
343 | RemSemantics () = () | 331 | remSemantics (Color a) = a |
344 | RemSemantics (Color a) = a | 332 | remSemantics (Depth a) = a |
345 | RemSemantics (Color a, Color b) = (a, b) | 333 | remSemantics (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) | 335 | remSemantics_ :: [ImageSemantics] -> Type |
348 | RemSemantics (Color a, Color b, Color c, Color d, Color e) = (a, b, c, d, e) | 336 | remSemantics_ [] = '() |
349 | RemSemantics (Depth Float) = () | 337 | remSemantics_ [a] = remSemantics a |
350 | RemSemantics (Depth Float, Color a) = a | 338 | remSemantics_ [a, b] = '(remSemantics a, remSemantics b) |
351 | RemSemantics (Depth Float, Color a, Color b) = (a, b) | 339 | remSemantics_ [a, b, c] = '(remSemantics a, remSemantics b, remSemantics c) |
352 | RemSemantics (Depth Float, Color a, Color b, Color c) = (a, b, c) | 340 | remSemantics_ [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) | 341 | remSemantics_ [a, b, c, d, e] = '(remSemantics a, remSemantics b, remSemantics c, remSemantics d, remSemantics e) |
342 | |||
343 | remSemantics' :: [ImageSemantics] -> Type | ||
344 | remSemantics' (Depth _: x) = remSemantics_ x | ||
345 | remSemantics' x = remSemantics_ x | ||
354 | 346 | ||
355 | ------------------- | 347 | ------------------- |
356 | 348 | ||
@@ -407,7 +399,7 @@ rasterizePrimitive | |||
407 | 399 | ||
408 | rasterizePrimitives ctx is s = concat (map (rasterizePrimitive is ctx) s) | 400 | rasterizePrimitives ctx is s = concat (map (rasterizePrimitive is ctx) s) |
409 | 401 | ||
410 | data Image :: Nat -> Type -> Type | 402 | data Image (n :: Nat) (t :: ImageSemantics) -- = Vector n [[t]] |
411 | 403 | ||
412 | ColorImage :: forall a d t color . (Num t, color ~ VecScalar d t) | 404 | ColorImage :: 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 | {- | |
422 | class DefaultFragOp a where defaultFragOp :: FragmentOperation a | 414 | class DefaultFragOp a where defaultFragOp :: FragmentOperation a |
423 | instance DefaultFragOp (Color (VecS Float 4)) where defaultFragOp = ColorOp NoBlending (V4 True True True True) | 415 | instance DefaultFragOp (Color (VecS Float 4)) where defaultFragOp = ColorOp NoBlending (V4 True True True True) |
424 | instance DefaultFragOp (Depth Float) where defaultFragOp = DepthOp Less True | 416 | instance DefaultFragOp (Depth Float) where defaultFragOp = DepthOp Less True |
425 | {- | 417 | |
426 | class DefaultFragOps a where defaultFragOps :: a | 418 | class DefaultFragOps a where defaultFragOps :: a |
427 | instance (DefaultFragOp a, DefaultFragOp b) => DefaultFragOps (FragmentOperation a, FragmentOperation b) where | 419 | instance (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 | -} |
431 | data FrameBuffer (n :: Nat) t | 423 | data FrameBuffer (n :: Nat) (t :: [ImageSemantics]) |
432 | Accumulate :: FragOps b -> FragmentStream n (RemSemantics b) -> FrameBuffer n b -> FrameBuffer n b | 424 | |
425 | Accumulate :: FragOps b -> FragmentStream n (remSemantics' b) -> FrameBuffer n b -> FrameBuffer n b | ||
433 | 426 | ||
434 | type family TFFrameBuffer a where | 427 | type 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 | |||
432 | class ValidFrameBuffer (a :: [ImageSemantics]) | ||
433 | instance ValidFrameBuffer a -- TODO | ||
438 | 434 | ||
439 | FrameBuffer :: (ValidFrameBuffer b, SameLayerCounts a, FrameBuffer n b ~ TFFrameBuffer a) => a -> FrameBuffer n b | 435 | FrameBuffer :: (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 | |||
443 | accumulationContext x = x | 439 | accumulationContext x = x |
444 | 440 | ||
445 | -- texture support | 441 | -- texture support |
446 | PrjImage :: FrameBuffer 1 a -> Image 1 a | 442 | PrjImage :: FrameBuffer 1 '[a] -> Image 1 a |
447 | PrjImageColor :: FrameBuffer 1 (Depth Float, Color (Vec 4 Float)) -> Image 1 (Color (Vec 4 Float)) | 443 | PrjImageColor :: FrameBuffer 1 '[Depth 'Float, Color '(Vec 4 Float)] -> Image 1 (Color (Vec 4 Float)) |
448 | 444 | ||
449 | data Output where | 445 | data Output where |
450 | ScreenOut :: FrameBuffer a b -> Output | 446 | ScreenOut :: FrameBuffer a b -> Output |