diff --git a/src/main/java/com/marginallyclever/makelangelo/DialogBadFirmwareVersion.java b/src/main/java/com/marginallyclever/makelangelo/DialogBadFirmwareVersion.java index ab75217fd..dffdd51f0 100644 --- a/src/main/java/com/marginallyclever/makelangelo/DialogBadFirmwareVersion.java +++ b/src/main/java/com/marginallyclever/makelangelo/DialogBadFirmwareVersion.java @@ -2,9 +2,9 @@ import com.marginallyclever.makelangelo.select.SelectReadOnlyText; -import java.awt.Component; -import javax.swing.JOptionPane; +import javax.swing.*; import javax.swing.text.JTextComponent; +import java.awt.*; @Deprecated public class DialogBadFirmwareVersion { diff --git a/src/main/java/com/marginallyclever/makelangelo/Makelangelo.java b/src/main/java/com/marginallyclever/makelangelo/Makelangelo.java index 17a05d0c6..7bc96d607 100644 --- a/src/main/java/com/marginallyclever/makelangelo/Makelangelo.java +++ b/src/main/java/com/marginallyclever/makelangelo/Makelangelo.java @@ -443,10 +443,6 @@ public Plotter getPlotter() { return myPlotter; } - public PlotterSettingsManager getPlotterSettingsManager() { - return plotterSettingsManager; - } - public MainFrame getFrame() { return mainFrame; } diff --git a/src/main/java/com/marginallyclever/makelangelo/MeshFactory.java b/src/main/java/com/marginallyclever/makelangelo/MeshFactory.java new file mode 100644 index 000000000..0ba8974fc --- /dev/null +++ b/src/main/java/com/marginallyclever/makelangelo/MeshFactory.java @@ -0,0 +1,43 @@ +package com.marginallyclever.makelangelo; + +import com.jogamp.opengl.GL3; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +/** + * A factory for creating and maintaining Mesh objects. + */ +public class MeshFactory { + private static final Logger logger = LoggerFactory.getLogger(MeshFactory.class); + + // the pool of all mesh loaded + private static final List meshPool = new ArrayList<>(); + + /** + * Create a new mesh and add it to the pool. This should be the only way to create a mesh. + * @return a new mesh + */ + public static Mesh createMesh() { + Mesh m = new Mesh(); + addMesh(m); + return m; + } + + public static void addMesh(Mesh mesh) { + if(meshPool.contains(mesh)) return; + meshPool.add(mesh); + } + + public static void removeMesh(Mesh mesh) { + meshPool.remove(mesh); + } + + public static void unloadAll(GL3 gl) { + for(Mesh m : meshPool) { + m.unload(gl); + } + } +} diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewListener.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewListener.java index 609ae4bb8..0f0263b97 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewListener.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewListener.java @@ -1,7 +1,5 @@ package com.marginallyclever.makelangelo.apps.previewpanel; -import com.jogamp.opengl.GL3; - import java.util.EventListener; /** @@ -15,5 +13,5 @@ public interface PreviewListener extends EventListener { * Callback from {@link PreviewPanel} that it is time to render to the WYSIWYG display. * @param gl the render context */ - void render(GL3 gl3); + void render(RenderContext context); } diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewPanel.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewPanel.java index 3a0b19f8d..1718a5f12 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewPanel.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewPanel.java @@ -7,6 +7,7 @@ import com.marginallyclever.convenience.helpers.OpenGLHelper; import com.marginallyclever.convenience.helpers.ResourceHelper; import com.marginallyclever.makelangelo.Camera; +import com.marginallyclever.makelangelo.MeshFactory; import com.marginallyclever.makelangelo.Translator; import com.marginallyclever.makelangelo.applicationsettings.GFXPreferences; import com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer.PlotterRenderer; @@ -95,9 +96,9 @@ public PreviewPanel(Paper paper, Plotter plotter) { addListener(paper); addListener(myTurtleRenderer); - addListener((gl) -> { + addListener(context -> { if(myPlotterRenderer!=null) { - myPlotterRenderer.render(gl, myPlotter); + myPlotterRenderer.render(context, myPlotter); } }); @@ -321,6 +322,7 @@ public void dispose(GLAutoDrawable glAutoDrawable) { logger.debug("dispose"); GL3 gl = glAutoDrawable.getGL().getGL3(); TextureFactory.unloadAll(gl); + MeshFactory.unloadAll(gl); shaderDefault.delete(gl); } @@ -392,7 +394,7 @@ public void display(GLAutoDrawable glautodrawable) { shaderDefault.use(gl3); paintCamera(gl3, shaderDefault); } - p.render(gl3); + p.render(new RenderContext(gl3, shaderDefault)); } } diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/RenderContext.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/RenderContext.java new file mode 100644 index 000000000..bd6c07b94 --- /dev/null +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/RenderContext.java @@ -0,0 +1,13 @@ +package com.marginallyclever.makelangelo.apps.previewpanel; + +import com.jogamp.opengl.GL3; + +public class RenderContext { + public GL3 gl; + public ShaderProgram shader; + + public RenderContext(GL3 gl, ShaderProgram shader) { + this.gl = gl; + this.shader = shader; + } +} diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Cartesian.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Cartesian.java index 418580ade..026c0d85c 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Cartesian.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Cartesian.java @@ -2,28 +2,43 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.makelangelo.Mesh; +import com.marginallyclever.makelangelo.MeshFactory; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.plotter.Plotter; import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings; import javax.vecmath.Point2d; public class Cartesian implements PlotterRenderer { - public final double CARTESIAN_MOTOR_MOUNT_SIZE =45; //cm - public final double CARTESIAN_PLOTTER_SIZE=60; //cm - public final double CARTESIAN_PLOTTER_OUTER_SIZE=70; //cm - public final double CARTESIAN_PLOTTER_HOLE_SIZE=20; //cm - public final double CARTESIAN_MOTOR_BODY_SIZE =42; //cm + public static final int CARTESIAN_MOTOR_MOUNT_SIZE =45; //cm + public static final int CARTESIAN_PLOTTER_SIZE=60; //cm + public static final int CARTESIAN_PLOTTER_OUTER_SIZE=70; //cm + public static final int CARTESIAN_PLOTTER_HOLE_SIZE=20; //cm + public static final int NEMA17_SIZE = 42; //cm - public final Mesh meshMotor = new Mesh(); - public final Mesh meshGantry = new Mesh(); - public final Mesh meshControlBox = new Mesh(); + public final Mesh meshQuad = MeshFactory.createMesh(); + public Cartesian() { + setupMesh(); + } + + private void setupMesh() { + meshQuad.setRenderStyle(GL3.GL_QUADS); + meshQuad.addColor(1,1,1, 1); + meshQuad.addColor(1,1,1, 1); + meshQuad.addColor(1,1,1, 1); + meshQuad.addColor(1,1,1, 1); + meshQuad.addVertex(0, 0,0); + meshQuad.addVertex(0, 1,0); + meshQuad.addVertex(1, 1,0); + meshQuad.addVertex(1, 0,0); + } @Override - public void render(GL3 gl,Plotter robot) { - paintGantryAndHead(gl,robot); - paintMotors(gl,robot); - paintControlBox(gl,robot); + public void render(RenderContext context, Plotter robot) { + paintGantryAndHead(context.gl,robot); + paintMotors(context.gl,robot); + paintControlBox(context.gl,robot); } @Override @@ -98,19 +113,10 @@ protected void paintMotors(GL3 gl,Plotter plotter) { } private void paintOneMotor(GL3 gl) { -// TODO implement me -/* - // motor - gl.glColor3f(0, 0, 0); - gl.glBegin(GL3.GL_QUADS); - gl.glVertex2d(0 , 0 ); - gl.glVertex2d(0 , CARTESIAN_MOTOR_BODY_SIZE); - gl.glVertex2d(CARTESIAN_MOTOR_BODY_SIZE, CARTESIAN_MOTOR_BODY_SIZE); - gl.glVertex2d(CARTESIAN_MOTOR_BODY_SIZE, 0 ); - gl.glVertex2d(0 , 0 ); - gl.glEnd();*/ + // TODO set color to black? load NEMA17 motor picture? + meshQuad.render(gl); } - + /** * paint the controller and the LCD panel * @param gl the render context diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo3.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo3.java index 41e771ca5..1e978b2e4 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo3.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo3.java @@ -1,7 +1,7 @@ package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer; import com.jogamp.opengl.GL3; -import com.marginallyclever.makelangelo.apps.previewpanel.ShaderProgram; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.plotter.Plotter; import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings; @@ -13,11 +13,11 @@ public class Makelangelo3 implements PlotterRenderer { @Override - public void render(GL3 gl,Plotter robot) { - paintControlBox(gl,robot); - Polargraph.paintMotors(gl,robot); + public void render(RenderContext context, Plotter robot) { + paintControlBox(context.gl,robot); + Polargraph.paintMotors(context,robot); if(robot.getDidFindHome()) - Polargraph.paintPenHolderToCounterweights(gl,robot); + Polargraph.paintPenHolderToCounterweights(context,robot); } @Override diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo3_3.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo3_3.java index c18e51257..a5b280e50 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo3_3.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo3_3.java @@ -1,18 +1,18 @@ package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer; import com.jogamp.opengl.GL3; -import com.marginallyclever.makelangelo.apps.previewpanel.ShaderProgram; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.plotter.Plotter; import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings; public class Makelangelo3_3 implements PlotterRenderer { @Override - public void render(GL3 gl,Plotter robot) { - paintControlBox(gl,robot); - Polargraph.paintMotors(gl,robot); + public void render(RenderContext context, Plotter robot) { + paintControlBox(context.gl,robot); + Polargraph.paintMotors(context,robot); if(robot.getDidFindHome()) - Polargraph.paintPenHolderToCounterweights(gl,robot); + Polargraph.paintPenHolderToCounterweights(context,robot); } @Override diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo5.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo5.java index 47c2fd988..f5b8356db 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo5.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo5.java @@ -3,6 +3,8 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.convenience.helpers.DrawingHelper; import com.marginallyclever.makelangelo.Mesh; +import com.marginallyclever.makelangelo.MeshFactory; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.plotter.Plotter; import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings; import com.marginallyclever.makelangelo.texture.TextureFactory; @@ -18,7 +20,7 @@ public class Makelangelo5 implements PlotterRenderer { private final TextureWithMetadata textureGondola = TextureFactory.loadTexture("/textures/phBody.png"); private final TextureWithMetadata textureArm = TextureFactory.loadTexture("/textures/phArm2.png"); - private final Mesh controlBox = new Mesh(); + private final Mesh controlBox = MeshFactory.createMesh(); private void setupControlBoxMesh(PlotterSettings settings) { float left = (float)settings.getDouble(PlotterSettings.LIMIT_LEFT); @@ -43,22 +45,22 @@ private void setupControlBoxMesh(PlotterSettings settings) { } @Override - public void render(GL3 gl, Plotter robot) { + public void render(RenderContext context, Plotter robot) { if (textureMainBody != null) { - paintControlBoxFancy(gl, textureMainBody); + paintControlBoxFancy(context, textureMainBody); } - Polargraph.paintSafeArea(gl, robot); + Polargraph.paintSafeArea(context, robot); if (robot.getDidFindHome()) - paintPenHolderToCounterweights(gl, robot); + paintPenHolderToCounterweights(context, robot); if (textureMotors != null) { - paintControlBoxFancy(gl, textureMotors); + paintControlBoxFancy(context, textureMotors); } if (textureLogo != null) { - paintLogoFancy(gl, robot.getSettings()); + paintLogoFancy(context, robot.getSettings()); } } @@ -67,7 +69,7 @@ public void updatePlotterSettings(PlotterSettings settings) { setupControlBoxMesh(settings); } - public void paintPenHolderToCounterweights(GL3 gl, Plotter robot) { + public void paintPenHolderToCounterweights(RenderContext context, Plotter robot) { Point2d pos = robot.getPos(); double gx = pos.x; double gy = pos.y; @@ -94,21 +96,21 @@ public void paintPenHolderToCounterweights(GL3 gl, Plotter robot) { double right_b = (beltLength - right_a) / 2 - 55; // belt from motor to pen holder left - drawBeltMinus10(gl,left,top,gx,gy); + drawBeltMinus10(context.gl,left,top,gx,gy); // belt from motor to pen holder right - drawBeltMinus10(gl,right,top,gx,gy); + drawBeltMinus10(context.gl,right,top,gx,gy); // belt from motor to counterweight left - paintBeltSide(gl,left,top,left_b); + paintBeltSide(context.gl,left,top,left_b); // belt from motor to counterweight right - paintBeltSide(gl,right,top,right_b); + paintBeltSide(context.gl,right,top,right_b); - paintGondola(gl,gx,gy,robot); + paintGondola(context.gl,gx,gy,robot); // left - paintCounterweight(gl,left,top-left_b); + paintCounterweight(context.gl,left,top-left_b); // right - paintCounterweight(gl,right,top-right_b); + paintCounterweight(context.gl,right,top-right_b); } private void drawBeltMinus10(GL3 gl, double cornerX, double cornerY, double penX, double penY) { @@ -175,20 +177,20 @@ private void paintCounterweight(GL3 gl,double x,double y) { DrawingHelper.paintTexture(gl, textureWeight, x-20, y-74, 40,80); } - private void paintControlBoxFancy(GL3 gl,TextureWithMetadata texture) { - //shaderProgram.set1i(gl,"useTexture",1); - texture.use(gl); - //controlBox.render(gl); + private void paintControlBoxFancy(RenderContext context,TextureWithMetadata texture) { + context.shader.set1i(context.gl,"useTexture",1); + texture.use(context.gl); + controlBox.render(context.gl); //shaderProgram.set1i(gl,"useTexture",0); } /** * Paint the Marginally Clever Logo * - * @param gl the render context + * @param context the render context * @param settings the machine settings */ - private void paintLogoFancy(GL3 gl, PlotterSettings settings) { + private void paintLogoFancy(RenderContext context, PlotterSettings settings) { // TODO implement me /* // bottom left corner of safe area diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo5Huge.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo5Huge.java index 439478146..d4ad3c559 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo5Huge.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Makelangelo5Huge.java @@ -1,6 +1,8 @@ package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer; import com.jogamp.opengl.GL3; +import com.marginallyclever.convenience.helpers.DrawingHelper; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.plotter.Plotter; import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings; import com.marginallyclever.makelangelo.texture.TextureFactory; @@ -8,8 +10,6 @@ import javax.vecmath.Point2d; -import static com.marginallyclever.convenience.helpers.DrawingHelper.paintTexture; - public class Makelangelo5Huge implements PlotterRenderer { private static TextureWithMetadata textureMainBody; private static TextureWithMetadata textureMotorMounts; @@ -19,7 +19,7 @@ public class Makelangelo5Huge implements PlotterRenderer { private static TextureWithMetadata textureArm; @Override - public void render(GL3 gl, Plotter robot) { + public void render(RenderContext context, Plotter robot) { if (textureMainBody == null) textureMainBody = TextureFactory.loadTexture("/textures/huge.png"); if (textureMotorMounts == null) textureMotorMounts = TextureFactory.loadTexture("/textures/huge-motors.png"); if (textureLogo == null) textureLogo = TextureFactory.loadTexture("/logo.png"); @@ -28,26 +28,26 @@ public void render(GL3 gl, Plotter robot) { if (textureArm == null) textureArm = TextureFactory.loadTexture("/textures/phArm2.png"); if (textureMainBody == null) { - paintControlBoxPlain(gl, robot); + paintControlBoxPlain(context, robot); } else { - paintControlBoxFancy(gl, robot, textureMainBody); + paintControlBoxFancy(context, robot, textureMainBody); } - Polargraph.paintSafeArea(gl, robot); + Polargraph.paintSafeArea(context, robot); if (robot.getDidFindHome()) - paintPenHolderToCounterweights(gl, robot); + paintPenHolderToCounterweights(context, robot); if (textureMotorMounts == null) { - Polargraph.paintMotors(gl, robot); + Polargraph.paintMotors(context, robot); } else { - paintControlBoxFancy(gl, robot, textureMotorMounts); + paintControlBoxFancy(context, robot, textureMotorMounts); } if (textureLogo == null) { // paintLogo(gl,robot); } else { - paintLogoFancy(gl, robot); + paintLogoFancy(context, robot); } } @@ -56,7 +56,7 @@ public void updatePlotterSettings(PlotterSettings settings) { } - private void paintControlBoxFancy(GL3 gl, Plotter robot,TextureWithMetadata texture) { + private void paintControlBoxFancy(RenderContext context, Plotter robot,TextureWithMetadata texture) { double left = robot.getSettings().getDouble(PlotterSettings.LIMIT_LEFT); final double scaleX = 1366 / 943.0; // machine is 1366 motor-to-motor. texture is 922. scaleX accordingly. @@ -65,10 +65,10 @@ private void paintControlBoxFancy(GL3 gl, Plotter robot,TextureWithMetadata text final double ox = left - 51 * scaleX; // 106 taken from offset in texture map final double oy = -280 * scaleX; // 109 taken from offset in texture map. TODO why -15 instead of top? - paintTexture(gl, texture, ox, oy, width, height); + DrawingHelper.paintTexture(context.gl, texture, ox, oy, width, height); } - public void paintPenHolderToCounterweights(GL3 gl, Plotter robot) { + public void paintPenHolderToCounterweights(RenderContext context, Plotter robot) { Point2d pos = robot.getPos(); double gx = pos.x; double gy = pos.y; @@ -96,21 +96,21 @@ public void paintPenHolderToCounterweights(GL3 gl, Plotter robot) { // belt from motor to pen holder left - drawBeltMinus10(gl,left,top,gx,gy); + drawBeltMinus10(context.gl,left,top,gx,gy); // belt from motor to pen holder right - drawBeltMinus10(gl,right,top,gx,gy); + drawBeltMinus10(context.gl,right,top,gx,gy); // belt from motor to counterweight left - paintBeltSide(gl,left,top,left_b); + paintBeltSide(context.gl,left,top,left_b); // belt from motor to counterweight right - paintBeltSide(gl,right,top,right_b); + paintBeltSide(context.gl,right,top,right_b); - paintGondola(gl,gx,gy,robot); + paintGondola(context.gl,gx,gy,robot); // left - paintCounterweight(gl,left,top-left_b); + paintCounterweight(context,left,top-left_b); // right - paintCounterweight(gl,right,top-right_b); + paintCounterweight(context,right,top-right_b); } private void drawBeltMinus10(GL3 gl, double cornerX, double cornerY, double penX, double penY) { @@ -166,35 +166,35 @@ private void paintGondolaFancy(GL3 gl, double gx, double gy,Plotter robot) { gl.glPushMatrix(); gl.glTranslated(gx,gy,0); gl.glRotated(Math.toDegrees(angleLeft)+90,0,0,1); - paintTexture(gl,textureArm,-100,-100,200,200); + DrawingHelper.paintTexture(gl,textureArm,-100,-100,200,200); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslated(gx,gy,0); gl.glRotated(Math.toDegrees(angleRight)+90,0,0,1); - paintTexture(gl,textureArm,-100,-100,200,200); + DrawingHelper.paintTexture(gl,textureArm,-100,-100,200,200); gl.glPopMatrix(); // paint body last so it's on top - paintTexture(gl,textureGondola,gx-50,gy-50,100,100);*/ + DrawingHelper.paintTexture(gl,textureGondola,gx-50,gy-50,100,100);*/ } - private void paintCounterweight(GL3 gl,double x,double y) { + private void paintCounterweight(RenderContext context,double x,double y) { if(textureWeight==null) { - Polargraph.paintCounterweight(gl,x,y); + Polargraph.paintCounterweight(context.gl,x,y); return; } - paintTexture(gl, textureWeight, x-20, y-74, 40,80); + DrawingHelper.paintTexture(context.gl, textureWeight, x-20, y-74, 40,80); } /** * paint the Marginally Clever Logo * - * @param gl the render context + * @param context the render context * @param robot the machine to draw. */ - private void paintLogoFancy(GL3 gl, Plotter robot) { + private void paintLogoFancy(RenderContext context, Plotter robot) { final double scale = 0.5; final double TW = 128 * scale; final double TH = 128 * scale; @@ -202,16 +202,16 @@ private void paintLogoFancy(GL3 gl, Plotter robot) { final float LOGO_X = (float)robot.getSettings().getDouble(PlotterSettings.LIMIT_LEFT) - 65; // bottom left corner of safe Area final float LOGO_Y = (float)robot.getSettings().getDouble(PlotterSettings.LIMIT_BOTTOM)+10; - paintTexture(gl, textureLogo, LOGO_X, LOGO_Y, TW, TH); + DrawingHelper.paintTexture(context.gl, textureLogo, LOGO_X, LOGO_Y, TW, TH); } /** * paint the controller and the LCD panel * - * @param gl the render context + * @param context the render context * @param robot the machine to draw. */ - private void paintControlBoxPlain(GL3 gl, Plotter robot) { + private void paintControlBoxPlain(RenderContext context, Plotter robot) { // TODO implement me /* double cy = robot.getSettings().getDouble(PlotterSettings.LIMIT_TOP); diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/MakelangeloCustom.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/MakelangeloCustom.java index 56ee77cc4..3c69f2325 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/MakelangeloCustom.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/MakelangeloCustom.java @@ -1,7 +1,7 @@ package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer; import com.jogamp.opengl.GL3; -import com.marginallyclever.makelangelo.apps.previewpanel.ShaderProgram; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.plotter.Plotter; import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings; import com.marginallyclever.makelangelo.texture.TextureFactory; @@ -20,13 +20,13 @@ public class MakelangeloCustom implements PlotterRenderer { } @Override - public void render(GL3 gl,Plotter robot) { + public void render(RenderContext context, Plotter robot) { PlotterSettings settings = robot.getSettings(); - paintControlBox(gl,settings); - paintMotors(gl,settings); + paintControlBox(context,settings); + paintMotors(context,settings); if(robot.getDidFindHome()) - paintPenHolderToCounterweights(gl,robot); + paintPenHolderToCounterweights(context,robot); } @Override @@ -39,7 +39,7 @@ public void updatePlotterSettings(PlotterSettings settings) { * @param gl the render context * @param settings plottersettings of the robot */ - private void paintControlBox(GL3 gl, PlotterSettings settings) { + private void paintControlBox(RenderContext context, PlotterSettings settings) { // TODO implement me /* double cy = settings.getDouble(PlotterSettings.LIMIT_TOP); @@ -94,7 +94,7 @@ private void paintControlBox(GL3 gl, PlotterSettings settings) { } // draw left & right motor - private void paintMotors(GL3 gl, PlotterSettings settings) { + private void paintMotors(RenderContext context, PlotterSettings settings) { // TODO implement me /* double top = settings.getDouble(PlotterSettings.LIMIT_TOP); @@ -152,7 +152,7 @@ private void renderLCD(GL3 gl, double left) { gl.glPopMatrix();*/ } - private void paintPenHolderToCounterweights(GL3 gl, Plotter robot ) { + private void paintPenHolderToCounterweights(RenderContext context, Plotter robot ) { // TODO implement me /* PlotterSettings settings = robot.getSettings(); diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/PlotterRenderer.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/PlotterRenderer.java index 8ee75039a..c635f93f1 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/PlotterRenderer.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/PlotterRenderer.java @@ -1,6 +1,6 @@ package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer; -import com.jogamp.opengl.GL3; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.plotter.Plotter; import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings; @@ -15,11 +15,12 @@ public interface PlotterRenderer { /** * Custom look and feel for each version - * - * @param gl the render context - * @param robot the machine to draw. + * + * @param gl the render context + * @param context + * @param robot the machine to draw. */ - void render(GL3 gl, Plotter robot); + void render(RenderContext context, Plotter robot); /** * Update the settings for the plotter. diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Polargraph.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Polargraph.java index 8bc99953d..7342c80b7 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Polargraph.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Polargraph.java @@ -2,6 +2,8 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.makelangelo.Mesh; +import com.marginallyclever.makelangelo.MeshFactory; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.plotter.Plotter; import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings; @@ -12,12 +14,12 @@ * @author Dan Royer */ public abstract class Polargraph implements PlotterRenderer { - public static final float PEN_HOLDER_RADIUS_2= 60f; // cm - public static final float MOTOR_SIZE= 21f; // cm + public static final float PEN_HOLDER_RADIUS_2 = 60f; // cm + public static final float MOTOR_SIZE = 21f; // cm public static final float COUNTERWEIGHT_HALF_WIDTH = 15; public static final float COUNTERWEIGHT_HEIGHT = 100; - public Mesh mesh = new Mesh(); + public Mesh mesh = MeshFactory.createMesh(); /** * convert from belt length mm to cartesian position. @@ -65,24 +67,24 @@ public Point2d IK(Plotter plotter,double x,double y) { } @Override - public void render(GL3 gl, Plotter robot) { + public void render(RenderContext context, Plotter robot) { mesh.clear(); mesh.setRenderStyle(GL3.GL_LINES); - drawPhysicalLimits(gl,robot); + drawPhysicalLimits(context,robot); - paintMotors(gl, robot); - paintControlBox(gl, robot); + paintMotors(context, robot); + paintControlBox(context, robot); if(robot.getDidFindHome()) { - paintPenHolderToCounterweights(gl, robot); + paintPenHolderToCounterweights(context, robot); } } /** * Outline the drawing limits - * @param gl + * @param context the rendering context */ - private void drawPhysicalLimits(GL3 gl,Plotter robot) { + private void drawPhysicalLimits(RenderContext context,Plotter robot) { // TODO implement me /* mesh.addColor(0.9f, 0.9f, 0.9f,1.0f); // #color @@ -96,7 +98,7 @@ private void drawPhysicalLimits(GL3 gl,Plotter robot) { gl.glEnd();*/ } - static public void paintMotors(GL3 gl,Plotter robot) { + static public void paintMotors(RenderContext context,Plotter robot) { // TODO implement me /* double top = robot.getSettings().getDouble(PlotterSettings.LIMIT_TOP); @@ -118,7 +120,7 @@ static public void paintMotors(GL3 gl,Plotter robot) { gl.glEnd();*/ } - private void paintControlBox(GL3 gl, Plotter robot) { + private void paintControlBox(RenderContext context, Plotter robot) { // TODO implement me /* double cy = robot.getSettings().getDouble(PlotterSettings.LIMIT_TOP); @@ -166,7 +168,7 @@ private void paintControlBox(GL3 gl, Plotter robot) { gl.glPopMatrix();*/ } - static public void paintPenHolderToCounterweights(GL3 gl, Plotter robot) { + static public void paintPenHolderToCounterweights(RenderContext context, Plotter robot) { Point2d pos = robot.getPos(); @@ -210,12 +212,12 @@ static public void paintPenHolderToCounterweights(GL3 gl, Plotter robot) { // belt from motor to counterweight right //paintBeltSide(gl,right,top,right_b); - paintGondola(gl,gx,gy,robot); + paintGondola(context.gl,gx,gy,robot); // left - paintCounterweight(gl,left,top-left_b); + paintCounterweight(context.gl,left,top-left_b); // right - paintCounterweight(gl,right,top-right_b); + paintCounterweight(context.gl,right,top-right_b); } private static void paintBeltSide(GL3 gl,double x, double y, double length) { @@ -295,7 +297,7 @@ public static void drawCircle(GL3 gl, double gx, double gy, float penHolderRadiu gl.glEnd();*/ } - public static void paintSafeArea(GL3 gl, Plotter robot) { + public static void paintSafeArea(RenderContext context, Plotter robot) { // TODO implement me /* PlotterSettings settings = robot.getSettings(); diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Zarplotter.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Zarplotter.java index 38eec88e2..3efe65e67 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Zarplotter.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Zarplotter.java @@ -1,7 +1,9 @@ package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer; import com.jogamp.opengl.GL3; -import com.marginallyclever.makelangelo.apps.previewpanel.ShaderProgram; +import com.marginallyclever.makelangelo.Mesh; +import com.marginallyclever.makelangelo.MeshFactory; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.plotter.Plotter; import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings; @@ -9,18 +11,36 @@ * @author Dan Royer */ public class Zarplotter implements PlotterRenderer { - final public double ZAR_MOTOR_MOUNT_SIZE=45; //cm - final public double ZAR_PLOTTER_SIZE=60; //cm - final public double ZAR_PLOTTER_OUTER_SIZE=70; //cm - final public double ZAR_PLOTTER_HOLE_SIZE=20; //cm - final public double ZAR_MOTOR_BODY_SIZE=42; //cm - + public static final int ZAR_MOTOR_MOUNT_SIZE=45; //cm + public static final int ZAR_PLOTTER_SIZE=60; //cm + public static final int ZAR_PLOTTER_OUTER_SIZE=70; //cm + public static final int ZAR_PLOTTER_HOLE_SIZE=20; //cm + public static final int NEMA17_SIZE = 42; //cm + + public final Mesh meshQuad = MeshFactory.createMesh(); + + public Zarplotter() { + setupMesh(); + } + + private void setupMesh() { + meshQuad.setRenderStyle(GL3.GL_QUADS); + meshQuad.addColor(1,1,1, 1); + meshQuad.addColor(1,1,1, 1); + meshQuad.addColor(1,1,1, 1); + meshQuad.addColor(1,1,1, 1); + meshQuad.addVertex(0,0,0); + meshQuad.addVertex(0,1,0); + meshQuad.addVertex(1,1,0); + meshQuad.addVertex(1,0,0); + } + @Override - public void render(GL3 gl,Plotter robot) { - paintMotors(gl,robot); - paintControlBox(gl,robot); + public void render(RenderContext context, Plotter robot) { + paintMotors(context,robot); + paintControlBox(context,robot); if(robot.getDidFindHome()) - paintPenHolderToCounterweights(gl,robot); + paintPenHolderToCounterweights(context,robot); } @Override @@ -28,7 +48,7 @@ public void updatePlotterSettings(PlotterSettings settings) { } - private void paintPenHolderToCounterweights(GL3 gl, Plotter robot) { + private void paintPenHolderToCounterweights(RenderContext context, Plotter robot) { // TODO implement me /* PlotterSettings settings = robot.getSettings(); @@ -82,7 +102,7 @@ private void paintPenHolderToCounterweights(GL3 gl, Plotter robot) { gl.glEnd();*/ } - private void paintMotors(GL3 gl,Plotter plotter) { + private void paintMotors(RenderContext context,Plotter plotter) { // TODO implement me /* double top = plotter.getSettings().getDouble(PlotterSettings.LIMIT_TOP); @@ -109,19 +129,13 @@ private void paintOneMotor(GL3 gl) { gl.glVertex2d(ZAR_MOTOR_MOUNT_SIZE, 0 ); gl.glVertex2d(0 , 0 ); gl.glEnd(); - - // motor - gl.glColor3f(0, 0, 0); - gl.glBegin(GL3.GL_QUADS); - gl.glVertex2d(0 , 0 ); - gl.glVertex2d(0 , ZAR_MOTOR_BODY_SIZE); - gl.glVertex2d(ZAR_MOTOR_BODY_SIZE, ZAR_MOTOR_BODY_SIZE); - gl.glVertex2d(ZAR_MOTOR_BODY_SIZE, 0 ); - gl.glVertex2d(0 , 0 ); - gl.glEnd();*/ + */ + + // TODO set color to black? load NEMA17 motor picture? + meshQuad.render(gl); } - private void paintControlBox(GL3 gl,Plotter plotter) { + private void paintControlBox(RenderContext context,Plotter plotter) { // TODO implement me /* double cy = plotter.getSettings().getDouble(PlotterSettings.LIMIT_TOP); @@ -154,79 +168,4 @@ private void paintControlBox(GL3 gl,Plotter plotter) { gl.glPopMatrix();*/ } -/* - @Override - public Point2d getHome() { - return new Point2d(0,0); - } - - @Override - public String getVersion() { - return "6"; - } - - @Override - public boolean canAutoHome() { - return false; - } - - @Override - public boolean canChangeMachineSize() { - return true; - } - - @Override - public boolean canAccelerate() { - return true; - } - - @Override - public boolean canChangeHome() { - // TODO Auto-generated method stub - return false; - } - - @Override - public float getWidth() { - return 3 * 12 * 25.4f; // 3' - } - - @Override - public float getHeight() { - return 3 * 12 * 25.4f; // 3' - } - - @Override - public float getFeedrateMax() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public float getFeedrateDefault() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public float getAccelerationMax() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public float getDouble(PlotterSettings.PEN_ANGLE_UP_TIME) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public float getZAngleOn() { - return 0; - } - - @Override - public float getZAngleOff() { - return 90; - }*/ } diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/BarberPoleTurtleRenderer.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/BarberPoleTurtleRenderer.java index 7e3b360ea..f090a48a9 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/BarberPoleTurtleRenderer.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/BarberPoleTurtleRenderer.java @@ -2,8 +2,10 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.makelangelo.Mesh; +import com.marginallyclever.makelangelo.MeshFactory; import com.marginallyclever.makelangelo.Translator; import com.marginallyclever.makelangelo.applicationsettings.GFXPreferences; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.turtle.TurtleMove; import java.awt.*; @@ -14,25 +16,25 @@ * */ public class BarberPoleTurtleRenderer implements TurtleRenderer { - private GL3 gl; + private RenderContext context; private Color colorTravel = Color.GREEN; private boolean showPenUp = false; private float penDiameter = 1; private int moveCounter; - private final Mesh mesh = new Mesh(); + private final Mesh mesh = MeshFactory.createMesh(); private boolean isDone=false; private Color colorDraw; @Override - public void start(GL3 gl) { - this.gl = gl; + public void start(RenderContext context) { + this.context = context; showPenUp = GFXPreferences.getShowPenUp(); mesh.setRenderStyle(GL3.GL_TRIANGLES); moveCounter = 0; if(!isDone) { - mesh.unload(gl); + mesh.unload(context.gl); mesh.clear(); } } @@ -40,7 +42,7 @@ public void start(GL3 gl) { @Override public void end() { isDone=true; - mesh.render(gl); + mesh.render(context.gl); } @Override diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/DefaultTurtleRenderer.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/DefaultTurtleRenderer.java index ad72a9354..e1b1e02cc 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/DefaultTurtleRenderer.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/DefaultTurtleRenderer.java @@ -2,8 +2,10 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.makelangelo.Mesh; +import com.marginallyclever.makelangelo.MeshFactory; import com.marginallyclever.makelangelo.Translator; import com.marginallyclever.makelangelo.applicationsettings.GFXPreferences; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.turtle.TurtleMove; import java.awt.*; @@ -14,23 +16,23 @@ * */ public class DefaultTurtleRenderer implements TurtleRenderer { - private GL3 gl; + private RenderContext context; private Color colorTravel = Color.GREEN; private Color colorDraw = Color.BLACK; private boolean showPenUp = false; private float penDiameter = 1; - private final Mesh mesh = new Mesh(); + private final Mesh mesh = MeshFactory.createMesh(); private boolean isDone = false; @Override - public void start(GL3 gl) { - this.gl = gl; + public void start(RenderContext context) { + this.context = context; showPenUp = GFXPreferences.getShowPenUp(); mesh.setRenderStyle(GL3.GL_TRIANGLES); if(!isDone) { - mesh.unload(gl); + mesh.unload(context.gl); mesh.clear(); } } @@ -39,7 +41,7 @@ public void start(GL3 gl) { public void end() { // end drawing lines isDone=true; - mesh.render(gl); + mesh.render(context.gl); } @Override diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/DirectionLoopTurtleRenderer.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/DirectionLoopTurtleRenderer.java index 7cc0417fb..67b647c23 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/DirectionLoopTurtleRenderer.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/DirectionLoopTurtleRenderer.java @@ -2,8 +2,10 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.makelangelo.Mesh; +import com.marginallyclever.makelangelo.MeshFactory; import com.marginallyclever.makelangelo.Translator; import com.marginallyclever.makelangelo.applicationsettings.GFXPreferences; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.turtle.TurtleMove; import javax.vecmath.Vector3d; @@ -17,23 +19,23 @@ * @since 7.48.0 */ public class DirectionLoopTurtleRenderer implements TurtleRenderer { - private GL3 gl; + private RenderContext context; private Color colorTravel = Color.GREEN; private boolean showPenUp = false; private final ArrayList points = new ArrayList<>(); private float penDiameter = 1; - private final Mesh mesh = new Mesh(); + private final Mesh mesh = MeshFactory.createMesh(); private boolean isDone = false; @Override - public void start(GL3 gl) { - this.gl = gl; + public void start(RenderContext context) { + this.context = context; points.clear(); showPenUp = GFXPreferences.getShowPenUp(); mesh.setRenderStyle(GL3.GL_TRIANGLES); if(!isDone) { - mesh.unload(gl); + mesh.unload(context.gl); mesh.clear(); } } @@ -57,7 +59,7 @@ public void travel(TurtleMove p0, TurtleMove p1) { public void end() { drawPoints(); isDone=true; - mesh.render(gl); + mesh.render(context.gl); } private void drawPoints() { diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/Line2QuadHelper.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/Line2QuadHelper.java index d19d38b91..21dff6ae9 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/Line2QuadHelper.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/Line2QuadHelper.java @@ -9,7 +9,7 @@ import java.awt.*; /** - * Helper class to add a quad to the mesh that represents a line between two points. + * Helper class to convert lines into quads. */ public class Line2QuadHelper { /** * Add a quad to the mesh that represents a line between two points. diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/MarlinSimulationVisualizer.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/MarlinSimulationVisualizer.java index 9148de9a3..491a5288f 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/MarlinSimulationVisualizer.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/MarlinSimulationVisualizer.java @@ -2,7 +2,9 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.makelangelo.Mesh; +import com.marginallyclever.makelangelo.MeshFactory; import com.marginallyclever.makelangelo.Translator; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.plotter.marlinsimulation.MarlinSimulation; import com.marginallyclever.makelangelo.plotter.marlinsimulation.MarlinSimulationBlock; import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings; @@ -33,8 +35,7 @@ public ColorPoint(Vector3d cc, Vector3d pp) { } }; - //private Turtle previousTurtle=null; - private GL3 gl; + private RenderContext context; private final Turtle myTurtle = new Turtle(); private Turtle previousTurtle=null; private PlotterSettings mySettings; @@ -46,7 +47,7 @@ public ColorPoint(Vector3d cc, Vector3d pp) { private float penDiameter = 1; private boolean isDone = false; - private final Mesh mesh = new Mesh(); + private final Mesh mesh = MeshFactory.createMesh(); public MarlinSimulationVisualizer() { mesh.setRenderStyle(GL3.GL_TRIANGLES); @@ -193,11 +194,11 @@ private Color rainbow(double v) { @Override - public void start(GL3 gl) { - this.gl = gl; + public void start(RenderContext context) { + this.context = context; myTurtle.history.clear(); if(!isDone) { - mesh.unload(gl); + mesh.unload(context.gl); mesh.clear(); } } @@ -222,7 +223,7 @@ public void end() { previousTurtle = myTurtle; } isDone=true; - mesh.render(gl); + mesh.render(context.gl); } @Override diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/SeparateLoopTurtleRenderer.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/SeparateLoopTurtleRenderer.java index 2fa9f5cce..a7d9c3085 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/SeparateLoopTurtleRenderer.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/SeparateLoopTurtleRenderer.java @@ -2,8 +2,10 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.makelangelo.Mesh; +import com.marginallyclever.makelangelo.MeshFactory; import com.marginallyclever.makelangelo.Translator; import com.marginallyclever.makelangelo.applicationsettings.GFXPreferences; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.turtle.TurtleMove; import java.awt.*; @@ -14,7 +16,7 @@ * @author Dan Royer */ public class SeparateLoopTurtleRenderer implements TurtleRenderer { - private GL3 gl; + private RenderContext context; private Color colorTravel = Color.GREEN; private boolean showPenUp = false; @@ -23,12 +25,12 @@ public class SeparateLoopTurtleRenderer implements TurtleRenderer { private Color colorDraw = Color.WHITE; private boolean isPenUp; - private final Mesh mesh = new Mesh(); + private final Mesh mesh = MeshFactory.createMesh(); private boolean isDone = false; @Override - public void start(GL3 gl) { - this.gl=gl; + public void start(RenderContext context) { + this.context = context; showPenUp = GFXPreferences.getShowPenUp(); mesh.setRenderStyle(GL3.GL_TRIANGLES); @@ -36,7 +38,7 @@ public void start(GL3 gl) { isPenUp=true; setDrawColor(); if(!isDone) { - mesh.unload(gl); + mesh.unload(context.gl); mesh.clear(); } } @@ -44,7 +46,7 @@ public void start(GL3 gl) { @Override public void end() { isDone=true; - mesh.render(gl); + mesh.render(context.gl); } private void setDrawColor() { diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/TurtleRenderFacade.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/TurtleRenderFacade.java index a9f9323e7..234d455d9 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/TurtleRenderFacade.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/TurtleRenderFacade.java @@ -1,8 +1,8 @@ package com.marginallyclever.makelangelo.apps.previewpanel.turtlerenderer; -import com.jogamp.opengl.GL3; import com.marginallyclever.convenience.helpers.OpenGLHelper; import com.marginallyclever.makelangelo.apps.previewpanel.PreviewListener; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.apps.previewpanel.ShaderProgram; import com.marginallyclever.makelangelo.turtle.MovementType; import com.marginallyclever.makelangelo.turtle.Turtle; @@ -31,7 +31,7 @@ public class TurtleRenderFacade implements PreviewListener { private ShaderProgram shaderLine; @Override - public void render(GL3 gl) { + public void render(RenderContext context) { if(myTurtle.isLocked()) return; myTurtle.lock(); try { @@ -42,18 +42,18 @@ public void render(GL3 gl) { try { float r = (float)penDiameter/2f; - shaderLine.use(gl); - OpenGLHelper.checkGLError(gl,logger); - shaderLine.set1f(gl,"thickness", r); - OpenGLHelper.checkGLError(gl,logger); - shaderLine.set1f(gl,"feather",r * 0.05f); - OpenGLHelper.checkGLError(gl,logger); + shaderLine.use(context.gl); + OpenGLHelper.checkGLError(context.gl,logger); + shaderLine.set1f(context.gl,"thickness", r); + OpenGLHelper.checkGLError(context.gl,logger); + shaderLine.set1f(context.gl,"feather",r * 0.05f); + OpenGLHelper.checkGLError(context.gl,logger); myRenderer.setPenDiameter(penDiameter); myRenderer.setPenUpColor(penUpColor); myRenderer.setPenDownColor(penDownColor); myRenderer.setPenDiameter(penDiameter); - myRenderer.start(gl); + myRenderer.start(context); showCount++; for (TurtleMove m : myTurtle.history) { diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/TurtleRenderer.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/TurtleRenderer.java index 17216e14c..bc041878d 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/TurtleRenderer.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/turtlerenderer/TurtleRenderer.java @@ -1,6 +1,6 @@ package com.marginallyclever.makelangelo.apps.previewpanel.turtlerenderer; -import com.jogamp.opengl.GL3; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.turtle.TurtleMove; import java.awt.*; @@ -9,7 +9,7 @@ * {@link TurtleRenderer} draws a {@link com.marginallyclever.makelangelo.turtle.Turtle} in a specific style. */ public interface TurtleRenderer { - void start(GL3 gl); + void start(RenderContext context); void draw(TurtleMove p0, TurtleMove p1); diff --git a/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_VoronoiStippling.java b/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_VoronoiStippling.java index c0ab328cf..176ace8f2 100644 --- a/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_VoronoiStippling.java +++ b/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_VoronoiStippling.java @@ -3,6 +3,7 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.convenience.voronoi.VoronoiCell; import com.marginallyclever.makelangelo.Translator; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.makeart.TransformedImage; import com.marginallyclever.makelangelo.makeart.tools.InfillTurtle; import com.marginallyclever.makelangelo.paper.Paper; @@ -59,8 +60,8 @@ public void start(Paper paper, TransformedImage image) { } @Override - public void render(GL3 gl) { - super.render(gl); + public void render(RenderContext context) { + super.render(context.gl); // TODO implement me /* diff --git a/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_VoronoiZigZag.java b/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_VoronoiZigZag.java index 5d63d0fba..acac0fdaf 100644 --- a/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_VoronoiZigZag.java +++ b/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_VoronoiZigZag.java @@ -3,6 +3,7 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.convenience.voronoi.VoronoiCell; import com.marginallyclever.makelangelo.Translator; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.makeart.TransformedImage; import com.marginallyclever.makelangelo.paper.Paper; import com.marginallyclever.makelangelo.select.SelectToggleButton; @@ -78,8 +79,8 @@ public boolean iterate() { public void resume() {} @Override - public void render(GL3 gl) { - super.render(gl); + public void render(RenderContext context) { + super.render(context.gl); if(getThread().getPaused()) return; // TODO implement me /* diff --git a/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/SelectImageConverterPanel.java b/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/SelectImageConverterPanel.java index 2e383d2c7..48f9cedeb 100644 --- a/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/SelectImageConverterPanel.java +++ b/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/SelectImageConverterPanel.java @@ -1,8 +1,8 @@ package com.marginallyclever.makelangelo.makeart.imageconverter; -import com.jogamp.opengl.GL3; import com.marginallyclever.makelangelo.Translator; import com.marginallyclever.makelangelo.apps.previewpanel.PreviewListener; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.makeart.TransformedImage; import com.marginallyclever.makelangelo.makeart.imagefilter.FilterContrastAdjust; import com.marginallyclever.makelangelo.makeart.io.LoadFilePanel; @@ -267,9 +267,9 @@ private void eraseOldTurtle() { } @Override - public void render(GL3 gl3) { + public void render(RenderContext context) { if( myConverter != null && myConverter instanceof PreviewListener ) { - ((PreviewListener)myConverter).render(gl3); + ((PreviewListener)myConverter).render(context); } } diff --git a/src/main/java/com/marginallyclever/makelangelo/makeart/io/LoadFilePanel.java b/src/main/java/com/marginallyclever/makelangelo/makeart/io/LoadFilePanel.java index 401218f4a..65f2c21d4 100644 --- a/src/main/java/com/marginallyclever/makelangelo/makeart/io/LoadFilePanel.java +++ b/src/main/java/com/marginallyclever/makelangelo/makeart/io/LoadFilePanel.java @@ -1,8 +1,8 @@ package com.marginallyclever.makelangelo.makeart.io; -import com.jogamp.opengl.GL3; import com.marginallyclever.makelangelo.Translator; import com.marginallyclever.makelangelo.apps.previewpanel.PreviewListener; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.makelangelo.makeart.TransformedImage; import com.marginallyclever.makelangelo.makeart.imageconverter.SelectImageConverterPanel; import com.marginallyclever.makelangelo.paper.Paper; @@ -90,8 +90,8 @@ public boolean onNewFilenameChosen(String filename) { } @Override - public void render(GL3 gl3) { - if(mySubPreviewListener!=null) mySubPreviewListener.render(gl3); + public void render(RenderContext context) { + if(mySubPreviewListener!=null) mySubPreviewListener.render(context); } public void setParent(JDialog parent) { diff --git a/src/main/java/com/marginallyclever/makelangelo/paper/Paper.java b/src/main/java/com/marginallyclever/makelangelo/paper/Paper.java index 31a457a14..bdbc11543 100644 --- a/src/main/java/com/marginallyclever/makelangelo/paper/Paper.java +++ b/src/main/java/com/marginallyclever/makelangelo/paper/Paper.java @@ -2,7 +2,9 @@ import com.jogamp.opengl.GL3; import com.marginallyclever.makelangelo.Mesh; +import com.marginallyclever.makelangelo.MeshFactory; import com.marginallyclever.makelangelo.apps.previewpanel.PreviewListener; +import com.marginallyclever.makelangelo.apps.previewpanel.RenderContext; import com.marginallyclever.util.PreferencesHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,8 +47,8 @@ public class Paper implements PreviewListener { private double centerX=0.0d; private double centerY=0.0d; private Color paperColor = Color.WHITE; - private final Mesh meshPaper = new Mesh(); - private final Mesh meshMargin = new Mesh(); + private final Mesh meshPaper = MeshFactory.createMesh(); + private final Mesh meshMargin = MeshFactory.createMesh(); public Paper() { super(); @@ -54,10 +56,10 @@ public Paper() { } @Override - public void render(GL3 gl) { + public void render(RenderContext context) { // TODO gl.glTranslated(centerX, centerY, 0); - meshPaper.render(gl); - meshMargin.render(gl); + meshPaper.render(context.gl); + meshMargin.render(context.gl); } /** diff --git a/src/main/java/com/marginallyclever/makelangelo/texture/TextureFactory.java b/src/main/java/com/marginallyclever/makelangelo/texture/TextureFactory.java index 7f6a9ef8f..5b5af9e88 100644 --- a/src/main/java/com/marginallyclever/makelangelo/texture/TextureFactory.java +++ b/src/main/java/com/marginallyclever/makelangelo/texture/TextureFactory.java @@ -47,6 +47,5 @@ public static void unloadAll(GL gl) { for(TextureWithMetadata tex : textures) { tex.unload(gl); } - textures.clear(); } }