module FWGL.Graphics.Generic (
Object((:~>)),
MemberGlobal((~~>)),
RemoveGlobal((*~>)),
nothing,
geom,
modifyGeometry,
Group,
group,
(~~),
unsafeJoin,
emptyGroup,
globalGroup,
Layer,
layer,
combineLayers,
subLayer,
depthSubLayer,
subRenderLayer,
renderColor,
renderDepth,
renderColorDepth,
renderColorInspect,
renderDepthInspect,
renderColorDepthInspect,
Program,
program,
Global((:=)),
(-=),
globalTexture,
globalTexSize,
globalFramebufferSize,
Geometry,
AttrList(..),
mkGeometry,
extend,
remove,
Texture,
mkTexture,
textureURL,
textureFile,
Color(..),
colorTex,
module Data.Vect.Float,
module FWGL.Graphics.Color
) where
import Control.Applicative
import Data.Typeable
import Data.Type.Equality
import Data.Vect.Float
import Data.Word (Word8)
import FRP.Yampa
import FWGL.Backend (BackendIO, GLES)
import FWGL.Geometry
import FWGL.Graphics.Color
import FWGL.Graphics.Draw
import FWGL.Graphics.Types hiding (program)
import FWGL.Internal.GL (GLES, ActiveTexture)
import FWGL.Internal.TList
import FWGL.Shader.CPU
import FWGL.Shader.Program
import FWGL.Graphics.Texture
import Unsafe.Coerce
emptyGroup :: Group is gs
emptyGroup = Empty
globalGroup :: UniformCPU c g => Global g -> Group gs is -> Group (g ': gs) is
globalGroup = Global
nothing :: Object '[] '[]
nothing = NoMesh
geom :: Geometry i -> Object '[] i
geom = Mesh
class MemberGlobal g gs where
(~~>) :: (UniformCPU c g)
=> (Draw c -> Global g)
-> Object gs is
-> Object gs is
instance MemberGlobal g (g ': gs) where
f ~~> (g := c :~> o) = f (uniformCastCPU (g undefined) c) :~> o
instance ((g == g1) ~ False, MemberGlobal g gs) =>
MemberGlobal g (g1 ': gs) where
f ~~> (g :~> o) = g :~> (f ~~> o)
uniformCastCPU :: (UniformCPU c g, UniformCPU c' g) => g -> k c -> k c'
uniformCastCPU _ = unsafeCoerce
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
(-=) :: (Typeable g, UniformCPU c g) => (a -> g) -> c -> Global g
g -= c = g := return c
infixr 4 -=
globalTexture :: (BackendIO, Typeable g, UniformCPU ActiveTexture g)
=> (a -> g) -> Texture -> Global g
globalTexture g c = g := textureUniform c
globalTexSize :: (BackendIO, Typeable g, UniformCPU c g) => (a -> g) -> Texture
-> ((Int, Int) -> c) -> Global g
globalTexSize g t fc = g := (fc <$> textureSize t)
globalFramebufferSize :: (BackendIO, Typeable g, UniformCPU c g) => (a -> g)
-> (Vec2 -> c) -> Global g
globalFramebufferSize g fc = g := (fc . tupleToVec <$>
(viewportSize <$> drawState))
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
(~~) :: (Equal gs gs', Equal is is')
=> 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 [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 [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 [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 [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 [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 [ColorLayer, DepthLayer] w h rx ry rw rh True True l $
\[ct, dt] (Just c) (Just d) -> f ct dt c d