From 5bc930a4b16e3faee029503754e9ab5faa17eac7 Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Wed, 21 Oct 2015 14:51:39 -0700 Subject: [PATCH] Made gcode renderer render faster if in opengl put in new functions to render fast gl lines and round lines Put in some comments for RenderOpenGL --- PartPreviewWindow/ViewGcodeWidget.cs | 56 ++++++++++++++++++++++++---- Submodules/agg-sharp | 2 +- Utilities/PerformanceTimer.cs | 2 + 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/PartPreviewWindow/ViewGcodeWidget.cs b/PartPreviewWindow/ViewGcodeWidget.cs index 3139d48fe..789f758d4 100644 --- a/PartPreviewWindow/ViewGcodeWidget.cs +++ b/PartPreviewWindow/ViewGcodeWidget.cs @@ -33,6 +33,7 @@ using MatterHackers.Agg.UI; using MatterHackers.Agg.VertexSource; using MatterHackers.GCodeVisualizer; using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.RenderOpenGl; using MatterHackers.VectorMath; using System; using System.ComponentModel; @@ -214,7 +215,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow this.gridSizeMm = gridSizeMm; this.gridCenterMm = gridCenterMm; LocalBounds = new RectangleDouble(0, 0, 100, 100); - DoubleBuffer = true; + //DoubleBuffer = true; AnchorAll(); } @@ -331,6 +332,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow } private PathStorage grid = new PathStorage(); + static RGBA_Bytes gridColor = new RGBA_Bytes(190, 190, 190, 255); public override void OnDraw(Graphics2D graphics2D) { @@ -340,16 +342,24 @@ namespace MatterHackers.MatterControl.PartPreviewWindow { Affine transform = TotalTransform; - CreateGrid(transform); - - double gridLineWidths = 0.2 * layerScale; - Stroke stroke = new Stroke(grid, gridLineWidths); - if (RenderGrid) { using (new PerformanceTimer("GCode Timer", "Render Grid")) { - graphics2D.Render(stroke, new RGBA_Bytes(190, 190, 190, 255)); + double gridLineWidths = 0.2 * layerScale; + + Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL; + if (graphics2DGl != null) + { + GlRenderGrid(graphics2DGl, transform, gridLineWidths); + } + else + { + CreateGrid(transform); + + Stroke stroke = new Stroke(grid, gridLineWidths); + graphics2D.Render(stroke, gridColor); + } } } @@ -389,6 +399,38 @@ namespace MatterHackers.MatterControl.PartPreviewWindow base.OnDraw(graphics2D); } + private void GlRenderGrid(Graphics2DOpenGL graphics2DGl, Affine transform, double width) + { + graphics2DGl.PreRender(); + + Vector2 gridOffset = gridCenterMm - gridSizeMm / 2; + if (gridSizeMm.x > 0 && gridSizeMm.y > 0) + { + grid.remove_all(); + for (int y = 0; y <= gridSizeMm.y; y += 10) + { + Vector2 start = new Vector2(0, y) + gridOffset; + Vector2 end = new Vector2(gridSizeMm.x, y) + gridOffset; + transform.transform(ref start); + transform.transform(ref end); + + graphics2DGl.DrawAALine(start, end, width, gridColor); + } + + for (int x = 0; x <= gridSizeMm.x; x += 10) + { + Vector2 start = new Vector2(x, 0) + gridOffset; + Vector2 end = new Vector2(x, gridSizeMm.y) + gridOffset; + transform.transform(ref start); + transform.transform(ref end); + + graphics2DGl.DrawAALine(start, end, width, gridColor); + } + } + + graphics2DGl.PopOrthoProjection(); + } + public void CreateGrid(Affine transform) { Vector2 gridOffset = gridCenterMm - gridSizeMm / 2; diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 4fe2fd156..be71e9d77 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 4fe2fd15604adb7c6dffec6e6311873cdd303056 +Subproject commit be71e9d77b78f77b7ff62afe8807401bee32e097 diff --git a/Utilities/PerformanceTimer.cs b/Utilities/PerformanceTimer.cs index 60ac42a22..0658634d0 100644 --- a/Utilities/PerformanceTimer.cs +++ b/Utilities/PerformanceTimer.cs @@ -54,7 +54,9 @@ namespace MatterHackers.MatterControl }; AddChild(topToBottom); + #if !__ANDROID__ ShowAsSystemWindow(); + #endif } public void SetTime(string name, double elapsedSeconds)