From dea8e9dd166ccdcd4b914d11538477d0c07eeaa0 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 22 May 2013 11:04:30 -0400 Subject: [PATCH 1/4] Smaller displacement for lines (issue #1790) --- core/src/processing/opengl/PGL.java | 4 ++++ core/src/processing/opengl/PGraphicsOpenGL.java | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 6e350e398..c2b2bd5c4 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -125,6 +125,10 @@ public class PGL { /** Minimum array size to use arrayCopy method(). **/ protected static final int MIN_ARRAYCOPY_SIZE = 2; + /** Factor used to displace the stroke vertices towards the camera in + * order to make sure the lines are always on top of the fill geometry **/ + protected static final float STROKE_DISPLACEMENT = 0.999f; + /** JOGL's windowing toolkit */ // The two windowing toolkits available to use in JOGL: protected static final int AWT = 0; // http://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 5bdab92de..08b04f175 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -7149,10 +7149,11 @@ public class PGraphicsOpenGL extends PGraphics { if (pgCurrent.getHint(DISABLE_OPTIMIZED_STROKE)) { setUniformValue(scaleLoc, 1.0f, 1.0f, 1.0f); } else { + float f = PGL.STROKE_DISPLACEMENT; if (orthoProjection()) { - setUniformValue(scaleLoc, 1.0f, 1.0f, 0.99f); + setUniformValue(scaleLoc, 1, 1, f); } else { - setUniformValue(scaleLoc, 0.99f, 0.99f, 0.99f); + setUniformValue(scaleLoc, f, f, f); } } From a96e68a497fa58497f09ab2b931d3bed5ee061ad Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 22 May 2013 11:11:26 -0400 Subject: [PATCH 2/4] Added STROKE_DISPLACEMENT to PGL in LWJGL --- java/libraries/lwjgl/src/processing/lwjgl/PGL.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java index feb5400d0..338a18d54 100644 --- a/java/libraries/lwjgl/src/processing/lwjgl/PGL.java +++ b/java/libraries/lwjgl/src/processing/lwjgl/PGL.java @@ -131,6 +131,10 @@ public class PGL extends processing.opengl.PGL { /** Minimum array size to use arrayCopy method(). **/ protected static final int MIN_ARRAYCOPY_SIZE = 2; + /** Factor used to displace the stroke vertices towards the camera in + * order to make sure the lines are always on top of the fill geometry **/ + protected static final float STROKE_DISPLACEMENT = 0.999f; + protected static int request_depth_bits = 24; protected static int request_stencil_bits = 8; protected static int request_alpha_bits = 8; From 423e59e934148612fac683fa5633aca70359f794 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Wed, 22 May 2013 10:58:55 -0700 Subject: [PATCH 3/4] Fixes processing/processing-web#138 --- core/src/processing/core/PVector.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/processing/core/PVector.java b/core/src/processing/core/PVector.java index 2a631449a..9f04977c5 100644 --- a/core/src/processing/core/PVector.java +++ b/core/src/processing/core/PVector.java @@ -543,8 +543,7 @@ public class PVector implements Serializable { * @webref pvector:method * @usage web_application * @param n the number to multiply with the vector - * @brief Multiply a vector by a scalar or one vector by another - * @nowebref + * @brief Multiply a vector by a scalar */ public void mult(float n) { x *= n; @@ -588,8 +587,7 @@ public class PVector implements Serializable { * @webref pvector:method * @usage web_application * @param n the value to divide by - * @brief Divide a vector by a scalar or one vector by another - * @nowebref + * @brief Divide a vector by a scalar */ public void div(float n) { x /= n; From c5017babaa4df5db5f909344475f3939393d4693 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 22 May 2013 14:48:01 -0400 Subject: [PATCH 4/4] Fixes issues #1805 and #1806 --- core/src/processing/opengl/PShapeOpenGL.java | 148 +++++++++++++------ 1 file changed, 105 insertions(+), 43 deletions(-) diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 9d0475a41..e58d3d598 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -182,15 +182,6 @@ public class PShapeOpenGL extends PShape { // ........................................................ - // Modes inherited from renderer - - protected int rectMode; - protected int ellipseMode; - protected int shapeMode; - protected int imageMode; - - // ........................................................ - // Bezier and Catmull-Rom curves protected int bezierDetail = 20; @@ -307,12 +298,8 @@ public class PShapeOpenGL extends PShape { inGeo = pg.newInGeometry(PGraphicsOpenGL.RETAINED); } - // Modes are retrieved from the current values in the renderer. + // Style parameters are retrieved from the current values in the renderer. textureMode = pg.textureMode; - rectMode = pg.rectMode; - ellipseMode = pg.ellipseMode; - shapeMode = pg.shapeMode; - imageMode = pg.imageMode; colorMode(pg.colorMode, pg.colorModeX, pg.colorModeY, pg.colorModeZ, pg.colorModeA); @@ -757,10 +744,25 @@ public class PShapeOpenGL extends PShape { if (family == GROUP) { for (int i = 0; i < childCount; i++) { PShapeOpenGL child = (PShapeOpenGL) children[i]; - child.textureMode(mode); + child.setTextureMode(mode); } } else { - textureMode = mode; + setTextureModeImpl(mode); + } + } + + + protected void setTextureModeImpl(int mode) { + if (textureMode == mode) return; + textureMode = mode; + if (image != null) { + float uFactor = image.width; + float vFactor = image.height; + if (textureMode == NORMAL) { + uFactor = 1.0f / uFactor; + vFactor = 1.0f / vFactor; + } + scaleTextureUV(uFactor, vFactor); } } @@ -778,17 +780,69 @@ public class PShapeOpenGL extends PShape { child.texture(tex); } } else { - PImage tex0 = image; - image = tex; - if (tex0 != tex && parent != null) { - ((PShapeOpenGL)parent).removeTexture(tex); + setTextureImpl(tex); + } + } + + + protected void setTextureImpl(PImage tex) { + PImage image0 = image; + image = tex; + + if (textureMode == IMAGE && image0 != image) { + // Need to rescale the texture coordinates + float uFactor = 1; + float vFactor = 1; + if (image != null) { + uFactor /= image.width; + vFactor /= image.height; } - if (parent != null) { - ((PShapeOpenGL)parent).addTexture(image); - if (is2D() && stroke) { - ((PShapeOpenGL)parent).strokedTexture(true); - } + if (image0 != null) { + uFactor *= image0.width; + vFactor *= image0.height; } + scaleTextureUV(uFactor, vFactor); + } + + if (image0 != tex && parent != null) { + ((PShapeOpenGL)parent).removeTexture(tex); + } + if (parent != null) { + ((PShapeOpenGL)parent).addTexture(image); + if (is2D() && stroke) { + ((PShapeOpenGL)parent).strokedTexture(true); + } + } + } + + + protected void scaleTextureUV(float uFactor, float vFactor) { + if (PGraphicsOpenGL.same(uFactor, 1) && + PGraphicsOpenGL.same(vFactor, 1)) return; + + for (int i = 0; i < inGeo.vertexCount; i++) { + float u = inGeo.texcoords[2 * i + 0]; + float v = inGeo.texcoords[2 * i + 1]; + inGeo.texcoords[2 * i + 0] = PApplet.min(1, u * uFactor); + inGeo.texcoords[2 * i + 1] = PApplet.min(1, v * uFactor); + } + + if (shapeCreated && tessellated && hasPolys) { + int last1 = 0; + if (is3D()) { + last1 = lastPolyVertex + 1; + } else if (is2D()) { + last1 = lastPolyVertex + 1; + if (-1 < firstLineVertex) last1 = firstLineVertex; + if (-1 < firstPointVertex) last1 = firstPointVertex; + } + for (int i = firstLineVertex; i < last1; i++) { + float u = tessGeo.polyTexCoords[2 * i + 0]; + float v = tessGeo.polyTexCoords[2 * i + 1]; + tessGeo.polyTexCoords[2 * i + 0] = PApplet.min(1, u * uFactor); + tessGeo.polyTexCoords[2 * i + 1] = PApplet.min(1, v * uFactor); + } + root.setModifiedPolyTexCoords(firstPolyVertex, last1 - 1); } } @@ -1524,8 +1578,13 @@ public class PShapeOpenGL extends PShape { return; } + if (image != null && textureMode == IMAGE) { + u = PApplet.min(1, u / image.width); + v = PApplet.min(1, v / image.height); + } inGeo.texcoords[2 * index + 0] = u; inGeo.texcoords[2 * index + 1] = v; + markForTessellation(); } @@ -2629,18 +2688,17 @@ public class PShapeOpenGL extends PShape { rounded = true; } - rectMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); if (rounded) { inGeo.addRect(a, b, c, d, tl, tr, br, bl, - fill, stroke, bezierDetail, rectMode); + fill, stroke, bezierDetail, CORNER); tessellator.tessellatePolygon(false, true, true); } else { inGeo.addRect(a, b, c, d, - fill, stroke, rectMode); + fill, stroke, CORNER); tessellator.tessellateQuads(); } } @@ -2655,11 +2713,10 @@ public class PShapeOpenGL extends PShape { d = params[3]; } -// ellipseMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); - inGeo.addEllipse(a, b, c, d, fill, stroke, ellipseMode); + inGeo.addEllipse(a, b, c, d, fill, stroke, CORNER); tessellator.tessellateTriangleFan(); } @@ -2667,7 +2724,7 @@ public class PShapeOpenGL extends PShape { protected void tessellateArc() { float a = 0, b = 0, c = 0, d = 0; float start = 0, stop = 0; - int mode = 0; +// int mode = 0; if (params.length == 6 || params.length == 7) { a = params[0]; b = params[1]; @@ -2675,16 +2732,16 @@ public class PShapeOpenGL extends PShape { d = params[3]; start = params[4]; stop = params[5]; - if (params.length == 7) { - mode = (int)(params[6]); - } + // Not using arc mode since PShape only uses CORNER +// if (params.length == 7) { +// mode = (int)(params[6]); +// } } -// ellipseMode = CORNER; inGeo.setMaterial(fillColor, strokeColor, strokeWeight, ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); - inGeo.addArc(a, b, c, d, start, stop, fill, stroke, mode); + inGeo.addArc(a, b, c, d, start, stop, fill, stroke, CORNER); tessellator.tessellateTriangleFan(); } @@ -3960,31 +4017,36 @@ public class PShapeOpenGL extends PShape { @Override protected void styles(PGraphics g) { if (g instanceof PGraphicsOpenGL) { - if (stroke) { + if (g.stroke) { + setStroke(true); setStroke(g.strokeColor); setStrokeWeight(g.strokeWeight); - - // These two don't to nothing probably: setStrokeCap(g.strokeCap); setStrokeJoin(g.strokeJoin); } else { setStroke(false); } - if (fill) { + if (g.fill) { + setFill(true); setFill(g.fillColor); } else { setFill(false); } + if (g.tint) { + setTint(true); + setTint(g.tintColor); + } + setAmbient(g.ambientColor); setSpecular(g.specularColor); setEmissive(g.emissiveColor); setShininess(g.shininess); - // What about other style parameters, such as rectMode, etc? - // These should force a tessellation update, same as stroke - // cap and weight... right? + if (image != null) { + setTextureMode(g.textureMode); + } } else { super.styles(g); }