From 8de31e2b5ddade6ffaec47964b26b4a73dd0d82d Mon Sep 17 00:00:00 2001 From: Jonathan Feinberg Date: Wed, 25 Dec 2013 22:53:05 -0500 Subject: [PATCH 01/11] Clear the global PGL on dispose(). --- core/src/processing/opengl/PGraphicsOpenGL.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 0cb501020..55edd5aa3 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -651,9 +651,13 @@ public class PGraphicsOpenGL extends PGraphics { deleteFinalizedGLResources(); if (primarySurface) pgl.deleteSurface(); + // This next line is critical to release many static allocations. + // This is important in the context of, say, a unit test suite, which + // runs more than one OpenGL sketch within the same classloader + // (as in the case of processing.py). Please don't remove it! + pgl = null; } -// @Override @Override protected void finalize() throws Throwable { try { From bee7509083368e49b19cf5035f8f6562a6e15bfd Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Tue, 31 Dec 2013 18:15:55 -0800 Subject: [PATCH 02/11] Added strokeWeight() as related to stroke() ref page, per request on processing/processing-web#293 --- core/src/processing/core/PApplet.java | 1 + core/src/processing/core/PGraphics.java | 1 + 2 files changed, 2 insertions(+) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index acb2a4801..a65e8f5c2 100755 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -14229,6 +14229,7 @@ public class PApplet extends Applet * * @param rgb color value in hexadecimal notation * @see PGraphics#noStroke() + * @see PGraphics#strokeWeight(float) * @see PGraphics#fill(int, float) * @see PGraphics#noFill() * @see PGraphics#tint(int, float) diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index 419ccb98b..2213965ba 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -6068,6 +6068,7 @@ public class PGraphics extends PImage implements PConstants { * * @param rgb color value in hexadecimal notation * @see PGraphics#noStroke() + * @see PGraphics#strokeWeight(float) * @see PGraphics#fill(int, float) * @see PGraphics#noFill() * @see PGraphics#tint(int, float) From 8981790c21147e74b6dbccfd91caee983ae6d34e Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 4 Jan 2014 16:09:05 -0500 Subject: [PATCH 03/11] set prevTexImage in setLastTexIndex, fix #2205 --- core/src/processing/opengl/PGraphicsOpenGL.java | 13 +++++-------- core/src/processing/opengl/PShapeOpenGL.java | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 55edd5aa3..cb5aab67f 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -483,7 +483,6 @@ public class PGraphicsOpenGL extends PGraphics { protected boolean openContour = false; protected boolean breakShape = false; protected boolean defaultEdges = false; - protected PImage textureImage0; static protected final int EDGE_MIDDLE = 0; static protected final int EDGE_START = 1; @@ -2047,7 +2046,6 @@ public class PGraphicsOpenGL extends PGraphics { breakShape = false; defaultEdges = true; - textureImage0 = textureImage; // The superclass method is called to avoid an early flush. super.noTexture(); @@ -2224,7 +2222,7 @@ public class PGraphicsOpenGL extends PGraphics { tessellator.setInGeometry(inGeo); tessellator.setTessGeometry(tessGeo); tessellator.setFill(fill || textureImage != null); - tessellator.setTexCache(texCache, textureImage0, textureImage); + tessellator.setTexCache(texCache, textureImage); tessellator.setStroke(stroke); tessellator.setStrokeColor(strokeColor); tessellator.setStrokeWeight(strokeWeight); @@ -2278,7 +2276,7 @@ public class PGraphicsOpenGL extends PGraphics { tessellator.setStrokeWeight(strokeWeight); tessellator.setStrokeCap(strokeCap); tessellator.setStrokeJoin(strokeJoin); - tessellator.setTexCache(texCache, textureImage0, textureImage); + tessellator.setTexCache(texCache, textureImage); tessellator.setTransform(modelview); tessellator.set3D(is3D()); @@ -9670,10 +9668,9 @@ public class PGraphicsOpenGL extends PGraphics { this.fill = fill; } - void setTexCache(TexCache texCache, PImage prevTexImage, - PImage newTexImage) { + void setTexCache(TexCache texCache, PImage newTexImage) { this.texCache = texCache; - this.prevTexImage = prevTexImage; + //this.prevTexImage = prevTexImage; this.newTexImage = newTexImage; } @@ -11138,7 +11135,6 @@ public class PGraphicsOpenGL extends PGraphics { } void beginNoTex() { - prevTexImage = newTexImage; newTexImage = null; setFirstTexIndex(tess.polyIndexCount, tess.polyIndexCache.size - 1); } @@ -11168,6 +11164,7 @@ public class PGraphicsOpenGL extends PGraphics { texCache.setLastIndex(lastIndex, lastCache); } } + prevTexImage = newTexImage; } // ----------------------------------------------------------------- diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 704bbdea5..d11841b9e 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -2643,7 +2643,7 @@ public class PShapeOpenGL extends PShape { tessellator.setInGeometry(inGeo); tessellator.setTessGeometry(tessGeo); tessellator.setFill(fill || image != null); - tessellator.setTexCache(null, null, null); + tessellator.setTexCache(null, null); tessellator.setStroke(stroke); tessellator.setStrokeColor(strokeColor); tessellator.setStrokeWeight(strokeWeight); From 4331296e1d6461c72bd3b2531276a414eccdffdd Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 5 Jan 2014 13:38:24 -0500 Subject: [PATCH 04/11] same changes related to #2259 --- core/src/processing/opengl/PGraphics2D.java | 15 ++++++-------- core/src/processing/opengl/PGraphics3D.java | 15 +++++++++++++- .../processing/opengl/PGraphicsOpenGL.java | 20 ++++--------------- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/core/src/processing/opengl/PGraphics2D.java b/core/src/processing/opengl/PGraphics2D.java index fbb8779e3..18df3b2a6 100644 --- a/core/src/processing/opengl/PGraphics2D.java +++ b/core/src/processing/opengl/PGraphics2D.java @@ -119,8 +119,11 @@ public class PGraphics2D extends PGraphicsOpenGL { @Override protected void defaultPerspective() { -// super.ortho(width/2f, (3f/2f) * width, -height/2f, height/2f, -1, +1); - super.ortho(0, width, 0, height, -1, +1); + // The camera part of the modelview is simply the identity matrix, so in + // order to the ortho projection to be consistent with this, it needs to be + // set as follows, because ortho() will shift the viewing rectangle at + // (width/2, height/2) and will also apply the axis inversion along Y: + super.ortho(width/2f, (3f/2f) * width, -height/2f, height/2f, -1, +1); } @@ -157,8 +160,7 @@ public class PGraphics2D extends PGraphicsOpenGL { @Override protected void defaultCamera() { - super.camera(width/2f, height/2f); -// resetMatrix(); + resetMatrix(); } @@ -182,11 +184,6 @@ public class PGraphics2D extends PGraphicsOpenGL { popProjection(); } - @Override - public void resetMatrix() { - super.resetMatrix(); - defaultCamera(); - } ////////////////////////////////////////////////////////////// diff --git a/core/src/processing/opengl/PGraphics3D.java b/core/src/processing/opengl/PGraphics3D.java index 43aa52251..38b3e775d 100644 --- a/core/src/processing/opengl/PGraphics3D.java +++ b/core/src/processing/opengl/PGraphics3D.java @@ -87,7 +87,20 @@ public class PGraphics3D extends PGraphicsOpenGL { pushProjection(); ortho(0, width, 0, height, -1, +1); pushMatrix(); - camera(width/2, height/2); + + // Set camera for 2D rendering, it simply centers at (width/2, height/2) + float centerX = width/2; + float centerY = height/2; + modelview.reset(); + modelview.translate(-centerX, -centerY); + + modelviewInv.set(modelview); + modelviewInv.invert(); + + camera.set(modelview); + cameraInv.set(modelviewInv); + + updateProjmodelview(); } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index cb5aab67f..e174b3254 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2508,7 +2508,7 @@ public class PGraphicsOpenGL extends PGraphics { // an 'in-place' implementation of quick I whipped together late at night // based off of the algorithm found on wikipedia: http://en.wikipedia.org/wiki/Quicksort private void quickSortTris(int leftI, int rightI) { - if(leftI < rightI) { + if (leftI < rightI) { int pivotIndex = (leftI + rightI)/2; int newPivotIndex = partition(leftI,rightI,pivotIndex); quickSortTris(leftI, newPivotIndex-1); @@ -4390,21 +4390,6 @@ public class PGraphicsOpenGL extends PGraphics { } - // Sets a camera for 2D rendering, which only involves centering - public void camera(float centerX, float centerY) { - modelview.reset(); - modelview.translate(-centerX, -centerY); - - modelviewInv.set(modelview); - modelviewInv.invert(); - - camera.set(modelview); - cameraInv.set(modelviewInv); - - updateProjmodelview(); - } - - /** * Print the current camera matrix. */ @@ -4453,6 +4438,9 @@ public class PGraphicsOpenGL extends PGraphics { public void ortho(float left, float right, float bottom, float top, float near, float far) { + // Translating the origin to (widht/2, height/2) since the matrix math + // below assumes the center of the screen to be (0, 0), but in Processing + // it is (w/2, h/2). left -= width/2f; right -= width/2f; bottom -= height/2f; From ac3248ca332654abd2c28d058526595553e2396d Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 5 Jan 2014 15:20:58 -0500 Subject: [PATCH 05/11] fix #2171 --- .../processing/opengl/PGraphicsOpenGL.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index e174b3254..8835fcb00 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5841,12 +5841,33 @@ public class PGraphicsOpenGL extends PGraphics { flush(); // make sure that the screen contents are up to date. Texture tex = getTexture(src); + boolean invX = tex.invertedX(); + boolean invY = tex.invertedY(); + int scrX0, scrX1; + int scrY0, scrY1; + if (invX) { + scrX0 = dx + dw; + scrX1 = dx; + } else { + scrX0 = dx; + scrX1 = dx + dw; + } + if (invY) { + scrY0 = height - (dy + dh); + scrY1 = height - dy; + } else { + // Because drawTexture uses bottom-to-top orientation of Y axis. + scrY0 = height - dy; + scrY1 = height - (dy + dh); + } + pgl.drawTexture(tex.glTarget, tex.glName, tex.glWidth, tex.glHeight, width, height, sx, tex.height - (sy + sh), sx + sw, tex.height - sy, - dx, height - (dy + dh), - dx + dw, height - dy); + scrX0, scrY0, + scrX1, scrY1); + if (needEndDraw) { endDraw(); From ce5ead73ee3034ae866c7f931eb4590ea28fb186 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 5 Jan 2014 15:36:07 -0500 Subject: [PATCH 06/11] fix #1900 --- core/src/processing/opengl/PGraphicsOpenGL.java | 2 +- core/src/processing/opengl/Texture.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 8835fcb00..498320f7a 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -6223,7 +6223,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void initOffscreen() { // Getting the context and capabilities from the main renderer. - loadTextureImpl(Texture.BILINEAR, false); + loadTextureImpl(textureSampling, false); // In case of reinitialization (for example, when the smooth level // is changed), we make sure that all the OpenGL resources associated diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index 1c45ef481..a8ea6662c 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -52,13 +52,13 @@ public class Texture implements PConstants { * to linear */ protected static final int LINEAR = 3; /** Bilinear sampling: both magnification filtering is set to linear and - * minification either to linear-mipmap-nearest (linear interplation is used + * minification either to linear-mipmap-nearest (linear interpolation is used * within a mipmap, but not between different mipmaps). */ protected static final int BILINEAR = 4; /** Trilinear sampling: magnification filtering set to linear, minification to * linear-mipmap-linear, which offers the best mipmap quality since linear * interpolation to compute the value in each of two maps and then - * interpolates linearly between these two value. */ + * interpolates linearly between these two values. */ protected static final int TRILINEAR = 5; From 2193ef87a458c13ceac948c53615fa2478947ffc Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 5 Jan 2014 16:01:31 -0500 Subject: [PATCH 07/11] some commented code to handle #2296 --- core/src/processing/opengl/PGraphicsOpenGL.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 498320f7a..63d74195d 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -5241,6 +5241,13 @@ public class PGraphicsOpenGL extends PGraphics { pgl.depthMask(true); } + // Code to use instead in order to fix + // https://github.com/processing/processing/issues/2296 +// if (!hints[DISABLE_DEPTH_MASK]) { +// pgl.clearDepth(1); +// pgl.clear(PGL.DEPTH_BUFFER_BIT); +// } + pgl.clearColor(backgroundR, backgroundG, backgroundB, backgroundA); pgl.clear(PGL.COLOR_BUFFER_BIT); if (0 < parent.frameCount) { From df0efa540f46c8b842ca8620bb830b9d66b43865 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 5 Jan 2014 16:39:29 -0500 Subject: [PATCH 08/11] fix #2193 --- core/src/processing/opengl/PGraphicsOpenGL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 63d74195d..54b419219 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -3115,7 +3115,7 @@ public class PGraphicsOpenGL extends PGraphics { ambientColor, specularColor, emissiveColor, shininess); inGeo.setNormal(normalX, normalY, normalZ); inGeo.addRect(x1, y1, x2, y2, tl, tr, br, bl, stroke); - endShape(); + endShape(CLOSE); } From 1cd4c57ec8e90acda2f093859c98cdd8768e1b25 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 6 Jan 2014 13:43:12 -0500 Subject: [PATCH 09/11] don't set pgl to null for offscreen surfaces. --- core/src/processing/opengl/PGraphicsOpenGL.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 54b419219..480b067f0 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -649,12 +649,15 @@ public class PGraphicsOpenGL extends PGraphics { deleteFinalizedGLResources(); - if (primarySurface) pgl.deleteSurface(); - // This next line is critical to release many static allocations. - // This is important in the context of, say, a unit test suite, which - // runs more than one OpenGL sketch within the same classloader - // (as in the case of processing.py). Please don't remove it! - pgl = null; + if (primarySurface) { + pgl.deleteSurface(); + + // This next line is critical to release many static allocations. + // This is important in the context of, say, a unit test suite, which + // runs more than one OpenGL sketch within the same classloader + // (as in the case of processing.py). Please don't remove it! + pgl = null; + } } @Override