diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-02-04 16:50:05 +0100 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-02-04 16:50:05 +0100 |
commit | 6a72593b019fdd3a1a144b73b518babf1cc33b54 (patch) | |
tree | 380687ce015be39f75348f089e30bed74739587c /lc | |
parent | 91b08d7eb8b3ba2e26862e389e1a58d6c7290a91 (diff) |
bugfix & improvements
Diffstat (limited to 'lc')
-rw-r--r-- | lc/Builtins.lc | 96 | ||||
-rw-r--r-- | lc/Internals.lc | 4 |
2 files changed, 56 insertions, 44 deletions
diff --git a/lc/Builtins.lc b/lc/Builtins.lc index 834b53eb..4147e107 100644 --- a/lc/Builtins.lc +++ b/lc/Builtins.lc | |||
@@ -8,11 +8,6 @@ import Internals | |||
8 | 8 | ||
9 | id x = x | 9 | id x = x |
10 | 10 | ||
11 | -- todo: move to Internals | ||
12 | data List a = Nil | Cons a (List a) | ||
13 | |||
14 | infixr 5 : | ||
15 | |||
16 | --------------------------------------- | 11 | --------------------------------------- |
17 | 12 | ||
18 | class AttributeTuple a | 13 | class AttributeTuple a |
@@ -103,23 +98,23 @@ class Component a where | |||
103 | oneComp :: a | 98 | oneComp :: a |
104 | 99 | ||
105 | instance Component Int where | 100 | instance Component Int where |
106 | zeroComp = 0 | 101 | zeroComp = 0 :: Int |
107 | oneComp = 1 | 102 | oneComp = 1 :: Int |
108 | instance Component Word where | 103 | instance Component Word where |
109 | zeroComp = 0 | 104 | zeroComp = 0 :: Word |
110 | oneComp = 1 | 105 | oneComp = 1 :: Word |
111 | instance Component Float where | 106 | instance Component Float where |
112 | zeroComp = 0 | 107 | zeroComp = 0.0 |
113 | oneComp = 1 | 108 | oneComp = 1.0 |
114 | instance Component (VecS Float 2) where | 109 | instance Component (VecS Float 2) where |
115 | zeroComp = V2 0 0 | 110 | zeroComp = V2 0.0 0.0 |
116 | oneComp = V2 1 1 | 111 | oneComp = V2 1.0 1.0 |
117 | instance Component (VecS Float 3) where | 112 | instance Component (VecS Float 3) where |
118 | zeroComp = V3 0 0 0 | 113 | zeroComp = V3 0.0 0.0 0.0 |
119 | oneComp = V3 1 1 1 | 114 | oneComp = V3 1.0 1.0 1.0 |
120 | instance Component (VecS Float 4) where | 115 | instance Component (VecS Float 4) where |
121 | zeroComp = V4 0 0 0 0 | 116 | zeroComp = V4 0.0 0.0 0.0 0.0 |
122 | oneComp = V4 1 1 1 1 | 117 | oneComp = V4 1.0 1.0 1.0 1.0 |
123 | instance Component Bool where | 118 | instance Component Bool where |
124 | zeroComp = False | 119 | zeroComp = False |
125 | oneComp = True | 120 | oneComp = True |
@@ -266,22 +261,11 @@ data RasterContext :: PrimitiveType -> Type where | |||
266 | PointCtx :: PointSize -> Float -> PointSpriteCoordOrigin -> RasterContext Point | 261 | PointCtx :: PointSize -> Float -> PointSpriteCoordOrigin -> RasterContext Point |
267 | LineCtx :: Float -> ProvokingVertex -> RasterContext Line | 262 | LineCtx :: Float -> ProvokingVertex -> RasterContext Line |
268 | 263 | ||
269 | data Interpolated t where | ||
270 | Smooth, NoPerspective | ||
271 | :: (Floating t) => Interpolated t | ||
272 | Flat :: Interpolated t | ||
273 | |||
274 | type family FTRepr' a where | 264 | type family FTRepr' a where |
275 | -- TODO | 265 | -- TODO |
276 | FTRepr' [a] = a | 266 | FTRepr' [a] = a |
277 | FTRepr' ([a], [b]) = (a, b) | 267 | FTRepr' ([a], [b]) = (a, b) |
278 | 268 | ||
279 | type family InterpolatedType a where | ||
280 | InterpolatedType () = () | ||
281 | InterpolatedType (Interpolated a) = a | ||
282 | InterpolatedType (Interpolated a, Interpolated b) = (a, b) | ||
283 | InterpolatedType (Interpolated a, Interpolated b, Interpolated c) = (a, b, c) | ||
284 | |||
285 | data Blending :: Type -> Type where | 269 | data Blending :: Type -> Type where |
286 | NoBlending :: Blending t | 270 | NoBlending :: Blending t |
287 | BlendLogicOp :: (Integral t) => LogicOperation -> Blending t | 271 | BlendLogicOp :: (Integral t) => LogicOperation -> Blending t |
@@ -324,11 +308,19 @@ mapStream :: (a -> b) -> Stream a -> Stream b | |||
324 | concatMapStream :: (a -> Stream b) -> Stream a -> Stream b | 308 | concatMapStream :: (a -> Stream b) -> Stream a -> Stream b |
325 | filterStream :: (a -> Bool) -> Stream a -> Stream a | 309 | filterStream :: (a -> Bool) -> Stream a -> Stream a |
326 | 310 | ||
327 | data Primitive (a :: PrimitiveType) t | 311 | data Primitive a :: PrimitiveType -> Type where |
312 | PrimPoint :: a -> Primitive a Point | ||
313 | PrimLine :: a -> a -> Primitive a Line | ||
314 | PrimTriangle :: a -> a -> a -> Primitive a Triangle | ||
328 | 315 | ||
329 | type PrimitiveStream a t = Stream (Primitive a t) | 316 | type PrimitiveStream a t = Stream (Primitive t a) |
330 | 317 | ||
331 | mapPrimitive :: (a -> b) -> Primitive p a -> Primitive p b | 318 | mapPrimitive :: (a -> b) -> Primitive a p -> Primitive b p |
319 | {- todo | ||
320 | mapPrimitive f (PrimPoint a) = PrimPoint (f a) | ||
321 | mapPrimitive f (PrimLine a b) = PrimLine (f a) (f b) | ||
322 | mapPrimitive f (PrimTriangle a b c) = PrimTriangle (f a) (f b) (f c) | ||
323 | -} | ||
332 | 324 | ||
333 | fetch_ :: forall a t . (AttributeTuple t) => String -> t -> PrimitiveStream a t | 325 | fetch_ :: forall a t . (AttributeTuple t) => String -> t -> PrimitiveStream a t |
334 | fetchArrays_ :: forall a t t' . (AttributeTuple t, t ~ FTRepr' t') => t' -> PrimitiveStream a t | 326 | fetchArrays_ :: forall a t t' . (AttributeTuple t, t ~ FTRepr' t') => t' -> PrimitiveStream a t |
@@ -352,32 +344,50 @@ type family RemSemantics a where | |||
352 | RemSemantics (Depth Float, Color a, Color b, Color c) = (a, b, c) | 344 | RemSemantics (Depth Float, Color a, Color b, Color c) = (a, b, c) |
353 | RemSemantics (Depth Float, Color a, Color b, Color c, Color d) = (a, b, c, d) | 345 | RemSemantics (Depth Float, Color a, Color b, Color c, Color d) = (a, b, c, d) |
354 | 346 | ||
347 | data Vector (n :: Nat) t | ||
348 | |||
355 | -- Render Operations | 349 | -- Render Operations |
356 | data Fragment :: Nat -> Type -> Type | 350 | data Fragment (l :: Nat) t |
351 | = Fragment (Vec 3 Float) (Vector l t) | ||
357 | 352 | ||
358 | type FragmentStream n t = Stream (Fragment n t) | 353 | type FragmentStream n t = Stream (Fragment n t) |
359 | 354 | ||
360 | customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a | 355 | customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a |
361 | 356 | ||
357 | customizeDepths :: (a -> Float) -> FragmentStream n a -> FragmentStream n a | ||
362 | customizeDepths f = mapStream (customizeDepth f) | 358 | customizeDepths f = mapStream (customizeDepth f) |
363 | 359 | ||
364 | rasterize_ :: (b ~ InterpolatedType y, a ~ JoinTupleType (Vec 4 Float) b) | 360 | data Interpolated t where |
365 | => (a -> Float) -- point size | 361 | Smooth, NoPerspective |
366 | -> y -- tuple of Smooth & Flat | 362 | :: (Floating t) => Interpolated t |
367 | -> RasterContext x | 363 | Flat :: Interpolated t |
368 | -> Primitive x a -> FragmentStream 1 b | 364 | |
365 | type family InterpolatedType a where | ||
366 | InterpolatedType () = () | ||
367 | InterpolatedType (Interpolated a) = a | ||
368 | InterpolatedType (Interpolated a, Interpolated b) = (a, b) | ||
369 | InterpolatedType (Interpolated a, Interpolated b, Interpolated c) = (a, b, c) | ||
370 | |||
371 | rasterize | ||
372 | :: (b ~ InterpolatedType interpolation, a ~ JoinTupleType (Vec 4 Float) b) | ||
373 | => (a -> Float) -- point size | ||
374 | -> interpolation -- tuple of Smooth & Flat | ||
375 | -> RasterContext x | ||
376 | -> Primitive a x -> FragmentStream 1 b | ||
377 | |||
378 | rasterizePrimitives ctx is = concatMapStream (rasterize (\_ -> 1) is ctx) | ||
379 | rasterizePrimitivesWithPointSize ctx ps is = concatMapStream (rasterize ps is ctx) | ||
369 | 380 | ||
370 | filterFragment :: (a -> Bool) -> Fragment n a -> Bool | 381 | checkFragment :: (a -> Bool) -> Fragment n a -> Bool |
371 | 382 | ||
372 | filterFragments :: (a -> Bool) -> (FragmentStream n a) -> (FragmentStream n a) | 383 | filterFragments :: (a -> Bool) -> FragmentStream n a -> FragmentStream n a |
373 | filterFragments p = filterStream (filterFragment p) | 384 | filterFragments p = filterStream (checkFragment p) |
374 | 385 | ||
375 | mapFragment :: (a -> b) -> Fragment n a -> Fragment n b | 386 | mapFragment :: (a -> b) -> Fragment n a -> Fragment n b |
376 | 387 | ||
388 | mapFragments :: (a -> b) -> FragmentStream n a -> FragmentStream n b | ||
377 | mapFragments f = mapStream (mapFragment f) | 389 | mapFragments f = mapStream (mapFragment f) |
378 | 390 | ||
379 | --data ShadedFragment :: Nat -> Type -> Type | ||
380 | |||
381 | data Image :: Nat -> Type -> Type where | 391 | data Image :: Nat -> Type -> Type where |
382 | ColorImage :: forall a d t color . (Num t, color ~ VecScalar d t) | 392 | ColorImage :: forall a d t color . (Num t, color ~ VecScalar d t) |
383 | => color -> Image a (Color color) | 393 | => color -> Image a (Color color) |
@@ -533,8 +543,6 @@ data Sampler = Sampler Filter EdgeMode Texture | |||
533 | texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float | 543 | texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float |
534 | 544 | ||
535 | 545 | ||
536 | rasterizePrimitives ctx is = concatMapStream (rasterize_ (\_ -> 1) is ctx) | ||
537 | rasterizePrimitivesWithPointSize ctx ps is = concatMapStream (rasterize_ ps is ctx) | ||
538 | accumulateWith ctx x = (ctx, x) | 546 | accumulateWith ctx x = (ctx, x) |
539 | overlay cl (ctx, str) = Accumulate ctx str cl | 547 | overlay cl (ctx, str) = Accumulate ctx str cl |
540 | renderFrame = ScreenOut | 548 | renderFrame = ScreenOut |
diff --git a/lc/Internals.lc b/lc/Internals.lc index 780835cc..92d66d2f 100644 --- a/lc/Internals.lc +++ b/lc/Internals.lc | |||
@@ -127,4 +127,8 @@ instance Eq Nat where | |||
127 | Succ a == Succ b = a == b | 127 | Succ a == Succ b = a == b |
128 | _ == _ = False | 128 | _ == _ = False |
129 | 129 | ||
130 | data List a = Nil | Cons a (List a) | ||
131 | |||
132 | infixr 5 : | ||
133 | |||
130 | 134 | ||