diff --git a/android/core/src/processing/core/PFontTexture.java b/android/core/src/processing/core/PFontTexture.java index 034a1f5d4..0f2b1aedd 100644 --- a/android/core/src/processing/core/PFontTexture.java +++ b/android/core/src/processing/core/PFontTexture.java @@ -48,7 +48,7 @@ import processing.core.PFont; */ class PFontTexture implements PConstants { protected PApplet parent; - protected PGraphicsAndroid3D renderer; + protected PGraphicsAndroid3D pg; protected PGL pgl; protected PGL.Context context; protected PFont font; @@ -68,8 +68,8 @@ class PFontTexture implements PConstants { public PFontTexture(PApplet parent, PFont font, int maxw, int maxh) { this.parent = parent; this.font = font; - renderer = (PGraphicsAndroid3D)parent.g; - pgl = renderer.pgl; + pg = (PGraphicsAndroid3D)parent.g; + pgl = pg.pgl; context = pgl.getContext(); initTexture(maxw, maxh); @@ -122,7 +122,7 @@ class PFontTexture implements PConstants { textures = new PTexture[1]; textures[0] = tex; images = new PImage[1]; - images[0] = renderer.wrapTexture(tex); + images[0] = pg.wrapTexture(tex); currentTex = 0; } else if (resize) { // Replacing old smaller texture with larger one. @@ -132,7 +132,7 @@ class PFontTexture implements PConstants { tex.put(tex0); textures[currentTex] = tex; - images[currentTex].setCache(renderer, tex); + images[currentTex].setCache(pg, tex); images[currentTex].width = tex.width; images[currentTex].height = tex.height; } else { @@ -146,7 +146,7 @@ class PFontTexture implements PConstants { PImage[] tempImg = images; images = new PImage[textures.length + 1]; PApplet.arrayCopy(tempImg, images, tempImg.length); - images[tempImg.length] = renderer.wrapTexture(tex); + images[tempImg.length] = pg.wrapTexture(tex); } lastTex = currentTex; diff --git a/android/core/src/processing/core/PFramebuffer.java b/android/core/src/processing/core/PFramebuffer.java index 473872180..a5b670b97 100644 --- a/android/core/src/processing/core/PFramebuffer.java +++ b/android/core/src/processing/core/PFramebuffer.java @@ -36,7 +36,7 @@ import java.nio.IntBuffer; */ public class PFramebuffer implements PConstants { protected PApplet parent; - protected PGraphicsAndroid3D renderer; + protected PGraphicsAndroid3D pg; protected PGL pgl; public int glFboID; @@ -76,8 +76,8 @@ public class PFramebuffer implements PConstants { int depthBits, int stencilBits, boolean combinedDepthStencil, boolean screen) { this.parent = parent; - renderer = (PGraphicsAndroid3D)parent.g; - pgl = renderer.pgl; + pg = (PGraphicsAndroid3D)parent.g; + pgl = pg.pgl; glFboID = 0; glDepthBufferID = 0; @@ -149,19 +149,19 @@ public class PFramebuffer implements PConstants { protected void finalize() throws Throwable { try { if (glFboID != 0) { - renderer.finalizeFrameBufferObject(glFboID); + pg.finalizeFrameBufferObject(glFboID); } if (glDepthBufferID != 0) { - renderer.finalizeRenderBufferObject(glDepthBufferID); + pg.finalizeRenderBufferObject(glDepthBufferID); } if (glStencilBufferID != 0) { - renderer.finalizeRenderBufferObject(glStencilBufferID); + pg.finalizeRenderBufferObject(glStencilBufferID); } if (glColorBufferMultisampleID != 0) { - renderer.finalizeRenderBufferObject(glColorBufferMultisampleID); + pg.finalizeRenderBufferObject(glColorBufferMultisampleID); } if (glDepthStencilBufferID != 0) { - renderer.finalizeRenderBufferObject(glDepthStencilBufferID); + pg.finalizeRenderBufferObject(glDepthStencilBufferID); } } finally { super.finalize(); @@ -169,11 +169,11 @@ public class PFramebuffer implements PConstants { } public void clear() { - renderer.pushFramebuffer(); - renderer.setFramebuffer(this); + pg.pushFramebuffer(); + pg.setFramebuffer(this); pgl.setClearColor(0, 0, 0, 0); pgl.clearAllBuffers(); - renderer.popFramebuffer(); + pg.popFramebuffer(); } public void copy(PFramebuffer dest) { @@ -195,7 +195,7 @@ public class PFramebuffer implements PConstants { if (0 < numColorBuffers) { // Drawing the current contents of the first color buffer to emulate // front-back buffer swap. - renderer.drawTexture(colorBufferTex[0].glTarget, colorBufferTex[0].glID, width, height, 0, 0, width, height, 0, 0, width, height); + pg.drawTexture(colorBufferTex[0].glTarget, colorBufferTex[0].glID, width, height, 0, 0, width, height, 0, 0, width, height); } if (noDepth) { @@ -211,7 +211,7 @@ public class PFramebuffer implements PConstants { public void finish() { if (noDepth) { // No need to clear depth buffer because depth testing was disabled. - if (renderer.hintEnabled(DISABLE_DEPTH_TEST)) { + if (pg.hintEnabled(DISABLE_DEPTH_TEST)) { pgl.disableDepthTest(); } else { pgl.enableDepthTest(); @@ -246,7 +246,7 @@ public class PFramebuffer implements PConstants { // Draws the contents of the backup texture to the screen. public void restoreBackup() { - renderer.drawTexture(backupTexture, 0, 0, width, height, 0, 0, width, height); + pg.drawTexture(backupTexture, 0, 0, width, height, 0, 0, width, height); } // Copies current content of screen to color buffers. @@ -311,8 +311,8 @@ public class PFramebuffer implements PConstants { } if (fboMode) { - renderer.pushFramebuffer(); - renderer.setFramebuffer(this); + pg.pushFramebuffer(); + pg.setFramebuffer(this); // Making sure nothing is attached. for (int i = 0; i < numColorBuffers; i++) { @@ -325,7 +325,7 @@ public class PFramebuffer implements PConstants { validateFbo(); - renderer.popFramebuffer(); + pg.popFramebuffer(); } } @@ -342,7 +342,7 @@ public class PFramebuffer implements PConstants { glFboID = 0; } else if (fboMode) { //glFboID = ogl.createGLResource(PGraphicsAndroid3D.GL_FRAME_BUFFER); - glFboID = renderer.createFrameBufferObject(); + glFboID = pg.createFrameBufferObject(); } else { glFboID = 0; } @@ -367,23 +367,23 @@ public class PFramebuffer implements PConstants { protected void release() { if (glFboID != 0) { - renderer.finalizeFrameBufferObject(glFboID); + pg.finalizeFrameBufferObject(glFboID); glFboID = 0; } if (glDepthBufferID != 0) { - renderer.finalizeRenderBufferObject(glDepthBufferID); + pg.finalizeRenderBufferObject(glDepthBufferID); glDepthBufferID = 0; } if (glStencilBufferID != 0) { - renderer.finalizeRenderBufferObject(glStencilBufferID); + pg.finalizeRenderBufferObject(glStencilBufferID); glStencilBufferID = 0; } if (glColorBufferMultisampleID != 0) { - renderer.finalizeRenderBufferObject(glColorBufferMultisampleID); + pg.finalizeRenderBufferObject(glColorBufferMultisampleID); glColorBufferMultisampleID = 0; } if (glDepthStencilBufferID != 0) { - renderer.finalizeRenderBufferObject(glDepthStencilBufferID); + pg.finalizeRenderBufferObject(glDepthStencilBufferID); glDepthStencilBufferID = 0; } } @@ -393,15 +393,15 @@ public class PFramebuffer implements PConstants { if (screenFb) return; if (fboMode) { - renderer.pushFramebuffer(); - renderer.setFramebuffer(this); + pg.pushFramebuffer(); + pg.setFramebuffer(this); - glColorBufferMultisampleID = renderer.createRenderBufferObject(); + glColorBufferMultisampleID = pg.createRenderBufferObject(); pgl.bindRenderbuffer(glColorBufferMultisampleID); pgl.setRenderbufferNumSamples(nsamples, PGL.RGBA8, width, height); pgl.setRenderbufferColorAttachment(glColorBufferMultisampleID); - renderer.popFramebuffer(); + pg.popFramebuffer(); } } @@ -414,10 +414,10 @@ public class PFramebuffer implements PConstants { } if (fboMode) { - renderer.pushFramebuffer(); - renderer.setFramebuffer(this); + pg.pushFramebuffer(); + pg.setFramebuffer(this); - glDepthStencilBufferID = renderer.createRenderBufferObject(); + glDepthStencilBufferID = pg.createRenderBufferObject(); pgl.bindRenderbuffer(glDepthStencilBufferID); if (multisample) { @@ -429,7 +429,7 @@ public class PFramebuffer implements PConstants { pgl.setRenderbufferDepthAttachment(glDepthStencilBufferID); pgl.setRenderbufferStencilAttachment(glDepthStencilBufferID); - renderer.popFramebuffer(); + pg.popFramebuffer(); } } @@ -442,10 +442,10 @@ public class PFramebuffer implements PConstants { } if (fboMode) { - renderer.pushFramebuffer(); - renderer.setFramebuffer(this); + pg.pushFramebuffer(); + pg.setFramebuffer(this); - glDepthBufferID = renderer.createRenderBufferObject(); + glDepthBufferID = pg.createRenderBufferObject(); pgl.bindRenderbuffer(glDepthBufferID); int glConst = PGL.DEPTH_16BIT; @@ -465,7 +465,7 @@ public class PFramebuffer implements PConstants { pgl.setRenderbufferDepthAttachment(glDepthBufferID); - renderer.popFramebuffer(); + pg.popFramebuffer(); } } @@ -478,10 +478,10 @@ public class PFramebuffer implements PConstants { } if (fboMode) { - renderer.pushFramebuffer(); - renderer.setFramebuffer(this); + pg.pushFramebuffer(); + pg.setFramebuffer(this); - glStencilBufferID = renderer.createRenderBufferObject(); + glStencilBufferID = pg.createRenderBufferObject(); pgl.bindRenderbuffer(glStencilBufferID); int glConst = PGL.STENCIL_1BIT; @@ -500,7 +500,7 @@ public class PFramebuffer implements PConstants { pgl.setRenderbufferStencilAttachment(glStencilBufferID); - renderer.popFramebuffer(); + pg.popFramebuffer(); } } diff --git a/android/core/src/processing/core/PShader.java b/android/core/src/processing/core/PShader.java index 543e231fa..2c9ccadae 100644 --- a/android/core/src/processing/core/PShader.java +++ b/android/core/src/processing/core/PShader.java @@ -32,7 +32,7 @@ import java.net.URL; */ public class PShader { protected PApplet parent; - protected PGraphicsAndroid3D renderer; + protected PGraphicsAndroid3D pg; protected PGL pgl; protected int programObject; @@ -47,10 +47,10 @@ public class PShader { */ public PShader(PApplet parent) { this.parent = parent; - renderer = (PGraphicsAndroid3D) parent.g; - pgl = renderer.pgl; + pg = (PGraphicsAndroid3D) parent.g; + pgl = pg.pgl; - programObject = renderer.createGLSLProgramObject(); + programObject = pg.createGLSLProgramObject(); vertexShader = 0; fragmentShader = 0; @@ -75,13 +75,13 @@ public class PShader { protected void finalize() throws Throwable { try { if (vertexShader != 0) { - renderer.finalizeGLSLVertShaderObject(vertexShader); + pg.finalizeGLSLVertShaderObject(vertexShader); } if (fragmentShader != 0) { - renderer.finalizeGLSLFragShaderObject(fragmentShader); + pg.finalizeGLSLFragShaderObject(fragmentShader); } if (programObject != 0) { - renderer.finalizeGLSLProgramObject(programObject); + pg.finalizeGLSLProgramObject(programObject); } } finally { super.finalize(); @@ -431,7 +431,7 @@ public class PShader { * @param filename the shader's filename, used to print error log information */ private void attachVertexShader(String shaderSource, String file) { - vertexShader = renderer.createGLSLVertShaderObject(); + vertexShader = pg.createGLSLVertShaderObject(); pgl.setShaderSource(vertexShader, shaderSource); pgl.compileShader(vertexShader); @@ -445,7 +445,7 @@ public class PShader { * @param filename the shader's filename, used to print error log information */ private void attachFragmentShader(String shaderSource, String file) { - fragmentShader = renderer.createGLSLFragShaderObject(); + fragmentShader = pg.createGLSLFragShaderObject(); pgl.setShaderSource(fragmentShader, shaderSource); pgl.compileShader(fragmentShader); @@ -468,15 +468,15 @@ public class PShader { protected void release() { if (vertexShader != 0) { - renderer.deleteGLSLVertShaderObject(vertexShader); + pg.deleteGLSLVertShaderObject(vertexShader); vertexShader = 0; } if (fragmentShader != 0) { - renderer.deleteGLSLFragShaderObject(fragmentShader); + pg.deleteGLSLFragShaderObject(fragmentShader); fragmentShader = 0; } if (programObject != 0) { - renderer.deleteGLSLProgramObject(programObject); + pg.deleteGLSLProgramObject(programObject); programObject = 0; } } diff --git a/android/core/src/processing/core/PShape3D.java b/android/core/src/processing/core/PShape3D.java index 3011c1d87..b5c3a7613 100644 --- a/android/core/src/processing/core/PShape3D.java +++ b/android/core/src/processing/core/PShape3D.java @@ -50,7 +50,7 @@ import java.io.BufferedReader; */ public class PShape3D extends PShape { - protected PGraphicsAndroid3D renderer; + protected PGraphicsAndroid3D pg; protected PGL pgl; protected PShape3D root; @@ -227,8 +227,8 @@ public class PShape3D extends PShape { protected int imageMode; public PShape3D(PApplet parent, int family) { - renderer = (PGraphicsAndroid3D)parent.g; - pgl = renderer.pgl; + pg = (PGraphicsAndroid3D)parent.g; + pgl = pg.pgl; glMode = PGL.STATIC_DRAW; @@ -250,53 +250,53 @@ public class PShape3D extends PShape { glPointAttribBufferID = 0; glPointIndexBufferID = 0; - this.tessellator = renderer.tessellator; + this.tessellator = pg.tessellator; this.family = family; this.root = this; this.parent = null; this.tessellated = false; if (family == GEOMETRY || family == PRIMITIVE || family == PATH) { - in = renderer.newInGeometry(RETAINED); + in = pg.newInGeometry(RETAINED); } - tess = renderer.newTessGeometry(RETAINED); + tess = pg.newTessGeometry(RETAINED); fillIndexData = new ArrayList(); lineIndexData = new ArrayList(); pointIndexData = new ArrayList(); // Modes are retrieved from the current values in the renderer. - textureMode = renderer.textureMode; - rectMode = renderer.rectMode; - ellipseMode = renderer.ellipseMode; - shapeMode = renderer.shapeMode; - imageMode = renderer.imageMode; + textureMode = pg.textureMode; + rectMode = pg.rectMode; + ellipseMode = pg.ellipseMode; + shapeMode = pg.shapeMode; + imageMode = pg.imageMode; - colorMode(renderer.colorMode, renderer.colorModeX, renderer.colorModeY, renderer.colorModeZ, renderer.colorModeA); + colorMode(pg.colorMode, pg.colorModeX, pg.colorModeY, pg.colorModeZ, pg.colorModeA); // Initial values for fill, stroke and tint colors are also imported from the renderer. // This is particular relevant for primitive shapes, since is not possible to set // their color separately when creating them, and their input vertices are actually // generated at rendering time, by which the color configuration of the renderer might // have changed. - fill = renderer.fill; - fillR = ((renderer.fillColor >> 16) & 0xFF) / 255.0f; - fillG = ((renderer.fillColor >> 8) & 0xFF) / 255.0f; - fillB = ((renderer.fillColor >> 0) & 0xFF) / 255.0f; - fillA = ((renderer.fillColor >> 24) & 0xFF) / 255.0f; + fill = pg.fill; + fillR = ((pg.fillColor >> 16) & 0xFF) / 255.0f; + fillG = ((pg.fillColor >> 8) & 0xFF) / 255.0f; + fillB = ((pg.fillColor >> 0) & 0xFF) / 255.0f; + fillA = ((pg.fillColor >> 24) & 0xFF) / 255.0f; - stroke = renderer.stroke; - strokeR = ((renderer.strokeColor >> 16) & 0xFF) / 255.0f; - strokeG = ((renderer.strokeColor >> 8) & 0xFF) / 255.0f; - strokeB = ((renderer.strokeColor >> 0) & 0xFF) / 255.0f; - strokeA = ((renderer.strokeColor >> 24) & 0xFF) / 255.0f; + stroke = pg.stroke; + strokeR = ((pg.strokeColor >> 16) & 0xFF) / 255.0f; + strokeG = ((pg.strokeColor >> 8) & 0xFF) / 255.0f; + strokeB = ((pg.strokeColor >> 0) & 0xFF) / 255.0f; + strokeA = ((pg.strokeColor >> 24) & 0xFF) / 255.0f; - strokeWeight = renderer.strokeWeight; + strokeWeight = pg.strokeWeight; - tint = renderer.tint; - tintR = ((renderer.tintColor >> 16) & 0xFF) / 255.0f; - tintG = ((renderer.tintColor >> 8) & 0xFF) / 255.0f; - tintB = ((renderer.tintColor >> 0) & 0xFF) / 255.0f; - tintA = ((renderer.tintColor >> 24) & 0xFF) / 255.0f; + tint = pg.tint; + tintR = ((pg.tintColor >> 16) & 0xFF) / 255.0f; + tintG = ((pg.tintColor >> 8) & 0xFF) / 255.0f; + tintB = ((pg.tintColor >> 0) & 0xFF) / 255.0f; + tintA = ((pg.tintColor >> 24) & 0xFF) / 255.0f; normalX = normalY = 0; normalZ = 1; @@ -358,67 +358,67 @@ public class PShape3D extends PShape { protected void finalizeFillBuffers() { if (glFillVertexBufferID != 0) { - renderer.finalizeVertexBufferObject(glFillVertexBufferID); + pg.finalizeVertexBufferObject(glFillVertexBufferID); } if (glFillColorBufferID != 0) { - renderer.finalizeVertexBufferObject(glFillColorBufferID); + pg.finalizeVertexBufferObject(glFillColorBufferID); } if (glFillNormalBufferID != 0) { - renderer.finalizeVertexBufferObject(glFillNormalBufferID); + pg.finalizeVertexBufferObject(glFillNormalBufferID); } if (glFillTexCoordBufferID != 0) { - renderer.finalizeVertexBufferObject(glFillTexCoordBufferID); + pg.finalizeVertexBufferObject(glFillTexCoordBufferID); } if (glFillIndexBufferID != 0) { - renderer.finalizeVertexBufferObject(glFillIndexBufferID); + pg.finalizeVertexBufferObject(glFillIndexBufferID); } } protected void finalizeLineBuffers() { if (glLineVertexBufferID != 0) { - renderer.finalizeVertexBufferObject(glLineVertexBufferID); + pg.finalizeVertexBufferObject(glLineVertexBufferID); } if (glLineColorBufferID != 0) { - renderer.finalizeVertexBufferObject(glLineColorBufferID); + pg.finalizeVertexBufferObject(glLineColorBufferID); } if (glLineNormalBufferID != 0) { - renderer.finalizeVertexBufferObject(glLineNormalBufferID); + pg.finalizeVertexBufferObject(glLineNormalBufferID); } if (glLineAttribBufferID != 0) { - renderer.finalizeVertexBufferObject(glLineAttribBufferID); + pg.finalizeVertexBufferObject(glLineAttribBufferID); } if (glLineIndexBufferID != 0) { - renderer.finalizeVertexBufferObject(glLineIndexBufferID); + pg.finalizeVertexBufferObject(glLineIndexBufferID); } } protected void finalizePointBuffers() { if (glPointVertexBufferID != 0) { - renderer.finalizeVertexBufferObject(glPointVertexBufferID); + pg.finalizeVertexBufferObject(glPointVertexBufferID); } if (glPointColorBufferID != 0) { - renderer.finalizeVertexBufferObject(glPointColorBufferID); + pg.finalizeVertexBufferObject(glPointColorBufferID); } if (glPointNormalBufferID != 0) { - renderer.finalizeVertexBufferObject(glPointNormalBufferID); + pg.finalizeVertexBufferObject(glPointNormalBufferID); } if (glPointAttribBufferID != 0) { - renderer.finalizeVertexBufferObject(glPointAttribBufferID); + pg.finalizeVertexBufferObject(glPointAttribBufferID); } if (glPointIndexBufferID != 0) { - renderer.finalizeVertexBufferObject(glPointIndexBufferID); + pg.finalizeVertexBufferObject(glPointIndexBufferID); } } @@ -618,7 +618,7 @@ public class PShape3D extends PShape { u /= texture.width; v /= texture.height; - PTexture tex = renderer.queryTexture(texture); + PTexture tex = pg.queryTexture(texture); if (tex != null && tex.isFlippedY()) { v = 1 - v; } @@ -1632,11 +1632,11 @@ public class PShape3D extends PShape { } // setup matrix for forward differencing to speed up drawing - renderer.splineForward(detail, bezierDrawMatrix); + pg.splineForward(detail, bezierDrawMatrix); // multiply the basis and forward diff matrices together // saves much time since this needn't be done for each curve - bezierDrawMatrix.apply(renderer.bezierBasisMatrix); + bezierDrawMatrix.apply(pg.bezierBasisMatrix); } public void bezierVertex(float x2, float y2, @@ -1803,10 +1803,10 @@ public class PShape3D extends PShape { (s-1)/2f, 0, (1-s)/2f, 0, 0, 1, 0, 0); - renderer.splineForward(curveDetail, curveDrawMatrix); + pg.splineForward(curveDetail, curveDrawMatrix); if (bezierBasisInverse == null) { - bezierBasisInverse = renderer.bezierBasisMatrix.get(); + bezierBasisInverse = pg.bezierBasisMatrix.get(); bezierBasisInverse.invert(); curveToBezierMatrix = new PMatrix3D(); } @@ -2393,8 +2393,8 @@ public class PShape3D extends PShape { protected void tessellateSphere() { // TODO: move to InGeometry float r = params[0]; - int nu = renderer.sphereDetailU; - int nv = renderer.sphereDetailV; + int nu = pg.sphereDetailU; + int nv = pg.sphereDetailV; if ((nu < 3) || (nv < 2)) { nu = nv = 30; @@ -2772,25 +2772,25 @@ public class PShape3D extends PShape { } protected void initFillBuffers(int nvert, int nind) { - glFillVertexBufferID = renderer.createVertexBufferObject(); + glFillVertexBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glFillVertexBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glFillColorBufferID = renderer.createVertexBufferObject(); + glFillColorBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glFillColorBufferID); pgl.initVertexBuffer(4 * nvert, glMode); - glFillNormalBufferID = renderer.createVertexBufferObject(); + glFillNormalBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glFillNormalBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glFillTexCoordBufferID = renderer.createVertexBufferObject(); + glFillTexCoordBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glFillTexCoordBufferID); pgl.initVertexBuffer(2 * nvert, glMode); pgl.unbindVertexBuffer(); - glFillIndexBufferID = renderer.createVertexBufferObject(); + glFillIndexBufferID = pg.createVertexBufferObject(); pgl.bindIndexBuffer(glFillIndexBufferID); pgl.initIndexBuffer(nind, glMode); @@ -3028,25 +3028,25 @@ public class PShape3D extends PShape { protected void initLineBuffers(int nvert, int nind) { - glLineVertexBufferID = renderer.createVertexBufferObject(); + glLineVertexBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glLineVertexBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glLineColorBufferID = renderer.createVertexBufferObject(); + glLineColorBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glLineColorBufferID); pgl.initVertexBuffer(4 * nvert, glMode); - glLineNormalBufferID = renderer.createVertexBufferObject(); + glLineNormalBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glLineNormalBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glLineAttribBufferID = renderer.createVertexBufferObject(); + glLineAttribBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glLineAttribBufferID); pgl.initVertexBuffer(4 * nvert, glMode); pgl.unbindVertexBuffer(); - glLineIndexBufferID = renderer.createVertexBufferObject(); + glLineIndexBufferID = pg.createVertexBufferObject(); pgl.bindIndexBuffer(glLineIndexBufferID); pgl.initIndexBuffer(nind, glMode); @@ -3127,25 +3127,25 @@ public class PShape3D extends PShape { protected void initPointBuffers(int nvert, int nind) { - glPointVertexBufferID = renderer.createVertexBufferObject(); + glPointVertexBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glPointVertexBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glPointColorBufferID = renderer.createVertexBufferObject(); + glPointColorBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glPointColorBufferID); pgl.initVertexBuffer(4 * nvert, glMode); - glPointNormalBufferID = renderer.createVertexBufferObject(); + glPointNormalBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glPointNormalBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glPointAttribBufferID = renderer.createVertexBufferObject(); + glPointAttribBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glPointAttribBufferID); pgl.initVertexBuffer(2 * nvert, glMode); pgl.unbindVertexBuffer(); - glPointIndexBufferID = renderer.createVertexBufferObject(); + glPointIndexBufferID = pg.createVertexBufferObject(); pgl.bindIndexBuffer(glPointIndexBufferID); pgl.initIndexBuffer(nind, glMode); @@ -3241,27 +3241,27 @@ public class PShape3D extends PShape { protected void deleteFillBuffers() { if (glFillVertexBufferID != 0) { - renderer.deleteVertexBufferObject(glFillVertexBufferID); + pg.deleteVertexBufferObject(glFillVertexBufferID); glFillVertexBufferID = 0; } if (glFillColorBufferID != 0) { - renderer.deleteVertexBufferObject(glFillColorBufferID); + pg.deleteVertexBufferObject(glFillColorBufferID); glFillColorBufferID = 0; } if (glFillNormalBufferID != 0) { - renderer.deleteVertexBufferObject(glFillNormalBufferID); + pg.deleteVertexBufferObject(glFillNormalBufferID); glFillNormalBufferID = 0; } if (glFillTexCoordBufferID != 0) { - renderer.deleteVertexBufferObject(glFillTexCoordBufferID); + pg.deleteVertexBufferObject(glFillTexCoordBufferID); glFillTexCoordBufferID = 0; } if (glFillIndexBufferID != 0) { - renderer.deleteVertexBufferObject(glFillIndexBufferID); + pg.deleteVertexBufferObject(glFillIndexBufferID); glFillIndexBufferID = 0; } } @@ -3269,27 +3269,27 @@ public class PShape3D extends PShape { protected void deleteLineBuffers() { if (glLineVertexBufferID != 0) { - renderer.deleteVertexBufferObject(glLineVertexBufferID); + pg.deleteVertexBufferObject(glLineVertexBufferID); glLineVertexBufferID = 0; } if (glLineColorBufferID != 0) { - renderer.deleteVertexBufferObject(glLineColorBufferID); + pg.deleteVertexBufferObject(glLineColorBufferID); glLineColorBufferID = 0; } if (glLineNormalBufferID != 0) { - renderer.deleteVertexBufferObject(glLineNormalBufferID); + pg.deleteVertexBufferObject(glLineNormalBufferID); glLineNormalBufferID = 0; } if (glLineAttribBufferID != 0) { - renderer.deleteVertexBufferObject(glLineAttribBufferID); + pg.deleteVertexBufferObject(glLineAttribBufferID); glLineAttribBufferID = 0; } if (glLineIndexBufferID != 0) { - renderer.deleteVertexBufferObject(glLineIndexBufferID); + pg.deleteVertexBufferObject(glLineIndexBufferID); glLineIndexBufferID = 0; } } @@ -3297,27 +3297,27 @@ public class PShape3D extends PShape { protected void deletePointBuffers() { if (glPointVertexBufferID != 0) { - renderer.deleteVertexBufferObject(glPointVertexBufferID); + pg.deleteVertexBufferObject(glPointVertexBufferID); glPointVertexBufferID = 0; } if (glPointColorBufferID != 0) { - renderer.deleteVertexBufferObject(glPointColorBufferID); + pg.deleteVertexBufferObject(glPointColorBufferID); glPointColorBufferID = 0; } if (glPointNormalBufferID != 0) { - renderer.deleteVertexBufferObject(glPointNormalBufferID); + pg.deleteVertexBufferObject(glPointNormalBufferID); glPointNormalBufferID = 0; } if (glPointAttribBufferID != 0) { - renderer.deleteVertexBufferObject(glPointAttribBufferID); + pg.deleteVertexBufferObject(glPointAttribBufferID); glPointAttribBufferID = 0; } if (glPointIndexBufferID != 0) { - renderer.deleteVertexBufferObject(glPointIndexBufferID); + pg.deleteVertexBufferObject(glPointIndexBufferID); glPointIndexBufferID = 0; } } @@ -3330,7 +3330,7 @@ public class PShape3D extends PShape { public void draw() { - draw(renderer); + draw(pg); } @@ -3407,7 +3407,7 @@ public class PShape3D extends PShape { protected void renderPoints() { - renderer.startPointShader(); + pg.startPointShader(); pgl.enableVertexArrays(); pgl.enableColorArrays(); @@ -3428,7 +3428,7 @@ public class PShape3D extends PShape { pgl.bindVertexBuffer(root.glPointNormalBufferID); pgl.setNormalFormat(3, first); - renderer.setupPointShader(root.glPointAttribBufferID); + pg.setupPointShader(root.glPointAttribBufferID); pgl.bindIndexBuffer(root.glPointIndexBufferID); pgl.renderIndexBuffer(offset, size); @@ -3441,12 +3441,12 @@ public class PShape3D extends PShape { pgl.disableColorArrays(); pgl.disableNormalArrays(); - renderer.stopPointShader(); + pg.stopPointShader(); } protected void renderLines() { - renderer.startLineShader(); + pg.startLineShader(); pgl.enableVertexArrays(); pgl.enableColorArrays(); @@ -3467,7 +3467,7 @@ public class PShape3D extends PShape { pgl.bindVertexBuffer(root.glLineNormalBufferID); pgl.setNormalFormat(3, first); - renderer.setupLineShader(root.glLineAttribBufferID); + pg.setupLineShader(root.glLineAttribBufferID); pgl.bindIndexBuffer(root.glLineIndexBufferID); pgl.renderIndexBuffer(offset, size); @@ -3480,7 +3480,7 @@ public class PShape3D extends PShape { pgl.disableColorArrays(); pgl.disableNormalArrays(); - renderer.stopLineShader(); + pg.stopLineShader(); } @@ -3510,7 +3510,7 @@ public class PShape3D extends PShape { PTexture tex = null; if (textureImage != null) { - tex = renderer.getTexture(textureImage); + tex = pg.getTexture(textureImage); if (tex != null) { pgl.enableTexturing(tex.glTarget); pgl.setActiveTexUnit(0); @@ -3930,23 +3930,23 @@ public class PShape3D extends PShape { int mtlIdxCur = -1; OBJMaterial mtl = null; - renderer.saveDrawingState(); + pg.saveDrawingState(); // The recorded shapes are not merged, they are grouped // according to the group names found in the OBJ file. //ogl.mergeRecShapes = false; // Using RGB mode for coloring. - renderer.colorMode = RGB; + pg.colorMode = RGB; // Strokes are not used to draw the model. - renderer.stroke = false; + pg.stroke = false; // Normals are automatically computed if not specified in the OBJ file. //renderer.autoNormal(true); // Using normal mode for texture coordinates (i.e.: normalized between 0 and 1). - renderer.textureMode = NORMAL; + pg.textureMode = NORMAL; //ogl.beginShapeRecorderImpl(); for (int i = 0; i < faces.size(); i++) { @@ -3959,26 +3959,26 @@ public class PShape3D extends PShape { mtl = materials.get(mtlIdxCur); // Setting colors. - renderer.specular(mtl.ks.x * 255.0f, mtl.ks.y * 255.0f, mtl.ks.z * 255.0f); - renderer.ambient(mtl.ka.x * 255.0f, mtl.ka.y * 255.0f, mtl.ka.z * 255.0f); - if (renderer.fill) { - renderer.fill(mtl.kd.x * 255.0f, mtl.kd.y * 255.0f, mtl.kd.z * 255.0f, mtl.d * 255.0f); + pg.specular(mtl.ks.x * 255.0f, mtl.ks.y * 255.0f, mtl.ks.z * 255.0f); + pg.ambient(mtl.ka.x * 255.0f, mtl.ka.y * 255.0f, mtl.ka.z * 255.0f); + if (pg.fill) { + pg.fill(mtl.kd.x * 255.0f, mtl.kd.y * 255.0f, mtl.kd.z * 255.0f, mtl.d * 255.0f); } - renderer.shininess(mtl.ns); + pg.shininess(mtl.ns); - if (renderer.tint && mtl.kdMap != null) { + if (pg.tint && mtl.kdMap != null) { // If current material is textured, then tinting the texture using the diffuse color. - renderer.tint(mtl.kd.x * 255.0f, mtl.kd.y * 255.0f, mtl.kd.z * 255.0f, mtl.d * 255.0f); + pg.tint(mtl.kd.x * 255.0f, mtl.kd.y * 255.0f, mtl.kd.z * 255.0f, mtl.d * 255.0f); } } // Recording current face. if (face.vertIdx.size() == 3) { - renderer.beginShape(TRIANGLES); // Face is a triangle, so using appropriate shape kind. + pg.beginShape(TRIANGLES); // Face is a triangle, so using appropriate shape kind. } else if (face.vertIdx.size() == 4) { - renderer.beginShape(QUADS); // Face is a quad, so using appropriate shape kind. + pg.beginShape(QUADS); // Face is a quad, so using appropriate shape kind. } else { - renderer.beginShape(); + pg.beginShape(); } //renderer.shapeName(face.name); @@ -4011,29 +4011,29 @@ public class PShape3D extends PShape { } } - PTexture texMtl = (PTexture)mtl.kdMap.getCache(renderer); + PTexture texMtl = (PTexture)mtl.kdMap.getCache(pg); if (texMtl != null) { // Texture orientation in Processing is inverted. texMtl.setFlippedY(true); } - renderer.texture(mtl.kdMap); + pg.texture(mtl.kdMap); if (norms != null) { - renderer.normal(norms.x, norms.y, norms.z); + pg.normal(norms.x, norms.y, norms.z); } if (tex != null) { - renderer.vertex(vert.x, vert.y, vert.z, tex.x, tex.y); + pg.vertex(vert.x, vert.y, vert.z, tex.x, tex.y); } else { - renderer.vertex(vert.x, vert.y, vert.z); + pg.vertex(vert.x, vert.y, vert.z); } } else { // This face is not textured. if (norms != null) { - renderer.normal(norms.x, norms.y, norms.z); + pg.normal(norms.x, norms.y, norms.z); } - renderer.vertex(vert.x, vert.y, vert.z); + pg.vertex(vert.x, vert.y, vert.z); } } - renderer.endShape(CLOSE); + pg.endShape(CLOSE); } // Allocate space for the geometry that the triangulator has generated from the OBJ model. @@ -4049,7 +4049,7 @@ public class PShape3D extends PShape { //ogl.endShapeRecorderImpl(this); //ogl.endShapeRecorderImpl(null); - renderer.restoreDrawingState(); + pg.restoreDrawingState(); } diff --git a/android/core/src/processing/core/PTexture.java b/android/core/src/processing/core/PTexture.java index c8f169c56..06592a008 100644 --- a/android/core/src/processing/core/PTexture.java +++ b/android/core/src/processing/core/PTexture.java @@ -37,9 +37,9 @@ public class PTexture implements PConstants { public int width, height; protected PApplet parent; // The Processing applet - protected PGraphicsAndroid3D renderer; // The main renderer + protected PGraphicsAndroid3D pg; // The main renderer protected PGL pgl; // The interface between Processing and OpenGL. - protected PGL.Context context; // The context that created this texture. + protected PGL.Context context; // The context that created this texture. // These are public but use at your own risk! public int glID; @@ -95,8 +95,8 @@ public class PTexture implements PConstants { public PTexture(PApplet parent, int width, int height, Object params) { this.parent = parent; - renderer = (PGraphicsAndroid3D)parent.g; - pgl = renderer.pgl; + pg = (PGraphicsAndroid3D)parent.g; + pgl = pg.pgl; context = pgl.getContext(); glID = 0; @@ -108,7 +108,7 @@ public class PTexture implements PConstants { protected void finalize() throws Throwable { try { if (glID != 0) { - renderer.finalizeTextureObject(glID); + pg.finalizeTextureObject(glID); } } finally { super.finalize(); @@ -194,13 +194,13 @@ public class PTexture implements PConstants { public void set(PImage img) { - PTexture tex = (PTexture)img.getCache(renderer); + PTexture tex = (PTexture)img.getCache(pg); set(tex); } public void set(PImage img, int x, int y, int w, int h) { - PTexture tex = (PTexture)img.getCache(renderer); + PTexture tex = (PTexture)img.getCache(pg); set(tex, x, y, w, h); } @@ -294,18 +294,18 @@ public class PTexture implements PConstants { // Attaching the texture to the color buffer of a FBO, binding the FBO and reading the pixels // from the current draw buffer (which is the color buffer of the FBO). tempFbo.setColorBuffer(this); - renderer.pushFramebuffer(); - renderer.setFramebuffer(tempFbo); + pg.pushFramebuffer(); + pg.setFramebuffer(tempFbo); tempFbo.readPixels(); - renderer.popFramebuffer(); + pg.popFramebuffer(); } else { // Here we don't have FBOs, so the method above is of no use. What we do instead is // to draw the texture to the screen framebuffer, and then grab the pixels from there. - renderer.pushFramebuffer(); - renderer.setFramebuffer(tempFbo); - renderer.drawTexture(this, 0, 0, glWidth, glHeight, 0, 0, glWidth, glHeight); + pg.pushFramebuffer(); + pg.setFramebuffer(tempFbo); + pg.drawTexture(this, 0, 0, glWidth, glHeight, 0, 0, glWidth, glHeight); tempFbo.readPixels(); - renderer.popFramebuffer(); + pg.popFramebuffer(); } if (tempPixels == null) { @@ -770,7 +770,7 @@ public class PTexture implements PConstants { pgl.enableTexturing(glTarget); - glID = renderer.createTextureObject(); + glID = pg.createTextureObject(); pgl.bindTexture(glTarget, glID); pgl.setTexMinFilter(glTarget, glMinFilter); @@ -807,7 +807,7 @@ public class PTexture implements PConstants { */ protected void release() { if (glID != 0) { - renderer.finalizeTextureObject(glID); + pg.finalizeTextureObject(glID); glID = 0; } } @@ -833,19 +833,19 @@ public class PTexture implements PConstants { tempFbo.disableDepthTest(); // FBO copy: - renderer.pushFramebuffer(); - renderer.setFramebuffer(tempFbo); + pg.pushFramebuffer(); + pg.setFramebuffer(tempFbo); if (scale) { // Rendering tex into "this", and scaling the source rectangle // to cover the entire destination region. - renderer.drawTexture(tex, x, y, w, h, 0, 0, width, height); + pg.drawTexture(tex, x, y, w, h, 0, 0, width, height); } else { // Rendering tex into "this" but without scaling so the contents // of the source texture fall in the corresponding texels of the // destination. - renderer.drawTexture(tex, x, y, w, h, x, y, w, h); + pg.drawTexture(tex, x, y, w, h, x, y, w, h); } - renderer.popFramebuffer(); + pg.popFramebuffer(); } protected void setTexels(int[] pix, int x, int y, int w, int h) { @@ -873,7 +873,7 @@ public class PTexture implements PConstants { height = src.height; parent = src.parent; - renderer = src.renderer; + pg = src.pg; glID = src.glID; glTarget = src.glTarget; diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java index f30264619..c029f6ed9 100644 --- a/java/libraries/opengl/src/processing/opengl/PGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGL.java @@ -98,14 +98,6 @@ public class PGL { public static final int DEFAULT_TESS_VERTICES = 64; public static final int DEFAULT_TESS_INDICES = 128; - /** In and tess increments used in retained mode, where - * arrays are not doubled in size but increased linearly. - * */ - public static final int IN_VERTICES_INCREMENT = 32; - public static final int IN_EDGES_INCREMENT = 64; - public static final int TESS_VERTICES_INCREMENT = 32; - public static final int TESS_INDICES_INCREMENT = 64; - /** Initial sizes for vertex cache used in PShape3D. */ public static final int DEFAULT_VERTEX_CACHE_SIZE = 128; diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 4b0fd54e5..d2d1c0b46 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -1890,7 +1890,7 @@ public class PGraphicsOpenGL extends PGraphics { } flush(); - } + } } @@ -3146,8 +3146,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void textLineImpl(char buffer[], int start, int stop, float x, float y) { textTex = (PFontTexture)textFont.getCache(pg); if (textTex == null) { - textTex = new PFontTexture(parent, textFont, PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), - PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize)); + textTex = new PFontTexture(parent, textFont, maxTextureSize, maxTextureSize); textFont.setCache(this, textTex); } else { if (!pgl.contextIsCurrent(textTex.context)) { @@ -3155,7 +3154,8 @@ public class PGraphicsOpenGL extends PGraphics { textTex.textures[i].glID = 0; // To avoid finalization (texture objects were already deleted when context changed). textTex.textures[i] = null; } - textTex = new PFontTexture(parent, textFont, maxTextureSize, maxTextureSize); + textTex = new PFontTexture(parent, textFont, PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize), + PApplet.min(PGL.MAX_FONT_TEX_SIZE, maxTextureSize)); textFont.setCache(this, textTex); } } @@ -6214,7 +6214,7 @@ public class PGraphicsOpenGL extends PGraphics { public InGeometry(int mode) { renderMode = mode; allocate(); - } + } public void reset() { vertexCount = firstVertex = lastVertex = 0; @@ -6232,6 +6232,16 @@ public class PGraphicsOpenGL extends PGraphics { reset(); } + public void trim() { + if (vertexCount < vertices.length / 3) { + trimVertices(); + trimColors(); + trimNormals(); + trimTexcoords(); + trimEdges(); + } + } + public void dispose() { codes = null; vertices = null; @@ -6358,22 +6368,7 @@ public class PGraphicsOpenGL extends PGraphics { public void vertexCheck() { if (vertexCount == vertices.length / 3) { - int newSize = vertexCount; - - // Increase of vertex arrays is different between - // immediate and retained modes: - // * in immediate mode, since we need to very quickly - // have larger arrays in order to accomodate the - // incoming geometry, doubling of size is used. - // * in retained mode, since the arrays are used - // to create arrays for individual shapes that - // don't change afterwards, we only need linear - // increase. - if (renderMode == IMMEDIATE) { - newSize <<= 1; - } else { - newSize += PGL.IN_VERTICES_INCREMENT; - } + int newSize = vertexCount << 1; expandCodes(newSize); expandVertices(newSize); @@ -6456,13 +6451,7 @@ public class PGraphicsOpenGL extends PGraphics { public void edgeCheck() { if (edgeCount == edges.length) { - int newLen = edgeCount; - - if (renderMode == IMMEDIATE) { - newLen <<= 1; - } else { - newLen += PGL.IN_EDGES_INCREMENT; - } + int newLen = edgeCount << 1; int temp[][] = new int[newLen][3]; PApplet.arrayCopy(edges, 0, temp, 0, edgeCount); @@ -6482,7 +6471,7 @@ public class PGraphicsOpenGL extends PGraphics { vertices = temp; } - protected void expandColors(int n){ + protected void expandColors(int n) { float temp[] = new float[4 * n]; PApplet.arrayCopy(colors, 0, temp, 0, 4 * vertexCount); colors = temp; @@ -6499,13 +6488,49 @@ public class PGraphicsOpenGL extends PGraphics { PApplet.arrayCopy(texcoords, 0, temp, 0, 2 * vertexCount); texcoords = temp; } - + protected void expandStrokes(int n) { float temp[] = new float[5 * n]; PApplet.arrayCopy(strokes, 0, temp, 0, 5 * vertexCount); strokes = temp; } + protected void trimVertices() { + float temp[] = new float[3 * vertexCount]; + PApplet.arrayCopy(vertices, 0, temp, 0, 3 * vertexCount); + vertices = temp; + } + + protected void trimColors() { + float temp[] = new float[4 * vertexCount]; + PApplet.arrayCopy(colors, 0, temp, 0, 4 * vertexCount); + colors = temp; + } + + protected void trimNormals() { + float temp[] = new float[3 * vertexCount]; + PApplet.arrayCopy(normals, 0, temp, 0, 3 * vertexCount); + normals = temp; + } + + protected void trimTexcoords() { + float temp[] = new float[2 * vertexCount]; + PApplet.arrayCopy(texcoords, 0, temp, 0, 2 * vertexCount); + texcoords = temp; + } + + protected void packStrokes() { + float temp[] = new float[5 * vertexCount]; + PApplet.arrayCopy(strokes, 0, temp, 0, 5 * vertexCount); + strokes = temp; + } + + protected void trimEdges() { + int temp[][] = new int[edgeCount][3]; + PApplet.arrayCopy(edges, 0, temp, 0, edgeCount); + edges = temp; + } + public int getNumLineVertices() { return 4 *(lastEdge - firstEdge + 1); } @@ -6865,6 +6890,131 @@ public class PGraphicsOpenGL extends PGraphics { reset(); } + public void trim() { + if (fillVertexCount < fillVertices.length / 3) { + trimFillVertices(); + trimFillColors(); + trimFillNormals(); + trimFillTexcoords(); + } + + if (fillIndexCount < fillIndices.length) { + trimFillIndices(); + } + + if (lineVertexCount < lineVertices.length / 3) { + trimLineVertices(); + trimLineColors(); + trimLineNormals(); + trimLineAttributes(); + } + + if (lineIndexCount < lineIndices.length) { + trimLineIndices(); + } + + if (pointVertexCount < pointVertices.length / 3) { + trimPointVertices(); + trimPointColors(); + trimPointNormals(); + trimPointAttributes(); + } + + if (pointIndexCount < pointIndices.length) { + trimPointIndices(); + } + } + + protected void trimFillVertices() { + float temp[] = new float[3 * fillVertexCount]; + PApplet.arrayCopy(fillVertices, 0, temp, 0, 3 * fillVertexCount); + fillVertices = temp; + } + + protected void trimFillColors() { + float temp[] = new float[4 * fillVertexCount]; + PApplet.arrayCopy(fillColors, 0, temp, 0, 4 * fillVertexCount); + fillColors = temp; + } + + protected void trimFillNormals() { + float temp[] = new float[3 * fillVertexCount]; + PApplet.arrayCopy(fillNormals, 0, temp, 0, 3 * fillVertexCount); + fillNormals = temp; + } + + protected void trimFillTexcoords() { + float temp[] = new float[2 * fillVertexCount]; + PApplet.arrayCopy(fillTexcoords, 0, temp, 0, 2 * fillVertexCount); + fillTexcoords = temp; + } + + public void trimFillIndices() { + int temp[] = new int[fillIndexCount]; + PApplet.arrayCopy(fillIndices, 0, temp, 0, fillIndexCount); + fillIndices = temp; + } + + protected void trimLineVertices() { + float temp[] = new float[3 * lineVertexCount]; + PApplet.arrayCopy(lineVertices, 0, temp, 0, 3 * lineVertexCount); + lineVertices = temp; + } + + protected void trimLineColors() { + float temp[] = new float[4 * lineVertexCount]; + PApplet.arrayCopy(lineColors, 0, temp, 0, 4 * lineVertexCount); + lineColors = temp; + } + + protected void trimLineNormals() { + float temp[] = new float[3 * lineVertexCount]; + PApplet.arrayCopy(lineNormals, 0, temp, 0, 3 * lineVertexCount); + lineNormals = temp; + } + + protected void trimLineAttributes() { + float temp[] = new float[4 * lineVertexCount]; + PApplet.arrayCopy(lineAttributes, 0, temp, 0, 4 * lineVertexCount); + lineAttributes = temp; + } + + protected void trimLineIndices() { + int temp[] = new int[lineVertexCount]; + PApplet.arrayCopy(lineIndices, 0, temp, 0, lineIndexCount); + lineIndices = temp; + } + + protected void trimPointVertices() { + float temp[] = new float[3 * pointVertexCount]; + PApplet.arrayCopy(pointVertices, 0, temp, 0, 3 * pointVertexCount); + pointVertices = temp; + } + + protected void trimPointColors() { + float temp[] = new float[4 * pointVertexCount]; + PApplet.arrayCopy(pointColors, 0, temp, 0, 4 * pointVertexCount); + pointColors = temp; + } + + protected void trimPointNormals() { + float temp[] = new float[3 * pointVertexCount]; + PApplet.arrayCopy(pointNormals, 0, temp, 0, 3 * pointVertexCount); + pointNormals = temp; + } + + protected void trimPointAttributes() { + float temp[] = new float[2 * pointVertexCount]; + PApplet.arrayCopy(pointAttributes, 0, temp, 0, 2 * pointVertexCount); + pointAttributes = temp; + } + + protected void trimPointIndices() { + int temp[] = new int[pointIndexCount]; + PApplet.arrayCopy(pointIndices, 0, temp, 0, pointIndexCount); + pointIndices = temp; + } + public void dipose() { fillVertices = null; fillColors = null; @@ -6902,7 +7052,7 @@ public class PGraphicsOpenGL extends PGraphics { PGL.MAX_TESS_INDICES < fillIndexCount || PGL.MAX_TESS_INDICES < fillIndexCount; } - + public void addCounts(TessGeometry other) { fillVertexCount += other.fillVertexCount; fillIndexCount += other.fillIndexCount; @@ -6945,12 +7095,12 @@ public class PGraphicsOpenGL extends PGraphics { } public int setFillVertex(int offset) { - firstFillVertex = 0; + firstFillVertex = 0; if (0 < offset) { firstFillVertex = offset + 1; - } + } lastFillVertex = firstFillVertex + fillVertexCount - 1; - return lastFillVertex; + return lastFillVertex; } public int setFillIndex(int voffset, int ioffset) { @@ -7112,7 +7262,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addFillVertices(int count) { int oldSize = fillVertices.length / 3; - if (fillVertexCount + count >= oldSize) { + if (fillVertexCount + count > oldSize) { int newSize = expandVertSize(oldSize, fillVertexCount + count); expandFillVertices(newSize); @@ -7128,7 +7278,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addFillIndices(int count) { int oldSize = fillIndices.length; - if (fillIndexCount + count >= oldSize) { + if (fillIndexCount + count > oldSize) { int newSize = expandIndSize(oldSize, fillIndexCount + count); expandFillIndices(newSize); @@ -7165,7 +7315,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addLineVertices(int count) { int oldSize = lineVertices.length / 3; - if (lineVertexCount + count >= oldSize) { + if (lineVertexCount + count > oldSize) { int newSize = expandVertSize(oldSize, lineVertexCount + count); expandLineVertices(newSize); @@ -7179,25 +7329,25 @@ public class PGraphicsOpenGL extends PGraphics { lastLineVertex = lineVertexCount - 1; } - public void expandLineVertices(int n) { + protected void expandLineVertices(int n) { float temp[] = new float[3 * n]; PApplet.arrayCopy(lineVertices, 0, temp, 0, 3 * lineVertexCount); lineVertices = temp; } - public void expandLineColors(int n) { + protected void expandLineColors(int n) { float temp[] = new float[4 * n]; PApplet.arrayCopy(lineColors, 0, temp, 0, 4 * lineVertexCount); lineColors = temp; } - public void expandLineNormals(int n) { + protected void expandLineNormals(int n) { float temp[] = new float[3 * n]; PApplet.arrayCopy(lineNormals, 0, temp, 0, 3 * lineVertexCount); lineNormals = temp; } - public void expandLineAttributes(int n) { + protected void expandLineAttributes(int n) { float temp[] = new float[4 * n]; PApplet.arrayCopy(lineAttributes, 0, temp, 0, 4 * lineVertexCount); lineAttributes = temp; @@ -7205,7 +7355,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addLineIndices(int count) { int oldSize = lineIndices.length; - if (lineIndexCount + count >= oldSize) { + if (lineIndexCount + count > oldSize) { int newSize = expandIndSize(oldSize, lineIndexCount + count); expandLineIndices(newSize); @@ -7216,7 +7366,7 @@ public class PGraphicsOpenGL extends PGraphics { lastLineIndex = lineIndexCount - 1; } - public void expandLineIndices(int n) { + protected void expandLineIndices(int n) { int temp[] = new int[n]; PApplet.arrayCopy(lineIndices, 0, temp, 0, lineIndexCount); lineIndices = temp; @@ -7224,7 +7374,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addPointVertices(int count) { int oldSize = pointVertices.length / 3; - if (pointVertexCount + count >= oldSize) { + if (pointVertexCount + count > oldSize) { int newSize = expandVertSize(oldSize, pointVertexCount + count); expandPointVertices(newSize); @@ -7238,25 +7388,25 @@ public class PGraphicsOpenGL extends PGraphics { lastPointVertex = pointVertexCount - 1; } - public void expandPointVertices(int n) { + protected void expandPointVertices(int n) { float temp[] = new float[3 * n]; PApplet.arrayCopy(pointVertices, 0, temp, 0, 3 * pointVertexCount); pointVertices = temp; } - public void expandPointColors(int n) { + protected void expandPointColors(int n) { float temp[] = new float[4 * n]; PApplet.arrayCopy(pointColors, 0, temp, 0, 4 * pointVertexCount); pointColors = temp; } - public void expandPointNormals(int n) { + protected void expandPointNormals(int n) { float temp[] = new float[3 * n]; PApplet.arrayCopy(pointNormals, 0, temp, 0, 3 * pointVertexCount); pointNormals = temp; } - public void expandPointAttributes(int n) { + protected void expandPointAttributes(int n) { float temp[] = new float[2 * n]; PApplet.arrayCopy(pointAttributes, 0, temp, 0, 2 * pointVertexCount); pointAttributes = temp; @@ -7264,7 +7414,7 @@ public class PGraphicsOpenGL extends PGraphics { public void addPointIndices(int count) { int oldSize = pointIndices.length; - if (pointIndexCount + count >= oldSize) { + if (pointIndexCount + count > oldSize) { int newSize = expandIndSize(oldSize, pointIndexCount + count); expandPointIndices(newSize); @@ -7275,7 +7425,7 @@ public class PGraphicsOpenGL extends PGraphics { lastPointIndex = pointIndexCount - 1; } - public void expandPointIndices(int n) { + protected void expandPointIndices(int n) { int temp[] = new int[n]; PApplet.arrayCopy(pointIndices, 0, temp, 0, pointIndexCount); pointIndices = temp; @@ -7548,11 +7698,7 @@ public class PGraphicsOpenGL extends PGraphics { public int expandVertSize(int currSize, int newMinSize) { int newSize = currSize; while (newSize < newMinSize) { - if (renderMode == IMMEDIATE) { - newSize <<= 1; - } else { - newSize += PGL.TESS_VERTICES_INCREMENT; - } + newSize <<= 1; } return newSize; } @@ -7560,11 +7706,7 @@ public class PGraphicsOpenGL extends PGraphics { public int expandIndSize(int currSize, int newMinSize) { int newSize = currSize; while (newSize < newMinSize) { - if (renderMode == IMMEDIATE) { - newSize <<= 1; - } else { - newSize += PGL.TESS_INDICES_INCREMENT; - } + newSize <<= 1; } return newSize; } @@ -7583,7 +7725,7 @@ public class PGraphicsOpenGL extends PGraphics { for (int i = 0; i < lineVertexCount; i++) { index = 3 * i; cx0 += lineVertices[index++]; - cy0 += lineVertices[index ]; + cy0 += lineVertices[index ]; } for (int i = 0; i < pointVertexCount; i++) { index = 3 * i; diff --git a/java/libraries/opengl/src/processing/opengl/PShape3D.java b/java/libraries/opengl/src/processing/opengl/PShape3D.java index e8c7fe7e6..a6111437a 100644 --- a/java/libraries/opengl/src/processing/opengl/PShape3D.java +++ b/java/libraries/opengl/src/processing/opengl/PShape3D.java @@ -74,7 +74,7 @@ import java.util.Hashtable; */ public class PShape3D extends PShape { - protected PGraphicsOpenGL renderer; + protected PGraphicsOpenGL pg; protected PGL pgl; protected PShape3D root; @@ -251,8 +251,8 @@ public class PShape3D extends PShape { protected int imageMode; public PShape3D(PApplet parent, int family) { - renderer = (PGraphicsOpenGL)parent.g; - pgl = renderer.pgl; + pg = (PGraphicsOpenGL)parent.g; + pgl = pg.pgl; glMode = PGL.STATIC_DRAW; @@ -274,53 +274,53 @@ public class PShape3D extends PShape { glPointAttribBufferID = 0; glPointIndexBufferID = 0; - this.tessellator = renderer.tessellator; + this.tessellator = pg.tessellator; this.family = family; this.root = this; this.parent = null; this.tessellated = false; if (family == GEOMETRY || family == PRIMITIVE || family == PATH) { - in = renderer.newInGeometry(RETAINED); - } - tess = renderer.newTessGeometry(RETAINED); + in = pg.newInGeometry(RETAINED); + } + tess = pg.newTessGeometry(RETAINED); fillIndexData = new ArrayList(); lineIndexData = new ArrayList(); pointIndexData = new ArrayList(); // Modes are retrieved from the current values in the renderer. - textureMode = renderer.textureMode; - rectMode = renderer.rectMode; - ellipseMode = renderer.ellipseMode; - shapeMode = renderer.shapeMode; - imageMode = renderer.imageMode; + textureMode = pg.textureMode; + rectMode = pg.rectMode; + ellipseMode = pg.ellipseMode; + shapeMode = pg.shapeMode; + imageMode = pg.imageMode; - colorMode(renderer.colorMode, renderer.colorModeX, renderer.colorModeY, renderer.colorModeZ, renderer.colorModeA); + colorMode(pg.colorMode, pg.colorModeX, pg.colorModeY, pg.colorModeZ, pg.colorModeA); // Initial values for fill, stroke and tint colors are also imported from the renderer. // This is particular relevant for primitive shapes, since is not possible to set // their color separately when creating them, and their input vertices are actually // generated at rendering time, by which the color configuration of the renderer might // have changed. - fill = renderer.fill; - fillR = ((renderer.fillColor >> 16) & 0xFF) / 255.0f; - fillG = ((renderer.fillColor >> 8) & 0xFF) / 255.0f; - fillB = ((renderer.fillColor >> 0) & 0xFF) / 255.0f; - fillA = ((renderer.fillColor >> 24) & 0xFF) / 255.0f; + fill = pg.fill; + fillR = ((pg.fillColor >> 16) & 0xFF) / 255.0f; + fillG = ((pg.fillColor >> 8) & 0xFF) / 255.0f; + fillB = ((pg.fillColor >> 0) & 0xFF) / 255.0f; + fillA = ((pg.fillColor >> 24) & 0xFF) / 255.0f; - stroke = renderer.stroke; - strokeR = ((renderer.strokeColor >> 16) & 0xFF) / 255.0f; - strokeG = ((renderer.strokeColor >> 8) & 0xFF) / 255.0f; - strokeB = ((renderer.strokeColor >> 0) & 0xFF) / 255.0f; - strokeA = ((renderer.strokeColor >> 24) & 0xFF) / 255.0f; + stroke = pg.stroke; + strokeR = ((pg.strokeColor >> 16) & 0xFF) / 255.0f; + strokeG = ((pg.strokeColor >> 8) & 0xFF) / 255.0f; + strokeB = ((pg.strokeColor >> 0) & 0xFF) / 255.0f; + strokeA = ((pg.strokeColor >> 24) & 0xFF) / 255.0f; - strokeWeight = renderer.strokeWeight; + strokeWeight = pg.strokeWeight; - tint = renderer.tint; - tintR = ((renderer.tintColor >> 16) & 0xFF) / 255.0f; - tintG = ((renderer.tintColor >> 8) & 0xFF) / 255.0f; - tintB = ((renderer.tintColor >> 0) & 0xFF) / 255.0f; - tintA = ((renderer.tintColor >> 24) & 0xFF) / 255.0f; + tint = pg.tint; + tintR = ((pg.tintColor >> 16) & 0xFF) / 255.0f; + tintG = ((pg.tintColor >> 8) & 0xFF) / 255.0f; + tintB = ((pg.tintColor >> 0) & 0xFF) / 255.0f; + tintA = ((pg.tintColor >> 24) & 0xFF) / 255.0f; normalX = normalY = 0; normalZ = 1; @@ -382,67 +382,67 @@ public class PShape3D extends PShape { protected void finalizeFillBuffers() { if (glFillVertexBufferID != 0) { - renderer.finalizeVertexBufferObject(glFillVertexBufferID); + pg.finalizeVertexBufferObject(glFillVertexBufferID); } if (glFillColorBufferID != 0) { - renderer.finalizeVertexBufferObject(glFillColorBufferID); + pg.finalizeVertexBufferObject(glFillColorBufferID); } if (glFillNormalBufferID != 0) { - renderer.finalizeVertexBufferObject(glFillNormalBufferID); + pg.finalizeVertexBufferObject(glFillNormalBufferID); } if (glFillTexCoordBufferID != 0) { - renderer.finalizeVertexBufferObject(glFillTexCoordBufferID); + pg.finalizeVertexBufferObject(glFillTexCoordBufferID); } if (glFillIndexBufferID != 0) { - renderer.finalizeVertexBufferObject(glFillIndexBufferID); + pg.finalizeVertexBufferObject(glFillIndexBufferID); } } protected void finalizeLineBuffers() { if (glLineVertexBufferID != 0) { - renderer.finalizeVertexBufferObject(glLineVertexBufferID); + pg.finalizeVertexBufferObject(glLineVertexBufferID); } if (glLineColorBufferID != 0) { - renderer.finalizeVertexBufferObject(glLineColorBufferID); + pg.finalizeVertexBufferObject(glLineColorBufferID); } if (glLineNormalBufferID != 0) { - renderer.finalizeVertexBufferObject(glLineNormalBufferID); + pg.finalizeVertexBufferObject(glLineNormalBufferID); } if (glLineAttribBufferID != 0) { - renderer.finalizeVertexBufferObject(glLineAttribBufferID); + pg.finalizeVertexBufferObject(glLineAttribBufferID); } if (glLineIndexBufferID != 0) { - renderer.finalizeVertexBufferObject(glLineIndexBufferID); + pg.finalizeVertexBufferObject(glLineIndexBufferID); } } protected void finalizePointBuffers() { if (glPointVertexBufferID != 0) { - renderer.finalizeVertexBufferObject(glPointVertexBufferID); + pg.finalizeVertexBufferObject(glPointVertexBufferID); } if (glPointColorBufferID != 0) { - renderer.finalizeVertexBufferObject(glPointColorBufferID); + pg.finalizeVertexBufferObject(glPointColorBufferID); } if (glPointNormalBufferID != 0) { - renderer.finalizeVertexBufferObject(glPointNormalBufferID); + pg.finalizeVertexBufferObject(glPointNormalBufferID); } if (glPointAttribBufferID != 0) { - renderer.finalizeVertexBufferObject(glPointAttribBufferID); + pg.finalizeVertexBufferObject(glPointAttribBufferID); } if (glPointIndexBufferID != 0) { - renderer.finalizeVertexBufferObject(glPointIndexBufferID); + pg.finalizeVertexBufferObject(glPointIndexBufferID); } } @@ -642,7 +642,7 @@ public class PShape3D extends PShape { u /= texture.width; v /= texture.height; - PTexture tex = renderer.queryTexture(texture); + PTexture tex = pg.queryTexture(texture); if (tex != null && tex.isFlippedY()) { v = 1 - v; } @@ -708,6 +708,10 @@ public class PShape3D extends PShape { return; } + // Input arrays are trimmed since they are expanded by doubling their old size, + // which might lead to arrays larger than the vertex counts. + in.trim(); + isClosed = mode == CLOSE; root.tessellated = false; tessellated = false; @@ -1652,11 +1656,11 @@ public class PShape3D extends PShape { } // setup matrix for forward differencing to speed up drawing - renderer.splineForward(detail, bezierDrawMatrix); + pg.splineForward(detail, bezierDrawMatrix); // multiply the basis and forward diff matrices together // saves much time since this needn't be done for each curve - bezierDrawMatrix.apply(renderer.bezierBasisMatrix); + bezierDrawMatrix.apply(pg.bezierBasisMatrix); } public void bezierVertex(float x2, float y2, @@ -1823,10 +1827,10 @@ public class PShape3D extends PShape { (s-1)/2f, 0, (1-s)/2f, 0, 0, 1, 0, 0); - renderer.splineForward(curveDetail, curveDrawMatrix); + pg.splineForward(curveDetail, curveDrawMatrix); if (bezierBasisInverse == null) { - bezierBasisInverse = renderer.bezierBasisMatrix.get(); + bezierBasisInverse = pg.bezierBasisMatrix.get(); bezierBasisInverse.invert(); curveToBezierMatrix = new PMatrix3D(); } @@ -2293,9 +2297,13 @@ public class PShape3D extends PShape { // equivalent to use POLYGON with fill disabled. } + // Tessellated arrays are trimmed since they are expanded by doubling their old size, + // which might lead to arrays larger than the vertex counts. + tess.trim(); + if (texture != null && parent != null) { ((PShape3D)parent).addTexture(texture); - } + } } } @@ -2409,8 +2417,8 @@ public class PShape3D extends PShape { protected void tessellateSphere() { // TODO: move to InGeometry float r = params[0]; - int nu = renderer.sphereDetailU; - int nv = renderer.sphereDetailV; + int nu = pg.sphereDetailU; + int nv = pg.sphereDetailV; if ((nu < 3) || (nv < 2)) { nu = nv = 30; @@ -2788,25 +2796,25 @@ public class PShape3D extends PShape { } protected void initFillBuffers(int nvert, int nind) { - glFillVertexBufferID = renderer.createVertexBufferObject(); + glFillVertexBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glFillVertexBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glFillColorBufferID = renderer.createVertexBufferObject(); + glFillColorBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glFillColorBufferID); pgl.initVertexBuffer(4 * nvert, glMode); - glFillNormalBufferID = renderer.createVertexBufferObject(); + glFillNormalBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glFillNormalBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glFillTexCoordBufferID = renderer.createVertexBufferObject(); + glFillTexCoordBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glFillTexCoordBufferID); pgl.initVertexBuffer(2 * nvert, glMode); pgl.unbindVertexBuffer(); - glFillIndexBufferID = renderer.createVertexBufferObject(); + glFillIndexBufferID = pg.createVertexBufferObject(); pgl.bindIndexBuffer(glFillIndexBufferID); pgl.initIndexBuffer(nind, glMode); @@ -3044,25 +3052,25 @@ public class PShape3D extends PShape { protected void initLineBuffers(int nvert, int nind) { - glLineVertexBufferID = renderer.createVertexBufferObject(); + glLineVertexBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glLineVertexBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glLineColorBufferID = renderer.createVertexBufferObject(); + glLineColorBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glLineColorBufferID); pgl.initVertexBuffer(4 * nvert, glMode); - glLineNormalBufferID = renderer.createVertexBufferObject(); + glLineNormalBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glLineNormalBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glLineAttribBufferID = renderer.createVertexBufferObject(); + glLineAttribBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glLineAttribBufferID); pgl.initVertexBuffer(4 * nvert, glMode); pgl.unbindVertexBuffer(); - glLineIndexBufferID = renderer.createVertexBufferObject(); + glLineIndexBufferID = pg.createVertexBufferObject(); pgl.bindIndexBuffer(glLineIndexBufferID); pgl.initIndexBuffer(nind, glMode); @@ -3143,25 +3151,25 @@ public class PShape3D extends PShape { protected void initPointBuffers(int nvert, int nind) { - glPointVertexBufferID = renderer.createVertexBufferObject(); + glPointVertexBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glPointVertexBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glPointColorBufferID = renderer.createVertexBufferObject(); + glPointColorBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glPointColorBufferID); pgl.initVertexBuffer(4 * nvert, glMode); - glPointNormalBufferID = renderer.createVertexBufferObject(); + glPointNormalBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glPointNormalBufferID); pgl.initVertexBuffer(3 * nvert, glMode); - glPointAttribBufferID = renderer.createVertexBufferObject(); + glPointAttribBufferID = pg.createVertexBufferObject(); pgl.bindVertexBuffer(glPointAttribBufferID); pgl.initVertexBuffer(2 * nvert, glMode); pgl.unbindVertexBuffer(); - glPointIndexBufferID = renderer.createVertexBufferObject(); + glPointIndexBufferID = pg.createVertexBufferObject(); pgl.bindIndexBuffer(glPointIndexBufferID); pgl.initIndexBuffer(nind, glMode); @@ -3257,27 +3265,27 @@ public class PShape3D extends PShape { protected void deleteFillBuffers() { if (glFillVertexBufferID != 0) { - renderer.deleteVertexBufferObject(glFillVertexBufferID); + pg.deleteVertexBufferObject(glFillVertexBufferID); glFillVertexBufferID = 0; } if (glFillColorBufferID != 0) { - renderer.deleteVertexBufferObject(glFillColorBufferID); + pg.deleteVertexBufferObject(glFillColorBufferID); glFillColorBufferID = 0; } if (glFillNormalBufferID != 0) { - renderer.deleteVertexBufferObject(glFillNormalBufferID); + pg.deleteVertexBufferObject(glFillNormalBufferID); glFillNormalBufferID = 0; } if (glFillTexCoordBufferID != 0) { - renderer.deleteVertexBufferObject(glFillTexCoordBufferID); + pg.deleteVertexBufferObject(glFillTexCoordBufferID); glFillTexCoordBufferID = 0; } if (glFillIndexBufferID != 0) { - renderer.deleteVertexBufferObject(glFillIndexBufferID); + pg.deleteVertexBufferObject(glFillIndexBufferID); glFillIndexBufferID = 0; } } @@ -3285,27 +3293,27 @@ public class PShape3D extends PShape { protected void deleteLineBuffers() { if (glLineVertexBufferID != 0) { - renderer.deleteVertexBufferObject(glLineVertexBufferID); + pg.deleteVertexBufferObject(glLineVertexBufferID); glLineVertexBufferID = 0; } if (glLineColorBufferID != 0) { - renderer.deleteVertexBufferObject(glLineColorBufferID); + pg.deleteVertexBufferObject(glLineColorBufferID); glLineColorBufferID = 0; } if (glLineNormalBufferID != 0) { - renderer.deleteVertexBufferObject(glLineNormalBufferID); + pg.deleteVertexBufferObject(glLineNormalBufferID); glLineNormalBufferID = 0; } if (glLineAttribBufferID != 0) { - renderer.deleteVertexBufferObject(glLineAttribBufferID); + pg.deleteVertexBufferObject(glLineAttribBufferID); glLineAttribBufferID = 0; } if (glLineIndexBufferID != 0) { - renderer.deleteVertexBufferObject(glLineIndexBufferID); + pg.deleteVertexBufferObject(glLineIndexBufferID); glLineIndexBufferID = 0; } } @@ -3313,27 +3321,27 @@ public class PShape3D extends PShape { protected void deletePointBuffers() { if (glPointVertexBufferID != 0) { - renderer.deleteVertexBufferObject(glPointVertexBufferID); + pg.deleteVertexBufferObject(glPointVertexBufferID); glPointVertexBufferID = 0; } if (glPointColorBufferID != 0) { - renderer.deleteVertexBufferObject(glPointColorBufferID); + pg.deleteVertexBufferObject(glPointColorBufferID); glPointColorBufferID = 0; } if (glPointNormalBufferID != 0) { - renderer.deleteVertexBufferObject(glPointNormalBufferID); + pg.deleteVertexBufferObject(glPointNormalBufferID); glPointNormalBufferID = 0; } if (glPointAttribBufferID != 0) { - renderer.deleteVertexBufferObject(glPointAttribBufferID); + pg.deleteVertexBufferObject(glPointAttribBufferID); glPointAttribBufferID = 0; } if (glPointIndexBufferID != 0) { - renderer.deleteVertexBufferObject(glPointIndexBufferID); + pg.deleteVertexBufferObject(glPointIndexBufferID); glPointIndexBufferID = 0; } } @@ -3346,7 +3354,7 @@ public class PShape3D extends PShape { public void draw() { - draw(renderer); + draw(pg); } @@ -3423,7 +3431,7 @@ public class PShape3D extends PShape { protected void renderPoints() { - renderer.startPointShader(); + pg.startPointShader(); pgl.enableVertexArrays(); pgl.enableColorArrays(); @@ -3444,7 +3452,7 @@ public class PShape3D extends PShape { pgl.bindVertexBuffer(root.glPointNormalBufferID); pgl.setNormalFormat(3, first); - renderer.setupPointShader(root.glPointAttribBufferID); + pg.setupPointShader(root.glPointAttribBufferID); pgl.bindIndexBuffer(root.glPointIndexBufferID); pgl.renderIndexBuffer(offset, size); @@ -3457,12 +3465,12 @@ public class PShape3D extends PShape { pgl.disableColorArrays(); pgl.disableNormalArrays(); - renderer.stopPointShader(); + pg.stopPointShader(); } protected void renderLines() { - renderer.startLineShader(); + pg.startLineShader(); pgl.enableVertexArrays(); pgl.enableColorArrays(); @@ -3483,7 +3491,7 @@ public class PShape3D extends PShape { pgl.bindVertexBuffer(root.glLineNormalBufferID); pgl.setNormalFormat(3, first); - renderer.setupLineShader(root.glLineAttribBufferID); + pg.setupLineShader(root.glLineAttribBufferID); pgl.bindIndexBuffer(root.glLineIndexBufferID); pgl.renderIndexBuffer(offset, size); @@ -3496,7 +3504,7 @@ public class PShape3D extends PShape { pgl.disableColorArrays(); pgl.disableNormalArrays(); - renderer.stopLineShader(); + pg.stopLineShader(); } @@ -3526,7 +3534,7 @@ public class PShape3D extends PShape { PTexture tex = null; if (textureImage != null) { - tex = renderer.getTexture(textureImage); + tex = pg.getTexture(textureImage); if (tex != null) { pgl.enableTexturing(tex.glTarget); pgl.setActiveTexUnit(0); @@ -3946,23 +3954,23 @@ public class PShape3D extends PShape { int mtlIdxCur = -1; OBJMaterial mtl = null; - renderer.saveDrawingState(); + pg.saveDrawingState(); // The recorded shapes are not merged, they are grouped // according to the group names found in the OBJ file. //ogl.mergeRecShapes = false; // Using RGB mode for coloring. - renderer.colorMode = RGB; + pg.colorMode = RGB; // Strokes are not used to draw the model. - renderer.stroke = false; + pg.stroke = false; // Normals are automatically computed if not specified in the OBJ file. //renderer.autoNormal(true); // Using normal mode for texture coordinates (i.e.: normalized between 0 and 1). - renderer.textureMode = NORMAL; + pg.textureMode = NORMAL; //ogl.beginShapeRecorderImpl(); for (int i = 0; i < faces.size(); i++) { @@ -3975,26 +3983,26 @@ public class PShape3D extends PShape { mtl = materials.get(mtlIdxCur); // Setting colors. - renderer.specular(mtl.ks.x * 255.0f, mtl.ks.y * 255.0f, mtl.ks.z * 255.0f); - renderer.ambient(mtl.ka.x * 255.0f, mtl.ka.y * 255.0f, mtl.ka.z * 255.0f); - if (renderer.fill) { - renderer.fill(mtl.kd.x * 255.0f, mtl.kd.y * 255.0f, mtl.kd.z * 255.0f, mtl.d * 255.0f); + pg.specular(mtl.ks.x * 255.0f, mtl.ks.y * 255.0f, mtl.ks.z * 255.0f); + pg.ambient(mtl.ka.x * 255.0f, mtl.ka.y * 255.0f, mtl.ka.z * 255.0f); + if (pg.fill) { + pg.fill(mtl.kd.x * 255.0f, mtl.kd.y * 255.0f, mtl.kd.z * 255.0f, mtl.d * 255.0f); } - renderer.shininess(mtl.ns); + pg.shininess(mtl.ns); - if (renderer.tint && mtl.kdMap != null) { + if (pg.tint && mtl.kdMap != null) { // If current material is textured, then tinting the texture using the diffuse color. - renderer.tint(mtl.kd.x * 255.0f, mtl.kd.y * 255.0f, mtl.kd.z * 255.0f, mtl.d * 255.0f); + pg.tint(mtl.kd.x * 255.0f, mtl.kd.y * 255.0f, mtl.kd.z * 255.0f, mtl.d * 255.0f); } } // Recording current face. if (face.vertIdx.size() == 3) { - renderer.beginShape(TRIANGLES); // Face is a triangle, so using appropriate shape kind. + pg.beginShape(TRIANGLES); // Face is a triangle, so using appropriate shape kind. } else if (face.vertIdx.size() == 4) { - renderer.beginShape(QUADS); // Face is a quad, so using appropriate shape kind. + pg.beginShape(QUADS); // Face is a quad, so using appropriate shape kind. } else { - renderer.beginShape(); + pg.beginShape(); } //renderer.shapeName(face.name); @@ -4027,29 +4035,29 @@ public class PShape3D extends PShape { } } - PTexture texMtl = (PTexture)mtl.kdMap.getCache(renderer); + PTexture texMtl = (PTexture)mtl.kdMap.getCache(pg); if (texMtl != null) { // Texture orientation in Processing is inverted. texMtl.setFlippedY(true); } - renderer.texture(mtl.kdMap); + pg.texture(mtl.kdMap); if (norms != null) { - renderer.normal(norms.x, norms.y, norms.z); + pg.normal(norms.x, norms.y, norms.z); } if (tex != null) { - renderer.vertex(vert.x, vert.y, vert.z, tex.x, tex.y); + pg.vertex(vert.x, vert.y, vert.z, tex.x, tex.y); } else { - renderer.vertex(vert.x, vert.y, vert.z); + pg.vertex(vert.x, vert.y, vert.z); } } else { // This face is not textured. if (norms != null) { - renderer.normal(norms.x, norms.y, norms.z); + pg.normal(norms.x, norms.y, norms.z); } - renderer.vertex(vert.x, vert.y, vert.z); + pg.vertex(vert.x, vert.y, vert.z); } } - renderer.endShape(CLOSE); + pg.endShape(CLOSE); } // Allocate space for the geometry that the triangulator has generated from the OBJ model. @@ -4065,7 +4073,7 @@ public class PShape3D extends PShape { //ogl.endShapeRecorderImpl(this); //ogl.endShapeRecorderImpl(null); - renderer.restoreDrawingState(); + pg.restoreDrawingState(); }