@@ -509,6 +509,12 @@ public class PGraphicsOpenGL extends PGraphics {
509
509
"to render this geometry properly, using default shader instead." ;
510
510
static final String TESSELLATION_ERROR =
511
511
"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()." ;
512
518
513
519
//////////////////////////////////////////////////////////////
514
520
@@ -677,15 +683,14 @@ public void requestDraw() {
677
683
}
678
684
679
685
680
- /*
686
+ /*
681
687
@Override
682
688
// Java only
683
689
public PSurface createSurface() { // ignore
684
690
return surface = new PSurfaceJOGL(this);
685
691
}
686
692
*/
687
693
688
-
689
694
public boolean saveImpl (String filename ) {
690
695
return super .save (filename ); // ASYNC save frame using PBOs not yet available on Android
691
696
@@ -1467,6 +1472,11 @@ public void beginDraw() {
1467
1472
getPrimaryPG ().setCurrentPG (this );
1468
1473
}
1469
1474
1475
+ if (!pgl .threadIsCurrent ()) {
1476
+ PGraphics .showWarning (GL_THREAD_NOT_CURRENT );
1477
+ return ;
1478
+ }
1479
+
1470
1480
// This has to go after the surface initialization, otherwise offscreen
1471
1481
// surfaces will have a null gl object.
1472
1482
report ("top beginDraw()" );
@@ -3788,6 +3798,30 @@ static protected void invTranslate(PMatrix3D matrix,
3788
3798
}
3789
3799
3790
3800
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
+
3791
3825
/**
3792
3826
* Two dimensional rotation. Same as rotateZ (this is identical to a 3D
3793
3827
* 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,
5138
5172
x *modelview .m20 + y *modelview .m21 + z *modelview .m22 + modelview .m23 ;
5139
5173
5140
5174
// 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 ;
5142
5176
}
5143
5177
5144
5178
@@ -10674,6 +10708,7 @@ void applyMatrixOnLineGeometry(PMatrix2D tr, int first, int last) {
10674
10708
if (first < last ) {
10675
10709
int index ;
10676
10710
10711
+ float scaleFactor = matrixScale (tr );
10677
10712
for (int i = first ; i <= last ; i ++) {
10678
10713
index = 4 * i ;
10679
10714
float x = lineVertices [index ++];
@@ -10690,6 +10725,7 @@ void applyMatrixOnLineGeometry(PMatrix2D tr, int first, int last) {
10690
10725
index = 4 * i ;
10691
10726
lineDirections [index ++] = dx *tr .m00 + dy *tr .m01 ;
10692
10727
lineDirections [index ] = dx *tr .m10 + dy *tr .m11 ;
10728
+ lineDirections [index + 2 ] *= scaleFactor ;
10693
10729
}
10694
10730
}
10695
10731
}
@@ -10698,6 +10734,7 @@ void applyMatrixOnPointGeometry(PMatrix2D tr, int first, int last) {
10698
10734
if (first < last ) {
10699
10735
int index ;
10700
10736
10737
+ float matrixScale = matrixScale (tr );
10701
10738
for (int i = first ; i <= last ; i ++) {
10702
10739
index = 4 * i ;
10703
10740
float x = pointVertices [index ++];
@@ -10706,6 +10743,10 @@ void applyMatrixOnPointGeometry(PMatrix2D tr, int first, int last) {
10706
10743
index = 4 * i ;
10707
10744
pointVertices [index ++] = x *tr .m00 + y *tr .m01 + tr .m02 ;
10708
10745
pointVertices [index ] = x *tr .m10 + y *tr .m11 + tr .m12 ;
10746
+
10747
+ index = 2 * i ;
10748
+ pointOffsets [index ++] *= matrixScale ;
10749
+ pointOffsets [index ] *= matrixScale ;
10709
10750
}
10710
10751
}
10711
10752
}
@@ -10771,6 +10812,7 @@ void applyMatrixOnLineGeometry(PMatrix3D tr, int first, int last) {
10771
10812
if (first < last ) {
10772
10813
int index ;
10773
10814
10815
+ float scaleFactor = matrixScale (tr );
10774
10816
for (int i = first ; i <= last ; i ++) {
10775
10817
index = 4 * i ;
10776
10818
float x = lineVertices [index ++];
@@ -10792,7 +10834,8 @@ void applyMatrixOnLineGeometry(PMatrix3D tr, int first, int last) {
10792
10834
index = 4 * i ;
10793
10835
lineDirections [index ++] = dx *tr .m00 + dy *tr .m01 + dz *tr .m02 ;
10794
10836
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 ;
10796
10839
}
10797
10840
}
10798
10841
}
@@ -10801,6 +10844,7 @@ void applyMatrixOnPointGeometry(PMatrix3D tr, int first, int last) {
10801
10844
if (first < last ) {
10802
10845
int index ;
10803
10846
10847
+ float matrixScale = matrixScale (tr );
10804
10848
for (int i = first ; i <= last ; i ++) {
10805
10849
index = 4 * i ;
10806
10850
float x = pointVertices [index ++];
@@ -10813,6 +10857,10 @@ void applyMatrixOnPointGeometry(PMatrix3D tr, int first, int last) {
10813
10857
pointVertices [index ++] = x *tr .m10 + y *tr .m11 + z *tr .m12 + w *tr .m13 ;
10814
10858
pointVertices [index ++] = x *tr .m20 + y *tr .m21 + z *tr .m22 + w *tr .m23 ;
10815
10859
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 ;
10816
10864
}
10817
10865
}
10818
10866
}
@@ -11954,28 +12002,7 @@ boolean noCapsJoins() {
11954
12002
11955
12003
float transformScale () {
11956
12004
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 );
11979
12006
}
11980
12007
11981
12008
boolean segmentIsAxisAligned (int i0 , int i1 ) {
0 commit comments