Skip to content

Commit 3a9637b

Browse files
committed
Merge branch 'android-0277-v4.1.1' of github.com:processing/processing-android into android-0277-v4.1.1
2 parents 5f1411f + fc22703 commit 3a9637b

File tree

1 file changed

+15
-239
lines changed

1 file changed

+15
-239
lines changed

core/src/processing/opengl/PGraphics2DX.java

+15-239
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ public final class PGraphics2DX extends PGraphicsOpenGL {
6969

7070
static protected final int SHADER2D = 7;
7171

72-
// Enables/disables matrix pre-multiplication
73-
// https://github.com/processing/processing/wiki/Advanced-OpenGL#vertex-coordinates-are-in-model-space
74-
// https://github.com/processing/processing/issues/2904
75-
// see above URLs for some discussion on premultiplying matrix vs. flushing buffer on matrix change.
76-
// rather than committing to one or the other, this implementation supports both
77-
public static boolean premultiplyMatrices = true;
78-
7972
// Uses the implementations in the parent PGraphicsOpenGL class, which is needed to to draw obj files
8073
// and apply shader filters.
8174
protected boolean useParentImpl = false;
@@ -1101,200 +1094,6 @@ protected void textCharModelImpl(FontTexture.TextureInfo info,
11011094
}
11021095

11031096

1104-
//////////////////////////////////////////////////////////////
1105-
1106-
// MATRIX OPS
1107-
1108-
1109-
/*
1110-
* Monkey-patch all methods that modify matrices to optionally flush the vertex buffer.
1111-
* If you see a method that isn't here but should be, or is here but shouldn't,
1112-
* feel free to add/remove it.
1113-
*/
1114-
1115-
1116-
@Override
1117-
public void applyMatrix(float n00, float n01, float n02, float n10, float n11, float n12) {
1118-
preMatrixChanged();
1119-
super.applyMatrix(n00, n01, n02, n10, n11, n12);
1120-
postMatrixChanged();
1121-
}
1122-
1123-
1124-
@Override
1125-
public void applyMatrix(PMatrix2D source) {
1126-
preMatrixChanged();
1127-
super.applyMatrix(source);
1128-
postMatrixChanged();
1129-
}
1130-
1131-
1132-
@Override
1133-
public void applyProjection(float n00, float n01, float n02, float n03,
1134-
float n10, float n11, float n12, float n13,
1135-
float n20, float n21, float n22, float n23,
1136-
float n30, float n31, float n32, float n33) {
1137-
preMatrixChanged();
1138-
super.applyProjection(n00, n01, n02, n03,
1139-
n10, n11, n12, n13,
1140-
n20, n21, n22, n23,
1141-
n30, n31, n32, n33);
1142-
postMatrixChanged();
1143-
}
1144-
1145-
1146-
@Override
1147-
public void applyProjection(PMatrix3D mat) {
1148-
preMatrixChanged();
1149-
super.applyProjection(mat);
1150-
postMatrixChanged();
1151-
}
1152-
1153-
1154-
@Override
1155-
public void popMatrix() {
1156-
preMatrixChanged();
1157-
super.popMatrix();
1158-
postMatrixChanged();
1159-
}
1160-
1161-
1162-
@Override
1163-
public void popProjection() {
1164-
preMatrixChanged();
1165-
super.popProjection();
1166-
postMatrixChanged();
1167-
}
1168-
1169-
1170-
@Override
1171-
public void pushMatrix() {
1172-
preMatrixChanged();
1173-
super.pushMatrix();
1174-
postMatrixChanged();
1175-
}
1176-
1177-
1178-
@Override
1179-
public void pushProjection() {
1180-
preMatrixChanged();
1181-
super.pushProjection();
1182-
postMatrixChanged();
1183-
}
1184-
1185-
1186-
@Override
1187-
public void resetMatrix() {
1188-
preMatrixChanged();
1189-
super.resetMatrix();
1190-
postMatrixChanged();
1191-
}
1192-
1193-
1194-
@Override
1195-
public void resetProjection() {
1196-
preMatrixChanged();
1197-
super.resetProjection();
1198-
postMatrixChanged();
1199-
}
1200-
1201-
1202-
@Override
1203-
public void rotate(float angle) {
1204-
preMatrixChanged();
1205-
super.rotate(angle);
1206-
postMatrixChanged();
1207-
}
1208-
1209-
1210-
@Override
1211-
public void scale(float s) {
1212-
preMatrixChanged();
1213-
super.scale(s);
1214-
postMatrixChanged();
1215-
}
1216-
1217-
1218-
@Override
1219-
public void scale(float sx, float sy) {
1220-
preMatrixChanged();
1221-
super.scale(sx, sy);
1222-
postMatrixChanged();
1223-
}
1224-
1225-
1226-
@Override
1227-
public void setMatrix(PMatrix2D source) {
1228-
preMatrixChanged();
1229-
super.setMatrix(source);
1230-
postMatrixChanged();
1231-
}
1232-
1233-
1234-
@Override
1235-
public void setProjection(PMatrix3D mat) {
1236-
preMatrixChanged();
1237-
super.setProjection(mat);
1238-
postMatrixChanged();
1239-
}
1240-
1241-
1242-
@Override
1243-
public void shearX(float angle) {
1244-
preMatrixChanged();
1245-
super.shearX(angle);
1246-
postMatrixChanged();
1247-
}
1248-
1249-
1250-
@Override
1251-
public void shearY(float angle) {
1252-
preMatrixChanged();
1253-
super.shearY(angle);
1254-
postMatrixChanged();
1255-
}
1256-
1257-
1258-
@Override
1259-
public void translate(float tx, float ty) {
1260-
preMatrixChanged();
1261-
super.translate(tx, ty);
1262-
postMatrixChanged();
1263-
}
1264-
1265-
1266-
@Override
1267-
public void updateProjmodelview() {
1268-
preMatrixChanged();
1269-
super.updateProjmodelview();
1270-
postMatrixChanged();
1271-
}
1272-
1273-
1274-
@Override
1275-
public void updateGLModelview() {
1276-
preMatrixChanged();
1277-
super.updateGLModelview();
1278-
postMatrixChanged();
1279-
}
1280-
1281-
1282-
@Override
1283-
public void updateGLProjection() {
1284-
preMatrixChanged();
1285-
super.updateGLProjection();
1286-
postMatrixChanged();
1287-
}
1288-
1289-
1290-
@Override
1291-
public void updateGLProjmodelview() {
1292-
preMatrixChanged();
1293-
super.updateGLProjmodelview();
1294-
postMatrixChanged();
1295-
}
1296-
1297-
12981097
//////////////////////////////////////////////////////////////
12991098

13001099
// MATRIX MORE!
@@ -1781,11 +1580,7 @@ private void setAttribs() {
17811580

17821581
private void loadUniforms() {
17831582
//set matrix uniform
1784-
if (premultiplyMatrices) {
1785-
pgl.uniformMatrix4fv(transformLoc, 1, true, FloatBuffer.wrap(new PMatrix3D().get(null)));
1786-
} else {
1787-
pgl.uniformMatrix4fv(transformLoc, 1, true, FloatBuffer.wrap(projmodelview.get(null)));
1788-
}
1583+
pgl.uniformMatrix4fv(transformLoc, 1, true, FloatBuffer.wrap(new PMatrix3D().get(null)));
17891584

17901585
//set texture info
17911586
pgl.activeTexture(PGL.TEXTURE0);
@@ -1820,14 +1615,9 @@ private void check(int newVerts) {
18201615

18211616
private void vertexImpl(float x, float y, float u, float v, int c, float f) {
18221617
int idx = usedVerts * 7;
1823-
if (premultiplyMatrices) {
1824-
//inline multiply only x and y to avoid an allocation and a few flops
1825-
vertexData[idx + 0] = projmodelview.m00*x + projmodelview.m01*y + projmodelview.m03;
1826-
vertexData[idx + 1] = projmodelview.m10*x + projmodelview.m11*y + projmodelview.m13;
1827-
} else {
1828-
vertexData[idx + 0] = x;
1829-
vertexData[idx + 1] = y;
1830-
}
1618+
//inline multiply only x and y to avoid an allocation and a few flops
1619+
vertexData[idx + 0] = projmodelview.m00*x + projmodelview.m01*y + projmodelview.m03;
1620+
vertexData[idx + 1] = projmodelview.m10*x + projmodelview.m11*y + projmodelview.m13;
18311621
vertexData[idx + 2] = depth;
18321622
vertexData[idx + 3] = u;
18331623
vertexData[idx + 4] = v;
@@ -1900,30 +1690,6 @@ private void shapeVertex(float x, float y, float u, float v, int c, float f) {
19001690
}
19011691

19021692

1903-
float ellipseDetailMultiplier = 1;
1904-
1905-
1906-
private void preMatrixChanged() {
1907-
if (!premultiplyMatrices) {
1908-
flushBuffer();
1909-
}
1910-
}
1911-
1912-
1913-
private void postMatrixChanged() {
1914-
//this serves as a rough approximation of how much the longest axis
1915-
//of an ellipse will be scaled by a given matrix
1916-
//(in other words, the amount by which its on-screen size changes)
1917-
float sxi = projmodelview.m00 * width / 2;
1918-
float syi = projmodelview.m10 * height / 2;
1919-
float sxj = projmodelview.m01 * width / 2;
1920-
float syj = projmodelview.m11 * height / 2;
1921-
float Imag2 = sxi * sxi + syi * syi;
1922-
float Jmag2 = sxj * sxj + syj * syj;
1923-
ellipseDetailMultiplier = PApplet.sqrt(PApplet.max(Imag2, Jmag2));
1924-
}
1925-
1926-
19271693
private void triangle(float x1, float y1, float x2, float y2, float x3, float y3, int color) {
19281694
check(3);
19291695
vertexImpl(x1, y1, 0, 0, color, 0);
@@ -2239,6 +2005,16 @@ void endLine(boolean closed) {
22392005

22402006
//returns the total number of points needed to approximate an arc of a given radius and extent
22412007
int circleDetail(float radius, float delta) {
2008+
//this serves as a rough approximation of how much the longest axis
2009+
//of an ellipse will be scaled by a given matrix
2010+
//(in other words, the amount by which its on-screen size changes)
2011+
float sxi = projmodelview.m00 * width / 2;
2012+
float syi = projmodelview.m10 * height / 2;
2013+
float sxj = projmodelview.m01 * width / 2;
2014+
float syj = projmodelview.m11 * height / 2;
2015+
float Imag2 = sxi * sxi + syi * syi;
2016+
float Jmag2 = sxj * sxj + syj * syj;
2017+
float ellipseDetailMultiplier = PApplet.sqrt(PApplet.max(Imag2, Jmag2));
22422018
radius *= ellipseDetailMultiplier;
22432019
return (int)(PApplet.min(127, PApplet.sqrt(radius) / QUARTER_PI * PApplet.abs(delta) * 0.75f) + 1);
22442020
}
@@ -2277,4 +2053,4 @@ public String toString() {
22772053
return x + ", " + y;
22782054
}
22792055
}
2280-
}
2056+
}

0 commit comments

Comments
 (0)