diff options
author | Joe Crayne <joe@jerkface.net> | 2019-06-03 22:46:05 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-06-03 22:46:05 -0400 |
commit | d763106d889c94bfb55096cdd154aeaf7d48f9df (patch) | |
tree | a29be169ca6c740c5482decd48881cda1fc00017 | |
parent | 07bcb2a2e4c52b0a0f3c34bc1a70772e4ab2dbb5 (diff) |
Render curve special points.
-rw-r--r-- | GPURing.hs | 6 | ||||
-rw-r--r-- | MeshSketch.hs | 47 | ||||
-rw-r--r-- | hello_obj2.lc | 24 |
3 files changed, 51 insertions, 26 deletions
@@ -25,15 +25,15 @@ import LambdaCube.GL.Input hiding (createObjectCommands) | |||
25 | -- > ringBuffer <- newRing capacity (VectorRing.new capacity) | 25 | -- > ringBuffer <- newRing capacity (VectorRing.new capacity) |
26 | type Update keys = (keys -> Writer [DSum AttributeKey GLUniformValue] ()) | 26 | type Update keys = (keys -> Writer [DSum AttributeKey GLUniformValue] ()) |
27 | 27 | ||
28 | new :: Data keys => String -> GLStorage -> (String -> String) -> Int -> IO (TargetBuffer (Update keys)) | 28 | new :: Data keys => Primitive -> String -> GLStorage -> (String -> String) -> Int -> IO (TargetBuffer (Update keys)) |
29 | new streamName storage toAttr sz = fix $ \retProxy -> do | 29 | new prim streamName storage toAttr sz = fix $ \retProxy -> do |
30 | let paramProxy = paramProxy' retProxy | 30 | let paramProxy = paramProxy' retProxy |
31 | where paramProxy' :: io (targetbuffer (keys -> writer)) -> Proxy keys | 31 | where paramProxy' :: io (targetbuffer (keys -> writer)) -> Proxy keys |
32 | paramProxy' _ = Proxy | 32 | paramProxy' _ = Proxy |
33 | let ps = fieldParameters paramProxy toAttr | 33 | let ps = fieldParameters paramProxy toAttr |
34 | putStrLn $ "Ring params: " ++ show ps | 34 | putStrLn $ "Ring params: " ++ show ps |
35 | gd0 <- uploadDynamicBuffer sz ps | 35 | gd0 <- uploadDynamicBuffer sz ps |
36 | let gd = gd0 { dPrimitive = LineStrip } | 36 | let gd = gd0 { dPrimitive = prim } |
37 | Just keys <- return $ lookupAttrKeys (lookupAttributeKey gd . toAttr) | 37 | Just keys <- return $ lookupAttrKeys (lookupAttributeKey gd . toAttr) |
38 | obj <- addToObjectArray storage streamName [] gd | 38 | obj <- addToObjectArray storage streamName [] gd |
39 | -- readIORef (objCommands obj) >>= mapM_ print | 39 | -- readIORef (objCommands obj) >>= mapM_ print |
diff --git a/MeshSketch.hs b/MeshSketch.hs index dc0adf1..4ddfec0 100644 --- a/MeshSketch.hs +++ b/MeshSketch.hs | |||
@@ -96,21 +96,22 @@ ringPointAttr ('r':'p':c:cs) = toLower c : cs | |||
96 | 96 | ||
97 | -- State created by uploadState. | 97 | -- State created by uploadState. |
98 | data State = State | 98 | data State = State |
99 | { stAnimator :: Animator | 99 | { stAnimator :: Animator |
100 | , stCamera :: IORef Camera | 100 | , stCamera :: IORef Camera |
101 | , stFullscreen :: IO () | 101 | , stFullscreen :: IO () |
102 | , stSkyboxes :: Skyboxes | 102 | , stSkyboxes :: Skyboxes |
103 | , stSkybox :: IORef Int | 103 | , stSkybox :: IORef Int |
104 | , stSkyTexture :: IORef TextureCubeData | 104 | , stSkyTexture :: IORef TextureCubeData |
105 | , stDragFrom :: IORef (Maybe (Vector Float,Camera)) | 105 | , stDragFrom :: IORef (Maybe (Vector Float,Camera)) |
106 | , stDataPoints :: MV.MVector RealWorld Vector.Point | 106 | , stDataPoints :: MV.MVector RealWorld Vector.Point |
107 | , stDataRing :: RingBuffer Vector.Point | 107 | , stDataRing :: RingBuffer Vector.Point |
108 | , stRingBuffer :: RingBuffer (GPU.Update RingPoint) | 108 | , stRingBuffer :: RingBuffer (GPU.Update RingPoint) |
109 | , stPenDown :: IORef Bool | 109 | , stCurveSpecial :: RingBuffer (GPU.Update RingPoint) |
110 | , stPlane :: IORef (Maybe Plane) | 110 | , stPenDown :: IORef Bool |
111 | , stDragPlane :: IORef (Maybe (Vector Float,Plane)) | 111 | , stPlane :: IORef (Maybe Plane) |
112 | , stRecentPts :: IORef (Giver (Vector Double)) | 112 | , stDragPlane :: IORef (Maybe (Vector Float,Plane)) |
113 | , stAngle :: IORef Int | 113 | , stRecentPts :: IORef (Giver (Vector Double)) |
114 | , stAngle :: IORef Int | ||
114 | } | 115 | } |
115 | 116 | ||
116 | initCamera :: Camera | 117 | initCamera :: Camera |
@@ -172,7 +173,8 @@ uploadState obj glarea storage = do | |||
172 | let bufsize = 1000 | 173 | let bufsize = 1000 |
173 | v <- MV.unsafeNew bufsize | 174 | v <- MV.unsafeNew bufsize |
174 | pts <- newRing bufsize (Vector.new v) | 175 | pts <- newRing bufsize (Vector.new v) |
175 | ring <- newRing bufsize (GPU.new "Points" storage ringPointAttr bufsize) | 176 | ring <- newRing bufsize (GPU.new LineStrip "Curve" storage ringPointAttr bufsize) |
177 | cpts <- newRing 100 (GPU.new PointList "Points" storage ringPointAttr 100) | ||
176 | 178 | ||
177 | -- setup FrameClock | 179 | -- setup FrameClock |
178 | w <- toWidget glarea | 180 | w <- toWidget glarea |
@@ -215,6 +217,7 @@ uploadState obj glarea storage = do | |||
215 | , stDataPoints = v | 217 | , stDataPoints = v |
216 | , stDataRing = pts | 218 | , stDataRing = pts |
217 | , stRingBuffer = ring | 219 | , stRingBuffer = ring |
220 | , stCurveSpecial = cpts | ||
218 | , stPenDown = pendown | 221 | , stPenDown = pendown |
219 | , stPlane = plane | 222 | , stPlane = plane |
220 | , stDragPlane = dragPlane | 223 | , stDragPlane = dragPlane |
@@ -294,7 +297,10 @@ new = do | |||
294 | "uvw" @: Attribute_V3F | 297 | "uvw" @: Attribute_V3F |
295 | defObjectArray "plane" Triangles $ do | 298 | defObjectArray "plane" Triangles $ do |
296 | "position" @: Attribute_V4F | 299 | "position" @: Attribute_V4F |
297 | defObjectArray "Points" Lines $ do | 300 | defObjectArray "Curve" Lines $ do |
301 | "position" @: Attribute_V3F | ||
302 | "color" @: Attribute_V3F | ||
303 | defObjectArray "Points" Points $ do | ||
298 | "position" @: Attribute_V3F | 304 | "position" @: Attribute_V3F |
299 | "color" @: Attribute_V3F | 305 | "color" @: Attribute_V3F |
300 | defUniforms $ do | 306 | defUniforms $ do |
@@ -607,8 +613,8 @@ pushRing w st endpt h k c = do | |||
607 | n = round $ θ/(pi/12) | 613 | n = round $ θ/(pi/12) |
608 | m <- readIORef (stAngle st) | 614 | m <- readIORef (stAngle st) |
609 | let isSpecial = x<0.3 -- || δ<0.5 | 615 | let isSpecial = x<0.3 -- || δ<0.5 |
616 | bb <- worldCoordinates st (b!0) (b!1) plane | ||
610 | go <- if (m /= n || isSpecial) then do | 617 | go <- if (m /= n || isSpecial) then do |
611 | bb <- worldCoordinates st (b!0) (b!1) plane | ||
612 | updateBack (stDataRing st) (Vector.Point (b!0) (b!1)) | 618 | updateBack (stDataRing st) (Vector.Point (b!0) (b!1)) |
613 | updateBack (stRingBuffer st) $ \RingPoint{..} -> do | 619 | updateBack (stRingBuffer st) $ \RingPoint{..} -> do |
614 | rpPosition @<- bb | 620 | rpPosition @<- bb |
@@ -627,6 +633,10 @@ pushRing w st endpt h k c = do | |||
627 | bool updateBack pushBack go (stRingBuffer st) $ \RingPoint{..} -> do | 633 | bool updateBack pushBack go (stRingBuffer st) $ \RingPoint{..} -> do |
628 | rpPosition @<- aa | 634 | rpPosition @<- aa |
629 | rpColor @<- yellow | 635 | rpColor @<- yellow |
636 | when isSpecial $ do | ||
637 | pushBack (stCurveSpecial st) $ \RingPoint{..} -> do | ||
638 | rpPosition @<- bb | ||
639 | rpColor @<- yellow | ||
630 | withEndpt = do | 640 | withEndpt = do |
631 | pushBack (stDataRing st) (Vector.Point h k) | 641 | pushBack (stDataRing st) (Vector.Point h k) |
632 | pushBack (stRingBuffer st) $ \RingPoint{..} -> do | 642 | pushBack (stRingBuffer st) $ \RingPoint{..} -> do |
@@ -697,6 +707,7 @@ onEvent w realized ev = do | |||
697 | writeIORef (stRecentPts st) Give0 | 707 | writeIORef (stRecentPts st) Give0 |
698 | clearRing (stRingBuffer st) | 708 | clearRing (stRingBuffer st) |
699 | clearRing (stDataRing st) | 709 | clearRing (stDataRing st) |
710 | clearRing (stCurveSpecial st) | ||
700 | d <- pushRing w st True h k red | 711 | d <- pushRing w st True h k red |
701 | Just win <- getWidgetWindow w | 712 | Just win <- getWidgetWindow w |
702 | windowInvalidateRect win Nothing False | 713 | windowInvalidateRect win Nothing False |
diff --git a/hello_obj2.lc b/hello_obj2.lc index b68a04d..7e7defc 100644 --- a/hello_obj2.lc +++ b/hello_obj2.lc | |||
@@ -19,7 +19,8 @@ makeFrame (cubemap :: TextureCube) | |||
19 | (texture :: Texture) | 19 | (texture :: Texture) |
20 | (prims :: PrimitiveStream Triangle (Vec 4 Float, Vec 3 Float, Vec 3 Float)) | 20 | (prims :: PrimitiveStream Triangle (Vec 4 Float, Vec 3 Float, Vec 3 Float)) |
21 | (plane :: PrimitiveStream Triangle ((Vec 4 Float))) | 21 | (plane :: PrimitiveStream Triangle ((Vec 4 Float))) |
22 | (points :: PrimitiveStream Line (Vec 3 Float, Vec 3 Float)) | 22 | (lines :: PrimitiveStream Line (Vec 3 Float, Vec 3 Float)) |
23 | (points :: PrimitiveStream Point (Vec 3 Float, Vec 3 Float)) | ||
23 | (plane_mat :: Mat 4 4 Float) | 24 | (plane_mat :: Mat 4 4 Float) |
24 | 25 | ||
25 | = imageFrame (emptyDepthImage 1, emptyColorImage (V4 0 0 0.4 1)) | 26 | = imageFrame (emptyDepthImage 1, emptyColorImage (V4 0 0 0.4 1)) |
@@ -46,6 +47,17 @@ makeFrame (cubemap :: TextureCube) | |||
46 | in ((r + V4 0 0 0 (0.8)))) | 47 | in ((r + V4 0 0 0 (0.8)))) |
47 | & accumulateWith (DepthOp Less True, ColorOp blendplane (V4 True True True True)) | 48 | & accumulateWith (DepthOp Less True, ColorOp blendplane (V4 True True True True)) |
48 | `overlay` | 49 | `overlay` |
50 | lines | ||
51 | & mapPrimitives (\(p,c) -> let p' = coordmap cam $ point p | ||
52 | w = p'%w | ||
53 | yellowish = normalize c `dot` V3 1 1 0 | ||
54 | p2 = if yellowish >= 0.9*sqrt 2 | ||
55 | then V4 p'%x p'%y 0.1 w | ||
56 | else V4 p'%x p'%y 0.11 w | ||
57 | in (p2, point c)) | ||
58 | |||
59 | & renderPoints cam (LineCtx 1.0 LastVertex) | ||
60 | `overlay` | ||
49 | points | 61 | points |
50 | & mapPrimitives (\(p,c) -> let p' = coordmap cam $ point p | 62 | & mapPrimitives (\(p,c) -> let p' = coordmap cam $ point p |
51 | w = p'%w | 63 | w = p'%w |
@@ -55,16 +67,17 @@ makeFrame (cubemap :: TextureCube) | |||
55 | else V4 p'%x p'%y 0.11 w | 67 | else V4 p'%x p'%y 0.11 w |
56 | in (p2, point c)) | 68 | in (p2, point c)) |
57 | 69 | ||
58 | & renderPoints cam | 70 | & renderPoints cam (PointCtx (PointSize 5.0) 1.0 LowerLeft) |
59 | 71 | ||
60 | renderPoints :: | 72 | renderPoints :: |
61 | Mat 4 4 Float | 73 | Mat 4 4 Float |
62 | -> PrimitiveStream Line (Vec 4 Float, Vec 4 Float) | 74 | -> RasterContext (Vec 4 Float, Vec 4 Float) pr |
75 | -> PrimitiveStream pr (Vec 4 Float, Vec 4 Float) | ||
63 | -> ( (FragmentOperation Depth, FragmentOperation (Color (VecScalar 4 Float))) | 76 | -> ( (FragmentOperation Depth, FragmentOperation (Color (VecScalar 4 Float))) |
64 | , FragmentStream 1 ((Vec 4 Float)) ) | 77 | , FragmentStream 1 ((Vec 4 Float)) ) |
65 | renderPoints cam points = | 78 | renderPoints cam ctx points = |
66 | points | 79 | points |
67 | & rasterizePrimitives (LineCtx 1.0 LastVertex) ((Flat)) | 80 | & rasterizePrimitives ctx ((Flat)) |
68 | & mapFragments (\((c)) -> ((c))) | 81 | & mapFragments (\((c)) -> ((c))) |
69 | & accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True)) | 82 | & accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True)) |
70 | 83 | ||
@@ -78,5 +91,6 @@ main = renderFrame $ | |||
78 | (Texture2DSlot "diffuseTexture") | 91 | (Texture2DSlot "diffuseTexture") |
79 | (fetch "objects" (Attribute "position", Attribute "normal", Attribute "uvw")) | 92 | (fetch "objects" (Attribute "position", Attribute "normal", Attribute "uvw")) |
80 | (fetch "plane" ((Attribute "position"))) | 93 | (fetch "plane" ((Attribute "position"))) |
94 | (fetch "Curve" (Attribute "position", Attribute "color")) | ||
81 | (fetch "Points" (Attribute "position", Attribute "color")) | 95 | (fetch "Points" (Attribute "position", Attribute "color")) |
82 | (Uniform "PlaneModel") | 96 | (Uniform "PlaneModel") |