summaryrefslogtreecommitdiff
path: root/lc
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-02-22 16:46:40 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-02-22 16:47:27 +0100
commitf183de529a6cab5539906e94c6d0104226dca398 (patch)
tree0fc2fecc59fb140dedf03500206fadd20e33ae98 /lc
parent55c705a119ba1eba24abffd6a3ba5ea432a038a6 (diff)
refactoring
Diffstat (limited to 'lc')
-rw-r--r--lc/Builtins.lc490
1 files changed, 250 insertions, 240 deletions
diff --git a/lc/Builtins.lc b/lc/Builtins.lc
index 9484a9d9..29533cbf 100644
--- a/lc/Builtins.lc
+++ b/lc/Builtins.lc
@@ -11,16 +11,16 @@ id x = x
11 11
12--------------------------------------- 12---------------------------------------
13 13
14class AttributeTuple a
15instance AttributeTuple a -- TODO
16class ValidOutput a
17instance ValidOutput a -- TODO
18
19data VecS (a :: Type) :: Nat -> Type where 14data VecS (a :: Type) :: Nat -> Type where
20 V2 :: a -> a -> VecS a 2 15 V2 :: a -> a -> VecS a 2
21 V3 :: a -> a -> a -> VecS a 3 16 V3 :: a -> a -> a -> VecS a 3
22 V4 :: a -> a -> a -> a -> VecS a 4 17 V4 :: a -> a -> a -> a -> VecS a 4
23 18
19mapVec :: (a -> b) -> VecS a n -> VecS b n
20mapVec f (V2 x y) = V2 (f x) (f y)
21mapVec f (V3 x y z) = V3 (f x) (f y) (f z)
22mapVec f (V4 x y z w) = V4 (f x) (f y) (f z) (f w)
23
24type family Vec (n :: Nat) t where Vec n t = VecS t n 24type family Vec (n :: Nat) t where Vec n t = VecS t n
25 25
26type family VecScalar (n :: Nat) a where 26type family VecScalar (n :: Nat) a where
@@ -46,53 +46,6 @@ type family MatVecScalarElem a where
46 MatVecScalarElem (VecS a n) = a 46 MatVecScalarElem (VecS a n) = a
47 MatVecScalarElem (Mat i j a) = a 47 MatVecScalarElem (Mat i j a) = a
48 48
49--------------------------------------- swizzling
50
51mapVec :: (a -> b) -> VecS a n -> VecS b n
52mapVec f (V2 x y) = V2 (f x) (f y)
53mapVec f (V3 x y z) = V3 (f x) (f y) (f z)
54mapVec f (V4 x y z w) = V4 (f x) (f y) (f z) (f w)
55
56data Swizz = Sx | Sy | Sz | Sw
57
58data Swizz' :: Nat -> Type where
59 Sx' :: forall n . Swizz' (Succ n)
60 Sy' :: forall n . Swizz' (Succ (Succ n))
61 Sz' :: forall n . Swizz' (Succ (Succ (Succ n)))
62 Sw' :: forall n . Swizz' (Succ (Succ (Succ (Succ n))))
63
64swizzscalar' :: forall n -> Vec n a -> Swizz' n -> a
65{-
66swizzscalar' 2 = \x -> case x of
67 V2 x y -> \s -> case s of
68 Sx' -> x
69 Sy' -> y
70swizzscalar' 3 = \x -> case x of
71 V3 x y z -> \s -> case s of
72 Sx' -> x
73-}
74-- todo: make it more type safe
75swizzscalar :: forall n . Vec n a -> Swizz -> a
76swizzscalar (V2 x y) Sx = x
77swizzscalar (V2 x y) Sy = y
78swizzscalar (V3 x y z) Sx = x
79swizzscalar (V3 x y z) Sy = y
80swizzscalar (V3 x y z) Sz = z
81swizzscalar (V4 x y z w) Sx = x
82swizzscalar (V4 x y z w) Sy = y
83swizzscalar (V4 x y z w) Sz = z
84swizzscalar (V4 x y z w) Sw = w
85
86-- used to prevent unfolding of swizzvector on variables (behind GPU lambda)
87definedVec :: forall a m . Vec m a -> Bool
88definedVec (V2 _ _) = True
89definedVec (V3 _ _ _) = True
90definedVec (V4 _ _ _ _) = True
91
92swizzvector :: forall n . forall m . Vec n a -> Vec m Swizz -> Vec m a
93swizzvector v w | definedVec v = mapVec (swizzscalar v) w
94
95
96--------------------------------------- type classes 49--------------------------------------- type classes
97 50
98class Signed a 51class Signed a
@@ -156,6 +109,239 @@ instance Floating (Mat 4 2 Float)
156instance Floating (Mat 4 3 Float) 109instance Floating (Mat 4 3 Float)
157instance Floating (Mat 4 4 Float) 110instance Floating (Mat 4 4 Float)
158 111
112
113-------------------------------------------------------------------
114-- * Builtin Primitive Functions *
115-- Arithmetic Functions (componentwise)
116
117PrimAdd, PrimSub, PrimMul :: Num (MatVecScalarElem a) => a -> a -> a
118PrimAddS, PrimSubS, PrimMulS :: (t ~ MatVecScalarElem a, Num t) => a -> t -> a
119PrimDiv, PrimMod :: (Num t, a ~ VecScalar d t) => a -> a -> a
120PrimDivS, PrimModS :: (Num t, a ~ VecScalar d t) => a -> t -> a
121PrimNeg :: Signed (MatVecScalarElem a) => a -> a
122-- Bit-wise Functions
123PrimBAnd, PrimBOr, PrimBXor :: (Integral t, a ~ VecScalar d t) => a -> a -> a
124PrimBAndS, PrimBOrS, PrimBXorS:: (Integral t, a ~ VecScalar d t) => a -> t -> a
125PrimBNot :: (Integral t, a ~ VecScalar d t) => a -> a
126PrimBShiftL, PrimBShiftR :: (Integral t, a ~ VecScalar d t, b ~ VecScalar d Word) => a -> b -> a
127PrimBShiftLS, PrimBShiftRS :: (Integral t, a ~ VecScalar d t) => a -> Word -> a
128-- Logic Functions
129PrimAnd, PrimOr, PrimXor :: Bool -> Bool -> Bool
130PrimNot :: forall a d . (a ~ VecScalar d Bool) => a -> a
131PrimAny, PrimAll :: VecScalar d Bool -> Bool
132
133-- Angle, Trigonometry and Exponential Functions
134PrimACos, PrimACosH, PrimASin, PrimASinH, PrimATan, PrimATanH, PrimCos, PrimCosH, PrimDegrees, PrimRadians, PrimSin, PrimSinH, PrimTan, PrimTanH, PrimExp, PrimLog, PrimExp2, PrimLog2, PrimSqrt, PrimInvSqrt
135 :: (a ~ VecScalar d Float) => a -> a
136PrimPow, PrimATan2 :: (a ~ VecScalar d Float) => a -> a -> a
137-- Common Functions
138PrimFloor, PrimTrunc, PrimRound, PrimRoundEven, PrimCeil, PrimFract
139 :: (a ~ VecScalar d Float) => a -> a
140PrimMin, PrimMax :: (Num t, a ~ VecScalar d t) => a -> a -> a
141PrimMinS, PrimMaxS :: (Num t, a ~ VecScalar d t) => a -> t -> a
142PrimIsNan, PrimIsInf :: (a ~ VecScalar d Float, b ~ VecScalar d Bool) => a -> b
143PrimAbs, PrimSign :: (Signed t, a ~ VecScalar d t) => a -> a
144PrimModF :: (a ~ VecScalar d Float) => a -> (a, a)
145PrimClamp :: (Num t, a ~ VecScalar d t) => a -> a -> a -> a
146PrimClampS :: (Num t, a ~ VecScalar d t) => a -> t -> t -> a
147PrimMix :: (a ~ VecScalar d Float) => a -> a -> a -> a
148PrimMixS :: (a ~ VecScalar d Float) => a -> a -> Float -> a
149PrimMixB :: (a ~ VecScalar d Float, b ~ VecScalar d Bool) => a -> a -> b -> a
150PrimStep :: (a ~ Vec d Float) => a -> a -> a
151PrimStepS :: (a ~ VecScalar d Float) => Float -> a -> a
152PrimSmoothStep :: (a ~ Vec d Float) => a -> a -> a -> a
153PrimSmoothStepS :: (a ~ VecScalar d Float) => Float -> Float -> a -> a
154
155-- Integer/Floatonversion Functions
156PrimFloatBitsToInt :: VecScalar d Float -> VecScalar d Int
157PrimFloatBitsToUInt :: VecScalar d Float -> VecScalar d Word
158PrimIntBitsToFloat :: VecScalar d Int -> VecScalar d Float
159PrimUIntBitsToFloat :: VecScalar d Word -> VecScalar d Float
160-- Geometric Functions
161PrimLength :: (a ~ VecScalar d Float) => a -> Float
162PrimDistance, PrimDot :: (a ~ VecScalar d Float) => a -> a -> Float
163PrimCross :: (a ~ VecScalar 3 Float) => a -> a -> a
164PrimNormalize :: (a ~ VecScalar d Float) => a -> a
165PrimFaceForward, PrimRefract :: (a ~ VecScalar d Float) => a -> a -> a -> a
166PrimReflect :: (a ~ VecScalar d Float) => a -> a -> a
167-- Matrix Functions
168PrimTranspose :: Mat h w a -> Mat w h a
169PrimDeterminant :: Mat s s a -> Float
170PrimInverse :: Mat s s a -> Mat s s a
171PrimOuterProduct :: Vec w a -> Vec h a -> Mat h w a
172PrimMulMatVec :: Mat h w a -> Vec w a -> Vec h a
173PrimMulVecMat :: Vec h a -> Mat h w a -> Vec w a
174PrimMulMatMat :: Mat i j a -> Mat j k a -> Mat i k a
175-- Vector and Scalar Relational Functions
176PrimLessThan, PrimLessThanEqual, PrimGreaterThan, PrimGreaterThanEqual, PrimEqualV, PrimNotEqualV
177 :: forall a d t b . (Num t, a ~ VecScalar d t, b ~ VecScalar d Bool) => a -> a -> b
178PrimEqual, PrimNotEqual :: forall a t . (t ~ MatVecScalarElem a) => a -> a -> Bool
179-- Fragment Processing Functions
180PrimDFdx, PrimDFdy, PrimFWidth
181 :: (a ~ VecScalar d Float) => a -> a
182-- Noise Functions
183PrimNoise1 :: VecScalar d Float -> Float
184PrimNoise2 :: VecScalar d Float -> Vec 2 Float
185PrimNoise3 :: VecScalar d Float -> Vec 3 Float
186PrimNoise4 :: VecScalar d Float -> Vec 4 Float
187
188{-
189-- Vec/Mat (de)construction
190PrimTupToV2 :: Component a => PrimFun stage ((a,a) -> V2 a)
191PrimTupToV3 :: Component a => PrimFun stage ((a,a,a) -> V3 a)
192PrimTupToV4 :: Component a => PrimFun stage ((a,a,a,a) -> V4 a)
193PrimV2ToTup :: Component a => PrimFun stage (V2 a -> (a,a))
194PrimV3ToTup :: Component a => PrimFun stage (V3 a -> (a,a,a))
195PrimV4ToTup :: Component a => PrimFun stage (V4 a -> (a,a,a,a))
196-}
197
198-------------------------------------------------------
199
200head (x: _) = x
201
202[] ++ ys = ys
203x:xs ++ ys = x : xs ++ ys
204
205foldr f e [] = e
206foldr f e (x: xs) = f x (foldr f e xs)
207
208concat = foldr (++) []
209
210map _ [] = []
211map f (x:xs) = f x : map f xs
212
213concatMap :: (a -> [b]) -> [a] -> [b]
214concatMap f x = concat (map f x)
215
216-------------------
217
218data Maybe a
219 = Nothing
220 | Just a
221-- deriving (Eq, Ord, Show)
222
223data Vector (n :: Nat) t
224
225-------------------------------------------------------
226
227data PrimitiveType
228 = Triangle
229 | Line
230 | Point
231 | TriangleAdjacency
232 | LineAdjacency
233
234data Primitive a :: PrimitiveType -> Type where
235 PrimPoint :: a -> Primitive a Point
236 PrimLine :: a -> a -> Primitive a Line
237 PrimTriangle :: a -> a -> a -> Primitive a Triangle
238
239mapPrimitive :: (a -> b) -> Primitive a p -> Primitive b p
240{- todo
241mapPrimitive f (PrimPoint a) = PrimPoint (f a)
242mapPrimitive f (PrimLine a b) = PrimLine (f a) (f b)
243mapPrimitive f (PrimTriangle a b c) = PrimTriangle (f a) (f b) (f c)
244-}
245
246type PrimitiveStream a t = [Primitive t a]
247
248mapPrimitives :: (a -> b) -> PrimitiveStream p a -> PrimitiveStream p b
249mapPrimitives f = map (mapPrimitive f)
250
251type family ListElem a where ListElem [a] = a
252
253--class AttributeTuple a
254--instance AttributeTuple a -- TODO
255
256fetchArrays :: forall a t t' . ({-AttributeTuple t, -} t ~ map ListElem t') => HList t' -> PrimitiveStream a (HList t)
257
258fetch :: forall a t . {-(AttributeTuple t) => -} String -> t -> PrimitiveStream a t
259
260------------------------------------------------------
261
262type Fragment n t = Vector n (Maybe (SimpleFragment t))
263
264data SimpleFragment t = SimpleFragment
265 { sFragmentCoords :: Vec 3 Float
266 , sFragmentValue :: t
267 }
268
269type FragmentStream n t = [Fragment n t]
270
271customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a
272
273customizeDepths :: (a -> Float) -> FragmentStream n a -> FragmentStream n a
274customizeDepths f = map (customizeDepth f)
275
276filterFragment :: (a -> Bool) -> Fragment n a -> Fragment n a
277
278filterFragments :: (a -> Bool) -> FragmentStream n a -> FragmentStream n a
279filterFragments p = map (filterFragment p)
280
281mapFragment :: (a -> b) -> Fragment n a -> Fragment n b
282
283mapFragments :: (a -> b) -> FragmentStream n a -> FragmentStream n b
284mapFragments f = map (mapFragment f)
285
286-------------------------------------------------------------------------
287
288data ImageSemantics = Depth Type | Stencil Type | Color Type
289
290data Image (n :: Nat) (t :: ImageSemantics) -- = Vector n [[t]]
291
292ColorImage :: forall a d t color . (Num t, color ~ VecScalar d t)
293 => color -> Image a (Color color)
294DepthImage :: forall a . Float -> Image a (Depth Float)
295StencilImage :: forall a . Int -> Image a (Stencil Int)
296
297emptyDepthImage = DepthImage @1
298emptyColorImage = ColorImage @1
299
300-------------------------------------------------------------------------
301
302
303--------------------------------------- swizzling
304
305data Swizz = Sx | Sy | Sz | Sw
306{-
307data Swizz' :: Nat -> Type where
308 Sx' :: forall n . Swizz' (Succ n)
309 Sy' :: forall n . Swizz' (Succ (Succ n))
310 Sz' :: forall n . Swizz' (Succ (Succ (Succ n)))
311 Sw' :: forall n . Swizz' (Succ (Succ (Succ (Succ n))))
312
313swizzscalar' :: forall n -> Vec n a -> Swizz' n -> a
314swizzscalar' 2 = \x -> case x of
315 V2 x y -> \s -> case s of
316 Sx' -> x
317 Sy' -> y
318swizzscalar' 3 = \x -> case x of
319 V3 x y z -> \s -> case s of
320 Sx' -> x
321-}
322-- todo: make it more type safe
323swizzscalar :: forall n . Vec n a -> Swizz -> a
324swizzscalar (V2 x y) Sx = x
325swizzscalar (V2 x y) Sy = y
326swizzscalar (V3 x y z) Sx = x
327swizzscalar (V3 x y z) Sy = y
328swizzscalar (V3 x y z) Sz = z
329swizzscalar (V4 x y z w) Sx = x
330swizzscalar (V4 x y z w) Sy = y
331swizzscalar (V4 x y z w) Sz = z
332swizzscalar (V4 x y z w) Sw = w
333
334-- used to prevent unfolding of swizzvector on variables (behind GPU lambda)
335definedVec :: forall a m . Vec m a -> Bool
336definedVec (V2 _ _) = True
337definedVec (V3 _ _ _) = True
338definedVec (V4 _ _ _ _) = True
339
340swizzvector :: forall n . forall m . Vec n a -> Vec m Swizz -> Vec m a
341swizzvector v w | definedVec v = mapVec (swizzscalar v) w
342
343-----------------------------------------------------------------------------
344
159data BlendingFactor 345data BlendingFactor
160 = Zero' --- FIXME: modified 346 = Zero' --- FIXME: modified
161 | One 347 | One
@@ -244,15 +430,6 @@ data PointSpriteCoordOrigin
244 = LowerLeft 430 = LowerLeft
245 | UpperLeft 431 | UpperLeft
246 432
247data ImageSemantics = Depth Type | Stencil Type | Color Type
248
249data PrimitiveType
250 = Triangle
251 | Line
252 | Point
253 | TriangleAdjacency
254 | LineAdjacency
255
256-- builtin 433-- builtin
257primTexture :: () -> Vec 2 Float -> Vec 4 Float 434primTexture :: () -> Vec 2 Float -> Vec 4 Float
258 435
@@ -265,13 +442,6 @@ data RasterContext a :: PrimitiveType -> Type where
265 PointCtx :: PointSize a -> Float -> PointSpriteCoordOrigin -> RasterContext a Point 442 PointCtx :: PointSize a -> Float -> PointSpriteCoordOrigin -> RasterContext a Point
266 LineCtx :: Float -> ProvokingVertex -> RasterContext a Line 443 LineCtx :: Float -> ProvokingVertex -> RasterContext a Line
267 444
268map _ [] = []
269map f (x:xs) = f x : map f xs
270
271type family ListElem a where ListElem [a] = a
272
273type family HListElem a :: [Type] where HListElem (HList l) = l
274
275data Blending :: Type -> Type where 445data Blending :: Type -> Type where
276 NoBlending :: Blending t 446 NoBlending :: Blending t
277 BlendLogicOp :: (Integral t) => LogicOperation -> Blending t 447 BlendLogicOp :: (Integral t) => LogicOperation -> Blending t
@@ -288,71 +458,6 @@ data FragmentOperation :: ImageSemantics -> Type where
288 DepthOp :: ComparisonFunction -> Bool -> FragmentOperation (Depth Float) 458 DepthOp :: ComparisonFunction -> Bool -> FragmentOperation (Depth Float)
289 StencilOp :: StencilTests -> StencilOps -> StencilOps -> FragmentOperation (Stencil Int32) 459 StencilOp :: StencilTests -> StencilOps -> StencilOps -> FragmentOperation (Stencil Int32)
290 460
291[] ++ ys = ys
292x:xs ++ ys = x : xs ++ ys
293
294foldr f e [] = e
295foldr f e (x: xs) = f x (foldr f e xs)
296
297concat = foldr (++) []
298
299concatMap :: (a -> [b]) -> [a] -> [b]
300concatMap f x = concat (map f x)
301
302data Primitive a :: PrimitiveType -> Type where
303 PrimPoint :: a -> Primitive a Point
304 PrimLine :: a -> a -> Primitive a Line
305 PrimTriangle :: a -> a -> a -> Primitive a Triangle
306
307type PrimitiveStream a t = [Primitive t a]
308
309mapPrimitive :: (a -> b) -> Primitive a p -> Primitive b p
310{- todo
311mapPrimitive f (PrimPoint a) = PrimPoint (f a)
312mapPrimitive f (PrimLine a b) = PrimLine (f a) (f b)
313mapPrimitive f (PrimTriangle a b c) = PrimTriangle (f a) (f b) (f c)
314-}
315
316fetch :: forall a t . (AttributeTuple t) => String -> t -> PrimitiveStream a t
317fetchArrays :: forall a t t' . (AttributeTuple t, t ~ HList (map ListElem (HListElem t'))) => t' -> PrimitiveStream a t
318
319mapPrimitives :: (a -> b) -> PrimitiveStream p a -> PrimitiveStream p b
320mapPrimitives f = map (mapPrimitive f)
321
322-------------------
323
324data Maybe a
325 = Nothing
326 | Just a
327-- deriving (Eq, Ord, Show)
328
329data Vector (n :: Nat) t
330
331type Fragment n t = Vector n (Maybe (SimpleFragment t))
332
333data SimpleFragment t = SimpleFragment
334 { sFragmentCoords :: Vec 3 Float
335 , sFragmentValue :: t
336 }
337
338type FragmentStream n t = [Fragment n t]
339
340customizeDepth :: (a -> Float) -> Fragment n a -> Fragment n a
341
342customizeDepths :: (a -> Float) -> FragmentStream n a -> FragmentStream n a
343customizeDepths f = map (customizeDepth f)
344
345filterFragment :: (a -> Bool) -> Fragment n a -> Fragment n a
346
347filterFragments :: (a -> Bool) -> FragmentStream n a -> FragmentStream n a
348filterFragments p = map (filterFragment p)
349
350mapFragment :: (a -> b) -> Fragment n a -> Fragment n b
351
352mapFragments :: (a -> b) -> FragmentStream n a -> FragmentStream n b
353mapFragments f = map (mapFragment f)
354
355
356data Interpolated t where 461data Interpolated t where
357 Smooth, NoPerspective 462 Smooth, NoPerspective
358 :: (Floating t) => Interpolated t 463 :: (Floating t) => Interpolated t
@@ -368,13 +473,6 @@ rasterizePrimitive
368 473
369rasterizePrimitives ctx is s = concat (map (rasterizePrimitive is ctx) s) 474rasterizePrimitives ctx is s = concat (map (rasterizePrimitive is ctx) s)
370 475
371data Image (n :: Nat) (t :: ImageSemantics) -- = Vector n [[t]]
372
373ColorImage :: forall a d t color . (Num t, color ~ VecScalar d t)
374 => color -> Image a (Color color)
375DepthImage :: forall a . Float -> Image a (Depth Float)
376StencilImage :: forall a . Int -> Image a (Stencil Int)
377
378type family ImageLC a :: Nat where ImageLC (Image n t) = n 476type family ImageLC a :: Nat where ImageLC (Image n t) = n
379 477
380allSame :: [a] -> Type 478allSame :: [a] -> Type
@@ -409,21 +507,21 @@ type family FragmentOperationSem a :: ImageSemantics where FragmentOperationSem
409 507
410Accumulate :: forall (n :: Nat) (c :: [Type]) . (b ~ map FragmentOperationSem c) => HList c -> FragmentStream n (HList (remSemantics' b)) -> FrameBuffer n b -> FrameBuffer n b 508Accumulate :: forall (n :: Nat) (c :: [Type]) . (b ~ map FragmentOperationSem c) => HList c -> FragmentStream n (HList (remSemantics' b)) -> FrameBuffer n b -> FrameBuffer n b
411 509
412type family ImageSem a :: ImageSemantics where ImageSem (Image n t) = t 510accumulateWith ctx x = (ctx, x)
511overlay cl (ctx, str) = Accumulate ctx str cl
413 512
414tfFrameBuffer t = map 'ImageSem t 513infixl 0 `overlay`
415 514
416class ValidFrameBuffer (a :: [ImageSemantics]) 515type family ImageSem a :: ImageSemantics where ImageSem (Image n t) = t
417instance ValidFrameBuffer a -- TODO
418 516
419head (x: _) = x 517--class ValidFrameBuffer (a :: [ImageSemantics])
518--instance ValidFrameBuffer a -- TODO
420 519
421FrameBuffer :: forall (a :: [Type]) . (sameLayerCounts a) => HList a -> FrameBuffer (ImageLC (head a)) (tfFrameBuffer a) 520FrameBuffer :: forall (a :: [Type]) . (sameLayerCounts a) => HList a -> FrameBuffer (ImageLC (head a)) (map ImageSem a)
422 521
423accumulate ctx fshader fstr fb = Accumulate ctx (mapFragments fshader fstr) fb 522imageFrame = FrameBuffer
424 523
425-- todo: remove 524accumulate ctx fshader fstr fb = Accumulate ctx (mapFragments fshader fstr) fb
426accumulationContext x = x
427 525
428-- texture support 526-- texture support
429PrjImage :: FrameBuffer 1 '[a] -> Image 1 a 527PrjImage :: FrameBuffer 1 '[a] -> Image 1 a
@@ -432,90 +530,7 @@ PrjImageColor :: FrameBuffer 1 '[Depth 'Float, Color '(Vec 4 Float)] -> Im
432data Output where 530data Output where
433 ScreenOut :: FrameBuffer a b -> Output 531 ScreenOut :: FrameBuffer a b -> Output
434 532
435------------------------------------------------------------------- 533renderFrame = ScreenOut
436-- * Builtin Primitive Functions *
437-- Arithmetic Functions (componentwise)
438
439PrimAdd, PrimSub, PrimMul :: Num (MatVecScalarElem a) => a -> a -> a
440PrimAddS, PrimSubS, PrimMulS :: (t ~ MatVecScalarElem a, Num t) => a -> t -> a
441PrimDiv, PrimMod :: (Num t, a ~ VecScalar d t) => a -> a -> a
442PrimDivS, PrimModS :: (Num t, a ~ VecScalar d t) => a -> t -> a
443PrimNeg :: Signed (MatVecScalarElem a) => a -> a
444-- Bit-wise Functions
445PrimBAnd, PrimBOr, PrimBXor :: (Integral t, a ~ VecScalar d t) => a -> a -> a
446PrimBAndS, PrimBOrS, PrimBXorS:: (Integral t, a ~ VecScalar d t) => a -> t -> a
447PrimBNot :: (Integral t, a ~ VecScalar d t) => a -> a
448PrimBShiftL, PrimBShiftR :: (Integral t, a ~ VecScalar d t, b ~ VecScalar d Word) => a -> b -> a
449PrimBShiftLS, PrimBShiftRS :: (Integral t, a ~ VecScalar d t) => a -> Word -> a
450-- Logic Functions
451PrimAnd, PrimOr, PrimXor :: Bool -> Bool -> Bool
452PrimNot :: forall a d . (a ~ VecScalar d Bool) => a -> a
453PrimAny, PrimAll :: VecScalar d Bool -> Bool
454
455-- Angle, Trigonometry and Exponential Functions
456PrimACos, PrimACosH, PrimASin, PrimASinH, PrimATan, PrimATanH, PrimCos, PrimCosH, PrimDegrees, PrimRadians, PrimSin, PrimSinH, PrimTan, PrimTanH, PrimExp, PrimLog, PrimExp2, PrimLog2, PrimSqrt, PrimInvSqrt
457 :: (a ~ VecScalar d Float) => a -> a
458PrimPow, PrimATan2 :: (a ~ VecScalar d Float) => a -> a -> a
459-- Common Functions
460PrimFloor, PrimTrunc, PrimRound, PrimRoundEven, PrimCeil, PrimFract
461 :: (a ~ VecScalar d Float) => a -> a
462PrimMin, PrimMax :: (Num t, a ~ VecScalar d t) => a -> a -> a
463PrimMinS, PrimMaxS :: (Num t, a ~ VecScalar d t) => a -> t -> a
464PrimIsNan, PrimIsInf :: (a ~ VecScalar d Float, b ~ VecScalar d Bool) => a -> b
465PrimAbs, PrimSign :: (Signed t, a ~ VecScalar d t) => a -> a
466PrimModF :: (a ~ VecScalar d Float) => a -> (a, a)
467PrimClamp :: (Num t, a ~ VecScalar d t) => a -> a -> a -> a
468PrimClampS :: (Num t, a ~ VecScalar d t) => a -> t -> t -> a
469PrimMix :: (a ~ VecScalar d Float) => a -> a -> a -> a
470PrimMixS :: (a ~ VecScalar d Float) => a -> a -> Float -> a
471PrimMixB :: (a ~ VecScalar d Float, b ~ VecScalar d Bool) => a -> a -> b -> a
472PrimStep :: (a ~ Vec d Float) => a -> a -> a
473PrimStepS :: (a ~ VecScalar d Float) => Float -> a -> a
474PrimSmoothStep :: (a ~ Vec d Float) => a -> a -> a -> a
475PrimSmoothStepS :: (a ~ VecScalar d Float) => Float -> Float -> a -> a
476
477-- Integer/Floatonversion Functions
478PrimFloatBitsToInt :: VecScalar d Float -> VecScalar d Int
479PrimFloatBitsToUInt :: VecScalar d Float -> VecScalar d Word
480PrimIntBitsToFloat :: VecScalar d Int -> VecScalar d Float
481PrimUIntBitsToFloat :: VecScalar d Word -> VecScalar d Float
482-- Geometric Functions
483PrimLength :: (a ~ VecScalar d Float) => a -> Float
484PrimDistance, PrimDot :: (a ~ VecScalar d Float) => a -> a -> Float
485PrimCross :: (a ~ VecScalar 3 Float) => a -> a -> a
486PrimNormalize :: (a ~ VecScalar d Float) => a -> a
487PrimFaceForward, PrimRefract :: (a ~ VecScalar d Float) => a -> a -> a -> a
488PrimReflect :: (a ~ VecScalar d Float) => a -> a -> a
489-- Matrix Functions
490PrimTranspose :: Mat h w a -> Mat w h a
491PrimDeterminant :: Mat s s a -> Float
492PrimInverse :: Mat s s a -> Mat s s a
493PrimOuterProduct :: Vec w a -> Vec h a -> Mat h w a
494PrimMulMatVec :: Mat h w a -> Vec w a -> Vec h a
495PrimMulVecMat :: Vec h a -> Mat h w a -> Vec w a
496PrimMulMatMat :: Mat i j a -> Mat j k a -> Mat i k a
497-- Vector and Scalar Relational Functions
498PrimLessThan, PrimLessThanEqual, PrimGreaterThan, PrimGreaterThanEqual, PrimEqualV, PrimNotEqualV
499 :: forall a d t b . (Num t, a ~ VecScalar d t, b ~ VecScalar d Bool) => a -> a -> b
500PrimEqual, PrimNotEqual :: forall a t . (t ~ MatVecScalarElem a) => a -> a -> Bool
501-- Fragment Processing Functions
502PrimDFdx, PrimDFdy, PrimFWidth
503 :: (a ~ VecScalar d Float) => a -> a
504-- Noise Functions
505PrimNoise1 :: VecScalar d Float -> Float
506PrimNoise2 :: VecScalar d Float -> Vec 2 Float
507PrimNoise3 :: VecScalar d Float -> Vec 3 Float
508PrimNoise4 :: VecScalar d Float -> Vec 4 Float
509
510{-
511-- Vec/Mat (de)construction
512PrimTupToV2 :: Component a => PrimFun stage ((a,a) -> V2 a)
513PrimTupToV3 :: Component a => PrimFun stage ((a,a,a) -> V3 a)
514PrimTupToV4 :: Component a => PrimFun stage ((a,a,a,a) -> V4 a)
515PrimV2ToTup :: Component a => PrimFun stage (V2 a -> (a,a))
516PrimV3ToTup :: Component a => PrimFun stage (V3 a -> (a,a,a))
517PrimV4ToTup :: Component a => PrimFun stage (V4 a -> (a,a,a,a))
518-}
519 534
520-------------------- 535--------------------
521-- * Texture support 536-- * Texture support
@@ -544,12 +559,7 @@ data Sampler = Sampler Filter EdgeMode Texture
544texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float 559texture2D :: Sampler -> Vec 2 Float -> Vec 4 Float
545 560
546 561
547accumulateWith ctx x = (ctx, x) 562-- todo: remove
548overlay cl (ctx, str) = Accumulate ctx str cl 563accumulationContext x = x
549renderFrame = ScreenOut
550imageFrame = FrameBuffer
551emptyDepthImage = DepthImage @1
552emptyColorImage = ColorImage @1
553 564
554infixl 0 `overlay`
555 565