Simplified shape creation API

This commit is contained in:
codeanticode
2011-12-04 01:40:20 +00:00
parent d70a5b1a98
commit 60377b0c13
4 changed files with 69 additions and 47 deletions
@@ -1554,27 +1554,46 @@ public class PGraphicsOpenGL extends PGraphics {
// SHAPE CREATORS
public PShape createGroup() {
return new PShape3D(parent, PShape.GROUP);
public PShape createShape() {
return createShape(POLYGON);
}
public PShape createGeometry() {
PShape3D shape = new PShape3D(parent, PShape.GEOMETRY);
shape.setKind(POLYGON);
return shape;
}
public PShape createGeometry(int kind) {
PShape3D shape = new PShape3D(parent, PShape.GEOMETRY);
shape.setKind(kind);
public PShape createShape(int type) {
PShape3D shape;
if (type == PShape.GROUP) {
shape = new PShape3D(parent, PShape.GROUP);
} else if (type == POINTS) {
shape = new PShape3D(parent, PShape.GEOMETRY);
shape.setKind(POINTS);
} else if (type == LINES) {
shape = new PShape3D(parent, PShape.GEOMETRY);
shape.setKind(LINES);
} else if (type == TRIANGLES) {
shape = new PShape3D(parent, PShape.GEOMETRY);
shape.setKind(TRIANGLES);
} else if (type == TRIANGLE_FAN) {
shape = new PShape3D(parent, PShape.GEOMETRY);
shape.setKind(TRIANGLE_FAN);
} else if (type == TRIANGLE_STRIP) {
shape = new PShape3D(parent, PShape.GEOMETRY);
shape.setKind(TRIANGLE_STRIP);
} else if (type == QUADS) {
shape = new PShape3D(parent, PShape.GEOMETRY);
shape.setKind(QUADS);
} else if (type == QUAD_STRIP) {
shape = new PShape3D(parent, PShape.GEOMETRY);
shape.setKind(QUAD_STRIP);
} else if (type == POLYGON) {
shape = new PShape3D(parent, PShape.GEOMETRY);
shape.setKind(POLYGON);
} else if (type == SPHERE) {
shape = new PShape3D(parent, PShape.PRIMITIVE);
shape.setKind(SPHERE);
} else {
shape = null;
}
return shape;
}
public PShape createPrimitive(int kind) {
PShape3D shape = new PShape3D(parent, PShape.PRIMITIVE);
shape.setKind(kind);
return shape;
}
//////////////////////////////////////////////////////////////
@@ -69,6 +69,8 @@ public class PShape3D extends PShape {
protected PImage texture;
protected boolean is3D;
// ........................................................
// OpenGL buffers
@@ -183,6 +185,7 @@ public class PShape3D extends PShape {
this.root = this;
this.parent = null;
this.modified = false;
this.is3D = true;
tess = ogl.newTessGeometry(RETAINED);
if (family == GEOMETRY || family == PRIMITIVE || family == PATH) {
@@ -206,6 +209,14 @@ public class PShape3D extends PShape {
this.kind = kind;
}
public void set2D() {
is3D = false;
}
public void set3D() {
is3D = true;
}
public void setMode(int mode) {
if (mode == STATIC) {
glMode = GL.GL_STATIC_DRAW;
@@ -329,6 +340,10 @@ public class PShape3D extends PShape {
strokeCap = cap;
}
public void end() {
// ?
}
///////////////////////////////////////////////////////////
//
@@ -1285,8 +1300,16 @@ public class PShape3D extends PShape {
texSet.addAll(childSet);
}
} else {
texSet.add(texture);
} else {
if (!is3D) {
// if is stroked and textured:
// texSet.add(texture); for the textured fill
// texSet.add(null); for the stroke
// else
texSet.add(texture);
} else {
texSet.add(texture);
}
}
return texSet;