diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index 26aba61b7..4c7fb35e8 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -67,6 +67,11 @@ public class PGraphicsJava2D extends PGraphics { GeneralPath gpath; + // path for contours so gpath can be closed + GeneralPath auxPath; + + boolean openContour; + /// break the shape at the next vertex (next vertex() call is a moveto()) boolean breakShape; @@ -597,6 +602,7 @@ public class PGraphicsJava2D extends PGraphics { // this way, just check to see if gpath is null, and if it isn't // then just use it to continue the shape. gpath = null; + auxPath = null; } @@ -752,31 +758,63 @@ public class PGraphicsJava2D extends PGraphics { @Override public void beginContour() { - breakShape = true; + if (openContour) { + PGraphics.showWarning("Already called beginContour()"); + return; + } + + // draw contours to auxiliary path so main path can be closed later + GeneralPath contourPath = auxPath; + auxPath = gpath; + gpath = contourPath; + + if (contourPath != null) { // first contour does not break + breakShape = true; + } + + openContour = true; } @Override public void endContour() { - // does nothing, just need the break in beginContour() + if (!openContour) { + PGraphics.showWarning("Need to call beginContour() first"); + return; + } + + // close this contour + if (gpath != null) gpath.closePath(); + + // switch back to main path + GeneralPath contourPath = gpath; + gpath = auxPath; + auxPath = contourPath; + + openContour = false; } @Override public void endShape(int mode) { + if (openContour) { // correct automagically, notify user + endContour(); + PGraphics.showWarning("Missing endContour() before endShape()"); + } if (gpath != null) { // make sure something has been drawn if (shape == POLYGON) { if (mode == CLOSE) { gpath.closePath(); } + if (auxPath != null) { + gpath.append(auxPath, false); + } drawShape(gpath); } } shape = 0; } - - ////////////////////////////////////////////////////////////// // CLIPPING diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index bb8189708..9aae40799 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -618,7 +618,9 @@ public class PShape implements PConstants { protected void beginContourImpl() { - if (vertexCodes.length == vertexCodeCount) { + if (vertexCodes == null) { + vertexCodes = new int[10]; + } else if (vertexCodes.length == vertexCodeCount) { vertexCodes = PApplet.expand(vertexCodes); } vertexCodes[vertexCodeCount++] = BREAK; diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 484dc8992..c88d0d51c 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2363,7 +2363,7 @@ public class PGraphicsOpenGL extends PGraphics { if (normalMode == NORMAL_MODE_AUTO) inGeo.calcQuadStripNormals(); tessellator.tessellateQuadStrip(); } else if (shape == POLYGON) { - tessellator.tessellatePolygon(false, mode == CLOSE, + tessellator.tessellatePolygon(true, mode == CLOSE, normalMode == NORMAL_MODE_AUTO); } } diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index a771ff053..d41f3132a 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -173,7 +173,7 @@ public class PShapeOpenGL extends PShape { protected boolean needBufferInit = false; // Flag to indicate if the shape can have holes or not. - protected boolean solid; + protected boolean solid = true; protected boolean breakShape = false; protected boolean shapeCreated = false; @@ -2995,7 +2995,7 @@ public class PShapeOpenGL extends PShape { if (rounded) { saveBezierVertexSettings(); inGeo.addRect(a, b, c, d, tl, tr, br, bl, stroke); - tessellator.tessellatePolygon(false, true, true); + tessellator.tessellatePolygon(true, true, true); restoreBezierVertexSettings(); } else { inGeo.addRect(a, b, c, d, stroke); @@ -3289,7 +3289,7 @@ public class PShapeOpenGL extends PShape { saveCurveVertexSettings(); tessellator.resetCurveVertexCount(); } - tessellator.tessellatePolygon(false, close, true); + tessellator.tessellatePolygon(true, close, true); if (bez || quad) restoreBezierVertexSettings(); if (curv) restoreCurveVertexSettings(); }