module Graphics.Rendering.Ombra.Generic (
Object((:~>)),
MemberGlobal((~~>)),
RemoveGlobal((*~>)),
nothing,
geom,
modifyGeometry,
Group,
group,
(~~),
unsafeJoin,
emptyGroup,
globalGroup,
depthTest,
blend,
noBlend,
Blend.transparency,
Blend.additive,
Layer,
layer,
combineLayers,
subLayer,
depthSubLayer,
subRenderLayer,
RenderLayer,
renderColor,
renderDepth,
renderColorDepth,
renderColorInspect,
renderDepthInspect,
renderColorDepthInspect,
renderBuffers,
Program,
program,
Global,
(-=),
globalTexture,
globalTexSize,
globalFramebufferSize,
Geometry,
AttrList(..),
mkGeometry,
extend,
remove,
Texture,
mkTexture,
Color(..),
colorTex,
GLES,
module Data.Vect.Float,
module Graphics.Rendering.Ombra.Color
) where
import Control.Applicative
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 Graphics.Rendering.Ombra.Geometry
import Graphics.Rendering.Ombra.Color
import Graphics.Rendering.Ombra.Draw
import Graphics.Rendering.Ombra.Types hiding (program, depthTest)
import Graphics.Rendering.Ombra.Internal.GL (GLES, 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.Texture
import Unsafe.Coerce
emptyGroup :: Group is gs
emptyGroup = Empty
globalGroup :: Global g -> Group gs is -> Group (g ': gs) is
globalGroup = 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
depthTest :: Bool -> Group gs is -> Group gs is
depthTest = DepthTest
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 ~~> (g := c :~> o) = f c :~> 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))
where tupleToVec (x, y) = Vec2 (fromIntegral x) (fromIntegral y)
group :: (Set is, Set gs) => [Object is gs] -> Group is gs
group = foldr (\obj grp -> grp ~~ Object obj) emptyGroup
type EqualJoin x y v = EqualOrErr x y (Text "Can't join groups with " :<>:
Text "different " :<>: v :<>:
Text "." :$$:
Text " Left group " :<>: v :<>:
Text ": " :<>: ShowType x :$$:
Text " Right group " :<>: v :<>:
Text ": " :<>: ShowType y)
(~~) :: (EqualJoin gs gs' (Text "globals"), EqualJoin is is' (Text "inputs"))
=> Group gs is -> Group gs' is'
-> Group (Union gs gs') (Union is is')
(~~) = Append
unsafeJoin :: Group gs is -> Group gs' is'
-> Group (Union gs gs') (Union is is')
unsafeJoin = Append
layer :: (Subset progAttr grpAttr, Subset progUni grpUni)
=> Program progUni progAttr -> Group grpUni grpAttr -> Layer
layer = Layer
combineLayers :: [Layer] -> Layer
combineLayers = MultiLayer
colorTex :: GLES => Color -> Texture
colorTex c = mkTexture 1 1 [ c ]
subLayer :: Int
-> Int
-> Layer
-> (Texture -> [Layer])
-> Layer
subLayer w h l = subRenderLayer . renderColor w h l
depthSubLayer :: Int
-> Int
-> Layer
-> (Texture -> [Layer])
-> Layer
depthSubLayer w h l = subRenderLayer . renderDepth w h 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
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
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