Make PShapeOpenGL.setFill(int,int) always update tessellated vertices#902
Make PShapeOpenGL.setFill(int,int) always update tessellated vertices#902Junology wants to merge 1 commit intoprocessing:mainfrom
Conversation
|
Thank you, @Junology , for this PR! Does |
|
If this change makes sense, then yes, Exploring |
|
I realized the change done in this PR is UNSAFE. Here is the code I tested: PShape[] t;
void setup() {
size(300, 200, P2D);
t = new PShape[2];
for (int i = 0; i < t.length; ++i) {
t[i] = createShape();
t[i].beginShape();
t[i].fill(#FFFFFFFF);
t[i].vertex(0, 0);
t[i].vertex(0, 100);
t[i].vertex(100, 0);
t[i].vertex(100, 100);
t[i].endShape(CLOSE);
}
}
void draw() {
background(0);
float offset = (float) (width - 100 * t.length) / (t.length + 1);
for (int i = 0; i < t.length; ++i) {
shape(t[i], offset + (100 + offset) * i, 50);
}
}
void mousePressed() {
// Reset fill colors in different ways
t[0].setFill(#FFFF0000);
// setFill(int,int) in "tessellation update mode" can cause ArrayIndexOutOfBoundsException
// t[1].beginTessellation();
for (int i = 0; i < t[1].getVertexCount(); i++) {
t[1].setFill(i, #FFFF0000);
}
// t[1].endTessellation();
}First notice that the above program does not work as expected; the color of the shape The source of the exception lies in how the function I decided to close the PR, thinking it is difficult to fix the problem mentioned above by refactoring If one is sure what happens in tessellation, then one can use the function in "tessellation update mode" anyway. |
Fixes #900 (and #677 too).
PShapeOpenGLprovides "Tessellation update mode"beginTessellation()andendTessellation().The current implementation of
PShapeOpenGL.setFill(int,int)does the following:root.tessUpdate == true), it updates the color associated with tessellated vertices;InGeometryand set "tessellation required" flag withmarkForTessellation().The problem is that once the shape is tessellated, the tessellation doesn't seem to be performed again even after markForTessellation().
Another concern is that the behavior described above is inconsistent with
PShape.OpenGL.setFill(int)overload, which does not care about "Tessellation update mode" and updates tessellated vertices anyway.This PR makes
PShapeOpenGL.setFill(int,int)behaves like the other overloads.As a result, it also ignores "Tessellation update mode".
I am not 100% sure it is safe, since
beginTessellation()andendTessellation()look doing a lot of stuff.In particular, I think this change should be tested for the cases where tessellation creates new vertices.
Since I do not know the tessellation process in detail, such test cases are really appreciated.