Skip to content

Commit

Permalink
Enable hardware acceleration
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Settimi committed Jun 7, 2024
1 parent 52ed625 commit 42776d3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
11 changes: 4 additions & 7 deletions LaserGRBL/PreviewForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class PreviewForm : System.Windows.Forms.UserControl
public PreviewForm()
{
InitializeComponent();
CreatePanel(Settings.LegacyPreview);
CreatePanel();
CustomButtonArea.OrderChanged += CustomButtonArea_OrderChanged;
IconsMgr.PrepareButton(BtnReset, "custom-reset");
IconsMgr.PrepareButton(BtnUnlock, "custom-unlock");
Expand Down Expand Up @@ -60,21 +60,18 @@ public PreviewForm()
}
}

private void CreatePanel(bool isLegacy)
private void CreatePanel()
{
if (GrblPanel != null)
{
tableLayoutPanel1.Controls.Remove(GrblPanel as Control);
(GrblPanel as Control).Dispose();
}
if (isLegacy)
{
if (Settings.LegacyPreview)
GrblPanel = new GrblPanel();
}
else
{
GrblPanel = new GrblPanel3D();
}

if (mCore != null) GrblPanel.SetCore(mCore);
(GrblPanel as Control).Dock = DockStyle.Fill;
tableLayoutPanel1.Controls.Add(GrblPanel as Control);
Expand Down
5 changes: 5 additions & 0 deletions LaserGRBL/UsageStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Net;
using System.Runtime.Serialization;
using System.Linq;
using LaserGRBL.UserControls;

namespace LaserGRBL
{
Expand Down Expand Up @@ -224,6 +225,10 @@ private bool TrueSend()
{ "bitflag", Tools.OSHelper.GetBitFlag().ToString() },
{ "vendor", VendorString },
{ "fPassthrough", Counters.Passthrough.ToString() },
{ "RenderType", GrblPanel3D.CurrentRendererType },
{ "RenderVendor", GrblPanel3D.CurrentVendor },
{ "RenderName", GrblPanel3D.CurrentRenderer },
{ "RenderGLVersion", GrblPanel3D.CurrentGLVersion },
};

// client.UploadValues returns page's source as byte array (byte[]) so it must be transformed into a string
Expand Down
6 changes: 5 additions & 1 deletion LaserGRBL/UserControls/GrblPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using LaserGRBL;
using SharpGL;

namespace LaserGRBL.UserControls
{
Expand All @@ -27,7 +28,10 @@ public partial class GrblPanel : UserControl, IGrblPanel
public GrblPanel()
{
InitializeComponent();

GrblPanel3D.CurrentRendererType = "GDI+";
GrblPanel3D.CurrentVendor = "LaserGRBL";
GrblPanel3D.CurrentRenderer = "Legacy Preview";
Logger.LogMessage("OpenGL", "{0} {1}, {2}", GrblPanel3D.CurrentRendererType, GrblPanel3D.CurrentVendor, GrblPanel3D.CurrentRenderer);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
Expand Down
25 changes: 24 additions & 1 deletion LaserGRBL/UserControls/GrblPanel3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public partial class GrblPanel3D : UserControl, IGrblPanel

private Exception FatalException;

public static string CurrentRendererType = "";
public static string CurrentVendor = "";
public static string CurrentRenderer = "";
public static string CurrentGLVersion = "";

public GrblPanel3D()
{
InitializeComponent();
Expand Down Expand Up @@ -121,6 +126,7 @@ private void GlThread()
}
catch (Exception ex)
{
Logger.LogException("OpenGL", ex);
FatalException = ex;
Invalidate();
ExceptionManager.OnHandledException(ex, true);
Expand Down Expand Up @@ -192,7 +198,24 @@ protected void InitializeOpenGL()
{
object parameter = null;
OpenGL = new OpenGL();
OpenGL.Create(OpenGLVersion.OpenGL2_1, RenderContextType.DIBSection, Width, Height, 32, parameter);

try
{
CurrentRendererType = "FBO";
OpenGL.Create(OpenGLVersion.OpenGL2_1, RenderContextType.FBO, Width, Height, 32, parameter);
}
catch
{
CurrentRendererType = "DIB";
OpenGL.Create(OpenGLVersion.OpenGL2_1, RenderContextType.DIBSection, Width, Height, 32, parameter);
}

try { CurrentVendor = OpenGL.Vendor; } catch { CurrentVendor = "Unknown"; }
try { CurrentRenderer = OpenGL.Renderer; } catch { CurrentRenderer = "Unknown"; }
try { CurrentGLVersion = OpenGL.Version; } catch { CurrentGLVersion = "0.0"; }

Logger.LogMessage("OpenGL", "{0} OpenGL {1}, {2}, {3}", CurrentRendererType, CurrentGLVersion, CurrentVendor, CurrentRenderer);

OpenGL.ShadeModel(OpenGL.GL_SMOOTH);
OpenGL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
OpenGL.ClearDepth(1.0f);
Expand Down

0 comments on commit 42776d3

Please sign in to comment.