diff options
author | Joe Crayne <joe@jerkface.net> | 2019-04-13 00:51:51 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-04-13 00:51:51 -0400 |
commit | 3899b660b11bf1d3179965ac92a039b8d449306f (patch) | |
tree | 9337ae45c733e0dd7237acdc4fd6353a515a20aa | |
parent | 705842f6dbbec605d26cd2d7a167f85d18e8275f (diff) |
Switched away from gtk-declarative.
-rw-r--r-- | LambdaCube/Gtk.hs | 25 | ||||
-rw-r--r-- | LambdaHello.hs | 20 | ||||
-rw-r--r-- | lambda-gtk.cabal | 21 | ||||
-rwxr-xr-x | run.sh | 2 |
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 @@ | |||
1 | module LambdaCube.Gtk where | ||
2 | |||
3 | import Control.Monad.IO.Class | ||
4 | import qualified Graphics.Rendering.OpenGL as GL | ||
5 | import qualified Unsafe.Coerce | ||
6 | |||
7 | import 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. | ||
14 | fixupRenderTarget :: MonadIO m => GLRenderer -> m GLRenderer | ||
15 | fixupRenderTarget 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 |
23 | import LambdaCube.GL as RF | 23 | import LambdaCube.GL as RF |
24 | import LambdaCube.GL.Type | 24 | import LambdaCube.GL.Type |
25 | 25 | import LambdaCube.Gtk | |
26 | import Control.Monad.IO.Class | ||
27 | import qualified Unsafe.Coerce | ||
28 | 26 | ||
29 | data State = State | 27 | data 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. | ||
54 | fixupRenderTarget :: MonadIO m => GLRenderer -> m GLRenderer | ||
55 | fixupRenderTarget 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 | |||
66 | render :: State -> GLArea -> GLContext -> IO Bool | 48 | render :: State -> GLArea -> GLContext -> IO Bool |
67 | render st w gl = do | 49 | render 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 @@ | |||
1 | cabal-version: >=1.10 | 1 | cabal-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 | |||
6 | name: lambda-gtk | 2 | name: lambda-gtk |
7 | version: 0.1.0.0 | 3 | version: 0.1.0.0 |
8 | -- synopsis: | 4 | -- synopsis: |
@@ -11,16 +7,25 @@ version: 0.1.0.0 | |||
11 | license: BSD3 | 7 | license: BSD3 |
12 | license-file: LICENSE | 8 | license-file: LICENSE |
13 | author: Joe Crayne | 9 | author: Joe Crayne |
14 | maintainer: jim.crayne@gmail.com | 10 | maintainer: oh.hello.joe@gmail.com |
15 | -- copyright: | 11 | -- copyright: |
16 | -- category: | 12 | -- category: |
17 | build-type: Simple | 13 | build-type: Simple |
18 | extra-source-files: CHANGELOG.md | 14 | extra-source-files: CHANGELOG.md |
19 | 15 | ||
20 | executable lambda-gtk | 16 | executable 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 |
@@ -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 | ||
42 | MESA_GL_VERSION_OVERRIDE=3.3 MESA_GLSL_VERSION_OVERRIDE=330 ./GtkHello | 42 | MESA_GL_VERSION_OVERRIDE=3.3 MESA_GLSL_VERSION_OVERRIDE=330 ./gix |