Some debugging methods for indexed mode in PShape3D

This commit is contained in:
codeanticode
2011-04-25 03:37:55 +00:00
parent 3bca23917c
commit 7aa43510b5
2 changed files with 57 additions and 3 deletions
@@ -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;
@@ -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<Integer> 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;