From c226badf22dfd5110ad3e83f38795bf154f0362f Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 31 Mar 2015 15:09:22 -0400 Subject: [PATCH] added bind and unbind to VertexAttribute class --- .../processing/opengl/PGraphicsOpenGL.java | 23 ++++++++++++------- core/src/processing/opengl/PShapeOpenGL.java | 11 ++++----- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 363ef1f22..4ac833b49 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2585,17 +2585,18 @@ public class PGraphicsOpenGL extends PGraphics { shader.setTexture(tex); } - for (String name: polyAttribs.keySet()) { - VertexAttribute attrib = polyAttribs.get(name); + for (VertexAttribute attrib: polyAttribs.values()) { attrib.updateLoc(shader); + attrib.bind(pgl); shader.setAttributeVBO(attrib.glLoc, attrib.glName, - attrib.size, attrib.type, + attrib.tessSize, attrib.type, attrib.isColor(), 0, attrib.sizeInBytes(voffset)); } shader.draw(glPolyIndex, icount, ioffset); } + for (VertexAttribute attrib: polyAttribs.values()) attrib.unbind(pgl); shader.unbind(); } unbindPolyBuffers(); @@ -7128,12 +7129,20 @@ public class PGraphicsOpenGL extends PGraphics { } } + void bind(PGL pgl) { + pgl.enableVertexAttribArray(glLoc); + } + + void unbind(PGL pgl) { + pgl.disableVertexAttribArray(glLoc); + } + void updateLoc(PShader shader) { if (glLoc == -1) glLoc = shader.getAttributeLoc(name); } int sizeInBytes(int length) { - return length * size * elementSize; + return length * tessSize * elementSize; } void set(float[] values) { @@ -8029,6 +8038,7 @@ public class PGraphicsOpenGL extends PGraphics { for (String name: attribs.keySet()) { VertexAttribute attrib = attribs.get(name); + index = attrib.size * vertexCount; if (attrib.type == PGL.FLOAT) { float[] values = fattribs.get(name); attrib.add(values, index); @@ -10411,12 +10421,9 @@ public class PGraphicsOpenGL extends PGraphics { } else if (attrib.isBool()) { inValues = in.battribs.get(name); tessValues = bpolyAttribs.get(name); - PApplet.arrayCopy(inValues, attrib.size * i0, - tessValues, attrib.size * firstPolyVertex, - attrib.size * nvert); } PApplet.arrayCopy(inValues, attrib.size * i0, - tessValues, attrib.size * firstPolyVertex, + tessValues, attrib.tessSize * firstPolyVertex, attrib.size * nvert); } } diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index c1498cdb7..53a6047b0 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -4902,20 +4902,19 @@ public class PShapeOpenGL extends PShape { shader.setTexture(tex); } - for (String name: polyAttribs.keySet()) { - VertexAttribute attrib = polyAttribs.get(name); + for (VertexAttribute attrib: polyAttribs.values()) { attrib.updateLoc(shader); + attrib.bind(pgl); shader.setAttributeVBO(attrib.glLoc, attrib.glName, - attrib.size, attrib.type, + attrib.tessSize, attrib.type, attrib.isColor(), 0, attrib.sizeInBytes(voffset)); } shader.draw(root.glPolyIndex, icount, ioffset); } - if (shader != null && shader.bound()) { - shader.unbind(); - } + for (VertexAttribute attrib: polyAttribs.values()) attrib.unbind(pgl); + if (shader != null && shader.bound()) shader.unbind(); }