module FWGL.Graphics.D2 (
Element,
rect,
image,
depth,
sprite,
Geometry,
Geometry2,
geom,
mkGeometry2,
module FWGL.Graphics.Color,
Texture,
C.textureURL,
C.textureFile,
C.colorTex,
mkTexture,
V2(..),
pos,
rot,
scale,
scaleV,
transform,
Layer,
elements,
view,
layer,
layerPrg,
program,
C.subLayer,
Object,
object,
object1,
(C.~~),
C.global,
C.globalTexture,
C.globalTexSize,
viewObject,
DefaultUniforms2D,
Image(..),
Depth(..),
Transform2(..),
View2(..),
V3(..),
M3(..),
mat3,
mul3,
idMat3,
transMat3,
rotMat3,
scaleMat3
) where
import Control.Applicative
import FWGL.Backend hiding (Texture, Image, Program)
import FWGL.Geometry
import qualified FWGL.Graphics.Custom as C
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.Vector
data Element = Element Float Texture (Draw M3) (Geometry Geometry2)
rect :: GLES => V2 -> Texture -> Element
rect v t = Element 0 t (return idMat3) $ rectGeometry v
geom :: Texture -> Geometry Geometry2 -> Element
geom t = Element 0 t $ return idMat3
image :: BackendIO
=> Float
-> Texture -> Element
image s t = Element 0 t ((\(w, h) -> scaleMat3 (V2 1 $ h /w)) <$> textureSize t)
(rectGeometry $ V2 s s)
depth :: Float -> Element -> Element
depth d (Element _ t m g) = Element d t m g
sprite :: BackendIO => Texture -> Element
sprite t = Element 0 t ((\(w, h) -> scaleMat3 $ V2 w h) <$> textureSize t)
(rectGeometry $ V2 1 1)
object :: BackendIO => M3 -> [Element] -> Object DefaultUniforms2D Geometry2
object m = viewObject m . foldl acc ObjectEmpty
where acc o e = o C.~~ object1 e
object1 :: BackendIO => Element -> Object '[Image, Depth, Transform2] Geometry2
object1 (Element d t m g) = C.globalTexture (undefined :: Image) t $
C.global (undefined :: Depth) d $
C.globalDraw (undefined :: Transform2) m $
C.static g
elements :: BackendIO => [Element] -> Layer
elements = layer . object idMat3
view :: BackendIO => M3 -> [Element] -> Layer
view m = layer . object m
viewObject :: BackendIO => M3 -> Object gs Geometry2
-> Object (View2 ': gs) Geometry2
viewObject = C.global (undefined :: View2)
layer :: BackendIO => Object DefaultUniforms2D Geometry2 -> Layer
layer = layerPrg defaultProgram2D
layerPrg :: (BackendIO, Subset og pg) => Program pg Geometry2
-> Object og Geometry2 -> Layer
layerPrg = C.layer
pos :: V2 -> Element -> Element
pos v = transform $ transMat3 v
rot :: Float -> Element -> Element
rot a = transform $ rotMat3 a
scale :: Float -> Element -> Element
scale f = transform $ scaleMat3 (V2 f f)
scaleV :: V2 -> Element -> Element
scaleV v = transform $ scaleMat3 v
transform :: M3 -> Element -> Element
transform m' (Element d t m g) = Element d t (mul3 <$> m <*> pure m') g