module Graphics.Rendering.Ombra.Generic (
Object((:~>)),
MemberGlobal((~~>)),
RemoveGlobal((*~>)),
nothing,
geom,
modifyGeometry,
Group,
group,
(~~),
groupEmpty,
groupGlobal,
depthTest,
depthMask,
colorMask,
ShaderVars,
VOShaderVars,
blend,
noBlend,
Blend.transparency,
Blend.additive,
stencil,
noStencil,
CullFace(..),
cull,
noCull,
Buffer(..),
Layer,
layer,
over,
clear,
subLayer,
colorSubLayer,
depthSubLayer,
colorDepthSubLayer,
colorStencilSubLayer,
colorSubLayer',
depthSubLayer',
colorDepthSubLayer',
colorStencilSubLayer',
buffersSubLayer,
buffersDepthSubLayer,
buffersStencilSubLayer,
Compatible,
Program,
program,
Global,
(-=),
globalTexture,
globalTexSize,
globalFramebufferSize,
CPUMirror,
globalMirror,
globalMirror',
Geometry,
AttrList(..),
mkGeometry,
extend,
remove,
Texture,
ActiveTexture,
mkTexture,
mkTextureFloat,
Filter(..),
setFilter,
Color(..),
colorTex,
GLES,
module Data.Vect.Float,
module Graphics.Rendering.Ombra.Color
) where
import Data.Typeable
import Data.Type.Equality
import Data.Vect.Float
import Data.Word (Word8)
import Graphics.Rendering.Ombra.Backend (GLES)
import qualified Graphics.Rendering.Ombra.Blend as Blend
import qualified Graphics.Rendering.Ombra.Stencil as Stencil
import Graphics.Rendering.Ombra.Geometry
import Graphics.Rendering.Ombra.Color
import Graphics.Rendering.Ombra.Draw
import Graphics.Rendering.Ombra.Types hiding (depthTest, depthMask, colorMask)
import Graphics.Rendering.Ombra.Internal.GL (ActiveTexture)
import Graphics.Rendering.Ombra.Internal.TList
import Graphics.Rendering.Ombra.Shader.CPU
import Graphics.Rendering.Ombra.Shader.Program
import Graphics.Rendering.Ombra.Shader.ShaderVar
import Graphics.Rendering.Ombra.Shader.Stages
import Graphics.Rendering.Ombra.Texture
groupEmpty :: Group gs is
groupEmpty = Empty
groupGlobal :: Global g -> Group gs is -> Group (g ': gs) is
groupGlobal = Global
blend :: Blend.Mode -> Group gs is -> Group gs is
blend m = Blend $ Just m
noBlend :: Group gs is -> Group gs is
noBlend = Blend Nothing
stencil :: Stencil.Mode -> Group gs is -> Group gs is
stencil m = Stencil $ Just m
noStencil :: Group gs is -> Group gs is
noStencil = Stencil Nothing
depthTest :: Bool -> Group gs is -> Group gs is
depthTest = DepthTest
depthMask :: Bool -> Group gs is -> Group gs is
depthMask = DepthMask
colorMask :: (Bool, Bool, Bool, Bool) -> Group gs is -> Group gs is
colorMask = ColorMask
cull :: CullFace -> Group gs is -> Group gs is
cull m = Cull $ Just m
noCull :: Group gs is -> Group gs is
noCull = Cull Nothing
nothing :: Object '[] '[]
nothing = NoMesh
geom :: Geometry i -> Object '[] i
geom = Mesh
class MemberGlobal g gs where
(~~>) :: (Uniform 'S g)
=> (Draw (CPU 'S g) -> Global g)
-> Object gs is
-> Object gs is
instance MemberGlobal g (g ': gs) where
f ~~> (_ := c :~> o) = f c :~> o
_ ~~> (glob :~> o) = glob :~> o
instance ((g == g1) ~ False, MemberGlobal g gs) =>
MemberGlobal g (g1 ': gs) where
f ~~> (g :~> o) = g :~> (f ~~> o)
infixr 2 ~~>
class RemoveGlobal g gs gs' where
(*~>) :: (a -> g) -> Object gs is -> Object gs' is
instance RemoveGlobal g (g ': gs) gs where
_ *~> (_ :~> o) = o
instance ((g == g1) ~ False, RemoveGlobal g gs gs') =>
RemoveGlobal g (g1 ': gs) (g1 ': gs') where
r *~> (g :~> o) = g :~> (r *~> o)
infixr 2 *~>
modifyGeometry :: (Empty is ~ False)
=> (Geometry is -> Geometry is')
-> Object gs is -> Object gs is'
modifyGeometry fg (g :~> o) = g :~> modifyGeometry fg o
modifyGeometry fg (Mesh g) = Mesh $ fg g
(-=) :: (ShaderVar g, Uniform 'S g) => (a -> g) -> CPU 'S g -> Global g
g -= c = g := return c
infixr 4 -=
globalTexture :: (Uniform 'S g, CPU 'S g ~ ActiveTexture, ShaderVar g, GLES)
=> (a -> g) -> Texture -> Global g
globalTexture g c = g := textureUniform c
globalTexSize :: (ShaderVar g, Uniform 'S g, GLES)
=> (a -> g) -> Texture
-> ((Int, Int) -> CPU 'S g) -> Global g
globalTexSize g t fc = g := (fc <$> textureSize t)
globalFramebufferSize :: (ShaderVar g, Uniform 'S g) => (a -> g)
-> (Vec2 -> CPU 'S g) -> Global g
globalFramebufferSize g fc = g := (fc . tupleToVec <$>
(viewportSize <$> drawGet))
tupleToVec :: (Int, Int) -> Vec2
tupleToVec (x, y) = Vec2 (fromIntegral x) (fromIntegral y)
globalMirror :: (ShaderVar g, Uniform 'M g) => Proxy g -> CPU 'M g -> Global g
globalMirror g c = Mirror g $ return c
globalMirror' :: (GLES, ShaderVar g, Uniform 'M g)
=> Proxy g
-> [Texture]
-> ([(ActiveTexture, (Int, Int))] -> Vec2 -> CPU 'M g)
-> Global g
globalMirror' g ts f = Mirror g $ f <$> mapM ( \t -> (,) <$> textureUniform t
<*> textureSize t) ts
<*> (tupleToVec . viewportSize <$> drawGet)
group :: (ShaderVars gs, ShaderVars is) => [Object gs is] -> Group gs is
group = foldr (\obj grp -> grp ~~ Object obj) groupEmpty
type EqualMerge x y v = EqualOrErr x y (Text "Can't merge groups with " :<>:
Text "different " :<>: v :<>:
Text "." :$$:
Text " Left group " :<>: v :<>:
Text ": " :<>: ShowType x :$$:
Text " Right group " :<>: v :<>:
Text ": " :<>: ShowType y)
(~~) :: (EqualMerge gs gs' (Text "globals"), EqualMerge is is' (Text "inputs"))
=> Group gs is -> Group gs' is'
-> Group (Union gs gs') (Union is is')
(~~) = Append
layer :: (Subset progAttr grpAttr, Subset progUni grpUni)
=> Program progUni progAttr -> Group grpUni grpAttr -> Layer
layer = Layer
infixl 1 `over`
over :: Layer -> Layer -> Layer
over = OverLayer
clear :: [Buffer] -> Layer -> Layer
clear = ClearLayer
colorTex :: GLES => Color -> Texture
colorTex c = mkTexture 1 1 [ c ]
subLayer :: Int -> Int -> Layer -> (Texture -> Layer) -> Layer
subLayer = colorSubLayer
colorSubLayer :: Int
-> Int
-> Layer
-> (Texture -> Layer)
-> Layer
colorSubLayer w h l = subRenderLayer . renderColor w h l
depthSubLayer :: Int
-> Int
-> Layer
-> (Texture -> Layer)
-> Layer
depthSubLayer w h l = subRenderLayer . renderDepth w h l
colorDepthSubLayer :: Int
-> Int
-> Layer
-> (Texture -> Texture -> Layer)
-> Layer
colorDepthSubLayer w h l = subRenderLayer . renderColorDepth w h l
colorStencilSubLayer :: Int
-> Int
-> Layer
-> (Texture -> Layer)
-> Layer
colorStencilSubLayer w h l = subRenderLayer . renderColorStencil w h l
colorSubLayer'
:: Int
-> Int
-> Layer
-> Int
-> Int
-> Int
-> Int
-> (Texture -> [Color] -> Layer)
-> Layer
colorSubLayer' w h l rx ry rw rh =
subRenderLayer . renderColorInspect w h l rx ry rw rh
depthSubLayer'
:: Int
-> Int
-> Layer
-> Int
-> Int
-> Int
-> Int
-> (Texture -> [Word8] -> Layer)
-> Layer
depthSubLayer' w h l rx ry rw rh =
subRenderLayer . renderDepthInspect w h l rx ry rw rh
colorDepthSubLayer'
:: Int
-> Int
-> Layer
-> Int
-> Int
-> Int
-> Int
-> (Texture -> Texture -> [Color] -> [Word8] -> Layer)
-> Layer
colorDepthSubLayer' w h l rx ry rw rh =
subRenderLayer . renderColorDepthInspect w h l rx ry rw rh
colorStencilSubLayer'
:: Int
-> Int
-> Layer
-> Int
-> Int
-> Int
-> Int
-> (Texture -> [Color] -> Layer)
-> Layer
colorStencilSubLayer' w h l rx ry rw rh =
subRenderLayer . renderColorStencilInspect w h l rx ry rw rh
buffersSubLayer :: Int
-> Int
-> Int
-> Layer
-> ([Texture] -> Layer)
-> Layer
buffersSubLayer w h n l = subRenderLayer . renderBuffers w h n l
buffersDepthSubLayer :: Int
-> Int
-> Int
-> Layer
-> ([Texture] -> Texture -> Layer)
-> Layer
buffersDepthSubLayer w h n l = subRenderLayer . renderBuffersDepth w h n l
buffersStencilSubLayer :: Int
-> Int
-> Int
-> Layer
-> ([Texture] -> Layer)
-> Layer
buffersStencilSubLayer w h n l = subRenderLayer . renderBuffersStencil w h n l
subRenderLayer :: RenderLayer Layer -> Layer
subRenderLayer = SubLayer
renderColor :: Int -> Int -> Layer -> (Texture -> a) -> RenderLayer a
renderColor w h l f = RenderLayer False [ColorLayer, DepthLayer] w h 0 0 0 0
False False l $ \[t, _] _ _ -> f t
renderDepth :: Int -> Int -> Layer -> (Texture -> a) -> RenderLayer a
renderDepth w h l f =
RenderLayer False [DepthLayer] w h 0 0 0 0 False False l $
\[t] _ _ -> f t
renderColorDepth :: Int
-> Int
-> Layer
-> (Texture -> Texture -> a)
-> RenderLayer a
renderColorDepth w h l f =
RenderLayer False [ColorLayer, DepthLayer] w h 0 0 0 0 False False l $
\[ct, dt] _ _ -> f ct dt
renderColorStencil :: Int
-> Int
-> Layer
-> (Texture -> a)
-> RenderLayer a
renderColorStencil w h l f =
RenderLayer False [ColorLayer, DepthStencilLayer] w h 0 0 0 0
False False l $
\[ct, _] _ _ -> f ct
renderColorInspect :: Int
-> Int
-> Layer
-> Int
-> Int
-> Int
-> Int
-> (Texture -> [Color] -> a)
-> RenderLayer a
renderColorInspect w h l rx ry rw rh f =
RenderLayer False [ColorLayer, DepthLayer] w h rx ry
rw rh True False l $
\[t, _] (Just c) _ -> f t c
renderDepthInspect :: Int
-> Int
-> Layer
-> Int
-> Int
-> Int
-> Int
-> (Texture -> [Word8] -> a)
-> RenderLayer a
renderDepthInspect w h l rx ry rw rh f =
RenderLayer False [DepthLayer] w h rx ry rw rh False True l $
\[t] _ (Just d) -> f t d
renderColorDepthInspect :: Int
-> Int
-> Layer
-> Int
-> Int
-> Int
-> Int
-> (Texture -> Texture -> [Color] -> [Word8] -> a)
-> RenderLayer a
renderColorDepthInspect w h l rx ry rw rh f =
RenderLayer False [ColorLayer, DepthLayer] w h rx ry rw rh True True l $
\[ct, dt] (Just c) (Just d) -> f ct dt c d
renderColorStencilInspect :: Int
-> Int
-> Layer
-> Int
-> Int
-> Int
-> Int
-> (Texture -> [Color] -> a)
-> RenderLayer a
renderColorStencilInspect w h l rx ry rw rh f =
RenderLayer False [ColorLayer, DepthStencilLayer] w h rx ry
rw rh True False l $
\[t, _] (Just c) _ -> f t c
renderBuffers :: Int -> Int -> Int -> Layer -> ([Texture] -> a) -> RenderLayer a
renderBuffers w h n l f =
RenderLayer True (DepthLayer : map BufferLayer [0 .. n 1]) w h
0 0 0 0 False False l $ \(_ : ts) _ _ -> f ts
renderBuffersDepth :: Int
-> Int
-> Int
-> Layer
-> ([Texture] -> Texture -> a)
-> RenderLayer a
renderBuffersDepth w h n l f =
RenderLayer True (DepthLayer : map BufferLayer [0 .. n 1]) w h
0 0 0 0 False False l $ \(dt : ts) _ _ -> f ts dt
renderBuffersStencil :: Int
-> Int
-> Int
-> Layer
-> ([Texture] -> a)
-> RenderLayer a
renderBuffersStencil w h n l f =
RenderLayer True (DepthStencilLayer : map BufferLayer [0 .. n 1]) w h
0 0 0 0 False False l $ \(_ : ts) _ _ -> f ts