module Graphics.Rendering.Ombra.D2 (
Object2D,
IsObject2D,
rect,
image,
sprite,
depth,
poly,
trans,
rot,
scale,
scaleV,
scaleTex,
scaleTexAR,
transform,
view,
viewScreen,
viewVP,
layerS,
transMat3,
rotMat3,
scaleMat3,
screenMat3,
Uniforms2D,
Image(..),
Depth(..),
Transform2(..),
View2(..),
) where
import Graphics.Rendering.Ombra.Backend hiding (Texture, Program)
import Graphics.Rendering.Ombra.Geometry
import Graphics.Rendering.Ombra.Draw
import Graphics.Rendering.Ombra.Layer
import Graphics.Rendering.Ombra.Object
import Graphics.Rendering.Ombra.Shapes
import Graphics.Rendering.Ombra.Internal.TList
import Graphics.Rendering.Ombra.Shader.Default2D (Image(..), Depth(..), Transform2(..), View2(..))
import Graphics.Rendering.Ombra.Shader.Program
import Graphics.Rendering.Ombra.Texture
import Graphics.Rendering.Ombra.Transformation
import Graphics.Rendering.Ombra.Vector
type Uniforms2D = '[Image, Depth, Transform2]
type Object2D = Object Uniforms2D Geometry2D
type IsObject2D gs is = ( Subset Geometry2D is, Subset (View2 ': Uniforms2D) gs
, ShaderVars is, ShaderVars gs )
rect :: GLES => Texture -> Object2D
rect = flip poly rectGeometry
poly :: GLES => Texture -> Geometry (i ': is) -> Object Uniforms2D (i ': is)
poly t g = withTexture t (Image -=) :~>
Depth -= 0 :~>
Transform2 -= idmtx :~>
geom g
image :: GLES => Texture -> Object2D
image t = scaleTexAR t $ rect t
depth :: (MemberGlobal Depth gs, GLES)
=> Float -> Object gs is -> Object gs is
depth d obj = const (Depth -= d) ~~> obj
sprite :: GLES => Texture -> Object2D
sprite t = scaleTex t $ rect t
view :: (ShaderVars gs, ShaderVars is, GLES)
=> Mat3 -> [Object gs is] -> Object (View2 ': gs) is
view m = viewVP $ const m
viewScreen :: (ShaderVars gs, ShaderVars is, GLES)
=> Mat3 -> [Object gs is] -> Object (View2 ': gs) is
viewScreen m = viewVP $ \s -> screenMat3 s .*. m
viewVP :: (ShaderVars gs, ShaderVars is, GLES)
=> (Vec2 -> Mat3) -> [Object gs is] -> Object (View2 ': gs) is
viewVP mf os = withFramebufferSize (\s -> View2 -= mf (tupleToVec s))
:~> mconcat os
layerS :: IsObject2D gs is => Object gs is -> Layer' s t ()
layerS = layer defaultProgram2D
trans :: (MemberGlobal Transform2 gs, GLES)
=> Vec2 -> Object gs is -> Object gs is
trans v = transform $ transMat3 v
rot :: (MemberGlobal Transform2 gs, GLES)
=> Float -> Object gs is -> Object gs is
rot a = transform $ rotMat3 a
scale :: (MemberGlobal Transform2 gs, GLES)
=> Float -> Object gs is -> Object gs is
scale f = transform $ scaleMat3 (Vec2 f f)
scaleV :: (MemberGlobal Transform2 gs, GLES)
=> Vec2 -> Object gs is -> Object gs is
scaleV v = transform $ scaleMat3 v
scaleTex :: (MemberGlobal Transform2 gs, GLES)
=> Texture -> Object gs is -> Object gs is
scaleTex t = transform' t $ scaleMat3
scaleTexAR :: (MemberGlobal Transform2 gs, GLES)
=> Texture -> Object gs is -> Object gs is
scaleTexAR t = transform' t $ (\(Vec2 w h) -> scaleMat3 $ Vec2 1 (h / w))
transform :: (MemberGlobal Transform2 gs, GLES)
=> Mat3 -> Object gs is -> Object gs is
transform m' o = (\m -> Transform2 -= m .*. m') ~~> o
transform' :: (MemberGlobal Transform2 gs, GLES)
=> Texture
-> (Vec2 -> Mat3)
-> Object gs is
-> Object gs is
transform' t m' o = (\m -> withTexSize t $
\s -> Transform2 -= m .*. m' (tupleToVec s)) ~~> o
screenMat3 :: Vec2
-> Mat3
screenMat3 (Vec2 w h) = Mat3 (Vec3 (2 / w) 0 0 )
(Vec3 0 ( 2 / h) 0 )
(Vec3 ( 1) 1 1 )
tupleToVec :: (Int, Int) -> Vec2
tupleToVec (w, h) = Vec2 (fromIntegral w) (fromIntegral h)