~alcinnz/Mondrian

05c8b4fe321de441c69e39e7e6350feb556157e6 — Adrian Cochrane 1 year, 4 months ago dc6acbc
Build texturing infrastructure.
M Mondrian.cabal => Mondrian.cabal +3 -1
@@ 20,6 20,7 @@ extra-source-files:  CHANGELOG.md
library
  exposed-modules:     Graphics.Rendering.Rect,
                       Graphics.Rendering.Rect.Backgrounds,
                       Graphics.Rendering.Rect.Image,
                       Graphics.Rendering.Rect.CSS,
                       Graphics.Rendering.Rect.CSS.Colour,
                       Graphics.Rendering.Rect.CSS.Backgrounds


@@ 27,7 28,8 @@ library
  -- other-extensions:
  build-depends:       base >=4.13 && <4.14, stylist-traits >= 0.1.3.1 && < 1,
                       css-syntax, colour >= 2.3.6 && < 3, scientific, text,
                       bytestring, typograffiti, linear, gl, vector, mtl
                       bytestring, typograffiti, linear, gl, vector, mtl,
                       unordered-containers, JuicyPixels >=3.0 && <4
  hs-source-dirs:      lib
  default-language:    Haskell2010


M lib/Graphics/Rendering/Rect/Backgrounds.hs => lib/Graphics/Rendering/Rect/Backgrounds.hs +1 -1
@@ 18,6 18,6 @@ renderBackgrounds :: (MonadIO m, MonadIO n) =>
    n (Backgrounds -> Rects -> M44 Float -> m ())
renderBackgrounds = do
    base <- renderRectWith baseFragmentShader ["colour"]
    return $ \self -> base [c $ background self] $ headDef borderBox $ clip self
    return $ \slf -> base [] [c $ background slf] $ headDef borderBox $ clip slf

headDef def = fromMaybe def . listToMaybe

M lib/Graphics/Rendering/Rect/Types.hs => lib/Graphics/Rendering/Rect/Types.hs +3 -2
@@ 19,6 19,7 @@ import System.Exit (die)
import Data.Colour (AlphaColour, over, alphaChannel)
import Data.Colour.SRGB (RGB(..), toSRGB)
import Data.Colour.Names (black)
import Graphics.Rendering.Rect.Image (Texture)

data Rect = Rect {
    left :: Float, top :: Float,


@@ 55,7 56,7 @@ c rgba = u $ V4 r g b a
    RGB r g b = toSRGB $ over rgba black

renderRectWith :: (MonadIO m, MonadIO n) => ByteString -> [String] ->
        n ([Uniform m] -> (a -> Rect) -> a -> M44 Float -> m ())
        n ([Texture] -> [Uniform m] -> (a -> Rect) -> a -> M44 Float -> m ())
renderRectWith fragmentShader uniformNames = do
    vs <- liftGL $ compileOGLShader vertexShader GL_VERTEX_SHADER
    fs <- liftGL $ compileOGLShader fragmentShader GL_FRAGMENT_SHADER


@@ 65,7 66,7 @@ renderRectWith fragmentShader uniformNames = do
    glUseProgram prog
    glEnable GL_BLEND
    glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
    return $ \uniforms getter rects mat -> do
    return $ \_ uniforms getter rects mat -> do
        vao <- liftIO $ newBoundVAO
        pbuf <- newBuffer
        bufferGeometry 0 pbuf $ rect2geom $ getter rects