From fcff028cf3df901a40dcb87c0366a7fc3ea04588 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 31 Mar 2015 15:39:46 -0400 Subject: [PATCH] check if attribute is active --- core/src/processing/opengl/PGraphicsOpenGL.java | 10 +++++++++- core/src/processing/opengl/PShapeOpenGL.java | 10 ++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index b7c83db04..541473504 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2586,6 +2586,7 @@ public class PGraphicsOpenGL extends PGraphics { } for (VertexAttribute attrib: polyAttribs.values()) { + if (!attrib.active()) continue; attrib.updateLoc(shader); attrib.bind(pgl); shader.setAttributeVBO(attrib.glLoc, attrib.glName, @@ -2596,7 +2597,10 @@ public class PGraphicsOpenGL extends PGraphics { shader.draw(glPolyIndex, icount, ioffset); } - for (VertexAttribute attrib: polyAttribs.values()) attrib.unbind(pgl); + for (VertexAttribute attrib: polyAttribs.values()) { + if (!attrib.active()) continue; + attrib.unbind(pgl); + } shader.unbind(); } unbindPolyBuffers(); @@ -7137,6 +7141,10 @@ public class PGraphicsOpenGL extends PGraphics { pgl.disableVertexAttribArray(glLoc); } + boolean active() { + return -1 < glLoc; + } + void updateLoc(PShader shader) { if (glLoc == -1) glLoc = shader.getAttributeLoc(name); } diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index 53a6047b0..a67b70aed 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -4903,6 +4903,7 @@ public class PShapeOpenGL extends PShape { } for (VertexAttribute attrib: polyAttribs.values()) { + if (!attrib.active()) continue; attrib.updateLoc(shader); attrib.bind(pgl); shader.setAttributeVBO(attrib.glLoc, attrib.glName, @@ -4913,8 +4914,13 @@ public class PShapeOpenGL extends PShape { shader.draw(root.glPolyIndex, icount, ioffset); } - for (VertexAttribute attrib: polyAttribs.values()) attrib.unbind(pgl); - if (shader != null && shader.bound()) shader.unbind(); + for (VertexAttribute attrib: polyAttribs.values()) { + if (!attrib.active()) continue; + attrib.unbind(pgl); + } + if (shader != null && shader.bound()) { + shader.unbind(); + } }