Rendering optimisations (mainly inlining)
This commit is contained in:
+31
-12
@@ -63,7 +63,7 @@ import Picture.Data
|
||||
--import Data.Bifunctor
|
||||
--import qualified Data.DList as DL
|
||||
--import Graphics.Rendering.OpenGL (lineWidth, ($=))
|
||||
import Control.Lens
|
||||
--import Control.Lens
|
||||
|
||||
blank :: Picture
|
||||
{-# INLINE blank #-}
|
||||
@@ -160,17 +160,16 @@ translate3 :: Float -> Float -> Point3 -> Point3
|
||||
translate3 !a !b !(V3 x y z) = V3 (x+a) (y+b) z
|
||||
|
||||
translate :: Float -> Float -> Picture -> Picture
|
||||
--{-# INLINE translate #-}
|
||||
--translate x y = map $ second $ overPos (translate3 x y)
|
||||
{-# INLINE translate #-}
|
||||
translate !x !y = map $! overPos $! translate3 x y
|
||||
|
||||
setDepth :: Float -> Picture -> Picture
|
||||
--{-# INLINE setDepth #-}
|
||||
{-# INLINE setDepth #-}
|
||||
--setDepth d = map $ second $ overPos (\(x,y,_) -> (x,y,d))
|
||||
setDepth d = map $ overPos (\(V3 x y _) -> V3 x y d)
|
||||
|
||||
addDepth :: Float -> Picture -> Picture
|
||||
--{-# INLINE addDepth #-}
|
||||
{-# INLINE addDepth #-}
|
||||
--addDepth d = map $ second $ overPos (\(x,y,z) -> (x,y,z+d))
|
||||
addDepth d = map $ overPos (\(V3 x y z) -> V3 x y (z+d))
|
||||
|
||||
@@ -185,12 +184,12 @@ scale3 :: Float -> Float -> Point3 -> Point3
|
||||
scale3 a b (V3 x y z) = (V3 (x*a) (y*b) (z))
|
||||
|
||||
scale :: Float -> Float -> Picture -> Picture
|
||||
--{-# INLINE scale #-}
|
||||
{-# INLINE scale #-}
|
||||
--scale x y = map . second . overPos $ scale3 x y
|
||||
scale x y = map $ overPos $ scale3 x y
|
||||
|
||||
rotate :: Float -> Picture -> Picture
|
||||
--{-# INLINE rotate #-}
|
||||
{-# INLINE rotate #-}
|
||||
rotate a = map $ overPos $ rotate3 a
|
||||
|
||||
pictures :: [Picture] -> Picture
|
||||
@@ -230,12 +229,10 @@ text s = map f $ stringToList s
|
||||
|
||||
line :: [Point2] -> Picture
|
||||
{-# INLINE line #-}
|
||||
--line = Line
|
||||
line = flip thickLine 1
|
||||
|
||||
lineCol :: [(Point2,RGBA)] -> Picture
|
||||
{-# INLINE lineCol #-}
|
||||
--lineCol = LineCol
|
||||
lineCol = flip thickLineCol 1
|
||||
|
||||
thickLine :: [Point2] -> Float -> Picture
|
||||
@@ -296,6 +293,7 @@ thickArc startA endA rad wdth
|
||||
w = 1 - wdth / r
|
||||
|
||||
thickArcHelp :: Float -> Float -> Float -> Float -> [Verx]
|
||||
{-# INLINE thickArcHelp #-}
|
||||
thickArcHelp startA endA rad wdth = map f
|
||||
[( (V3 0 0 0),black,(V3 0 0 wdth))
|
||||
,((V3 xa ya 0),black,(V3 1 0 wdth))
|
||||
@@ -330,9 +328,23 @@ chartreuse= V4 0.5 1 0 1
|
||||
orange = V4 1 0.5 0 1
|
||||
white = V4 1 1 1 1
|
||||
black = V4 0 0 0 1
|
||||
|
||||
{-# INLINE red #-}
|
||||
{-# INLINE green #-}
|
||||
{-# INLINE blue #-}
|
||||
{-# INLINE yellow #-}
|
||||
{-# INLINE cyan #-}
|
||||
{-# INLINE magenta #-}
|
||||
{-# INLINE rose #-}
|
||||
{-# INLINE violet #-}
|
||||
{-# INLINE azure #-}
|
||||
{-# INLINE aquamarine #-}
|
||||
{-# INLINE chartreuse #-}
|
||||
{-# INLINE orange #-}
|
||||
{-# INLINE white #-}
|
||||
{-# INLINE black #-}
|
||||
|
||||
mixColors :: Float -> Float -> Color -> Color -> Color
|
||||
{-# INLINE mixColors #-}
|
||||
mixColors rata ratb (V4 r0 g0 b0 a0) (V4 r2 g2 b2 a2) =
|
||||
let fullrat = rata + ratb
|
||||
normrata = rata / fullrat
|
||||
@@ -341,26 +353,33 @@ mixColors rata ratb (V4 r0 g0 b0 a0) (V4 r2 g2 b2 a2) =
|
||||
in (V4 (f r0 r2 ) ( f g0 g2 ) ( f b0 b2 ) ( normrata * a0 + normratb * a2))
|
||||
|
||||
light :: Color -> Color
|
||||
{-# INLINE light #-}
|
||||
light (V4 r g b a) = (V4 (r+0.2) (g+0.2) (b+0.2) (a))
|
||||
|
||||
dark :: Color -> Color
|
||||
{-# INLINE dark #-}
|
||||
dark (V4 r g b a) = (V4 (r-0.2) (g-0.2) (b-0.2) (a))
|
||||
|
||||
dim :: Color -> Color
|
||||
{-# INLINE dim #-}
|
||||
dim (V4 r g b a) = (V4 (r/1.2) (g/1.2) (b/1.2) (a))
|
||||
|
||||
bright :: Color -> Color
|
||||
{-# INLINE bright #-}
|
||||
bright (V4 r g b a) = (V4 (r*1.2) (g*1.2) (b*1.2) (a))
|
||||
|
||||
greyN :: Float -> Color
|
||||
{-# INLINE greyN #-}
|
||||
greyN x = toV4 (x,x,x,1)
|
||||
|
||||
overPos :: (Point3 -> Point3) -> Verx -> Verx
|
||||
{-# INLINE overPos #-}
|
||||
overPos = over vxPos
|
||||
--overPos = over vxPos
|
||||
overPos f vx = vx {_vxPos = f (_vxPos vx)}
|
||||
|
||||
overCol :: (Point4 -> Point4) -> Verx -> Verx
|
||||
overCol = over vxCol
|
||||
{-# INLINE overCol #-}
|
||||
overCol f vx = vx {_vxCol = f (_vxCol vx)}
|
||||
|
||||
-- no premature optimisation, consider changing to use texture arrays
|
||||
stringToList :: String -> [(Point3,Point4,Point2)]
|
||||
|
||||
Reference in New Issue
Block a user