summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-04-13 00:51:51 -0400
committerJoe Crayne <joe@jerkface.net>2019-04-13 00:51:51 -0400
commit3899b660b11bf1d3179965ac92a039b8d449306f (patch)
tree9337ae45c733e0dd7237acdc4fd6353a515a20aa
parent705842f6dbbec605d26cd2d7a167f85d18e8275f (diff)
Switched away from gtk-declarative.
-rw-r--r--LambdaCube/Gtk.hs25
-rw-r--r--LambdaHello.hs20
-rw-r--r--lambda-gtk.cabal21
-rwxr-xr-xrun.sh2
4 files changed, 40 insertions, 28 deletions
diff --git a/LambdaCube/Gtk.hs b/LambdaCube/Gtk.hs
new file mode 100644
index 0000000..1a9c1b9
--- /dev/null
+++ b/LambdaCube/Gtk.hs
@@ -0,0 +1,25 @@
1module LambdaCube.Gtk where
2
3import Control.Monad.IO.Class
4import qualified Graphics.Rendering.OpenGL as GL
5import qualified Unsafe.Coerce
6
7import LambdaCube.GL.Type
8
9
10-- | LambdaCube.GL assumes we are rendering to the default framebuffer #0 but
11-- Gtk.GLArea actually uses an unpredictable framebuffer object target. As a
12-- workaround, we read the current framebuffer target and patch up the render
13-- commands to use it instead of 0.
14fixupRenderTarget :: MonadIO m => GLRenderer -> m GLRenderer
15fixupRenderTarget r = do
16 fbo0 <- GL.get $ GL.bindFramebuffer GL.DrawFramebuffer
17 let fbo = Unsafe.Coerce.unsafeCoerce fbo0 :: GL.GLuint -- XXX: Is there a better way to get this?
18 setFBO rt | framebufferObject rt == 0 = rt { framebufferObject = fbo }
19 | otherwise = rt
20 updateDC dc = dc { glRenderTarget = rt' } where rt' = setFBO (glRenderTarget dc)
21 update (GLClearRenderTarget rt imgs) = GLClearRenderTarget (setFBO rt) imgs
22 update (GLRenderSlot dc s p) = GLRenderSlot (updateDC dc) s p
23 update (GLRenderStream dc s p) = GLRenderStream (updateDC dc) s p
24 return r { glCommands = map update (glCommands r) }
25
diff --git a/LambdaHello.hs b/LambdaHello.hs
index 78d4f0d..5615ca8 100644
--- a/LambdaHello.hs
+++ b/LambdaHello.hs
@@ -22,9 +22,7 @@ import qualified Data.Vector as V
22-- import qualified Backend as RF 22-- import qualified Backend as RF
23import LambdaCube.GL as RF 23import LambdaCube.GL as RF
24import LambdaCube.GL.Type 24import LambdaCube.GL.Type
25 25import LambdaCube.Gtk
26import Control.Monad.IO.Class
27import qualified Unsafe.Coerce
28 26
29data State = State 27data State = State
30 { stConfig :: Config 28 { stConfig :: Config
@@ -47,22 +45,6 @@ initState = do
47 } 45 }
48 46
49 47
50-- | LambdaCube.GL assumes we are rendering to the default framebuffer #0 but
51-- Gtk.GLArea actually uses an unpredictable framebuffer object target. As a
52-- workaround, we read the current framebuffer target and patch up the render
53-- commands to use it instead of 0.
54fixupRenderTarget :: MonadIO m => GLRenderer -> m GLRenderer
55fixupRenderTarget r = do
56 fbo0 <- GL.get $ GL.bindFramebuffer GL.DrawFramebuffer
57 let fbo = Unsafe.Coerce.unsafeCoerce fbo0 :: GL.GLuint -- XXX: Is there a better way to get this?
58 setFBO rt | framebufferObject rt == 0 = rt { framebufferObject = fbo }
59 | otherwise = rt
60 updateDC dc = dc { glRenderTarget = rt' } where rt' = setFBO (glRenderTarget dc)
61 update (GLClearRenderTarget rt imgs) = GLClearRenderTarget (setFBO rt) imgs
62 update (GLRenderSlot dc s p) = GLRenderSlot (updateDC dc) s p
63 update (GLRenderStream dc s p) = GLRenderStream (updateDC dc) s p
64 return r { glCommands = map update (glCommands r) }
65
66render :: State -> GLArea -> GLContext -> IO Bool 48render :: State -> GLArea -> GLContext -> IO Bool
67render st w gl = do 49render st w gl = do
68 mr <- tryTakeMVar (stRealized st) 50 mr <- tryTakeMVar (stRealized st)
diff --git a/lambda-gtk.cabal b/lambda-gtk.cabal
index 7d3889d..8fcf7e4 100644
--- a/lambda-gtk.cabal
+++ b/lambda-gtk.cabal
@@ -1,8 +1,4 @@
1cabal-version: >=1.10 1cabal-version: >=1.10
2-- Initial package description 'lambda-gtk.cabal' generated by 'cabal
3-- init'. For further documentation, see
4-- http://haskell.org/cabal/users-guide/
5
6name: lambda-gtk 2name: lambda-gtk
7version: 0.1.0.0 3version: 0.1.0.0
8-- synopsis: 4-- synopsis:
@@ -11,16 +7,25 @@ version: 0.1.0.0
11license: BSD3 7license: BSD3
12license-file: LICENSE 8license-file: LICENSE
13author: Joe Crayne 9author: Joe Crayne
14maintainer: jim.crayne@gmail.com 10maintainer: oh.hello.joe@gmail.com
15-- copyright: 11-- copyright:
16-- category: 12-- category:
17build-type: Simple 13build-type: Simple
18extra-source-files: CHANGELOG.md 14extra-source-files: CHANGELOG.md
19 15
20executable lambda-gtk 16executable lambda-gtk
21 main-is: GtkHello.hs 17 main-is: gix.hs
22 -- other-modules: 18 other-modules: LambdaCube.Gtk LambdaHello
19 extensions: NondecreasingIndentation
23 other-extensions: OverloadedLabels, OverloadedLists, OverloadedStrings 20 other-extensions: OverloadedLabels, OverloadedLists, OverloadedStrings
24 build-depends: base, containers >=0.5 && <0.6, bytestring >=0.10 && <0.11, lambdacube-ir, lambdacube-gl, gi-gtk-declarative, gi-gtk, aeson, vector, gi-gtk-declarative-app-simple, JuicyPixels, gi-gdk 21 build-depends: base, containers >=0.5 && <0.6, bytestring >=0.10 && <0.11,
22 vector, aeson, JuicyPixels,
23 -- rendering
24 lambdacube-ir, lambdacube-gl, OpenGL,
25 -- GUI
26 gi-gdk , gi-glib , gi-gobject , gi-gtk , haskell-gi-base
27 -- , gi-gtk-declarative, gi-gtk-declarative-app-simple,
28
25 -- hs-source-dirs: 29 -- hs-source-dirs:
30
26 default-language: Haskell2010 31 default-language: Haskell2010
diff --git a/run.sh b/run.sh
index 0df74ba..f004906 100755
--- a/run.sh
+++ b/run.sh
@@ -39,4 +39,4 @@
39# Mesa may not really implement all the features of the given version. (for 39# Mesa may not really implement all the features of the given version. (for
40# developers only) 40# developers only)
41 41
42MESA_GL_VERSION_OVERRIDE=3.3 MESA_GLSL_VERSION_OVERRIDE=330 ./GtkHello 42MESA_GL_VERSION_OVERRIDE=3.3 MESA_GLSL_VERSION_OVERRIDE=330 ./gix