diff options
author | Joe Crayne <joe@jerkface.net> | 2019-05-19 22:16:55 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-05-19 22:16:55 -0400 |
commit | dc5aecfffbe071e9b8714988b9824c4f445f8dfc (patch) | |
tree | d3cc59ca11d2e4183d7eb2757b6aa723d5510398 /MeshSketch.hs | |
parent | eb02d7ac3e47cba80a1701fc4d755073941e02dd (diff) |
Use Data.Data to specify ring buffer attributes.
Diffstat (limited to 'MeshSketch.hs')
-rw-r--r-- | MeshSketch.hs | 33 |
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 #-} | ||
7 | module MeshSketch where | 9 | module MeshSketch where |
8 | 10 | ||
9 | import Codec.Picture as Juicy | 11 | import Codec.Picture as Juicy |
10 | import Control.Concurrent | 12 | import Control.Concurrent |
11 | import Control.Monad | 13 | import Control.Monad |
14 | import Data.Data | ||
12 | import Data.Word | 15 | import Data.Word |
13 | import Data.Function ((&)) | 16 | import Data.Function ((&)) |
14 | import Data.Functor ((<&>)) | 17 | import Data.Functor ((<&>)) |
@@ -44,6 +47,7 @@ import Text.Printf | |||
44 | 47 | ||
45 | import CubeMap | 48 | import CubeMap |
46 | import GLWidget (nullableContext, withCurrentGL) | 49 | import GLWidget (nullableContext, withCurrentGL) |
50 | import LambdaCube.GL.Input.Type | ||
47 | import LambdaCube.GL.HMatrix | 51 | import LambdaCube.GL.HMatrix |
48 | import LambdaCubeWidget (loadPipeline,DynamicPipeline(..)) | 52 | import LambdaCubeWidget (loadPipeline,DynamicPipeline(..)) |
49 | import Animator | 53 | import Animator |
@@ -52,6 +56,7 @@ import InfinitePlane | |||
52 | import MtlParser (ObjMaterial(..)) | 56 | import MtlParser (ObjMaterial(..)) |
53 | import Matrix | 57 | import Matrix |
54 | import PointPrimitiveRing | 58 | import PointPrimitiveRing |
59 | import MaskableStream (AttributeKey,(@<-)) | ||
55 | 60 | ||
56 | 61 | ||
57 | prettyDebug :: GL.DebugMessage -> String | 62 | prettyDebug :: GL.DebugMessage -> String |
@@ -75,6 +80,14 @@ setupGLDebugging = do | |||
75 | 80 | ||
76 | type Plane = Vector Float | 81 | type Plane = Vector Float |
77 | 82 | ||
83 | data RingPoint = RingPoint | ||
84 | { rpPosition :: AttributeKey (GLVector 3 Float) | ||
85 | } | ||
86 | deriving Data | ||
87 | |||
88 | ringPointAttr :: String -> String | ||
89 | ringPointAttr ('r':'p':c:cs) = toLower c : cs | ||
90 | |||
78 | -- State created by uploadState. | 91 | -- State created by uploadState. |
79 | data State = State | 92 | data 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 | ||