Skip to content

Commit 86a0103

Browse files
committed
synched latest gl changes
1 parent 7f6fcc9 commit 86a0103

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ public class PGraphicsOpenGL extends PGraphics {
509509
"to render this geometry properly, using default shader instead.";
510510
static final String TESSELLATION_ERROR =
511511
"Tessellation Error: %1$s";
512+
static final String GL_THREAD_NOT_CURRENT =
513+
"You are trying to draw outside OpenGL's animation thread.\n" +
514+
"Place all drawing commands in the draw() function, or inside\n" +
515+
"your own functions as long as they are called from draw(),\n" +
516+
"but not in event handling functions such as keyPressed()\n" +
517+
"or mousePressed().";
512518

513519
//////////////////////////////////////////////////////////////
514520

@@ -677,15 +683,14 @@ public void requestDraw() {
677683
}
678684

679685

680-
/*
686+
/*
681687
@Override
682688
// Java only
683689
public PSurface createSurface() { // ignore
684690
return surface = new PSurfaceJOGL(this);
685691
}
686692
*/
687693

688-
689694
public boolean saveImpl(String filename) {
690695
return super.save(filename); // ASYNC save frame using PBOs not yet available on Android
691696

@@ -1467,6 +1472,11 @@ public void beginDraw() {
14671472
getPrimaryPG().setCurrentPG(this);
14681473
}
14691474

1475+
if (!pgl.threadIsCurrent()) {
1476+
PGraphics.showWarning(GL_THREAD_NOT_CURRENT);
1477+
return;
1478+
}
1479+
14701480
// This has to go after the surface initialization, otherwise offscreen
14711481
// surfaces will have a null gl object.
14721482
report("top beginDraw()");
@@ -3788,6 +3798,30 @@ static protected void invTranslate(PMatrix3D matrix,
37883798
}
37893799

37903800

3801+
static protected float matrixScale(PMatrix matrix) {
3802+
// Volumetric scaling factor that is associated to the given
3803+
// transformation matrix, which is given by the absolute value of its
3804+
// determinant:
3805+
float factor = 1;
3806+
3807+
if (matrix != null) {
3808+
if (matrix instanceof PMatrix2D) {
3809+
PMatrix2D tr = (PMatrix2D)matrix;
3810+
float areaScaleFactor = Math.abs(tr.m00 * tr.m11 - tr.m01 * tr.m10);
3811+
factor = (float) Math.sqrt(areaScaleFactor);
3812+
} else if (matrix instanceof PMatrix3D) {
3813+
PMatrix3D tr = (PMatrix3D)matrix;
3814+
float volumeScaleFactor =
3815+
Math.abs(tr.m00 * (tr.m11 * tr.m22 - tr.m12 * tr.m21) +
3816+
tr.m01 * (tr.m12 * tr.m20 - tr.m10 * tr.m22) +
3817+
tr.m02 * (tr.m10 * tr.m21 - tr.m11 * tr.m20));
3818+
factor = (float) Math.pow(volumeScaleFactor, 1.0f / 3.0f);
3819+
}
3820+
}
3821+
return factor;
3822+
}
3823+
3824+
37913825
/**
37923826
* Two dimensional rotation. Same as rotateZ (this is identical to a 3D
37933827
* rotation along the z-axis) but included for clarity -- it'd be weird for
@@ -5138,7 +5172,7 @@ protected void lightPosition(int num, float x, float y, float z,
51385172
x*modelview.m20 + y*modelview.m21 + z*modelview.m22 + modelview.m23;
51395173

51405174
// Used to indicate if the light is directional or not.
5141-
lightPosition[4 * num + 3] = dir ? 1: 0;
5175+
lightPosition[4 * num + 3] = dir ? 0 : 1;
51425176
}
51435177

51445178

@@ -10674,6 +10708,7 @@ void applyMatrixOnLineGeometry(PMatrix2D tr, int first, int last) {
1067410708
if (first < last) {
1067510709
int index;
1067610710

10711+
float scaleFactor = matrixScale(tr);
1067710712
for (int i = first; i <= last; i++) {
1067810713
index = 4 * i;
1067910714
float x = lineVertices[index++];
@@ -10690,6 +10725,7 @@ void applyMatrixOnLineGeometry(PMatrix2D tr, int first, int last) {
1069010725
index = 4 * i;
1069110726
lineDirections[index++] = dx*tr.m00 + dy*tr.m01;
1069210727
lineDirections[index ] = dx*tr.m10 + dy*tr.m11;
10728+
lineDirections[index + 2] *= scaleFactor;
1069310729
}
1069410730
}
1069510731
}
@@ -10698,6 +10734,7 @@ void applyMatrixOnPointGeometry(PMatrix2D tr, int first, int last) {
1069810734
if (first < last) {
1069910735
int index;
1070010736

10737+
float matrixScale = matrixScale(tr);
1070110738
for (int i = first; i <= last; i++) {
1070210739
index = 4 * i;
1070310740
float x = pointVertices[index++];
@@ -10706,6 +10743,10 @@ void applyMatrixOnPointGeometry(PMatrix2D tr, int first, int last) {
1070610743
index = 4 * i;
1070710744
pointVertices[index++] = x*tr.m00 + y*tr.m01 + tr.m02;
1070810745
pointVertices[index ] = x*tr.m10 + y*tr.m11 + tr.m12;
10746+
10747+
index = 2 * i;
10748+
pointOffsets[index++] *= matrixScale;
10749+
pointOffsets[index] *= matrixScale;
1070910750
}
1071010751
}
1071110752
}
@@ -10771,6 +10812,7 @@ void applyMatrixOnLineGeometry(PMatrix3D tr, int first, int last) {
1077110812
if (first < last) {
1077210813
int index;
1077310814

10815+
float scaleFactor = matrixScale(tr);
1077410816
for (int i = first; i <= last; i++) {
1077510817
index = 4 * i;
1077610818
float x = lineVertices[index++];
@@ -10792,7 +10834,8 @@ void applyMatrixOnLineGeometry(PMatrix3D tr, int first, int last) {
1079210834
index = 4 * i;
1079310835
lineDirections[index++] = dx*tr.m00 + dy*tr.m01 + dz*tr.m02;
1079410836
lineDirections[index++] = dx*tr.m10 + dy*tr.m11 + dz*tr.m12;
10795-
lineDirections[index ] = dx*tr.m20 + dy*tr.m21 + dz*tr.m22;
10837+
lineDirections[index++] = dx*tr.m20 + dy*tr.m21 + dz*tr.m22;
10838+
lineDirections[index] *= scaleFactor;
1079610839
}
1079710840
}
1079810841
}
@@ -10801,6 +10844,7 @@ void applyMatrixOnPointGeometry(PMatrix3D tr, int first, int last) {
1080110844
if (first < last) {
1080210845
int index;
1080310846

10847+
float matrixScale = matrixScale(tr);
1080410848
for (int i = first; i <= last; i++) {
1080510849
index = 4 * i;
1080610850
float x = pointVertices[index++];
@@ -10813,6 +10857,10 @@ void applyMatrixOnPointGeometry(PMatrix3D tr, int first, int last) {
1081310857
pointVertices[index++] = x*tr.m10 + y*tr.m11 + z*tr.m12 + w*tr.m13;
1081410858
pointVertices[index++] = x*tr.m20 + y*tr.m21 + z*tr.m22 + w*tr.m23;
1081510859
pointVertices[index ] = x*tr.m30 + y*tr.m31 + z*tr.m32 + w*tr.m33;
10860+
10861+
index = 2 * i;
10862+
pointOffsets[index++] *= matrixScale;
10863+
pointOffsets[index] *= matrixScale;
1081610864
}
1081710865
}
1081810866
}
@@ -11954,28 +12002,7 @@ boolean noCapsJoins() {
1195412002

1195512003
float transformScale() {
1195612004
if (-1 < transformScale) return transformScale;
11957-
11958-
// Volumetric scaling factor that is associated to the current
11959-
// transformation matrix, which is given by the absolute value of its
11960-
// determinant:
11961-
float factor = 1;
11962-
11963-
if (transform != null) {
11964-
if (transform instanceof PMatrix2D) {
11965-
PMatrix2D tr = (PMatrix2D)transform;
11966-
float areaScaleFactor = Math.abs(tr.m00 * tr.m11 - tr.m01 * tr.m10);
11967-
factor = (float) Math.sqrt(areaScaleFactor);
11968-
} else if (transform instanceof PMatrix3D) {
11969-
PMatrix3D tr = (PMatrix3D)transform;
11970-
float volumeScaleFactor =
11971-
Math.abs(tr.m00 * (tr.m11 * tr.m22 - tr.m12 * tr.m21) +
11972-
tr.m01 * (tr.m12 * tr.m20 - tr.m10 * tr.m22) +
11973-
tr.m02 * (tr.m10 * tr.m21 - tr.m11 * tr.m20));
11974-
factor = (float) Math.pow(volumeScaleFactor, 1.0f / 3.0f);
11975-
}
11976-
}
11977-
11978-
return transformScale = factor;
12005+
return transformScale = matrixScale(transform);
1197912006
}
1198012007

1198112008
boolean segmentIsAxisAligned(int i0, int i1) {

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,7 @@ protected void applyMatrixImpl(PMatrix matrix) {
14591459
tessGeo.applyMatrixOnPointGeometry(matrix,
14601460
firstPointVertex, lastPointVertex);
14611461
root.setModifiedPointVertices(firstPointVertex, lastPointVertex);
1462+
root.setModifiedPointAttributes(firstPointVertex, lastPointVertex);
14621463
}
14631464
}
14641465
}

core/src/processing/opengl/shaders/LightVert.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void main() {
9898
if (lightCount == i) break;
9999

100100
vec3 lightPos = lightPosition[i].xyz;
101-
bool isDir = zero_float < lightPosition[i].w;
101+
bool isDir = lightPosition[i].w < one_float;
102102
float spotCos = lightSpot[i].x;
103103
float spotExp = lightSpot[i].y;
104104

core/src/processing/opengl/shaders/TexLightVert.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void main() {
101101
if (lightCount == i) break;
102102

103103
vec3 lightPos = lightPosition[i].xyz;
104-
bool isDir = zero_float < lightPosition[i].w;
104+
bool isDir = lightPosition[i].w < one_float;
105105
float spotCos = lightSpot[i].x;
106106
float spotExp = lightSpot[i].y;
107107

0 commit comments

Comments
 (0)