Skip to content

Commit 4d00746

Browse files
committed
Merge branch 'master' of github.com:processing/processing
2 parents 70d9bf5 + 9c021f3 commit 4d00746

5 files changed

Lines changed: 118 additions & 49 deletions

File tree

core/src/processing/core/PVector.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,7 @@ static public PVector sub(PVector v1, PVector v2, PVector target) {
543543
* @webref pvector:method
544544
* @usage web_application
545545
* @param n the number to multiply with the vector
546-
* @brief Multiply a vector by a scalar or one vector by another
547-
* @nowebref
546+
* @brief Multiply a vector by a scalar
548547
*/
549548
public void mult(float n) {
550549
x *= n;
@@ -588,8 +587,7 @@ static public PVector mult(PVector v, float n, PVector target) {
588587
* @webref pvector:method
589588
* @usage web_application
590589
* @param n the value to divide by
591-
* @brief Divide a vector by a scalar or one vector by another
592-
* @nowebref
590+
* @brief Divide a vector by a scalar
593591
*/
594592
public void div(float n) {
595593
x /= n;

core/src/processing/opengl/PGL.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ public class PGL {
125125
/** Minimum array size to use arrayCopy method(). **/
126126
protected static final int MIN_ARRAYCOPY_SIZE = 2;
127127

128+
/** Factor used to displace the stroke vertices towards the camera in
129+
* order to make sure the lines are always on top of the fill geometry **/
130+
protected static final float STROKE_DISPLACEMENT = 0.999f;
131+
128132
/** JOGL's windowing toolkit */
129133
// The two windowing toolkits available to use in JOGL:
130134
protected static final int AWT = 0; // http://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7149,10 +7149,11 @@ public void bind() {
71497149
if (pgCurrent.getHint(DISABLE_OPTIMIZED_STROKE)) {
71507150
setUniformValue(scaleLoc, 1.0f, 1.0f, 1.0f);
71517151
} else {
7152+
float f = PGL.STROKE_DISPLACEMENT;
71527153
if (orthoProjection()) {
7153-
setUniformValue(scaleLoc, 1.0f, 1.0f, 0.99f);
7154+
setUniformValue(scaleLoc, 1, 1, f);
71547155
} else {
7155-
setUniformValue(scaleLoc, 0.99f, 0.99f, 0.99f);
7156+
setUniformValue(scaleLoc, f, f, f);
71567157
}
71577158
}
71587159

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 105 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,6 @@ public class PShapeOpenGL extends PShape {
182182

183183
// ........................................................
184184

185-
// Modes inherited from renderer
186-
187-
protected int rectMode;
188-
protected int ellipseMode;
189-
protected int shapeMode;
190-
protected int imageMode;
191-
192-
// ........................................................
193-
194185
// Bezier and Catmull-Rom curves
195186

196187
protected int bezierDetail = 20;
@@ -307,12 +298,8 @@ public PShapeOpenGL(PApplet parent, int family) {
307298
inGeo = pg.newInGeometry(PGraphicsOpenGL.RETAINED);
308299
}
309300

310-
// Modes are retrieved from the current values in the renderer.
301+
// Style parameters are retrieved from the current values in the renderer.
311302
textureMode = pg.textureMode;
312-
rectMode = pg.rectMode;
313-
ellipseMode = pg.ellipseMode;
314-
shapeMode = pg.shapeMode;
315-
imageMode = pg.imageMode;
316303

317304
colorMode(pg.colorMode,
318305
pg.colorModeX, pg.colorModeY, pg.colorModeZ, pg.colorModeA);
@@ -757,10 +744,25 @@ public void setTextureMode(int mode) {
757744
if (family == GROUP) {
758745
for (int i = 0; i < childCount; i++) {
759746
PShapeOpenGL child = (PShapeOpenGL) children[i];
760-
child.textureMode(mode);
747+
child.setTextureMode(mode);
761748
}
762749
} else {
763-
textureMode = mode;
750+
setTextureModeImpl(mode);
751+
}
752+
}
753+
754+
755+
protected void setTextureModeImpl(int mode) {
756+
if (textureMode == mode) return;
757+
textureMode = mode;
758+
if (image != null) {
759+
float uFactor = image.width;
760+
float vFactor = image.height;
761+
if (textureMode == NORMAL) {
762+
uFactor = 1.0f / uFactor;
763+
vFactor = 1.0f / vFactor;
764+
}
765+
scaleTextureUV(uFactor, vFactor);
764766
}
765767
}
766768

@@ -778,17 +780,69 @@ public void setTexture(PImage tex) {
778780
child.texture(tex);
779781
}
780782
} else {
781-
PImage tex0 = image;
782-
image = tex;
783-
if (tex0 != tex && parent != null) {
784-
((PShapeOpenGL)parent).removeTexture(tex);
783+
setTextureImpl(tex);
784+
}
785+
}
786+
787+
788+
protected void setTextureImpl(PImage tex) {
789+
PImage image0 = image;
790+
image = tex;
791+
792+
if (textureMode == IMAGE && image0 != image) {
793+
// Need to rescale the texture coordinates
794+
float uFactor = 1;
795+
float vFactor = 1;
796+
if (image != null) {
797+
uFactor /= image.width;
798+
vFactor /= image.height;
785799
}
786-
if (parent != null) {
787-
((PShapeOpenGL)parent).addTexture(image);
788-
if (is2D() && stroke) {
789-
((PShapeOpenGL)parent).strokedTexture(true);
790-
}
800+
if (image0 != null) {
801+
uFactor *= image0.width;
802+
vFactor *= image0.height;
803+
}
804+
scaleTextureUV(uFactor, vFactor);
805+
}
806+
807+
if (image0 != tex && parent != null) {
808+
((PShapeOpenGL)parent).removeTexture(tex);
809+
}
810+
if (parent != null) {
811+
((PShapeOpenGL)parent).addTexture(image);
812+
if (is2D() && stroke) {
813+
((PShapeOpenGL)parent).strokedTexture(true);
814+
}
815+
}
816+
}
817+
818+
819+
protected void scaleTextureUV(float uFactor, float vFactor) {
820+
if (PGraphicsOpenGL.same(uFactor, 1) &&
821+
PGraphicsOpenGL.same(vFactor, 1)) return;
822+
823+
for (int i = 0; i < inGeo.vertexCount; i++) {
824+
float u = inGeo.texcoords[2 * i + 0];
825+
float v = inGeo.texcoords[2 * i + 1];
826+
inGeo.texcoords[2 * i + 0] = PApplet.min(1, u * uFactor);
827+
inGeo.texcoords[2 * i + 1] = PApplet.min(1, v * uFactor);
828+
}
829+
830+
if (shapeCreated && tessellated && hasPolys) {
831+
int last1 = 0;
832+
if (is3D()) {
833+
last1 = lastPolyVertex + 1;
834+
} else if (is2D()) {
835+
last1 = lastPolyVertex + 1;
836+
if (-1 < firstLineVertex) last1 = firstLineVertex;
837+
if (-1 < firstPointVertex) last1 = firstPointVertex;
791838
}
839+
for (int i = firstLineVertex; i < last1; i++) {
840+
float u = tessGeo.polyTexCoords[2 * i + 0];
841+
float v = tessGeo.polyTexCoords[2 * i + 1];
842+
tessGeo.polyTexCoords[2 * i + 0] = PApplet.min(1, u * uFactor);
843+
tessGeo.polyTexCoords[2 * i + 1] = PApplet.min(1, v * uFactor);
844+
}
845+
root.setModifiedPolyTexCoords(firstPolyVertex, last1 - 1);
792846
}
793847
}
794848

@@ -1524,8 +1578,13 @@ public void setTextureUV(int index, float u, float v) {
15241578
return;
15251579
}
15261580

1581+
if (image != null && textureMode == IMAGE) {
1582+
u = PApplet.min(1, u / image.width);
1583+
v = PApplet.min(1, v / image.height);
1584+
}
15271585
inGeo.texcoords[2 * index + 0] = u;
15281586
inGeo.texcoords[2 * index + 1] = v;
1587+
15291588
markForTessellation();
15301589
}
15311590

@@ -2629,18 +2688,17 @@ protected void tessellateRect() {
26292688
rounded = true;
26302689
}
26312690

2632-
rectMode = CORNER;
26332691
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
26342692
ambientColor, specularColor, emissiveColor, shininess);
26352693
inGeo.setNormal(normalX, normalY, normalZ);
26362694
if (rounded) {
26372695
inGeo.addRect(a, b, c, d,
26382696
tl, tr, br, bl,
2639-
fill, stroke, bezierDetail, rectMode);
2697+
fill, stroke, bezierDetail, CORNER);
26402698
tessellator.tessellatePolygon(false, true, true);
26412699
} else {
26422700
inGeo.addRect(a, b, c, d,
2643-
fill, stroke, rectMode);
2701+
fill, stroke, CORNER);
26442702
tessellator.tessellateQuads();
26452703
}
26462704
}
@@ -2655,36 +2713,35 @@ protected void tessellateEllipse() {
26552713
d = params[3];
26562714
}
26572715

2658-
// ellipseMode = CORNER;
26592716
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
26602717
ambientColor, specularColor, emissiveColor, shininess);
26612718
inGeo.setNormal(normalX, normalY, normalZ);
2662-
inGeo.addEllipse(a, b, c, d, fill, stroke, ellipseMode);
2719+
inGeo.addEllipse(a, b, c, d, fill, stroke, CORNER);
26632720
tessellator.tessellateTriangleFan();
26642721
}
26652722

26662723

26672724
protected void tessellateArc() {
26682725
float a = 0, b = 0, c = 0, d = 0;
26692726
float start = 0, stop = 0;
2670-
int mode = 0;
2727+
// int mode = 0;
26712728
if (params.length == 6 || params.length == 7) {
26722729
a = params[0];
26732730
b = params[1];
26742731
c = params[2];
26752732
d = params[3];
26762733
start = params[4];
26772734
stop = params[5];
2678-
if (params.length == 7) {
2679-
mode = (int)(params[6]);
2680-
}
2735+
// Not using arc mode since PShape only uses CORNER
2736+
// if (params.length == 7) {
2737+
// mode = (int)(params[6]);
2738+
// }
26812739
}
26822740

2683-
// ellipseMode = CORNER;
26842741
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
26852742
ambientColor, specularColor, emissiveColor, shininess);
26862743
inGeo.setNormal(normalX, normalY, normalZ);
2687-
inGeo.addArc(a, b, c, d, start, stop, fill, stroke, mode);
2744+
inGeo.addArc(a, b, c, d, start, stop, fill, stroke, CORNER);
26882745
tessellator.tessellateTriangleFan();
26892746
}
26902747

@@ -3960,31 +4017,36 @@ public void disableStyle() {
39604017
@Override
39614018
protected void styles(PGraphics g) {
39624019
if (g instanceof PGraphicsOpenGL) {
3963-
if (stroke) {
4020+
if (g.stroke) {
4021+
setStroke(true);
39644022
setStroke(g.strokeColor);
39654023
setStrokeWeight(g.strokeWeight);
3966-
3967-
// These two don't to nothing probably:
39684024
setStrokeCap(g.strokeCap);
39694025
setStrokeJoin(g.strokeJoin);
39704026
} else {
39714027
setStroke(false);
39724028
}
39734029

3974-
if (fill) {
4030+
if (g.fill) {
4031+
setFill(true);
39754032
setFill(g.fillColor);
39764033
} else {
39774034
setFill(false);
39784035
}
39794036

4037+
if (g.tint) {
4038+
setTint(true);
4039+
setTint(g.tintColor);
4040+
}
4041+
39804042
setAmbient(g.ambientColor);
39814043
setSpecular(g.specularColor);
39824044
setEmissive(g.emissiveColor);
39834045
setShininess(g.shininess);
39844046

3985-
// What about other style parameters, such as rectMode, etc?
3986-
// These should force a tessellation update, same as stroke
3987-
// cap and weight... right?
4047+
if (image != null) {
4048+
setTextureMode(g.textureMode);
4049+
}
39884050
} else {
39894051
super.styles(g);
39904052
}

java/libraries/lwjgl/src/processing/lwjgl/PGL.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ public class PGL extends processing.opengl.PGL {
131131
/** Minimum array size to use arrayCopy method(). **/
132132
protected static final int MIN_ARRAYCOPY_SIZE = 2;
133133

134+
/** Factor used to displace the stroke vertices towards the camera in
135+
* order to make sure the lines are always on top of the fill geometry **/
136+
protected static final float STROKE_DISPLACEMENT = 0.999f;
137+
134138
protected static int request_depth_bits = 24;
135139
protected static int request_stencil_bits = 8;
136140
protected static int request_alpha_bits = 8;

0 commit comments

Comments
 (0)