From 7aa43510b56887d9199b3a479e2dd3b88e363ce1 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Mon, 25 Apr 2011 03:37:55 +0000 Subject: [PATCH] Some debugging methods for indexed mode in PShape3D --- .../processing/opengl2/PGraphicsOpenGL2.java | 20 +++++++++- .../src/processing/opengl2/PShape3D.java | 40 ++++++++++++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/java/libraries/opengl2/src/processing/opengl2/PGraphicsOpenGL2.java b/java/libraries/opengl2/src/processing/opengl2/PGraphicsOpenGL2.java index 225982884..12c6ce4dc 100644 --- a/java/libraries/opengl2/src/processing/opengl2/PGraphicsOpenGL2.java +++ b/java/libraries/opengl2/src/processing/opengl2/PGraphicsOpenGL2.java @@ -852,6 +852,14 @@ public class PGraphicsOpenGL2 extends PGraphics { public GLCapabilities getCapabilities() { return capabilities; } + + + /** + * Get the current drawable. + */ + public GLDrawable getDrawable() { + return drawable; + } /** @@ -6687,7 +6695,9 @@ public class PGraphicsOpenGL2 extends PGraphics { profile = null; profile = GLProfile.getDefault(); - profile = GLProfile.get(GLProfile.GL2ES1); + //profile = GLProfile.get(GLProfile.GL2ES1); + //profile = GLProfile.get(GLProfile.GL4bc); + //profile = GLProfile.getMaxProgrammable(); pipeline = FIXED; /* @@ -6744,6 +6754,9 @@ public class PGraphicsOpenGL2 extends PGraphics { GLDrawableFactory factory = GLDrawableFactory.getFactory(profile); drawable = factory.createGLDrawable(win); context = drawable.createContext(null); + + PApplet.println("PROFILE:\n" + profile); + PApplet.println("CONTEXT:\n" + context); } @@ -6837,6 +6850,11 @@ public class PGraphicsOpenGL2 extends PGraphics { protected void getGLObjects() { gl = context.getGL(); + + //PApplet.println("GL:\n" + gl.getClass()); + //PApplet.println("GL3:\n" + gl.getGL4bc()); + + if (pipeline == PROG_GL4) { gl4p = gl.getGL4(); gl3p = gl4p; diff --git a/java/libraries/opengl2/src/processing/opengl2/PShape3D.java b/java/libraries/opengl2/src/processing/opengl2/PShape3D.java index cb0f7684f..029c15f49 100644 --- a/java/libraries/opengl2/src/processing/opengl2/PShape3D.java +++ b/java/libraries/opengl2/src/processing/opengl2/PShape3D.java @@ -95,6 +95,7 @@ public class PShape3D extends PShape { protected IntBuffer indexBuffer = null; protected int indexCount = 0; protected int[] indices; + protected boolean useIndices; // To put the texture coordinate values adjusted according to texture // flipping mode, max UV range, etc. @@ -1892,6 +1893,7 @@ public class PShape3D extends PShape { gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); indices = new int[indexCount]; + useIndices = true; } public void setIndices(ArrayList recordedIndices) { @@ -1907,6 +1909,40 @@ public class PShape3D extends PShape { gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); } + public void setIndices(int src[]) { + gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, glIndexBufferID); + indexBuffer = gl.glMapBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, GL.GL_WRITE_ONLY).asIntBuffer(); + + PApplet.arrayCopy(src, indices); + indexBuffer.put(indices); + + gl.glUnmapBuffer(GL.GL_ELEMENT_ARRAY_BUFFER); + gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); + } + + public void useIndices(boolean val) { + if (family == GROUP) { + init(); + for (int i = 0; i < childCount; i++) { + useIndices(i, val); + } + } else { + useIndices = val; + } + } + + public void useIndices(int idx, boolean val) { + if (0 <= idx && idx < childCount) { + ((PShape3D)children[idx]).useIndices = val; + + // Debugging. This mess needs to be fixed soon, which means + // using the indexed mode everywhere and sorting out the + // issues with children data. + ((PShape3D)children[idx]).firstIndex = 0; + ((PShape3D)children[idx]).lastIndex = indexCount - 1; + } + } + //////////////////////////////////////////////////////////// // Data allocation, deletion. @@ -2425,8 +2461,8 @@ public class PShape3D extends PShape { pgl.setFillColor(); } } - - if (glIndexBufferID != 0) { + + if (glIndexBufferID != 0 && useIndices) { gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, glIndexBufferID); // Here the vertex indices are understood as the range of indices. int last = lastIndex;