module Graphics.Rendering.Ombra.Layer.Internal where
import Data.Word (Word8)
import Graphics.Rendering.Ombra.Color
import Graphics.Rendering.Ombra.Internal.TList
import Graphics.Rendering.Ombra.Object.Internal
import Graphics.Rendering.Ombra.Shader.Program
import Graphics.Rendering.Ombra.Texture.Internal
type Layer = Layer' Drawable () ()
data Layer' (s :: LayerStatus) t a where
Layer :: (Subset pi oi, Subset pg og)
=> Program pg pi
-> Object og oi
-> Layer' s t ()
TextureLayer :: Bool
-> [LayerType]
-> (Int, Int)
-> (Int, Int, Int, Int)
-> Bool
-> Bool
-> Layer' s t a
-> Layer' NonDrawable t
(a, [TTexture t], Maybe [Color], Maybe [Word8])
Permanent :: TTexture t -> Layer' NonDrawable t Texture
WithTTextures :: [TTexture t]
-> ([Texture] -> Layer)
-> Layer' NonDrawable t ()
Free :: (forall t. Layer' NonDrawable t a) -> Layer' s t a
Clear :: [Buffer] -> Layer' s t ()
Cast :: Layer' Drawable t a -> Layer' Drawable t' a
Bind :: Layer' s t a -> (a -> Layer' s t b) -> Layer' s t b
Return :: a -> Layer' s t a
newtype TTexture t = TTexture LoadedTexture deriving Eq
data LayerStatus = Drawable | NonDrawable
data Buffer = ColorBuffer | DepthBuffer | StencilBuffer
data LayerType = ColorLayer
| DepthLayer
| DepthStencilLayer
| BufferLayer Int deriving Eq
instance Functor (Layer' s t) where
fmap f = flip Bind $ Return . f
instance Applicative (Layer' s t) where
lf <*> lx = Bind lf $ \f -> Bind lx $ \x -> Return $ f x
pure = Return
instance Monad (Layer' s t) where
(>>=) = Bind
return = Return
clear :: [Buffer] -> Layer' s t ()
clear = Clear
drawable :: (forall t. Layer' NonDrawable t a) -> Layer' s t a
drawable = Free
castDrawable :: Layer' Drawable t a -> Layer' Drawable t' a
castDrawable = Cast
castLayer :: Layer -> Layer' Drawable t ()
castLayer = castDrawable
permanent :: TTexture t -> Layer' NonDrawable t Texture
permanent = Permanent
withTTexture :: TTexture t -> (Texture -> Layer) -> Layer' NonDrawable t ()
withTTexture pt f = WithTTextures [pt] $ \[t] -> f t
withTTextures :: [TTexture t] -> ([Texture] -> Layer) -> Layer' NonDrawable t ()
withTTextures = WithTTextures
castTTexture :: TTexture t -> TTexture t'
castTTexture (TTexture lt) = TTexture lt
depthToTexture :: Int
-> Int
-> Layer' s t a
-> Layer' NonDrawable t (a, TTexture t)
depthToTexture w h l =
fmap (\(x, [t], _, _) -> (x, t)) $
TextureLayer False [DepthLayer] (w, h) (0, 0, 0, 0)
False False l
colorDepthToTexture :: Int
-> Int
-> Layer' s t a
-> Layer' NonDrawable t (a, TTexture t, TTexture t)
colorDepthToTexture w h l =
fmap (\(x, [ct, dt], _, _) -> (x, ct, dt)) $
TextureLayer False [ColorLayer, DepthLayer] (w, h) (0, 0, 0, 0)
False False l
colorStencilToTexture :: Int
-> Int
-> Layer' s t a
-> Layer' NonDrawable t (a, TTexture t)
colorStencilToTexture w h l =
fmap (\(x, [ct, _], _, _) -> (x, ct)) $
TextureLayer False [ColorLayer, DepthStencilLayer] (w, h)
(0, 0, 0, 0) False False l
colorToTexture' :: Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Layer' s t a
-> Layer' NonDrawable t (a, TTexture t, [Color])
colorToTexture' w h rx ry rw rh l =
fmap (\(x, [t, _], Just c, _) -> (x, t, c)) $
TextureLayer False [ColorLayer, DepthLayer] (w, h)
(rx, ry, rw, rh) True False l
depthToTexture' :: Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Layer' s t a
-> Layer' NonDrawable t (a, TTexture t, [Word8])
depthToTexture' w h rx ry rw rh l =
fmap (\(x, [t], _, Just d) -> (x, t, d)) $
TextureLayer False [DepthLayer] (w, h) (rx, ry, rw, rh)
False True l
colorDepthToTexture' :: Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Layer' s t a
-> Layer' NonDrawable t
(a, TTexture t, TTexture t, [Color], [Word8])
colorDepthToTexture' w h rx ry rw rh l =
fmap (\(x, [ct, dt], Just c, Just d) -> (x, ct, dt, c, d)) $
TextureLayer False [ColorLayer, DepthLayer] (w, h)
(rx, ry, rw, rh) True True l
colorStencilToTexture' :: Int
-> Int
-> Int
-> Int
-> Int
-> Int
-> Layer' s t a
-> Layer' NonDrawable t (a, TTexture t, [Color])
colorStencilToTexture' w h rx ry rw rh l =
fmap (\(x, [t, _], Just c, _) -> (x, t, c)) $
TextureLayer False [ColorLayer, DepthStencilLayer] (w, h)
(rx, ry, rw, rh) True False l
buffersDepthToTexture :: Int
-> Int
-> Int
-> Layer' s t a
-> Layer' NonDrawable t (a, [TTexture t], TTexture t)
buffersDepthToTexture w h n l =
fmap (\(x, dt : ts, _, _) -> (x, ts, dt)) $
TextureLayer True (DepthLayer : map BufferLayer [0 .. n 1])
(w, h) (0, 0, 0, 0) False False l
buffersStencilToTexture :: Int
-> Int
-> Int
-> Layer' s t a
-> Layer' NonDrawable t (a, [TTexture t])
buffersStencilToTexture w h n l =
fmap (\(x, _ : ts, _, _) -> (x, ts)) $
TextureLayer True
(DepthStencilLayer : map BufferLayer [0 .. n 1])
(w, h) (0, 0, 0, 0) False False l