summaryrefslogtreecommitdiff
path: root/MeshSketch.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-05-19 22:16:55 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-19 22:16:55 -0400
commitdc5aecfffbe071e9b8714988b9824c4f445f8dfc (patch)
treed3cc59ca11d2e4183d7eb2757b6aa723d5510398 /MeshSketch.hs
parenteb02d7ac3e47cba80a1701fc4d755073941e02dd (diff)
Use Data.Data to specify ring buffer attributes.
Diffstat (limited to 'MeshSketch.hs')
-rw-r--r--MeshSketch.hs33
1 files changed, 24 insertions, 9 deletions
diff --git a/MeshSketch.hs b/MeshSketch.hs
index d06e905..cca9524 100644
--- a/MeshSketch.hs
+++ b/MeshSketch.hs
@@ -1,14 +1,17 @@
1{-# LANGUAGE CPP #-} 1{-# LANGUAGE CPP #-}
2{-# LANGUAGE FlexibleContexts #-} 2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE LambdaCase #-} 3{-# LANGUAGE DeriveDataTypeable #-}
4{-# LANGUAGE OverloadedLabels #-} 4{-# LANGUAGE FlexibleContexts #-}
5{-# LANGUAGE OverloadedStrings #-} 5{-# LANGUAGE LambdaCase #-}
6{-# LANGUAGE RecordWildCards #-} 6{-# LANGUAGE OverloadedLabels #-}
7{-# LANGUAGE OverloadedStrings #-}
8{-# LANGUAGE RecordWildCards #-}
7module MeshSketch where 9module MeshSketch where
8 10
9import Codec.Picture as Juicy 11import Codec.Picture as Juicy
10import Control.Concurrent 12import Control.Concurrent
11import Control.Monad 13import Control.Monad
14import Data.Data
12import Data.Word 15import Data.Word
13import Data.Function ((&)) 16import Data.Function ((&))
14import Data.Functor ((<&>)) 17import Data.Functor ((<&>))
@@ -44,6 +47,7 @@ import Text.Printf
44 47
45import CubeMap 48import CubeMap
46import GLWidget (nullableContext, withCurrentGL) 49import GLWidget (nullableContext, withCurrentGL)
50import LambdaCube.GL.Input.Type
47import LambdaCube.GL.HMatrix 51import LambdaCube.GL.HMatrix
48import LambdaCubeWidget (loadPipeline,DynamicPipeline(..)) 52import LambdaCubeWidget (loadPipeline,DynamicPipeline(..))
49import Animator 53import Animator
@@ -52,6 +56,7 @@ import InfinitePlane
52import MtlParser (ObjMaterial(..)) 56import MtlParser (ObjMaterial(..))
53import Matrix 57import Matrix
54import PointPrimitiveRing 58import PointPrimitiveRing
59import MaskableStream (AttributeKey,(@<-))
55 60
56 61
57prettyDebug :: GL.DebugMessage -> String 62prettyDebug :: GL.DebugMessage -> String
@@ -75,6 +80,14 @@ setupGLDebugging = do
75 80
76type Plane = Vector Float 81type Plane = Vector Float
77 82
83data RingPoint = RingPoint
84 { rpPosition :: AttributeKey (GLVector 3 Float)
85 }
86 deriving Data
87
88ringPointAttr :: String -> String
89ringPointAttr ('r':'p':c:cs) = toLower c : cs
90
78-- State created by uploadState. 91-- State created by uploadState.
79data State = State 92data State = State
80 { stAnimator :: Animator 93 { stAnimator :: Animator
@@ -84,7 +97,7 @@ data State = State
84 , stSkybox :: IORef Int 97 , stSkybox :: IORef Int
85 , stSkyTexture :: IORef TextureCubeData 98 , stSkyTexture :: IORef TextureCubeData
86 , stDragFrom :: IORef (Maybe (Vector Float,Camera)) 99 , stDragFrom :: IORef (Maybe (Vector Float,Camera))
87 , stRingBuffer :: Ring 100 , stRingBuffer :: Ring RingPoint
88 , stPenDown :: IORef Bool 101 , stPenDown :: IORef Bool
89 , stPlane :: IORef (Maybe Plane) 102 , stPlane :: IORef (Maybe Plane)
90 , stDragPlane :: IORef (Maybe (Vector Float,Plane)) 103 , stDragPlane :: IORef (Maybe (Vector Float,Plane))
@@ -183,7 +196,7 @@ uploadState obj glarea storage = do
183 -- grid plane 196 -- grid plane
184 uploadMeshToGPU xzplane >>= addMeshToObjectArray storage "plane" [] 197 uploadMeshToGPU xzplane >>= addMeshToObjectArray storage "plane" []
185 198
186 ring <- newRing storage 100 199 ring <- newRing storage 100 ringPointAttr
187 200
188 -- setup FrameClock 201 -- setup FrameClock
189 w <- toWidget glarea 202 w <- toWidget glarea
@@ -560,7 +573,9 @@ pushRing w st h k = do
560 plane <- readIORef (stPlane st) 573 plane <- readIORef (stPlane st)
561 d <- worldCoordinates st h k plane 574 d <- worldCoordinates st h k plane
562 Just win <- getWidgetWindow w 575 Just win <- getWidgetWindow w
563 pushBack (stRingBuffer st) (d!0) (d!1) (d!2) 576 pushBack (stRingBuffer st) $ do
577 RingPoint{..} <- return $ rKeys (stRingBuffer st)
578 rpPosition @<- d
564 windowInvalidateRect win Nothing False 579 windowInvalidateRect win Nothing False
565 return d 580 return d
566 581