module FWGL.Graphics.D2 (
module FWGL.Graphics.Generic,
Object2D,
IsObject2D,
Group2D,
IsGroup2D,
rect,
image,
sprite,
depth,
Geometry2D,
poly,
mkGeometry2D,
trans,
rot,
scale,
scaleV,
scaleTex,
scaleTexAR,
transform,
view,
viewScreen,
viewVP,
layerS,
transMat3,
rotMat3,
scaleMat3,
screenMat3,
Uniforms2D,
Image(..),
Depth(..),
Transform2(..),
View2(..),
) where
import Control.Applicative
import Data.Vect.Float
import FWGL.Backend hiding (Texture, Image, Program)
import FWGL.Geometry
import FWGL.Graphics.Generic
import FWGL.Graphics.Color
import FWGL.Graphics.Draw
import FWGL.Graphics.Shapes
import FWGL.Graphics.Types hiding (program)
import FWGL.Graphics.Texture
import FWGL.Internal.TList
import FWGL.Shader.Default2D (Image(..), Depth(..), Transform2(..), View2(..))
import FWGL.Shader.Program
import FWGL.Transformation
type Uniforms2D = '[Image, Depth, Transform2]
type Object2D = Object Uniforms2D Geometry2D
type Group2D = Group (View2 ': Uniforms2D) Geometry2D
type IsObject2D globals inputs = ( Subset Geometry2D inputs
, Subset Uniforms2D globals
, Set inputs, Set globals )
type IsGroup2D gs is = ( Subset Geometry2D is, Subset (View2 ': Uniforms2D) gs
, Set is, Set gs )
rect :: Backend => Texture -> Object2D
rect = flip poly . rectGeometry $ Vec2 1 1
poly :: (IsObject2D Uniforms2D is, Backend)
=> Texture -> Geometry is -> Object Uniforms2D is
poly t g = globalTexture Image t :~>
Depth -= 0 :~> Transform2 -= idmtx :~> geom g
image :: Backend => 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 :: BackendIO => Texture -> Object2D
sprite t = scaleTex t $ rect t
view :: (IsObject2D gs is, Backend)
=> Mat3 -> [Object gs is] -> Group (View2 ': gs) is
view m = viewVP $ const m
viewScreen :: (IsObject2D gs is, Backend)
=> Mat3 -> [Object gs is] -> Group (View2 ': gs) is
viewScreen m = viewVP $ \s -> screenMat3 s .*. m
viewVP :: (IsObject2D gs is, Backend)
=> (Vec2 -> Mat3) -> [Object gs is] -> Group (View2 ': gs) is
viewVP mf = globalGroup (globalFramebufferSize View2 mf) . group
layerS :: IsGroup2D gs is => Group gs is -> Layer
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, Backend)
=> Texture -> Object gs is -> Object gs is
scaleTex t = transformDraw $
(\(w, h) -> scaleMat3 $ Vec2 w h) <$> textureSize t
scaleTexAR :: (MemberGlobal Transform2 gs, Backend)
=> Texture -> Object gs is -> Object gs is
scaleTexAR t = transformDraw $
(\(w, h) -> scaleMat3 $ Vec2 1 (h / w)) <$> textureSize t
transform :: (MemberGlobal Transform2 gs, GLES)
=> Mat3 -> Object gs is -> Object gs is
transform m' o = (\m -> Transform2 := (.*. m') <$> m) ~~> o
transformDraw :: (MemberGlobal Transform2 gs, GLES)
=> Draw Mat3 -> Object gs is -> Object gs is
transformDraw m' o = (\m -> Transform2 := (.*.) <$> m <*> m') ~~> o
screenMat3 :: Vec2
-> Mat3
screenMat3 (Vec2 w h) = Mat3 (Vec3 (2 / w) 0 0 )
(Vec3 0 ( 2 / h) 0 )
(Vec3 ( 1) 1 1 )