Interesting.
Saw this thread a while ago, and wanted to test if a fixed/static(?) shape improves the speed. Like done from the reference page for createShape.
Posting it here in case others find it interesting, even if the thread is marked solved.
Click to (un) expand
// Static shape test
// 2021-08-07 - Mod by raron
// Built on:
// Texture Cube
// v1.0.0
// GLV 2021-07-29
// drawWall() courtesy of CosmicCrowMC:
//https://discourse.processing.org/t/faster-rendering-techniques-in-p3d/31465
PImage img;
final int DEFAULT = 20; // default beginShape() parameter
int w = 25; // width of cube
int w2 = w+5; // Add space between cubes
int n = 15; // number of cubes along each axis
int p; // beginShape() parameter
boolean t; // toggles parameter
// For the static shape test:
int sp = QUADS; // shape's createShape() parameter
boolean s; // toggles shape method
PShape testcube, wall1, wall2, wall3, wall4;
void setup()
{
size(800, 800, P3D);
noFill();
noStroke();
img = loadImage("https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Processing_3_logo.png/240px-Processing_3_logo.png");
img.resize(w, w);
textureMode(NORMAL);
String s1 = "Press t to toggle between beginShape() and beginShape(QUAD)";
String s2 = "Press s to toggle between createShape() and shape()";
println(s1);
println(s2);
println();
//hint(ENABLE_DEPTH_SORT); // frameRates < 15 with this!
//hint(DISABLE_DEPTH_TEST); // cool effect! Watch a few rotations.
makeCube(0, 0, 0, w, w, w);
}
void draw()
{
background(255, 255, 0);
lights();
translate(width/2, height/2, -25);
rotateY(frameCount*TAU/500);
float offset = -n*w2/2;
translate(offset, offset, offset);
for(int z=0; z<n; z++)
{
for(int y=0; y<n; y++)
{
for(int x=0; x<n; x++)
{
if (!s) {
drawWall(x*w2, y*w2, z*w2, w, w, w);
} else {
pushMatrix();
translate(x*w2, y*w2, z*w2);
shape(testcube);
popMatrix();
}
}
}
}
if (frameCount%15 == 0) println(frameRate);
if (t)
p = DEFAULT;
else
p = QUAD;
}
void drawWall(int x, float y, float z, float thickness, float width, float height)
{
float xw = x + width;
float yw = y + height;
float xt = z + thickness;
beginShape(p);
texture(img);
vertex(x, y, z, 0, 0);
vertex(xw, y, z, 1, 0);
vertex(xw, yw, z, 1, 1);
vertex(x, yw, z, 0, 1);
endShape();
beginShape(p);
texture(img);
vertex(xw, y, z, 0, 0);
vertex(xw, y, xt, 1, 0);
vertex(xw, yw, xt, 1, 1);
vertex(xw, yw, z, 0, 1);
endShape();
beginShape(p);
texture(img);
vertex(x, y, xt, 0, 0);
vertex(xw, y, xt, 1, 0);
vertex(xw, yw, xt, 1, 1);
vertex(x, yw, xt, 0, 1);
endShape();
beginShape(p);
texture(img);
vertex(x, y, z, 0, 0);
vertex(x, y, xt, 1, 0);
vertex(x, yw, xt, 1, 1);
vertex(x, yw, z, 0, 1);
endShape();
}
void makeCube(int x, float y, float z, float thickness, float width, float height)
{
wall1 = createShape();
wall2 = createShape();
wall3 = createShape();
wall4 = createShape();
float xw = x + width;
float yw = y + height;
float xt = z + thickness;
wall1.beginShape(sp);
wall1.texture(img);
wall1.vertex(x, y, z, 0, 0);
wall1.vertex(xw, y, z, 1, 0);
wall1.vertex(xw, yw, z, 1, 1);
wall1.vertex(x, yw, z, 0, 1);
wall1.endShape(CLOSE);
wall2.beginShape(sp);
wall2.texture(img);
wall2.vertex(xw, y, z, 0, 0);
wall2.vertex(xw, y, xt, 1, 0);
wall2.vertex(xw, yw, xt, 1, 1);
wall2.vertex(xw, yw, z, 0, 1);
wall2.endShape(CLOSE);
wall3.beginShape(sp);
wall3.texture(img);
wall3.vertex(x, y, xt, 0, 0);
wall3.vertex(xw, y, xt, 1, 0);
wall3.vertex(xw, yw, xt, 1, 1);
wall3.vertex(x, yw, xt, 0, 1);
wall3.endShape(CLOSE);
wall4.beginShape(sp);
wall4.texture(img);
wall4.vertex(x, y, z, 0, 0);
wall4.vertex(x, y, xt, 1, 0);
wall4.vertex(x, yw, xt, 1, 1);
wall4.vertex(x, yw, z, 0, 1);
wall4.endShape(CLOSE);
testcube = createShape(GROUP);
testcube.addChild(wall1);
testcube.addChild(wall2);
testcube.addChild(wall3);
testcube.addChild(wall4);
}
void keyPressed()
{
if (key == 't') t = !t;
if (key == 's') s = !s;
println();
println();
if (t) println("beginShape()");
else println("beginShape(QUAD)");
if (s) println("shape()");
else println("createshape()");
println();
}