summaryrefslogtreecommitdiff
path: root/lc
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-02-04 16:50:05 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-02-04 16:50:05 +0100
commit6a72593b019fdd3a1a144b73b518babf1cc33b54 (patch)
tree380687ce015be39f75348f089e30bed74739587c /lc
parent91b08d7eb8b3ba2e26862e389e1a58d6c7290a91 (diff)
bugfix & improvements
Diffstat (limited to 'lc')
-rw-r--r--lc/Builtins.lc96
-rw-r--r--lc/Internals.lc4
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
9id x = x 9id x = x
10 10
11-- todo: move to Internals
12data List a = Nil | Cons a (List a)
13
14infixr 5 :
15
16--------------------------------------- 11---------------------------------------
17 12
18class AttributeTuple a 13class AttributeTuple a
@@ -103,23 +98,23 @@ class Component a where
103 oneComp :: a 98 oneComp :: a
104 99
105instance Component Int where 100instance Component Int where
106 zeroComp = 0 101 zeroComp = 0 :: Int
107 oneComp = 1 102 oneComp = 1 :: Int
108instance Component Word where 103instance Component Word where
109 zeroComp = 0 104 zeroComp = 0 :: Word
110 oneComp = 1 105 oneComp = 1 :: Word
111instance Component Float where 106instance Component Float where
112 zeroComp = 0 107 zeroComp = 0.0
113 oneComp = 1 108 oneComp = 1.0
114instance Component (VecS Float 2) where 109instance 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
117instance Component (VecS Float 3) where 112instance 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
120instance Component (VecS Float 4) where 115instance 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
123instance Component Bool where 118instance 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
269data Interpolated t where
270 Smooth, NoPerspective
271 :: (Floating t) => Interpolated t
272 Flat :: Interpolated t
273
274type family FTRepr' a where 264type 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
279type 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
285data Blending :: Type -> Type where 269data 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
324concatMapStream :: (a -> Stream b) -> Stream a -> Stream b 308concatMapStream :: (a -> Stream b) -> Stream a -> Stream b
325filterStream :: (a -> Bool) -> Stream a -> Stream a 309filterStream :: (a -> Bool) -> Stream a -> Stream a
326 310
327data Primitive (a :: PrimitiveType) t 311data 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
329type PrimitiveStream a t = Stream (Primitive a t) 316type PrimitiveStream a t = Stream (Primitive t a)
330 317
331mapPrimitive :: (a -> b) -> Primitive p a -> Primitive p b 318mapPrimitive :: (a -> b) -> Primitive a p -> Primitive b p
319{- todo
320mapPrimitive f (PrimPoint a) = PrimPoint (f a)
321mapPrimitive f (PrimLine a b) = PrimLine (f a) (f b)
322mapPrimitive f (PrimTriangle a b c) = PrimTriangle (f a) (f b) (f c)
323-}
332 324
333fetch_ :: forall a t . (AttributeTuple t) => String -> t -> PrimitiveStream a t 325fetch_ :: forall a t . (AttributeTuple t) => String -> t -> PrimitiveStream a t
334fetchArrays_ :: forall a t t' . (AttributeTuple t, t ~ FTRepr' t') => t' -> PrimitiveStream a t 326fetchArrays_ :: 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
347data Vector (n :: Nat) t
348
355 -- Render Operations 349 -- Render Operations
356data Fragment :: Nat -> Type -> Type 350data Fragment (l :: Nat) t
351 = Fragment (Vec 3 Float) (Vector l t)
357 352
358type FragmentStream n t = Stream (Fragment n t) 353type FragmentStream n t = Stream (Fragment n t)
359 354
360customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a 355customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a
361 356
357customizeDepths :: (a -> Float) -> FragmentStream n a -> FragmentStream n a
362customizeDepths f = mapStream (customizeDepth f) 358customizeDepths f = mapStream (customizeDepth f)
363 359
364rasterize_ :: (b ~ InterpolatedType y, a ~ JoinTupleType (Vec 4 Float) b) 360data 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
365type 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
371rasterize
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
378rasterizePrimitives ctx is = concatMapStream (rasterize (\_ -> 1) is ctx)
379rasterizePrimitivesWithPointSize ctx ps is = concatMapStream (rasterize ps is ctx)
369 380
370filterFragment :: (a -> Bool) -> Fragment n a -> Bool 381checkFragment :: (a -> Bool) -> Fragment n a -> Bool
371 382
372filterFragments :: (a -> Bool) -> (FragmentStream n a) -> (FragmentStream n a) 383filterFragments :: (a -> Bool) -> FragmentStream n a -> FragmentStream n a
373filterFragments p = filterStream (filterFragment p) 384filterFragments p = filterStream (checkFragment p)
374 385
375mapFragment :: (a -> b) -> Fragment n a -> Fragment n b 386mapFragment :: (a -> b) -> Fragment n a -> Fragment n b
376 387
388mapFragments :: (a -> b) -> FragmentStream n a -> FragmentStream n b
377mapFragments f = mapStream (mapFragment f) 389mapFragments f = mapStream (mapFragment f)
378 390
379--data ShadedFragment :: Nat -> Type -> Type
380
381data Image :: Nat -> Type -> Type where 391data 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
533texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float 543texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float
534 544
535 545
536rasterizePrimitives ctx is = concatMapStream (rasterize_ (\_ -> 1) is ctx)
537rasterizePrimitivesWithPointSize ctx ps is = concatMapStream (rasterize_ ps is ctx)
538accumulateWith ctx x = (ctx, x) 546accumulateWith ctx x = (ctx, x)
539overlay cl (ctx, str) = Accumulate ctx str cl 547overlay cl (ctx, str) = Accumulate ctx str cl
540renderFrame = ScreenOut 548renderFrame = 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
130data List a = Nil | Cons a (List a)
131
132infixr 5 :
133
130 134