picrate 0.7.0-java → 0.8.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -1
  5. data/.travis.yml +2 -5
  6. data/CHANGELOG.md +4 -0
  7. data/README.md +3 -3
  8. data/Rakefile +15 -27
  9. data/docs/_config.yml +1 -1
  10. data/docs/_posts/2018-05-11-arch-linux-arm.md +1 -1
  11. data/docs/_posts/2018-11-18-building-gem.md +1 -1
  12. data/lib/picrate/app.rb +1 -1
  13. data/lib/picrate/native_folder.rb +1 -1
  14. data/lib/picrate/version.rb +1 -1
  15. data/mvnw +127 -51
  16. data/mvnw.cmd +182 -0
  17. data/pom.rb +39 -30
  18. data/pom.xml +50 -37
  19. data/src/main/java/monkstone/ColorUtil.java +1 -1
  20. data/src/main/java/monkstone/core/LibraryProxy.java +0 -1
  21. data/src/main/java/monkstone/noise/SimplexNoise.java +1 -1
  22. data/src/main/java/monkstone/vecmath/GfxRender.java +87 -0
  23. data/src/main/java/monkstone/vecmath/ShapeRender.java +1 -1
  24. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  25. data/src/main/java/processing/awt/PGraphicsJava2D.java +48 -50
  26. data/src/main/java/processing/awt/PShapeJava2D.java +10 -0
  27. data/src/main/java/processing/awt/PSurfaceAWT.java +315 -371
  28. data/src/main/java/processing/core/PApplet.java +15424 -15495
  29. data/src/main/java/processing/core/PConstants.java +4 -4
  30. data/src/main/java/processing/core/PFont.java +394 -369
  31. data/src/main/java/processing/core/PGraphics.java +11 -10
  32. data/src/main/java/processing/core/PImage.java +1389 -1435
  33. data/src/main/java/processing/core/PMatrix2D.java +297 -294
  34. data/src/main/java/processing/core/PMatrix3D.java +641 -594
  35. data/src/main/java/processing/core/PShape.java +1755 -1784
  36. data/src/main/java/processing/core/PShapeOBJ.java +145 -133
  37. data/src/main/java/processing/core/PShapeSVG.java +808 -801
  38. data/src/main/java/processing/core/PStyle.java +141 -149
  39. data/src/main/java/processing/core/PSurface.java +111 -117
  40. data/src/main/java/processing/core/PSurfaceNone.java +178 -187
  41. data/src/main/java/processing/javafx/PGraphicsFX2D.java +349 -346
  42. data/src/main/java/processing/opengl/FontTexture.java +40 -59
  43. data/src/main/java/processing/opengl/FrameBuffer.java +28 -18
  44. data/src/main/java/processing/opengl/LinePath.java +7 -7
  45. data/src/main/java/processing/opengl/LineStroker.java +6 -10
  46. data/src/main/java/processing/opengl/PGL.java +56 -44
  47. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +909 -2338
  48. data/src/main/java/processing/opengl/PJOGL.java +1722 -1763
  49. data/src/main/java/processing/opengl/PShader.java +1308 -1192
  50. data/src/main/java/processing/opengl/PShapeOpenGL.java +487 -1811
  51. data/src/main/java/processing/opengl/PSurfaceJOGL.java +482 -497
  52. data/src/main/java/processing/opengl/Texture.java +99 -76
  53. data/src/main/java/processing/opengl/VertexBuffer.java +41 -43
  54. data/vendors/Rakefile +1 -1
  55. metadata +7 -4
@@ -1,6 +1,6 @@
1
1
  /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
2
 
3
- /*
3
+ /*
4
4
  Part of the Processing project - http://processing.org
5
5
 
6
6
  Copyright (c) 2012-15 The Processing Foundation
@@ -20,8 +20,7 @@
20
20
  Public License along with this library; if not, write to the
21
21
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
22
  Boston, MA 02111-1307 USA
23
- */
24
-
23
+ */
25
24
  package processing.opengl;
26
25
 
27
26
  import processing.core.*;
@@ -33,132 +32,132 @@ import java.nio.IntBuffer;
33
32
  import java.util.HashMap;
34
33
 
35
34
  /**
36
- * This class encapsulates a GLSL shader program, including a vertex
37
- * and a fragment shader. Based on the GLSLShader class from GLGraphics, which
38
- * in turn was originally based in the code by JohnG:
35
+ * This class encapsulates a GLSL shader program, including a vertex and a
36
+ * fragment shader. Based on the GLSLShader class from GLGraphics, which in turn
37
+ * was originally based in the code by JohnG:
39
38
  * http://processing.org/discourse/beta/num_1159494801.html
40
39
  *
41
40
  * @webref rendering:shaders
42
41
  */
43
42
  public class PShader implements PConstants {
44
43
 
45
- /**
46
- *
47
- */
48
- static protected final int POINT = 0;
49
-
50
- /**
51
- *
52
- */
53
- static protected final int LINE = 1;
54
-
55
- /**
56
- *
57
- */
58
- static protected final int POLY = 2;
59
-
60
- /**
61
- *
62
- */
63
- static protected final int COLOR = 3;
64
-
65
- /**
66
- *
67
- */
68
- static protected final int LIGHT = 4;
69
-
70
- /**
71
- *
72
- */
73
- static protected final int TEXTURE = 5;
74
-
75
- /**
76
- *
77
- */
78
- static protected final int TEXLIGHT = 6;
79
-
80
- /**
81
- *
82
- */
83
- static protected String pointShaderAttrRegexp =
84
- "attribute *vec2 *offset";
85
-
86
- /**
87
- *
88
- */
89
- static protected String pointShaderInRegexp =
90
- "in *vec2 *offset;";
91
-
92
- /**
93
- *
94
- */
95
- static protected String lineShaderAttrRegexp =
96
- "attribute *vec4 *direction";
97
-
98
- /**
99
- *
100
- */
101
- static protected String lineShaderInRegexp =
102
- "in *vec4 *direction";
103
-
104
- /**
105
- *
106
- */
107
- static protected String pointShaderDefRegexp =
108
- "#define *PROCESSING_POINT_SHADER";
109
-
110
- /**
111
- *
112
- */
113
- static protected String lineShaderDefRegexp =
114
- "#define *PROCESSING_LINE_SHADER";
115
-
116
- /**
117
- *
118
- */
119
- static protected String colorShaderDefRegexp =
120
- "#define *PROCESSING_COLOR_SHADER";
121
-
122
- /**
123
- *
124
- */
125
- static protected String lightShaderDefRegexp =
126
- "#define *PROCESSING_LIGHT_SHADER";
127
-
128
- /**
129
- *
130
- */
131
- static protected String texShaderDefRegexp =
132
- "#define *PROCESSING_TEXTURE_SHADER";
133
-
134
- /**
135
- *
136
- */
137
- static protected String texlightShaderDefRegexp =
138
- "#define *PROCESSING_TEXLIGHT_SHADER";
139
-
140
- /**
141
- *
142
- */
143
- static protected String polyShaderDefRegexp =
144
- "#define *PROCESSING_POLYGON_SHADER";
145
-
146
- /**
147
- *
148
- */
149
- static protected String triShaderAttrRegexp =
150
- "#define *PROCESSING_TRIANGLES_SHADER";
151
-
152
- /**
153
- *
154
- */
155
- static protected String quadShaderAttrRegexp =
156
- "#define *PROCESSING_QUADS_SHADER";
157
-
158
- /**
159
- *
160
- */
161
- protected PApplet parent;
44
+ /**
45
+ *
46
+ */
47
+ static protected final int POINT = 0;
48
+
49
+ /**
50
+ *
51
+ */
52
+ static protected final int LINE = 1;
53
+
54
+ /**
55
+ *
56
+ */
57
+ static protected final int POLY = 2;
58
+
59
+ /**
60
+ *
61
+ */
62
+ static protected final int COLOR = 3;
63
+
64
+ /**
65
+ *
66
+ */
67
+ static protected final int LIGHT = 4;
68
+
69
+ /**
70
+ *
71
+ */
72
+ static protected final int TEXTURE = 5;
73
+
74
+ /**
75
+ *
76
+ */
77
+ static protected final int TEXLIGHT = 6;
78
+
79
+ /**
80
+ *
81
+ */
82
+ static protected String pointShaderAttrRegexp
83
+ = "attribute *vec2 *offset";
84
+
85
+ /**
86
+ *
87
+ */
88
+ static protected String pointShaderInRegexp
89
+ = "in *vec2 *offset;";
90
+
91
+ /**
92
+ *
93
+ */
94
+ static protected String lineShaderAttrRegexp
95
+ = "attribute *vec4 *direction";
96
+
97
+ /**
98
+ *
99
+ */
100
+ static protected String lineShaderInRegexp
101
+ = "in *vec4 *direction";
102
+
103
+ /**
104
+ *
105
+ */
106
+ static protected String pointShaderDefRegexp
107
+ = "#define *PROCESSING_POINT_SHADER";
108
+
109
+ /**
110
+ *
111
+ */
112
+ static protected String lineShaderDefRegexp
113
+ = "#define *PROCESSING_LINE_SHADER";
114
+
115
+ /**
116
+ *
117
+ */
118
+ static protected String colorShaderDefRegexp
119
+ = "#define *PROCESSING_COLOR_SHADER";
120
+
121
+ /**
122
+ *
123
+ */
124
+ static protected String lightShaderDefRegexp
125
+ = "#define *PROCESSING_LIGHT_SHADER";
126
+
127
+ /**
128
+ *
129
+ */
130
+ static protected String texShaderDefRegexp
131
+ = "#define *PROCESSING_TEXTURE_SHADER";
132
+
133
+ /**
134
+ *
135
+ */
136
+ static protected String texlightShaderDefRegexp
137
+ = "#define *PROCESSING_TEXLIGHT_SHADER";
138
+
139
+ /**
140
+ *
141
+ */
142
+ static protected String polyShaderDefRegexp
143
+ = "#define *PROCESSING_POLYGON_SHADER";
144
+
145
+ /**
146
+ *
147
+ */
148
+ static protected String triShaderAttrRegexp
149
+ = "#define *PROCESSING_TRIANGLES_SHADER";
150
+
151
+ /**
152
+ *
153
+ */
154
+ static protected String quadShaderAttrRegexp
155
+ = "#define *PROCESSING_QUADS_SHADER";
156
+
157
+ /**
158
+ *
159
+ */
160
+ protected PApplet parent;
162
161
  // The main renderer associated to the parent PApplet.
163
162
  //protected PGraphicsOpenGL pgMain;
164
163
  // We need a reference to the renderer since a shader might
@@ -166,305 +165,298 @@ public class PShader implements PConstants {
166
165
  // (the one corresponding to the main surface, or other offscreen
167
166
  // renderers).
168
167
 
169
- /**
170
- *
171
- */
168
+ /**
169
+ *
170
+ */
172
171
  protected PGraphicsOpenGL primaryPG;
173
172
 
174
- /**
175
- *
176
- */
177
- protected PGraphicsOpenGL currentPG;
173
+ /**
174
+ *
175
+ */
176
+ protected PGraphicsOpenGL currentPG;
178
177
 
179
- /**
180
- *
181
- */
182
- protected PGL pgl;
178
+ /**
179
+ *
180
+ */
181
+ protected PGL pgl;
183
182
 
184
- /**
185
- *
186
- */
187
- protected int context; // The context that created this shader.
183
+ /**
184
+ *
185
+ */
186
+ protected int context; // The context that created this shader.
188
187
 
189
188
  // The shader type: POINT, LINE, POLY, etc.
190
-
191
- /**
192
- *
193
- */
189
+ /**
190
+ *
191
+ */
194
192
  protected int type;
195
193
 
196
- /**
197
- *
198
- */
199
- public int glProgram;
194
+ /**
195
+ *
196
+ */
197
+ public int glProgram;
200
198
 
201
- /**
202
- *
203
- */
204
- public int glVertex;
199
+ /**
200
+ *
201
+ */
202
+ public int glVertex;
205
203
 
206
- /**
207
- *
208
- */
209
- public int glFragment;
204
+ /**
205
+ *
206
+ */
207
+ public int glFragment;
210
208
  private GLResourceShader glres;
211
209
 
212
- /**
213
- *
214
- */
215
- protected URL vertexURL;
216
-
217
- /**
218
- *
219
- */
220
- protected URL fragmentURL;
221
-
222
- /**
223
- *
224
- */
225
- protected String vertexFilename;
226
-
227
- /**
228
- *
229
- */
230
- protected String fragmentFilename;
231
-
232
- /**
233
- *
234
- */
235
- protected String[] vertexShaderSource;
236
-
237
- /**
238
- *
239
- */
240
- protected String[] fragmentShaderSource;
241
-
242
- /**
243
- *
244
- */
245
- protected boolean bound;
246
-
247
- /**
248
- *
249
- */
250
- protected HashMap<String, UniformValue> uniformValues = null;
251
-
252
- /**
253
- *
254
- */
255
- protected HashMap<Integer, Texture> textures;
256
-
257
- /**
258
- *
259
- */
260
- protected HashMap<Integer, Integer> texUnits;
210
+ /**
211
+ *
212
+ */
213
+ protected URL vertexURL;
261
214
 
262
- // Direct buffers to pass shader data to GL
215
+ /**
216
+ *
217
+ */
218
+ protected URL fragmentURL;
219
+
220
+ /**
221
+ *
222
+ */
223
+ protected String vertexFilename;
224
+
225
+ /**
226
+ *
227
+ */
228
+ protected String fragmentFilename;
229
+
230
+ /**
231
+ *
232
+ */
233
+ protected String[] vertexShaderSource;
234
+
235
+ /**
236
+ *
237
+ */
238
+ protected String[] fragmentShaderSource;
239
+
240
+ /**
241
+ *
242
+ */
243
+ protected boolean bound;
244
+
245
+ /**
246
+ *
247
+ */
248
+ protected HashMap<String, UniformValue> uniformValues = null;
263
249
 
264
- /**
265
- *
266
- */
250
+ /**
251
+ *
252
+ */
253
+ protected HashMap<Integer, Texture> textures;
254
+
255
+ /**
256
+ *
257
+ */
258
+ protected HashMap<Integer, Integer> texUnits;
259
+
260
+ // Direct buffers to pass shader data to GL
261
+ /**
262
+ *
263
+ */
267
264
  protected IntBuffer intBuffer;
268
265
 
269
- /**
270
- *
271
- */
272
- protected FloatBuffer floatBuffer;
266
+ /**
267
+ *
268
+ */
269
+ protected FloatBuffer floatBuffer;
273
270
 
274
- /**
275
- *
276
- */
277
- protected boolean loadedAttributes = false;
271
+ /**
272
+ *
273
+ */
274
+ protected boolean loadedAttributes = false;
278
275
 
279
- /**
280
- *
281
- */
282
- protected boolean loadedUniforms = false;
276
+ /**
277
+ *
278
+ */
279
+ protected boolean loadedUniforms = false;
283
280
 
284
281
  // Uniforms common to all shader types
285
-
286
- /**
287
- *
288
- */
282
+ /**
283
+ *
284
+ */
289
285
  protected int transformMatLoc;
290
286
 
291
- /**
292
- *
293
- */
294
- protected int modelviewMatLoc;
287
+ /**
288
+ *
289
+ */
290
+ protected int modelviewMatLoc;
295
291
 
296
- /**
297
- *
298
- */
299
- protected int projectionMatLoc;
292
+ /**
293
+ *
294
+ */
295
+ protected int projectionMatLoc;
300
296
 
301
- /**
302
- *
303
- */
304
- protected int ppixelsLoc;
297
+ /**
298
+ *
299
+ */
300
+ protected int ppixelsLoc;
305
301
 
306
- /**
307
- *
308
- */
309
- protected int ppixelsUnit;
302
+ /**
303
+ *
304
+ */
305
+ protected int ppixelsUnit;
310
306
 
311
- /**
312
- *
313
- */
314
- protected int viewportLoc;
307
+ /**
308
+ *
309
+ */
310
+ protected int viewportLoc;
315
311
 
316
- /**
317
- *
318
- */
319
- protected int resolutionLoc;
312
+ /**
313
+ *
314
+ */
315
+ protected int resolutionLoc;
320
316
 
321
317
  // Uniforms only for lines and points
322
-
323
- /**
324
- *
325
- */
318
+ /**
319
+ *
320
+ */
326
321
  protected int perspectiveLoc;
327
322
 
328
- /**
329
- *
330
- */
331
- protected int scaleLoc;
323
+ /**
324
+ *
325
+ */
326
+ protected int scaleLoc;
332
327
 
333
328
  // Lighting uniforms
334
-
335
- /**
336
- *
337
- */
329
+ /**
330
+ *
331
+ */
338
332
  protected int lightCountLoc;
339
333
 
340
- /**
341
- *
342
- */
343
- protected int lightPositionLoc;
344
-
345
- /**
346
- *
347
- */
348
- protected int lightNormalLoc;
349
-
350
- /**
351
- *
352
- */
353
- protected int lightAmbientLoc;
354
-
355
- /**
356
- *
357
- */
358
- protected int lightDiffuseLoc;
359
-
360
- /**
361
- *
362
- */
363
- protected int lightSpecularLoc;
364
-
365
- /**
366
- *
367
- */
368
- protected int lightFalloffLoc;
369
-
370
- /**
371
- *
372
- */
373
- protected int lightSpotLoc;
334
+ /**
335
+ *
336
+ */
337
+ protected int lightPositionLoc;
374
338
 
375
- // Texturing uniforms
339
+ /**
340
+ *
341
+ */
342
+ protected int lightNormalLoc;
376
343
 
377
- /**
378
- *
379
- */
344
+ /**
345
+ *
346
+ */
347
+ protected int lightAmbientLoc;
348
+
349
+ /**
350
+ *
351
+ */
352
+ protected int lightDiffuseLoc;
353
+
354
+ /**
355
+ *
356
+ */
357
+ protected int lightSpecularLoc;
358
+
359
+ /**
360
+ *
361
+ */
362
+ protected int lightFalloffLoc;
363
+
364
+ /**
365
+ *
366
+ */
367
+ protected int lightSpotLoc;
368
+
369
+ // Texturing uniforms
370
+ /**
371
+ *
372
+ */
380
373
  protected Texture texture;
381
374
 
382
- /**
383
- *
384
- */
385
- protected int texUnit;
375
+ /**
376
+ *
377
+ */
378
+ protected int texUnit;
386
379
 
387
- /**
388
- *
389
- */
390
- protected int textureLoc;
380
+ /**
381
+ *
382
+ */
383
+ protected int textureLoc;
391
384
 
392
- /**
393
- *
394
- */
395
- protected int texMatrixLoc;
385
+ /**
386
+ *
387
+ */
388
+ protected int texMatrixLoc;
396
389
 
397
- /**
398
- *
399
- */
400
- protected int texOffsetLoc;
390
+ /**
391
+ *
392
+ */
393
+ protected int texOffsetLoc;
401
394
 
402
- /**
403
- *
404
- */
405
- protected float[] tcmat;
395
+ /**
396
+ *
397
+ */
398
+ protected float[] tcmat;
406
399
 
407
400
  // Vertex attributes
408
-
409
- /**
410
- *
411
- */
401
+ /**
402
+ *
403
+ */
412
404
  protected int vertexLoc;
413
405
 
414
- /**
415
- *
416
- */
417
- protected int colorLoc;
418
-
419
- /**
420
- *
421
- */
422
- protected int normalLoc;
423
-
424
- /**
425
- *
426
- */
427
- protected int texCoordLoc;
428
-
429
- /**
430
- *
431
- */
432
- protected int normalMatLoc;
433
-
434
- /**
435
- *
436
- */
437
- protected int directionLoc;
438
-
439
- /**
440
- *
441
- */
442
- protected int offsetLoc;
443
-
444
- /**
445
- *
446
- */
447
- protected int ambientLoc;
448
-
449
- /**
450
- *
451
- */
452
- protected int specularLoc;
453
-
454
- /**
455
- *
456
- */
457
- protected int emissiveLoc;
458
-
459
- /**
460
- *
461
- */
462
- protected int shininessLoc;
463
-
464
- /**
465
- *
466
- */
467
- public PShader() {
406
+ /**
407
+ *
408
+ */
409
+ protected int colorLoc;
410
+
411
+ /**
412
+ *
413
+ */
414
+ protected int normalLoc;
415
+
416
+ /**
417
+ *
418
+ */
419
+ protected int texCoordLoc;
420
+
421
+ /**
422
+ *
423
+ */
424
+ protected int normalMatLoc;
425
+
426
+ /**
427
+ *
428
+ */
429
+ protected int directionLoc;
430
+
431
+ /**
432
+ *
433
+ */
434
+ protected int offsetLoc;
435
+
436
+ /**
437
+ *
438
+ */
439
+ protected int ambientLoc;
440
+
441
+ /**
442
+ *
443
+ */
444
+ protected int specularLoc;
445
+
446
+ /**
447
+ *
448
+ */
449
+ protected int emissiveLoc;
450
+
451
+ /**
452
+ *
453
+ */
454
+ protected int shininessLoc;
455
+
456
+ /**
457
+ *
458
+ */
459
+ public PShader() {
468
460
  parent = null;
469
461
  pgl = null;
470
462
  context = -1;
@@ -486,22 +478,20 @@ public class PShader implements PConstants {
486
478
  type = -1;
487
479
  }
488
480
 
489
- /**
490
- *
491
- * @param parent
492
- */
493
- public PShader(PApplet parent) {
481
+ /**
482
+ *
483
+ * @param parent
484
+ */
485
+ public PShader(PApplet parent) {
494
486
  this();
495
487
  this.parent = parent;
496
- primaryPG = (PGraphicsOpenGL)parent.g;
488
+ primaryPG = (PGraphicsOpenGL) parent.g;
497
489
  pgl = primaryPG.pgl;
498
490
  context = pgl.createEmptyContext();
499
491
  }
500
492
 
501
-
502
493
  /**
503
- * Creates a shader program using the specified vertex and fragment
504
- * shaders.
494
+ * Creates a shader program using the specified vertex and fragment shaders.
505
495
  *
506
496
  * @param parent the parent program
507
497
  * @param vertFilename name of the vertex shader
@@ -509,7 +499,7 @@ public class PShader implements PConstants {
509
499
  */
510
500
  public PShader(PApplet parent, String vertFilename, String fragFilename) {
511
501
  this.parent = parent;
512
- primaryPG = (PGraphicsOpenGL)parent.g;
502
+ primaryPG = (PGraphicsOpenGL) parent.g;
513
503
  pgl = primaryPG.pgl;
514
504
 
515
505
  this.vertexURL = null;
@@ -534,22 +524,21 @@ public class PShader implements PConstants {
534
524
  type = fragType;
535
525
  } else if (fragType == -1) {
536
526
  type = vertType;
537
- } else if (fragType == vertType) {
527
+ } else if (fragType == vertType) {
538
528
  type = vertType;
539
529
  } else {
540
530
  PGraphics.showWarning(PGraphicsOpenGL.INCONSISTENT_SHADER_TYPES);
541
531
  }
542
532
  }
543
533
 
544
-
545
534
  /**
546
- * @param parent
535
+ * @param parent
547
536
  * @param vertURL network location of the vertex shader
548
537
  * @param fragURL network location of the fragment shader
549
538
  */
550
539
  public PShader(PApplet parent, URL vertURL, URL fragURL) {
551
540
  this.parent = parent;
552
- primaryPG = (PGraphicsOpenGL)parent.g;
541
+ primaryPG = (PGraphicsOpenGL) parent.g;
553
542
  pgl = primaryPG.pgl;
554
543
 
555
544
  this.vertexURL = vertURL;
@@ -574,22 +563,22 @@ public class PShader implements PConstants {
574
563
  type = fragType;
575
564
  } else if (fragType == -1) {
576
565
  type = vertType;
577
- } else if (fragType == vertType) {
566
+ } else if (fragType == vertType) {
578
567
  type = vertType;
579
568
  } else {
580
569
  PGraphics.showWarning(PGraphicsOpenGL.INCONSISTENT_SHADER_TYPES);
581
570
  }
582
571
  }
583
572
 
584
- /**
585
- *
586
- * @param parent
587
- * @param vertSource
588
- * @param fragSource
589
- */
590
- public PShader(PApplet parent, String[] vertSource, String[] fragSource) {
573
+ /**
574
+ *
575
+ * @param parent
576
+ * @param vertSource
577
+ * @param fragSource
578
+ */
579
+ public PShader(PApplet parent, String[] vertSource, String[] fragSource) {
591
580
  this.parent = parent;
592
- primaryPG = (PGraphicsOpenGL)parent.g;
581
+ primaryPG = (PGraphicsOpenGL) parent.g;
593
582
  pgl = primaryPG.pgl;
594
583
 
595
584
  this.vertexURL = null;
@@ -614,66 +603,65 @@ public class PShader implements PConstants {
614
603
  type = fragType;
615
604
  } else if (fragType == -1) {
616
605
  type = vertType;
617
- } else if (fragType == vertType) {
606
+ } else if (fragType == vertType) {
618
607
  type = vertType;
619
608
  } else {
620
609
  PGraphics.showWarning(PGraphicsOpenGL.INCONSISTENT_SHADER_TYPES);
621
610
  }
622
611
  }
623
612
 
624
- /**
625
- *
626
- * @param vertFilename
627
- */
628
- public void setVertexShader(String vertFilename) {
613
+ /**
614
+ *
615
+ * @param vertFilename
616
+ */
617
+ public void setVertexShader(String vertFilename) {
629
618
  this.vertexFilename = vertFilename;
630
619
  vertexShaderSource = pgl.loadVertexShader(vertFilename);
631
620
  }
632
621
 
633
- /**
634
- *
635
- * @param vertURL
636
- */
637
- public void setVertexShader(URL vertURL) {
622
+ /**
623
+ *
624
+ * @param vertURL
625
+ */
626
+ public void setVertexShader(URL vertURL) {
638
627
  this.vertexURL = vertURL;
639
628
  vertexShaderSource = pgl.loadVertexShader(vertURL);
640
629
  }
641
630
 
642
- /**
643
- *
644
- * @param vertSource
645
- */
646
- public void setVertexShader(String[] vertSource) {
631
+ /**
632
+ *
633
+ * @param vertSource
634
+ */
635
+ public void setVertexShader(String[] vertSource) {
647
636
  vertexShaderSource = vertSource;
648
637
  }
649
638
 
650
- /**
651
- *
652
- * @param fragFilename
653
- */
654
- public void setFragmentShader(String fragFilename) {
639
+ /**
640
+ *
641
+ * @param fragFilename
642
+ */
643
+ public void setFragmentShader(String fragFilename) {
655
644
  this.fragmentFilename = fragFilename;
656
645
  fragmentShaderSource = pgl.loadFragmentShader(fragFilename);
657
646
  }
658
647
 
659
- /**
660
- *
661
- * @param fragURL
662
- */
663
- public void setFragmentShader(URL fragURL) {
648
+ /**
649
+ *
650
+ * @param fragURL
651
+ */
652
+ public void setFragmentShader(URL fragURL) {
664
653
  this.fragmentURL = fragURL;
665
654
  fragmentShaderSource = pgl.loadFragmentShader(fragURL);
666
655
  }
667
656
 
668
- /**
669
- *
670
- * @param fragSource
671
- */
672
- public void setFragmentShader(String[] fragSource) {
657
+ /**
658
+ *
659
+ * @param fragSource
660
+ */
661
+ public void setFragmentShader(String[] fragSource) {
673
662
  fragmentShaderSource = fragSource;
674
663
  }
675
664
 
676
-
677
665
  /**
678
666
  * Initializes (if needed) and binds the shader program.
679
667
  */
@@ -686,15 +674,18 @@ public class PShader implements PConstants {
686
674
  bindTextures();
687
675
  }
688
676
 
689
- if (hasType()) bindTyped();
677
+ if (hasType()) {
678
+ bindTyped();
679
+ }
690
680
  }
691
681
 
692
-
693
682
  /**
694
683
  * Unbinds the shader program.
695
684
  */
696
685
  public void unbind() {
697
- if (hasType()) unbindTyped();
686
+ if (hasType()) {
687
+ unbindTyped();
688
+ }
698
689
 
699
690
  if (bound) {
700
691
  unbindTextures();
@@ -703,10 +694,10 @@ public class PShader implements PConstants {
703
694
  }
704
695
  }
705
696
 
706
-
707
697
  /**
708
698
  * Returns true if the shader is bound, false otherwise.
709
- * @return
699
+ *
700
+ * @return
710
701
  */
711
702
  public boolean bound() {
712
703
  return bound;
@@ -719,149 +710,152 @@ public class PShader implements PConstants {
719
710
  * @param x first component of the variable to modify
720
711
  */
721
712
  public void set(String name, int x) {
722
- setUniformImpl(name, UniformValue.INT1, new int[] { x });
713
+ setUniformImpl(name, UniformValue.INT1, new int[]{x});
723
714
  }
724
715
 
725
716
  /**
726
- * @param name
727
- * @param y second component of the variable to modify. The variable has to be declared with an array/vector type in the shader (i.e.: int[2], vec2)
728
- * @param x
717
+ * @param name
718
+ * @param y second component of the variable to modify. The variable has to be
719
+ * declared with an array/vector type in the shader (i.e.: int[2], vec2)
720
+ * @param x
729
721
  */
730
722
  public void set(String name, int x, int y) {
731
- setUniformImpl(name, UniformValue.INT2, new int[] { x, y });
723
+ setUniformImpl(name, UniformValue.INT2, new int[]{x, y});
732
724
  }
733
725
 
734
726
  /**
735
- * @param name
736
- * @param z third component of the variable to modify. The variable has to be declared with an array/vector type in the shader (i.e.: int[3], vec3)
737
- * @param x
738
- * @param y
727
+ * @param name
728
+ * @param z third component of the variable to modify. The variable has to be
729
+ * declared with an array/vector type in the shader (i.e.: int[3], vec3)
730
+ * @param x
731
+ * @param y
739
732
  */
740
733
  public void set(String name, int x, int y, int z) {
741
- setUniformImpl(name, UniformValue.INT3, new int[] { x, y, z });
734
+ setUniformImpl(name, UniformValue.INT3, new int[]{x, y, z});
742
735
  }
743
736
 
744
737
  /**
745
- * @param name
746
- * @param x
747
- * @param w fourth component of the variable to modify. The variable has to be declared with an array/vector type in the shader (i.e.: int[4], vec4)
748
- * @param z
749
- * @param y
738
+ * @param name
739
+ * @param x
740
+ * @param w fourth component of the variable to modify. The variable has to be
741
+ * declared with an array/vector type in the shader (i.e.: int[4], vec4)
742
+ * @param z
743
+ * @param y
750
744
  */
751
745
  public void set(String name, int x, int y, int z, int w) {
752
- setUniformImpl(name, UniformValue.INT4, new int[] { x, y, z, w });
746
+ setUniformImpl(name, UniformValue.INT4, new int[]{x, y, z, w});
753
747
  }
754
748
 
755
- /**
756
- *
757
- * @param name
758
- * @param x
759
- */
760
- public void set(String name, float x) {
761
- setUniformImpl(name, UniformValue.FLOAT1, new float[] { x });
749
+ /**
750
+ *
751
+ * @param name
752
+ * @param x
753
+ */
754
+ public void set(String name, float x) {
755
+ setUniformImpl(name, UniformValue.FLOAT1, new float[]{x});
762
756
  }
763
757
 
764
- /**
765
- *
766
- * @param name
767
- * @param x
768
- * @param y
769
- */
770
- public void set(String name, float x, float y) {
771
- setUniformImpl(name, UniformValue.FLOAT2, new float[] { x, y });
758
+ /**
759
+ *
760
+ * @param name
761
+ * @param x
762
+ * @param y
763
+ */
764
+ public void set(String name, float x, float y) {
765
+ setUniformImpl(name, UniformValue.FLOAT2, new float[]{x, y});
772
766
  }
773
767
 
774
- /**
775
- *
776
- * @param name
777
- * @param x
778
- * @param y
779
- * @param z
780
- */
781
- public void set(String name, float x, float y, float z) {
782
- setUniformImpl(name, UniformValue.FLOAT3, new float[] { x, y, z });
768
+ /**
769
+ *
770
+ * @param name
771
+ * @param x
772
+ * @param y
773
+ * @param z
774
+ */
775
+ public void set(String name, float x, float y, float z) {
776
+ setUniformImpl(name, UniformValue.FLOAT3, new float[]{x, y, z});
783
777
  }
784
778
 
785
- /**
786
- *
787
- * @param name
788
- * @param x
789
- * @param y
790
- * @param z
791
- * @param w
792
- */
793
- public void set(String name, float x, float y, float z, float w) {
794
- setUniformImpl(name, UniformValue.FLOAT4, new float[] { x, y, z, w });
779
+ /**
780
+ *
781
+ * @param name
782
+ * @param x
783
+ * @param y
784
+ * @param z
785
+ * @param w
786
+ */
787
+ public void set(String name, float x, float y, float z, float w) {
788
+ setUniformImpl(name, UniformValue.FLOAT4, new float[]{x, y, z, w});
795
789
  }
796
790
 
797
791
  /**
798
- * @param name
799
- * @param vec modifies all the components of an array/vector uniform variable. PVector can only be used if the type of the variable is vec3.
792
+ * @param name
793
+ * @param vec modifies all the components of an array/vector uniform variable.
794
+ * PVector can only be used if the type of the variable is vec3.
800
795
  */
801
796
  public void set(String name, PVector vec) {
802
797
  setUniformImpl(name, UniformValue.FLOAT3,
803
- new float[] { vec.x, vec.y, vec.z });
798
+ new float[]{vec.x, vec.y, vec.z});
804
799
  }
805
800
 
806
- /**
807
- *
808
- * @param name
809
- * @param x
810
- */
811
- public void set(String name, boolean x) {
812
- setUniformImpl(name, UniformValue.INT1, new int[] { (x)?1:0 });
801
+ /**
802
+ *
803
+ * @param name
804
+ * @param x
805
+ */
806
+ public void set(String name, boolean x) {
807
+ setUniformImpl(name, UniformValue.INT1, new int[]{(x) ? 1 : 0});
813
808
  }
814
809
 
815
- /**
816
- *
817
- * @param name
818
- * @param x
819
- * @param y
820
- */
821
- public void set(String name, boolean x, boolean y) {
810
+ /**
811
+ *
812
+ * @param name
813
+ * @param x
814
+ * @param y
815
+ */
816
+ public void set(String name, boolean x, boolean y) {
822
817
  setUniformImpl(name, UniformValue.INT2,
823
- new int[] { (x)?1:0, (y)?1:0 });
818
+ new int[]{(x) ? 1 : 0, (y) ? 1 : 0});
824
819
  }
825
820
 
826
- /**
827
- *
828
- * @param name
829
- * @param x
830
- * @param y
831
- * @param z
832
- */
833
- public void set(String name, boolean x, boolean y, boolean z) {
821
+ /**
822
+ *
823
+ * @param name
824
+ * @param x
825
+ * @param y
826
+ * @param z
827
+ */
828
+ public void set(String name, boolean x, boolean y, boolean z) {
834
829
  setUniformImpl(name, UniformValue.INT3,
835
- new int[] { (x)?1:0, (y)?1:0, (z)?1:0 });
836
- }
837
-
838
- /**
839
- *
840
- * @param name
841
- * @param x
842
- * @param y
843
- * @param z
844
- * @param w
845
- */
846
- public void set(String name, boolean x, boolean y, boolean z, boolean w) {
830
+ new int[]{(x) ? 1 : 0, (y) ? 1 : 0, (z) ? 1 : 0});
831
+ }
832
+
833
+ /**
834
+ *
835
+ * @param name
836
+ * @param x
837
+ * @param y
838
+ * @param z
839
+ * @param w
840
+ */
841
+ public void set(String name, boolean x, boolean y, boolean z, boolean w) {
847
842
  setUniformImpl(name, UniformValue.INT4,
848
- new int[] { (x)?1:0, (y)?1:0, (z)?1:0, (w)?1:0 });
843
+ new int[]{(x) ? 1 : 0, (y) ? 1 : 0, (z) ? 1 : 0, (w) ? 1 : 0});
849
844
  }
850
845
 
851
- /**
852
- *
853
- * @param name
854
- * @param vec
855
- */
856
- public void set(String name, int[] vec) {
846
+ /**
847
+ *
848
+ * @param name
849
+ * @param vec
850
+ */
851
+ public void set(String name, int[] vec) {
857
852
  set(name, vec, 1);
858
853
  }
859
854
 
860
-
861
855
  /**
862
- * @param name
856
+ * @param name
863
857
  * @param ncoords number of coordinates per element, max 4
864
- * @param vec
858
+ * @param vec
865
859
  */
866
860
  public void set(String name, int[] vec, int ncoords) {
867
861
  if (ncoords == 1) {
@@ -873,29 +867,29 @@ public class PShader implements PConstants {
873
867
  } else if (ncoords == 4) {
874
868
  setUniformImpl(name, UniformValue.INT4VEC, vec);
875
869
  } else if (4 < ncoords) {
876
- PGraphics.showWarning("Only up to 4 coordinates per element are " +
877
- "supported.");
870
+ PGraphics.showWarning("Only up to 4 coordinates per element are "
871
+ + "supported.");
878
872
  } else {
879
873
  PGraphics.showWarning("Wrong number of coordinates: it is negative!");
880
874
  }
881
875
  }
882
876
 
883
- /**
884
- *
885
- * @param name
886
- * @param vec
887
- */
888
- public void set(String name, float[] vec) {
877
+ /**
878
+ *
879
+ * @param name
880
+ * @param vec
881
+ */
882
+ public void set(String name, float[] vec) {
889
883
  set(name, vec, 1);
890
884
  }
891
885
 
892
- /**
893
- *
894
- * @param name
895
- * @param vec
896
- * @param ncoords
897
- */
898
- public void set(String name, float[] vec, int ncoords) {
886
+ /**
887
+ *
888
+ * @param name
889
+ * @param vec
890
+ * @param ncoords
891
+ */
892
+ public void set(String name, float[] vec, int ncoords) {
899
893
  if (ncoords == 1) {
900
894
  setUniformImpl(name, UniformValue.FLOAT1VEC, vec);
901
895
  } else if (ncoords == 2) {
@@ -905,108 +899,106 @@ public class PShader implements PConstants {
905
899
  } else if (ncoords == 4) {
906
900
  setUniformImpl(name, UniformValue.FLOAT4VEC, vec);
907
901
  } else if (4 < ncoords) {
908
- PGraphics.showWarning("Only up to 4 coordinates per element are " +
909
- "supported.");
902
+ PGraphics.showWarning("Only up to 4 coordinates per element are "
903
+ + "supported.");
910
904
  } else {
911
905
  PGraphics.showWarning("Wrong number of coordinates: it is negative!");
912
906
  }
913
907
  }
914
908
 
915
- /**
916
- *
917
- * @param name
918
- * @param vec
919
- */
920
- public void set(String name, boolean[] vec) {
909
+ /**
910
+ *
911
+ * @param name
912
+ * @param vec
913
+ */
914
+ public void set(String name, boolean[] vec) {
921
915
  set(name, vec, 1);
922
916
  }
923
917
 
924
- /**
925
- *
926
- * @param name
927
- * @param boolvec
928
- * @param ncoords
929
- */
930
- public void set(String name, boolean[] boolvec, int ncoords) {
918
+ /**
919
+ *
920
+ * @param name
921
+ * @param boolvec
922
+ * @param ncoords
923
+ */
924
+ public void set(String name, boolean[] boolvec, int ncoords) {
931
925
  int[] vec = new int[boolvec.length];
932
926
  for (int i = 0; i < boolvec.length; i++) {
933
- vec[i] = (boolvec[i])?1:0;
927
+ vec[i] = (boolvec[i]) ? 1 : 0;
934
928
  }
935
929
  set(name, vec, ncoords);
936
930
  }
937
931
 
938
-
939
932
  /**
940
- * @param name
933
+ * @param name
941
934
  * @param mat matrix of values
942
935
  */
943
936
  public void set(String name, PMatrix2D mat) {
944
- float[] matv = { mat.m00, mat.m01,
945
- mat.m10, mat.m11 };
937
+ float[] matv = {mat.m00, mat.m01,
938
+ mat.m10, mat.m11};
946
939
  setUniformImpl(name, UniformValue.MAT2, matv);
947
940
  }
948
941
 
949
- /**
950
- *
951
- * @param name
952
- * @param mat
953
- */
954
- public void set(String name, PMatrix3D mat) {
942
+ /**
943
+ *
944
+ * @param name
945
+ * @param mat
946
+ */
947
+ public void set(String name, PMatrix3D mat) {
955
948
  set(name, mat, false);
956
949
  }
957
950
 
958
951
  /**
959
- * @param name
952
+ * @param name
960
953
  * @param use3x3 enforces the matrix is 3 x 3
961
- * @param mat
954
+ * @param mat
962
955
  */
963
956
  public void set(String name, PMatrix3D mat, boolean use3x3) {
964
957
  if (use3x3) {
965
- float[] matv = { mat.m00, mat.m01, mat.m02,
966
- mat.m10, mat.m11, mat.m12,
967
- mat.m20, mat.m21, mat.m22 };
958
+ float[] matv = {mat.m00, mat.m01, mat.m02,
959
+ mat.m10, mat.m11, mat.m12,
960
+ mat.m20, mat.m21, mat.m22};
968
961
  setUniformImpl(name, UniformValue.MAT3, matv);
969
962
  } else {
970
- float[] matv = { mat.m00, mat.m01, mat.m02, mat.m03,
971
- mat.m10, mat.m11, mat.m12, mat.m13,
972
- mat.m20, mat.m21, mat.m22, mat.m23,
973
- mat.m30, mat.m31, mat.m32, mat.m33 };
963
+ float[] matv = {mat.m00, mat.m01, mat.m02, mat.m03,
964
+ mat.m10, mat.m11, mat.m12, mat.m13,
965
+ mat.m20, mat.m21, mat.m22, mat.m23,
966
+ mat.m30, mat.m31, mat.m32, mat.m33};
974
967
  setUniformImpl(name, UniformValue.MAT4, matv);
975
968
  }
976
969
  }
977
970
 
978
971
  /**
979
- * @param name
980
- * @param tex sets the sampler uniform variable to read from this image texture
972
+ * @param name
973
+ * @param tex sets the sampler uniform variable to read from this image
974
+ * texture
981
975
  */
982
976
  public void set(String name, PImage tex) {
983
977
  setUniformImpl(name, UniformValue.SAMPLER2D, tex);
984
978
  }
985
979
 
986
-
987
980
  /**
988
981
  * Extra initialization method that can be used by subclasses, called after
989
- * compiling and attaching the vertex and fragment shaders, and before
990
- * linking the shader program.
982
+ * compiling and attaching the vertex and fragment shaders, and before linking
983
+ * the shader program.
991
984
  *
992
985
  */
993
986
  protected void setup() {
994
987
  }
995
988
 
996
- /**
997
- *
998
- * @param idxId
999
- * @param count
1000
- * @param offset
1001
- */
1002
- protected void draw(int idxId, int count, int offset) {
989
+ /**
990
+ *
991
+ * @param idxId
992
+ * @param count
993
+ * @param offset
994
+ */
995
+ protected void draw(int idxId, int count, int offset) {
1003
996
  pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, idxId);
1004
997
  pgl.drawElements(PGL.TRIANGLES, count, PGL.INDEX_TYPE,
1005
- offset * PGL.SIZEOF_INDEX);
998
+ offset * PGL.SIZEOF_INDEX);
1006
999
  pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
1007
1000
  }
1008
1001
 
1009
-
1010
1002
  /**
1011
1003
  * Returns the ID location of the attribute parameter given its name.
1012
1004
  *
@@ -1018,7 +1010,6 @@ public class PShader implements PConstants {
1018
1010
  return pgl.getAttribLocation(glProgram, name);
1019
1011
  }
1020
1012
 
1021
-
1022
1013
  /**
1023
1014
  * Returns the ID location of the uniform parameter given its name.
1024
1015
  *
@@ -1030,194 +1021,214 @@ public class PShader implements PConstants {
1030
1021
  return pgl.getUniformLocation(glProgram, name);
1031
1022
  }
1032
1023
 
1033
- /**
1034
- *
1035
- * @param loc
1036
- * @param vboId
1037
- * @param size
1038
- * @param type
1039
- * @param normalized
1040
- * @param stride
1041
- * @param offset
1042
- */
1043
- protected void setAttributeVBO(int loc, int vboId, int size, int type,
1044
- boolean normalized, int stride, int offset) {
1024
+ /**
1025
+ *
1026
+ * @param loc
1027
+ * @param vboId
1028
+ * @param size
1029
+ * @param type
1030
+ * @param normalized
1031
+ * @param stride
1032
+ * @param offset
1033
+ */
1034
+ protected void setAttributeVBO(int loc, int vboId, int size, int type,
1035
+ boolean normalized, int stride, int offset) {
1045
1036
  if (-1 < loc) {
1046
1037
  pgl.bindBuffer(PGL.ARRAY_BUFFER, vboId);
1047
1038
  pgl.vertexAttribPointer(loc, size, type, normalized, stride, offset);
1048
1039
  }
1049
1040
  }
1050
1041
 
1051
- /**
1052
- *
1053
- * @param loc
1054
- * @param x
1055
- */
1056
- protected void setUniformValue(int loc, int x) {
1042
+ /**
1043
+ *
1044
+ * @param loc
1045
+ * @param x
1046
+ */
1047
+ protected void setUniformValue(int loc, int x) {
1057
1048
  if (-1 < loc) {
1058
1049
  pgl.uniform1i(loc, x);
1059
1050
  }
1060
1051
  }
1061
1052
 
1062
- /**
1063
- *
1064
- * @param loc
1065
- * @param x
1066
- * @param y
1067
- */
1068
- protected void setUniformValue(int loc, int x, int y) {
1053
+ /**
1054
+ *
1055
+ * @param loc
1056
+ * @param x
1057
+ * @param y
1058
+ */
1059
+ protected void setUniformValue(int loc, int x, int y) {
1069
1060
  if (-1 < loc) {
1070
1061
  pgl.uniform2i(loc, x, y);
1071
1062
  }
1072
1063
  }
1073
1064
 
1074
- /**
1075
- *
1076
- * @param loc
1077
- * @param x
1078
- * @param y
1079
- * @param z
1080
- */
1081
- protected void setUniformValue(int loc, int x, int y, int z) {
1065
+ /**
1066
+ *
1067
+ * @param loc
1068
+ * @param x
1069
+ * @param y
1070
+ * @param z
1071
+ */
1072
+ protected void setUniformValue(int loc, int x, int y, int z) {
1082
1073
  if (-1 < loc) {
1083
1074
  pgl.uniform3i(loc, x, y, z);
1084
1075
  }
1085
1076
  }
1086
1077
 
1087
- /**
1088
- *
1089
- * @param loc
1090
- * @param x
1091
- * @param y
1092
- * @param z
1093
- * @param w
1094
- */
1095
- protected void setUniformValue(int loc, int x, int y, int z, int w) {
1078
+ /**
1079
+ *
1080
+ * @param loc
1081
+ * @param x
1082
+ * @param y
1083
+ * @param z
1084
+ * @param w
1085
+ */
1086
+ protected void setUniformValue(int loc, int x, int y, int z, int w) {
1096
1087
  if (-1 < loc) {
1097
1088
  pgl.uniform4i(loc, x, y, z, w);
1098
1089
  }
1099
1090
  }
1100
1091
 
1101
- /**
1102
- *
1103
- * @param loc
1104
- * @param x
1105
- */
1106
- protected void setUniformValue(int loc, float x) {
1092
+ /**
1093
+ *
1094
+ * @param loc
1095
+ * @param x
1096
+ */
1097
+ protected void setUniformValue(int loc, float x) {
1107
1098
  if (-1 < loc) {
1108
1099
  pgl.uniform1f(loc, x);
1109
1100
  }
1110
1101
  }
1111
1102
 
1112
- /**
1113
- *
1114
- * @param loc
1115
- * @param x
1116
- * @param y
1117
- */
1118
- protected void setUniformValue(int loc, float x, float y) {
1103
+ /**
1104
+ *
1105
+ * @param loc
1106
+ * @param x
1107
+ * @param y
1108
+ */
1109
+ protected void setUniformValue(int loc, float x, float y) {
1119
1110
  if (-1 < loc) {
1120
1111
  pgl.uniform2f(loc, x, y);
1121
1112
  }
1122
1113
  }
1123
1114
 
1124
- /**
1125
- *
1126
- * @param loc
1127
- * @param x
1128
- * @param y
1129
- * @param z
1130
- */
1131
- protected void setUniformValue(int loc, float x, float y, float z) {
1115
+ /**
1116
+ *
1117
+ * @param loc
1118
+ * @param x
1119
+ * @param y
1120
+ * @param z
1121
+ */
1122
+ protected void setUniformValue(int loc, float x, float y, float z) {
1132
1123
  if (-1 < loc) {
1133
1124
  pgl.uniform3f(loc, x, y, z);
1134
1125
  }
1135
1126
  }
1136
1127
 
1137
- /**
1138
- *
1139
- * @param loc
1140
- * @param x
1141
- * @param y
1142
- * @param z
1143
- * @param w
1144
- */
1145
- protected void setUniformValue(int loc, float x, float y, float z, float w) {
1128
+ /**
1129
+ *
1130
+ * @param loc
1131
+ * @param x
1132
+ * @param y
1133
+ * @param z
1134
+ * @param w
1135
+ */
1136
+ protected void setUniformValue(int loc, float x, float y, float z, float w) {
1146
1137
  if (-1 < loc) {
1147
1138
  pgl.uniform4f(loc, x, y, z, w);
1148
1139
  }
1149
1140
  }
1150
1141
 
1151
- /**
1152
- *
1153
- * @param loc
1154
- * @param vec
1155
- * @param ncoords
1156
- * @param length
1157
- */
1158
- protected void setUniformVector(int loc, int[] vec, int ncoords,
1159
- int length) {
1142
+ /**
1143
+ *
1144
+ * @param loc
1145
+ * @param vec
1146
+ * @param ncoords
1147
+ * @param length
1148
+ */
1149
+ protected void setUniformVector(int loc, int[] vec, int ncoords,
1150
+ int length) {
1160
1151
  if (-1 < loc) {
1161
1152
  updateIntBuffer(vec);
1162
- if (ncoords == 1) {
1163
- pgl.uniform1iv(loc, length, intBuffer);
1164
- } else if (ncoords == 2) {
1165
- pgl.uniform2iv(loc, length, intBuffer);
1166
- } else if (ncoords == 3) {
1167
- pgl.uniform3iv(loc, length, intBuffer);
1168
- } else if (ncoords == 4) {
1169
- pgl.uniform3iv(loc, length, intBuffer);
1153
+ switch (ncoords) {
1154
+ case 1:
1155
+ pgl.uniform1iv(loc, length, intBuffer);
1156
+ break;
1157
+ case 2:
1158
+ pgl.uniform2iv(loc, length, intBuffer);
1159
+ break;
1160
+ case 3:
1161
+ pgl.uniform3iv(loc, length, intBuffer);
1162
+ break;
1163
+ case 4:
1164
+ pgl.uniform3iv(loc, length, intBuffer);
1165
+ break;
1166
+ default:
1167
+ break;
1170
1168
  }
1171
1169
  }
1172
1170
  }
1173
1171
 
1174
- /**
1175
- *
1176
- * @param loc
1177
- * @param vec
1178
- * @param ncoords
1179
- * @param length
1180
- */
1181
- protected void setUniformVector(int loc, float[] vec, int ncoords,
1182
- int length) {
1172
+ /**
1173
+ *
1174
+ * @param loc
1175
+ * @param vec
1176
+ * @param ncoords
1177
+ * @param length
1178
+ */
1179
+ protected void setUniformVector(int loc, float[] vec, int ncoords,
1180
+ int length) {
1183
1181
  if (-1 < loc) {
1184
1182
  updateFloatBuffer(vec);
1185
- if (ncoords == 1) {
1186
- pgl.uniform1fv(loc, length, floatBuffer);
1187
- } else if (ncoords == 2) {
1188
- pgl.uniform2fv(loc, length, floatBuffer);
1189
- } else if (ncoords == 3) {
1190
- pgl.uniform3fv(loc, length, floatBuffer);
1191
- } else if (ncoords == 4) {
1192
- pgl.uniform4fv(loc, length, floatBuffer);
1183
+ switch (ncoords) {
1184
+ case 1:
1185
+ pgl.uniform1fv(loc, length, floatBuffer);
1186
+ break;
1187
+ case 2:
1188
+ pgl.uniform2fv(loc, length, floatBuffer);
1189
+ break;
1190
+ case 3:
1191
+ pgl.uniform3fv(loc, length, floatBuffer);
1192
+ break;
1193
+ case 4:
1194
+ pgl.uniform4fv(loc, length, floatBuffer);
1195
+ break;
1196
+ default:
1197
+ break;
1193
1198
  }
1194
1199
  }
1195
1200
  }
1196
1201
 
1197
- /**
1198
- *
1199
- * @param loc
1200
- * @param mat
1201
- */
1202
- protected void setUniformMatrix(int loc, float[] mat) {
1202
+ /**
1203
+ *
1204
+ * @param loc
1205
+ * @param mat
1206
+ */
1207
+ protected void setUniformMatrix(int loc, float[] mat) {
1203
1208
  if (-1 < loc) {
1204
1209
  updateFloatBuffer(mat);
1205
- if (mat.length == 4) {
1206
- pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
1207
- } else if (mat.length == 9) {
1208
- pgl.uniformMatrix3fv(loc, 1, false, floatBuffer);
1209
- } else if (mat.length == 16) {
1210
- pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
1210
+ switch (mat.length) {
1211
+ case 4:
1212
+ pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
1213
+ break;
1214
+ case 9:
1215
+ pgl.uniformMatrix3fv(loc, 1, false, floatBuffer);
1216
+ break;
1217
+ case 16:
1218
+ pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
1219
+ break;
1220
+ default:
1221
+ break;
1211
1222
  }
1212
1223
  }
1213
1224
  }
1214
1225
 
1215
- /**
1216
- *
1217
- * @param loc
1218
- * @param tex
1219
- */
1220
- protected void setUniformTex(int loc, Texture tex) {
1226
+ /**
1227
+ *
1228
+ * @param loc
1229
+ * @param tex
1230
+ */
1231
+ protected void setUniformTex(int loc, Texture tex) {
1221
1232
  if (texUnits != null) {
1222
1233
  Integer unit = texUnits.get(loc);
1223
1234
  if (unit != null) {
@@ -1229,146 +1240,190 @@ public class PShader implements PConstants {
1229
1240
  }
1230
1241
  }
1231
1242
 
1232
- /**
1233
- *
1234
- * @param name
1235
- * @param type
1236
- * @param value
1237
- */
1238
- protected void setUniformImpl(String name, int type, Object value) {
1243
+ /**
1244
+ *
1245
+ * @param name
1246
+ * @param type
1247
+ * @param value
1248
+ */
1249
+ protected void setUniformImpl(String name, int type, Object value) {
1239
1250
  if (uniformValues == null) {
1240
- uniformValues = new HashMap<String, UniformValue>();
1251
+ uniformValues = new HashMap<>();
1241
1252
  }
1242
1253
  uniformValues.put(name, new UniformValue(type, value));
1243
1254
  }
1244
1255
 
1245
- /**
1246
- *
1247
- */
1248
- protected void consumeUniforms() {
1256
+ /**
1257
+ *
1258
+ */
1259
+ protected void consumeUniforms() {
1249
1260
  if (uniformValues != null && 0 < uniformValues.size()) {
1250
1261
  int unit = 0;
1251
- for (String name: uniformValues.keySet()) {
1262
+ for (String name : uniformValues.keySet()) {
1252
1263
  int loc = getUniformLoc(name);
1253
1264
  if (loc == -1) {
1254
- PGraphics.showWarning("The shader doesn't have a uniform called \"" +
1255
- name + "\" OR the uniform was removed during " +
1256
- "compilation because it was unused.");
1265
+ PGraphics.showWarning("The shader doesn't have a uniform called \""
1266
+ + name + "\" OR the uniform was removed during "
1267
+ + "compilation because it was unused.");
1257
1268
  continue;
1258
1269
  }
1259
1270
  UniformValue val = uniformValues.get(name);
1260
- if (val.type == UniformValue.INT1) {
1261
- int[] v = ((int[])val.value);
1262
- pgl.uniform1i(loc, v[0]);
1263
- } else if (val.type == UniformValue.INT2) {
1264
- int[] v = ((int[])val.value);
1265
- pgl.uniform2i(loc, v[0], v[1]);
1266
- } else if (val.type == UniformValue.INT3) {
1267
- int[] v = ((int[])val.value);
1268
- pgl.uniform3i(loc, v[0], v[1], v[2]);
1269
- } else if (val.type == UniformValue.INT4) {
1270
- int[] v = ((int[])val.value);
1271
- pgl.uniform4i(loc, v[0], v[1], v[2], v[3]);
1272
- } else if (val.type == UniformValue.FLOAT1) {
1273
- float[] v = ((float[])val.value);
1274
- pgl.uniform1f(loc, v[0]);
1275
- } else if (val.type == UniformValue.FLOAT2) {
1276
- float[] v = ((float[])val.value);
1277
- pgl.uniform2f(loc, v[0], v[1]);
1278
- } else if (val.type == UniformValue.FLOAT3) {
1279
- float[] v = ((float[])val.value);
1280
- pgl.uniform3f(loc, v[0], v[1], v[2]);
1281
- } else if (val.type == UniformValue.FLOAT4) {
1282
- float[] v = ((float[])val.value);
1283
- pgl.uniform4f(loc, v[0], v[1], v[2], v[3]);
1284
- } else if (val.type == UniformValue.INT1VEC) {
1285
- int[] v = ((int[])val.value);
1286
- updateIntBuffer(v);
1287
- pgl.uniform1iv(loc, v.length, intBuffer);
1288
- } else if (val.type == UniformValue.INT2VEC) {
1289
- int[] v = ((int[])val.value);
1290
- updateIntBuffer(v);
1291
- pgl.uniform2iv(loc, v.length / 2, intBuffer);
1292
- } else if (val.type == UniformValue.INT3VEC) {
1293
- int[] v = ((int[])val.value);
1294
- updateIntBuffer(v);
1295
- pgl.uniform3iv(loc, v.length / 3, intBuffer);
1296
- } else if (val.type == UniformValue.INT4VEC) {
1297
- int[] v = ((int[])val.value);
1298
- updateIntBuffer(v);
1299
- pgl.uniform4iv(loc, v.length / 4, intBuffer);
1300
- } else if (val.type == UniformValue.FLOAT1VEC) {
1301
- float[] v = ((float[])val.value);
1302
- updateFloatBuffer(v);
1303
- pgl.uniform1fv(loc, v.length, floatBuffer);
1304
- } else if (val.type == UniformValue.FLOAT2VEC) {
1305
- float[] v = ((float[])val.value);
1306
- updateFloatBuffer(v);
1307
- pgl.uniform2fv(loc, v.length / 2, floatBuffer);
1308
- } else if (val.type == UniformValue.FLOAT3VEC) {
1309
- float[] v = ((float[])val.value);
1310
- updateFloatBuffer(v);
1311
- pgl.uniform3fv(loc, v.length / 3, floatBuffer);
1312
- } else if (val.type == UniformValue.FLOAT4VEC) {
1313
- float[] v = ((float[])val.value);
1314
- updateFloatBuffer(v);
1315
- pgl.uniform4fv(loc, v.length / 4, floatBuffer);
1316
- } else if (val.type == UniformValue.MAT2) {
1317
- float[] v = ((float[])val.value);
1318
- updateFloatBuffer(v);
1319
- pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
1320
- } else if (val.type == UniformValue.MAT3) {
1321
- float[] v = ((float[])val.value);
1322
- updateFloatBuffer(v);
1323
- pgl.uniformMatrix3fv(loc, 1, false, floatBuffer);
1324
- } else if (val.type == UniformValue.MAT4) {
1325
- float[] v = ((float[])val.value);
1326
- updateFloatBuffer(v);
1327
- pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
1328
- } else if (val.type == UniformValue.SAMPLER2D) {
1329
- PImage img = (PImage)val.value;
1330
- Texture tex = currentPG.getTexture(img);
1331
-
1332
- if (textures == null) textures = new HashMap<Integer, Texture>();
1333
- textures.put(loc, tex);
1334
-
1335
- if (texUnits == null) texUnits = new HashMap<Integer, Integer>();
1336
- if (texUnits.containsKey(loc)) {
1337
- unit = texUnits.get(loc);
1338
- pgl.uniform1i(loc, unit);
1339
- } else {
1340
- texUnits.put(loc, unit);
1341
- pgl.uniform1i(loc, unit);
1271
+ switch (val.type) {
1272
+ case UniformValue.INT1: {
1273
+ int[] v = ((int[]) val.value);
1274
+ pgl.uniform1i(loc, v[0]);
1275
+ break;
1276
+ }
1277
+ case UniformValue.INT2: {
1278
+ int[] v = ((int[]) val.value);
1279
+ pgl.uniform2i(loc, v[0], v[1]);
1280
+ break;
1342
1281
  }
1343
- unit++;
1282
+ case UniformValue.INT3: {
1283
+ int[] v = ((int[]) val.value);
1284
+ pgl.uniform3i(loc, v[0], v[1], v[2]);
1285
+ break;
1286
+ }
1287
+ case UniformValue.INT4: {
1288
+ int[] v = ((int[]) val.value);
1289
+ pgl.uniform4i(loc, v[0], v[1], v[2], v[3]);
1290
+ break;
1291
+ }
1292
+ case UniformValue.FLOAT1: {
1293
+ float[] v = ((float[]) val.value);
1294
+ pgl.uniform1f(loc, v[0]);
1295
+ break;
1296
+ }
1297
+ case UniformValue.FLOAT2: {
1298
+ float[] v = ((float[]) val.value);
1299
+ pgl.uniform2f(loc, v[0], v[1]);
1300
+ break;
1301
+ }
1302
+ case UniformValue.FLOAT3: {
1303
+ float[] v = ((float[]) val.value);
1304
+ pgl.uniform3f(loc, v[0], v[1], v[2]);
1305
+ break;
1306
+ }
1307
+ case UniformValue.FLOAT4: {
1308
+ float[] v = ((float[]) val.value);
1309
+ pgl.uniform4f(loc, v[0], v[1], v[2], v[3]);
1310
+ break;
1311
+ }
1312
+ case UniformValue.INT1VEC: {
1313
+ int[] v = ((int[]) val.value);
1314
+ updateIntBuffer(v);
1315
+ pgl.uniform1iv(loc, v.length, intBuffer);
1316
+ break;
1317
+ }
1318
+ case UniformValue.INT2VEC: {
1319
+ int[] v = ((int[]) val.value);
1320
+ updateIntBuffer(v);
1321
+ pgl.uniform2iv(loc, v.length / 2, intBuffer);
1322
+ break;
1323
+ }
1324
+ case UniformValue.INT3VEC: {
1325
+ int[] v = ((int[]) val.value);
1326
+ updateIntBuffer(v);
1327
+ pgl.uniform3iv(loc, v.length / 3, intBuffer);
1328
+ break;
1329
+ }
1330
+ case UniformValue.INT4VEC: {
1331
+ int[] v = ((int[]) val.value);
1332
+ updateIntBuffer(v);
1333
+ pgl.uniform4iv(loc, v.length / 4, intBuffer);
1334
+ break;
1335
+ }
1336
+ case UniformValue.FLOAT1VEC: {
1337
+ float[] v = ((float[]) val.value);
1338
+ updateFloatBuffer(v);
1339
+ pgl.uniform1fv(loc, v.length, floatBuffer);
1340
+ break;
1341
+ }
1342
+ case UniformValue.FLOAT2VEC: {
1343
+ float[] v = ((float[]) val.value);
1344
+ updateFloatBuffer(v);
1345
+ pgl.uniform2fv(loc, v.length / 2, floatBuffer);
1346
+ break;
1347
+ }
1348
+ case UniformValue.FLOAT3VEC: {
1349
+ float[] v = ((float[]) val.value);
1350
+ updateFloatBuffer(v);
1351
+ pgl.uniform3fv(loc, v.length / 3, floatBuffer);
1352
+ break;
1353
+ }
1354
+ case UniformValue.FLOAT4VEC: {
1355
+ float[] v = ((float[]) val.value);
1356
+ updateFloatBuffer(v);
1357
+ pgl.uniform4fv(loc, v.length / 4, floatBuffer);
1358
+ break;
1359
+ }
1360
+ case UniformValue.MAT2: {
1361
+ float[] v = ((float[]) val.value);
1362
+ updateFloatBuffer(v);
1363
+ pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
1364
+ break;
1365
+ }
1366
+ case UniformValue.MAT3: {
1367
+ float[] v = ((float[]) val.value);
1368
+ updateFloatBuffer(v);
1369
+ pgl.uniformMatrix3fv(loc, 1, false, floatBuffer);
1370
+ break;
1371
+ }
1372
+ case UniformValue.MAT4: {
1373
+ float[] v = ((float[]) val.value);
1374
+ updateFloatBuffer(v);
1375
+ pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
1376
+ break;
1377
+ }
1378
+ case UniformValue.SAMPLER2D:
1379
+ PImage img = (PImage) val.value;
1380
+ Texture tex = currentPG.getTexture(img);
1381
+ if (textures == null) {
1382
+ textures = new HashMap<>();
1383
+ }
1384
+ textures.put(loc, tex);
1385
+ if (texUnits == null) {
1386
+ texUnits = new HashMap<>();
1387
+ }
1388
+ if (texUnits.containsKey(loc)) {
1389
+ unit = texUnits.get(loc);
1390
+ pgl.uniform1i(loc, unit);
1391
+ } else {
1392
+ texUnits.put(loc, unit);
1393
+ pgl.uniform1i(loc, unit);
1394
+ }
1395
+ unit++;
1396
+ break;
1397
+ default:
1398
+ break;
1344
1399
  }
1345
1400
  }
1346
1401
  uniformValues.clear();
1347
1402
  }
1348
1403
  }
1349
1404
 
1350
- /**
1351
- *
1352
- * @param vec
1353
- */
1354
- protected void updateIntBuffer(int[] vec) {
1405
+ /**
1406
+ *
1407
+ * @param vec
1408
+ */
1409
+ protected void updateIntBuffer(int[] vec) {
1355
1410
  intBuffer = PGL.updateIntBuffer(intBuffer, vec, false);
1356
1411
  }
1357
1412
 
1358
- /**
1359
- *
1360
- * @param vec
1361
- */
1362
- protected void updateFloatBuffer(float[] vec) {
1413
+ /**
1414
+ *
1415
+ * @param vec
1416
+ */
1417
+ protected void updateFloatBuffer(float[] vec) {
1363
1418
  floatBuffer = PGL.updateFloatBuffer(floatBuffer, vec, false);
1364
1419
  }
1365
1420
 
1366
- /**
1367
- *
1368
- */
1369
- protected void bindTextures() {
1421
+ /**
1422
+ *
1423
+ */
1424
+ protected void bindTextures() {
1370
1425
  if (textures != null && texUnits != null) {
1371
- for (int loc: textures.keySet()) {
1426
+ textures.keySet().forEach((loc) -> {
1372
1427
  Texture tex = textures.get(loc);
1373
1428
  Integer unit = texUnits.get(loc);
1374
1429
  if (unit != null) {
@@ -1377,16 +1432,16 @@ public class PShader implements PConstants {
1377
1432
  } else {
1378
1433
  throw new RuntimeException("Cannot find unit for texture " + tex);
1379
1434
  }
1380
- }
1435
+ });
1381
1436
  }
1382
1437
  }
1383
1438
 
1384
- /**
1385
- *
1386
- */
1387
- protected void unbindTextures() {
1439
+ /**
1440
+ *
1441
+ */
1442
+ protected void unbindTextures() {
1388
1443
  if (textures != null && texUnits != null) {
1389
- for (int loc: textures.keySet()) {
1444
+ textures.keySet().forEach((loc) -> {
1390
1445
  Texture tex = textures.get(loc);
1391
1446
  Integer unit = texUnits.get(loc);
1392
1447
  if (unit != null) {
@@ -1395,15 +1450,15 @@ public class PShader implements PConstants {
1395
1450
  } else {
1396
1451
  throw new RuntimeException("Cannot find unit for texture " + tex);
1397
1452
  }
1398
- }
1453
+ });
1399
1454
  pgl.activeTexture(PGL.TEXTURE0);
1400
1455
  }
1401
1456
  }
1402
1457
 
1403
- /**
1404
- *
1405
- */
1406
- public void init() {
1458
+ /**
1459
+ *
1460
+ */
1461
+ public void init() {
1407
1462
  if (glProgram == 0 || contextIsOutdated()) {
1408
1463
  create();
1409
1464
  if (compile()) {
@@ -1419,19 +1474,19 @@ public class PShader implements PConstants {
1419
1474
  }
1420
1475
  }
1421
1476
 
1422
- /**
1423
- *
1424
- */
1425
- protected void create() {
1477
+ /**
1478
+ *
1479
+ */
1480
+ protected void create() {
1426
1481
  context = pgl.getCurrentContext();
1427
1482
  glres = new GLResourceShader(this);
1428
1483
  }
1429
1484
 
1430
- /**
1431
- *
1432
- * @return
1433
- */
1434
- protected boolean compile() {
1485
+ /**
1486
+ *
1487
+ * @return
1488
+ */
1489
+ protected boolean compile() {
1435
1490
  boolean vertRes = true;
1436
1491
  if (hasVertexShader()) {
1437
1492
  vertRes = compileVertexShader();
@@ -1449,31 +1504,31 @@ public class PShader implements PConstants {
1449
1504
  return vertRes && fragRes;
1450
1505
  }
1451
1506
 
1452
- /**
1453
- *
1454
- */
1455
- protected void validate() {
1507
+ /**
1508
+ *
1509
+ */
1510
+ protected void validate() {
1456
1511
  pgl.getProgramiv(glProgram, PGL.LINK_STATUS, intBuffer);
1457
- boolean linked = intBuffer.get(0) == 0 ? false : true;
1512
+ boolean linked = intBuffer.get(0) != 0;
1458
1513
  if (!linked) {
1459
- PGraphics.showException("Cannot link shader program:\n" +
1460
- pgl.getProgramInfoLog(glProgram));
1514
+ PGraphics.showException("Cannot link shader program:\n"
1515
+ + pgl.getProgramInfoLog(glProgram));
1461
1516
  }
1462
1517
 
1463
1518
  pgl.validateProgram(glProgram);
1464
1519
  pgl.getProgramiv(glProgram, PGL.VALIDATE_STATUS, intBuffer);
1465
- boolean validated = intBuffer.get(0) == 0 ? false : true;
1520
+ boolean validated = intBuffer.get(0) != 0;
1466
1521
  if (!validated) {
1467
- PGraphics.showException("Cannot validate shader program:\n" +
1468
- pgl.getProgramInfoLog(glProgram));
1522
+ PGraphics.showException("Cannot validate shader program:\n"
1523
+ + pgl.getProgramInfoLog(glProgram));
1469
1524
  }
1470
1525
  }
1471
1526
 
1472
- /**
1473
- *
1474
- * @return
1475
- */
1476
- protected boolean contextIsOutdated() {
1527
+ /**
1528
+ *
1529
+ * @return
1530
+ */
1531
+ protected boolean contextIsOutdated() {
1477
1532
  boolean outdated = !pgl.contextIsCurrent(context);
1478
1533
  if (outdated) {
1479
1534
  dispose();
@@ -1481,66 +1536,62 @@ public class PShader implements PConstants {
1481
1536
  return outdated;
1482
1537
  }
1483
1538
 
1484
- /**
1485
- *
1486
- * @return
1487
- */
1488
- protected boolean hasVertexShader() {
1539
+ /**
1540
+ *
1541
+ * @return
1542
+ */
1543
+ protected boolean hasVertexShader() {
1489
1544
  return vertexShaderSource != null && 0 < vertexShaderSource.length;
1490
1545
  }
1491
1546
 
1492
- /**
1493
- *
1494
- * @return
1495
- */
1496
- protected boolean hasFragmentShader() {
1547
+ /**
1548
+ *
1549
+ * @return
1550
+ */
1551
+ protected boolean hasFragmentShader() {
1497
1552
  return fragmentShaderSource != null && 0 < fragmentShaderSource.length;
1498
1553
  }
1499
1554
 
1500
-
1501
1555
  /**
1502
- * @param shaderSource a string containing the shader's code
1503
- * @return
1556
+ * @return
1504
1557
  */
1505
1558
  protected boolean compileVertexShader() {
1506
1559
  pgl.shaderSource(glVertex, PApplet.join(vertexShaderSource, "\n"));
1507
1560
  pgl.compileShader(glVertex);
1508
1561
 
1509
1562
  pgl.getShaderiv(glVertex, PGL.COMPILE_STATUS, intBuffer);
1510
- boolean compiled = intBuffer.get(0) == 0 ? false : true;
1563
+ boolean compiled = intBuffer.get(0) != 0;
1511
1564
  if (!compiled) {
1512
- PGraphics.showException("Cannot compile vertex shader:\n" +
1513
- pgl.getShaderInfoLog(glVertex));
1565
+ PGraphics.showException("Cannot compile vertex shader:\n"
1566
+ + pgl.getShaderInfoLog(glVertex));
1514
1567
  return false;
1515
1568
  } else {
1516
1569
  return true;
1517
1570
  }
1518
1571
  }
1519
1572
 
1520
-
1521
1573
  /**
1522
- * @param shaderSource a string containing the shader's code
1523
- * @return
1574
+ * @return
1524
1575
  */
1525
1576
  protected boolean compileFragmentShader() {
1526
1577
  pgl.shaderSource(glFragment, PApplet.join(fragmentShaderSource, "\n"));
1527
1578
  pgl.compileShader(glFragment);
1528
1579
 
1529
1580
  pgl.getShaderiv(glFragment, PGL.COMPILE_STATUS, intBuffer);
1530
- boolean compiled = intBuffer.get(0) == 0 ? false : true;
1581
+ boolean compiled = intBuffer.get(0) != 0;
1531
1582
  if (!compiled) {
1532
- PGraphics.showException("Cannot compile fragment shader:\n" +
1533
- pgl.getShaderInfoLog(glFragment));
1583
+ PGraphics.showException("Cannot compile fragment shader:\n"
1584
+ + pgl.getShaderInfoLog(glFragment));
1534
1585
  return false;
1535
1586
  } else {
1536
1587
  return true;
1537
1588
  }
1538
1589
  }
1539
1590
 
1540
- /**
1541
- *
1542
- */
1543
- protected void dispose() {
1591
+ /**
1592
+ *
1593
+ */
1594
+ protected void dispose() {
1544
1595
  if (glres != null) {
1545
1596
  glres.dispose();
1546
1597
  glVertex = 0;
@@ -1550,118 +1601,123 @@ public class PShader implements PConstants {
1550
1601
  }
1551
1602
  }
1552
1603
 
1553
- /**
1554
- *
1555
- * @param source
1556
- * @param defaultType
1557
- * @return
1558
- */
1559
- static protected int getShaderType(String[] source, int defaultType) {
1560
- for (int i = 0; i < source.length; i++) {
1561
- String line = source[i].trim();
1562
-
1563
- if (PApplet.match(line, colorShaderDefRegexp) != null)
1604
+ /**
1605
+ *
1606
+ * @param source
1607
+ * @param defaultType
1608
+ * @return
1609
+ */
1610
+ static protected int getShaderType(String[] source, int defaultType) {
1611
+ for (String source1 : source) {
1612
+ String line = source1.trim();
1613
+ if (PApplet.match(line, colorShaderDefRegexp) != null) {
1564
1614
  return PShader.COLOR;
1565
- else if (PApplet.match(line, lightShaderDefRegexp) != null)
1615
+ } else if (PApplet.match(line, lightShaderDefRegexp) != null) {
1566
1616
  return PShader.LIGHT;
1567
- else if (PApplet.match(line, texShaderDefRegexp) != null)
1617
+ } else if (PApplet.match(line, texShaderDefRegexp) != null) {
1568
1618
  return PShader.TEXTURE;
1569
- else if (PApplet.match(line, texlightShaderDefRegexp) != null)
1619
+ } else if (PApplet.match(line, texlightShaderDefRegexp) != null) {
1570
1620
  return PShader.TEXLIGHT;
1571
- else if (PApplet.match(line, polyShaderDefRegexp) != null)
1621
+ } else if (PApplet.match(line, polyShaderDefRegexp) != null) {
1572
1622
  return PShader.POLY;
1573
- else if (PApplet.match(line, triShaderAttrRegexp) != null)
1623
+ } else if (PApplet.match(line, triShaderAttrRegexp) != null) {
1574
1624
  return PShader.POLY;
1575
- else if (PApplet.match(line, quadShaderAttrRegexp) != null)
1625
+ } else if (PApplet.match(line, quadShaderAttrRegexp) != null) {
1576
1626
  return PShader.POLY;
1577
- else if (PApplet.match(line, pointShaderDefRegexp) != null)
1627
+ } else if (PApplet.match(line, pointShaderDefRegexp) != null) {
1578
1628
  return PShader.POINT;
1579
- else if (PApplet.match(line, lineShaderDefRegexp) != null)
1629
+ } else if (PApplet.match(line, lineShaderDefRegexp) != null) {
1580
1630
  return PShader.LINE;
1581
- else if (PApplet.match(line, pointShaderAttrRegexp) != null)
1631
+ } else if (PApplet.match(line, pointShaderAttrRegexp) != null) {
1582
1632
  return PShader.POINT;
1583
- else if (PApplet.match(line, pointShaderInRegexp) != null)
1633
+ } else if (PApplet.match(line, pointShaderInRegexp) != null) {
1584
1634
  return PShader.POINT;
1585
- else if (PApplet.match(line, lineShaderAttrRegexp) != null)
1635
+ } else if (PApplet.match(line, lineShaderAttrRegexp) != null) {
1586
1636
  return PShader.LINE;
1587
- else if (PApplet.match(line, lineShaderInRegexp) != null)
1637
+ } else if (PApplet.match(line, lineShaderInRegexp) != null) {
1588
1638
  return PShader.LINE;
1639
+ }
1589
1640
  }
1590
1641
  return defaultType;
1591
1642
  }
1592
1643
 
1593
-
1594
1644
  // ***************************************************************************
1595
1645
  //
1596
1646
  // Processing specific
1597
-
1598
- /**
1599
- *
1600
- * @return
1601
- */
1602
-
1603
-
1647
+ /**
1648
+ *
1649
+ * @return
1650
+ */
1604
1651
  protected int getType() {
1605
1652
  return type;
1606
1653
  }
1607
1654
 
1608
- /**
1609
- *
1610
- * @param type
1611
- */
1612
- protected void setType(int type) {
1655
+ /**
1656
+ *
1657
+ * @param type
1658
+ */
1659
+ protected void setType(int type) {
1613
1660
  this.type = type;
1614
1661
  }
1615
1662
 
1616
- /**
1617
- *
1618
- * @return
1619
- */
1620
- protected boolean hasType() {
1663
+ /**
1664
+ *
1665
+ * @return
1666
+ */
1667
+ protected boolean hasType() {
1621
1668
  return POINT <= type && type <= TEXLIGHT;
1622
1669
  }
1623
1670
 
1624
- /**
1625
- *
1626
- * @return
1627
- */
1628
- protected boolean isPointShader() {
1671
+ /**
1672
+ *
1673
+ * @return
1674
+ */
1675
+ protected boolean isPointShader() {
1629
1676
  return type == POINT;
1630
1677
  }
1631
1678
 
1632
- /**
1633
- *
1634
- * @return
1635
- */
1636
- protected boolean isLineShader() {
1679
+ /**
1680
+ *
1681
+ * @return
1682
+ */
1683
+ protected boolean isLineShader() {
1637
1684
  return type == LINE;
1638
1685
  }
1639
1686
 
1640
- /**
1641
- *
1642
- * @return
1643
- */
1644
- protected boolean isPolyShader() {
1687
+ /**
1688
+ *
1689
+ * @return
1690
+ */
1691
+ protected boolean isPolyShader() {
1645
1692
  return POLY <= type && type <= TEXLIGHT;
1646
1693
  }
1647
1694
 
1648
- /**
1649
- *
1650
- * @param type
1651
- * @return
1652
- */
1653
- protected boolean checkPolyType(int type) {
1654
- if (getType() == PShader.POLY) return true;
1695
+ /**
1696
+ *
1697
+ * @param type
1698
+ * @return
1699
+ */
1700
+ protected boolean checkPolyType(int type) {
1701
+ if (getType() == PShader.POLY) {
1702
+ return true;
1703
+ }
1655
1704
 
1656
1705
  if (getType() != type) {
1657
- if (type == TEXLIGHT) {
1658
- PGraphics.showWarning(PGraphicsOpenGL.NO_TEXLIGHT_SHADER_ERROR);
1659
- } else if (type == LIGHT) {
1660
- PGraphics.showWarning(PGraphicsOpenGL.NO_LIGHT_SHADER_ERROR);
1661
- } else if (type == TEXTURE) {
1662
- PGraphics.showWarning(PGraphicsOpenGL.NO_TEXTURE_SHADER_ERROR);
1663
- } else if (type == COLOR) {
1664
- PGraphics.showWarning(PGraphicsOpenGL.NO_COLOR_SHADER_ERROR);
1706
+ switch (type) {
1707
+ case TEXLIGHT:
1708
+ PGraphics.showWarning(PGraphicsOpenGL.NO_TEXLIGHT_SHADER_ERROR);
1709
+ break;
1710
+ case LIGHT:
1711
+ PGraphics.showWarning(PGraphicsOpenGL.NO_LIGHT_SHADER_ERROR);
1712
+ break;
1713
+ case TEXTURE:
1714
+ PGraphics.showWarning(PGraphicsOpenGL.NO_TEXTURE_SHADER_ERROR);
1715
+ break;
1716
+ case COLOR:
1717
+ PGraphics.showWarning(PGraphicsOpenGL.NO_COLOR_SHADER_ERROR);
1718
+ break;
1719
+ default:
1720
+ break;
1665
1721
  }
1666
1722
  return false;
1667
1723
  }
@@ -1669,30 +1725,34 @@ public class PShader implements PConstants {
1669
1725
  return true;
1670
1726
  }
1671
1727
 
1672
- /**
1673
- *
1674
- * @return
1675
- */
1676
- protected int getLastTexUnit() {
1728
+ /**
1729
+ *
1730
+ * @return
1731
+ */
1732
+ protected int getLastTexUnit() {
1677
1733
  return texUnits == null ? -1 : texUnits.size() - 1;
1678
1734
  }
1679
1735
 
1680
- /**
1681
- *
1682
- * @param pg
1683
- */
1684
- protected void setRenderer(PGraphicsOpenGL pg) {
1736
+ /**
1737
+ *
1738
+ * @param pg
1739
+ */
1740
+ protected void setRenderer(PGraphicsOpenGL pg) {
1685
1741
  this.currentPG = pg;
1686
1742
  }
1687
1743
 
1688
- /**
1689
- *
1690
- */
1691
- protected void loadAttributes() {
1692
- if (loadedAttributes) return;
1744
+ /**
1745
+ *
1746
+ */
1747
+ protected void loadAttributes() {
1748
+ if (loadedAttributes) {
1749
+ return;
1750
+ }
1693
1751
 
1694
1752
  vertexLoc = getAttributeLoc("vertex");
1695
- if (vertexLoc == -1) vertexLoc = getAttributeLoc("position");
1753
+ if (vertexLoc == -1) {
1754
+ vertexLoc = getAttributeLoc("position");
1755
+ }
1696
1756
 
1697
1757
  colorLoc = getAttributeLoc("color");
1698
1758
  texCoordLoc = getAttributeLoc("texCoord");
@@ -1713,22 +1773,27 @@ public class PShader implements PConstants {
1713
1773
  loadedAttributes = true;
1714
1774
  }
1715
1775
 
1716
- /**
1717
- *
1718
- */
1719
- protected void loadUniforms() {
1720
- if (loadedUniforms) return;
1776
+ /**
1777
+ *
1778
+ */
1779
+ protected void loadUniforms() {
1780
+ if (loadedUniforms) {
1781
+ return;
1782
+ }
1721
1783
  transformMatLoc = getUniformLoc("transform");
1722
- if (transformMatLoc == -1)
1784
+ if (transformMatLoc == -1) {
1723
1785
  transformMatLoc = getUniformLoc("transformMatrix");
1786
+ }
1724
1787
 
1725
1788
  modelviewMatLoc = getUniformLoc("modelview");
1726
- if (modelviewMatLoc == -1)
1789
+ if (modelviewMatLoc == -1) {
1727
1790
  modelviewMatLoc = getUniformLoc("modelviewMatrix");
1791
+ }
1728
1792
 
1729
1793
  projectionMatLoc = getUniformLoc("projection");
1730
- if (projectionMatLoc == -1)
1794
+ if (projectionMatLoc == -1) {
1731
1795
  projectionMatLoc = getUniformLoc("projectionMatrix");
1796
+ }
1732
1797
 
1733
1798
  viewportLoc = getUniformLoc("viewport");
1734
1799
  resolutionLoc = getUniformLoc("resolution");
@@ -1758,10 +1823,10 @@ public class PShader implements PConstants {
1758
1823
  loadedUniforms = true;
1759
1824
  }
1760
1825
 
1761
- /**
1762
- *
1763
- */
1764
- protected void setCommonUniforms() {
1826
+ /**
1827
+ *
1828
+ */
1829
+ protected void setCommonUniforms() {
1765
1830
  if (-1 < transformMatLoc) {
1766
1831
  currentPG.updateGLProjmodelview();
1767
1832
  setUniformMatrix(transformMatLoc, currentPG.glProjmodelview);
@@ -1801,10 +1866,10 @@ public class PShader implements PConstants {
1801
1866
  }
1802
1867
  }
1803
1868
 
1804
- /**
1805
- *
1806
- */
1807
- protected void bindTyped() {
1869
+ /**
1870
+ *
1871
+ */
1872
+ protected void bindTyped() {
1808
1873
  if (currentPG == null) {
1809
1874
  setRenderer(primaryPG.getCurrentPG());
1810
1875
  loadAttributes();
@@ -1812,20 +1877,36 @@ public class PShader implements PConstants {
1812
1877
  }
1813
1878
  setCommonUniforms();
1814
1879
 
1815
- if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
1816
- if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
1817
- if (-1 < texCoordLoc) pgl.enableVertexAttribArray(texCoordLoc);
1818
- if (-1 < normalLoc) pgl.enableVertexAttribArray(normalLoc);
1880
+ if (-1 < vertexLoc) {
1881
+ pgl.enableVertexAttribArray(vertexLoc);
1882
+ }
1883
+ if (-1 < colorLoc) {
1884
+ pgl.enableVertexAttribArray(colorLoc);
1885
+ }
1886
+ if (-1 < texCoordLoc) {
1887
+ pgl.enableVertexAttribArray(texCoordLoc);
1888
+ }
1889
+ if (-1 < normalLoc) {
1890
+ pgl.enableVertexAttribArray(normalLoc);
1891
+ }
1819
1892
 
1820
1893
  if (-1 < normalMatLoc) {
1821
1894
  currentPG.updateGLNormal();
1822
1895
  setUniformMatrix(normalMatLoc, currentPG.glNormal);
1823
1896
  }
1824
1897
 
1825
- if (-1 < ambientLoc) pgl.enableVertexAttribArray(ambientLoc);
1826
- if (-1 < specularLoc) pgl.enableVertexAttribArray(specularLoc);
1827
- if (-1 < emissiveLoc) pgl.enableVertexAttribArray(emissiveLoc);
1828
- if (-1 < shininessLoc) pgl.enableVertexAttribArray(shininessLoc);
1898
+ if (-1 < ambientLoc) {
1899
+ pgl.enableVertexAttribArray(ambientLoc);
1900
+ }
1901
+ if (-1 < specularLoc) {
1902
+ pgl.enableVertexAttribArray(specularLoc);
1903
+ }
1904
+ if (-1 < emissiveLoc) {
1905
+ pgl.enableVertexAttribArray(emissiveLoc);
1906
+ }
1907
+ if (-1 < shininessLoc) {
1908
+ pgl.enableVertexAttribArray(shininessLoc);
1909
+ }
1829
1910
 
1830
1911
  int count = currentPG.lightCount;
1831
1912
  setUniformValue(lightCountLoc, count);
@@ -1836,17 +1917,21 @@ public class PShader implements PConstants {
1836
1917
  setUniformVector(lightDiffuseLoc, currentPG.lightDiffuse, 3, count);
1837
1918
  setUniformVector(lightSpecularLoc, currentPG.lightSpecular, 3, count);
1838
1919
  setUniformVector(lightFalloffLoc, currentPG.lightFalloffCoefficients,
1839
- 3, count);
1920
+ 3, count);
1840
1921
  setUniformVector(lightSpotLoc, currentPG.lightSpotParameters, 2, count);
1841
1922
  }
1842
1923
 
1843
- if (-1 < directionLoc) pgl.enableVertexAttribArray(directionLoc);
1924
+ if (-1 < directionLoc) {
1925
+ pgl.enableVertexAttribArray(directionLoc);
1926
+ }
1844
1927
 
1845
- if (-1 < offsetLoc) pgl.enableVertexAttribArray(offsetLoc);
1928
+ if (-1 < offsetLoc) {
1929
+ pgl.enableVertexAttribArray(offsetLoc);
1930
+ }
1846
1931
 
1847
1932
  if (-1 < perspectiveLoc) {
1848
- if (currentPG.getHint(ENABLE_STROKE_PERSPECTIVE) &&
1849
- currentPG.nonOrthoProjection()) {
1933
+ if (currentPG.getHint(ENABLE_STROKE_PERSPECTIVE)
1934
+ && currentPG.nonOrthoProjection()) {
1850
1935
  setUniformValue(perspectiveLoc, 1);
1851
1936
  } else {
1852
1937
  setUniformValue(perspectiveLoc, 0);
@@ -1867,13 +1952,17 @@ public class PShader implements PConstants {
1867
1952
  }
1868
1953
  }
1869
1954
 
1870
- /**
1871
- *
1872
- */
1873
- protected void unbindTyped() {
1874
- if (-1 < offsetLoc) pgl.disableVertexAttribArray(offsetLoc);
1955
+ /**
1956
+ *
1957
+ */
1958
+ protected void unbindTyped() {
1959
+ if (-1 < offsetLoc) {
1960
+ pgl.disableVertexAttribArray(offsetLoc);
1961
+ }
1875
1962
 
1876
- if (-1 < directionLoc) pgl.disableVertexAttribArray(directionLoc);
1963
+ if (-1 < directionLoc) {
1964
+ pgl.disableVertexAttribArray(directionLoc);
1965
+ }
1877
1966
 
1878
1967
  if (-1 < textureLoc && texture != null) {
1879
1968
  pgl.activeTexture(PGL.TEXTURE0 + texUnit);
@@ -1882,15 +1971,31 @@ public class PShader implements PConstants {
1882
1971
  texture = null;
1883
1972
  }
1884
1973
 
1885
- if (-1 < ambientLoc) pgl.disableVertexAttribArray(ambientLoc);
1886
- if (-1 < specularLoc) pgl.disableVertexAttribArray(specularLoc);
1887
- if (-1 < emissiveLoc) pgl.disableVertexAttribArray(emissiveLoc);
1888
- if (-1 < shininessLoc) pgl.disableVertexAttribArray(shininessLoc);
1974
+ if (-1 < ambientLoc) {
1975
+ pgl.disableVertexAttribArray(ambientLoc);
1976
+ }
1977
+ if (-1 < specularLoc) {
1978
+ pgl.disableVertexAttribArray(specularLoc);
1979
+ }
1980
+ if (-1 < emissiveLoc) {
1981
+ pgl.disableVertexAttribArray(emissiveLoc);
1982
+ }
1983
+ if (-1 < shininessLoc) {
1984
+ pgl.disableVertexAttribArray(shininessLoc);
1985
+ }
1889
1986
 
1890
- if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
1891
- if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
1892
- if (-1 < texCoordLoc) pgl.disableVertexAttribArray(texCoordLoc);
1893
- if (-1 < normalLoc) pgl.disableVertexAttribArray(normalLoc);
1987
+ if (-1 < vertexLoc) {
1988
+ pgl.disableVertexAttribArray(vertexLoc);
1989
+ }
1990
+ if (-1 < colorLoc) {
1991
+ pgl.disableVertexAttribArray(colorLoc);
1992
+ }
1993
+ if (-1 < texCoordLoc) {
1994
+ pgl.disableVertexAttribArray(texCoordLoc);
1995
+ }
1996
+ if (-1 < normalLoc) {
1997
+ pgl.disableVertexAttribArray(normalLoc);
1998
+ }
1894
1999
 
1895
2000
  if (-1 < ppixelsLoc) {
1896
2001
  pgl.enableFBOLayer();
@@ -1902,38 +2007,38 @@ public class PShader implements PConstants {
1902
2007
  pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
1903
2008
  }
1904
2009
 
1905
- /**
1906
- *
1907
- * @param tex
1908
- */
1909
- protected void setTexture(Texture tex) {
2010
+ /**
2011
+ *
2012
+ * @param tex
2013
+ */
2014
+ protected void setTexture(Texture tex) {
1910
2015
  texture = tex;
1911
2016
 
1912
2017
  float scaleu = 1;
1913
2018
  float scalev = 1;
1914
- float dispu = 0;
1915
- float dispv = 0;
2019
+ float dispu = 0;
2020
+ float dispv = 0;
1916
2021
 
1917
2022
  if (tex != null) {
1918
2023
  if (tex.invertedX()) {
1919
2024
  scaleu = -1;
1920
- dispu = 1;
2025
+ dispu = 1;
1921
2026
  }
1922
2027
 
1923
2028
  if (tex.invertedY()) {
1924
2029
  scalev = -1;
1925
- dispv = 1;
2030
+ dispv = 1;
1926
2031
  }
1927
2032
 
1928
2033
  scaleu *= tex.maxTexcoordU();
1929
- dispu *= tex.maxTexcoordU();
2034
+ dispu *= tex.maxTexcoordU();
1930
2035
  scalev *= tex.maxTexcoordV();
1931
- dispv *= tex.maxTexcoordV();
2036
+ dispv *= tex.maxTexcoordV();
1932
2037
 
1933
2038
  setUniformValue(texOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
1934
2039
 
1935
2040
  if (-1 < textureLoc) {
1936
- texUnit = -1 < ppixelsUnit ? ppixelsUnit + 1 : getLastTexUnit() + 1;
2041
+ texUnit = -1 < ppixelsUnit ? ppixelsUnit + 1 : getLastTexUnit() + 1;
1937
2042
  setUniformValue(textureLoc, texUnit);
1938
2043
  pgl.activeTexture(PGL.TEXTURE0 + texUnit);
1939
2044
  tex.bind();
@@ -1944,214 +2049,225 @@ public class PShader implements PConstants {
1944
2049
  if (tcmat == null) {
1945
2050
  tcmat = new float[16];
1946
2051
  }
1947
- tcmat[0] = scaleu; tcmat[4] = 0; tcmat[ 8] = 0; tcmat[12] = dispu;
1948
- tcmat[1] = 0; tcmat[5] = scalev; tcmat[ 9] = 0; tcmat[13] = dispv;
1949
- tcmat[2] = 0; tcmat[6] = 0; tcmat[10] = 0; tcmat[14] = 0;
1950
- tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0;
2052
+ tcmat[0] = scaleu;
2053
+ tcmat[4] = 0;
2054
+ tcmat[8] = 0;
2055
+ tcmat[12] = dispu;
2056
+ tcmat[1] = 0;
2057
+ tcmat[5] = scalev;
2058
+ tcmat[9] = 0;
2059
+ tcmat[13] = dispv;
2060
+ tcmat[2] = 0;
2061
+ tcmat[6] = 0;
2062
+ tcmat[10] = 0;
2063
+ tcmat[14] = 0;
2064
+ tcmat[3] = 0;
2065
+ tcmat[7] = 0;
2066
+ tcmat[11] = 0;
2067
+ tcmat[15] = 0;
1951
2068
  setUniformMatrix(texMatrixLoc, tcmat);
1952
2069
  }
1953
2070
  }
1954
2071
 
1955
- /**
1956
- *
1957
- * @return
1958
- */
1959
- protected boolean supportsTexturing() {
2072
+ /**
2073
+ *
2074
+ * @return
2075
+ */
2076
+ protected boolean supportsTexturing() {
1960
2077
  return -1 < textureLoc;
1961
2078
  }
1962
2079
 
1963
- /**
1964
- *
1965
- * @return
1966
- */
1967
- protected boolean supportLighting() {
2080
+ /**
2081
+ *
2082
+ * @return
2083
+ */
2084
+ protected boolean supportLighting() {
1968
2085
  return -1 < lightCountLoc || -1 < lightPositionLoc || -1 < lightNormalLoc;
1969
2086
  }
1970
2087
 
1971
- /**
1972
- *
1973
- * @return
1974
- */
1975
- protected boolean accessTexCoords() {
2088
+ /**
2089
+ *
2090
+ * @return
2091
+ */
2092
+ protected boolean accessTexCoords() {
1976
2093
  return -1 < texCoordLoc;
1977
2094
  }
1978
2095
 
1979
- /**
1980
- *
1981
- * @return
1982
- */
1983
- protected boolean accessNormals() {
2096
+ /**
2097
+ *
2098
+ * @return
2099
+ */
2100
+ protected boolean accessNormals() {
1984
2101
  return -1 < normalLoc;
1985
2102
  }
1986
2103
 
1987
- /**
1988
- *
1989
- * @return
1990
- */
1991
- protected boolean accessLightAttribs() {
1992
- return -1 < ambientLoc || -1 < specularLoc || -1 < emissiveLoc ||
1993
- -1 < shininessLoc;
1994
- }
1995
-
1996
- /**
1997
- *
1998
- * @param vboId
1999
- * @param size
2000
- * @param type
2001
- * @param stride
2002
- * @param offset
2003
- */
2004
- protected void setVertexAttribute(int vboId, int size, int type,
2005
- int stride, int offset) {
2104
+ /**
2105
+ *
2106
+ * @return
2107
+ */
2108
+ protected boolean accessLightAttribs() {
2109
+ return -1 < ambientLoc || -1 < specularLoc || -1 < emissiveLoc
2110
+ || -1 < shininessLoc;
2111
+ }
2112
+
2113
+ /**
2114
+ *
2115
+ * @param vboId
2116
+ * @param size
2117
+ * @param type
2118
+ * @param stride
2119
+ * @param offset
2120
+ */
2121
+ protected void setVertexAttribute(int vboId, int size, int type,
2122
+ int stride, int offset) {
2006
2123
  setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset);
2007
2124
  }
2008
2125
 
2009
- /**
2010
- *
2011
- * @param vboId
2012
- * @param size
2013
- * @param type
2014
- * @param stride
2015
- * @param offset
2016
- */
2017
- protected void setColorAttribute(int vboId, int size, int type,
2018
- int stride, int offset) {
2126
+ /**
2127
+ *
2128
+ * @param vboId
2129
+ * @param size
2130
+ * @param type
2131
+ * @param stride
2132
+ * @param offset
2133
+ */
2134
+ protected void setColorAttribute(int vboId, int size, int type,
2135
+ int stride, int offset) {
2019
2136
  setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset);
2020
2137
  }
2021
2138
 
2022
- /**
2023
- *
2024
- * @param vboId
2025
- * @param size
2026
- * @param type
2027
- * @param stride
2028
- * @param offset
2029
- */
2030
- protected void setNormalAttribute(int vboId, int size, int type,
2031
- int stride, int offset) {
2139
+ /**
2140
+ *
2141
+ * @param vboId
2142
+ * @param size
2143
+ * @param type
2144
+ * @param stride
2145
+ * @param offset
2146
+ */
2147
+ protected void setNormalAttribute(int vboId, int size, int type,
2148
+ int stride, int offset) {
2032
2149
  setAttributeVBO(normalLoc, vboId, size, type, false, stride, offset);
2033
2150
  }
2034
2151
 
2035
- /**
2036
- *
2037
- * @param vboId
2038
- * @param size
2039
- * @param type
2040
- * @param stride
2041
- * @param offset
2042
- */
2043
- protected void setTexcoordAttribute(int vboId, int size, int type,
2044
- int stride, int offset) {
2152
+ /**
2153
+ *
2154
+ * @param vboId
2155
+ * @param size
2156
+ * @param type
2157
+ * @param stride
2158
+ * @param offset
2159
+ */
2160
+ protected void setTexcoordAttribute(int vboId, int size, int type,
2161
+ int stride, int offset) {
2045
2162
  setAttributeVBO(texCoordLoc, vboId, size, type, false, stride, offset);
2046
2163
  }
2047
2164
 
2048
- /**
2049
- *
2050
- * @param vboId
2051
- * @param size
2052
- * @param type
2053
- * @param stride
2054
- * @param offset
2055
- */
2056
- protected void setAmbientAttribute(int vboId, int size, int type,
2057
- int stride, int offset) {
2165
+ /**
2166
+ *
2167
+ * @param vboId
2168
+ * @param size
2169
+ * @param type
2170
+ * @param stride
2171
+ * @param offset
2172
+ */
2173
+ protected void setAmbientAttribute(int vboId, int size, int type,
2174
+ int stride, int offset) {
2058
2175
  setAttributeVBO(ambientLoc, vboId, size, type, true, stride, offset);
2059
2176
  }
2060
2177
 
2061
- /**
2062
- *
2063
- * @param vboId
2064
- * @param size
2065
- * @param type
2066
- * @param stride
2067
- * @param offset
2068
- */
2069
- protected void setSpecularAttribute(int vboId, int size, int type,
2070
- int stride, int offset) {
2178
+ /**
2179
+ *
2180
+ * @param vboId
2181
+ * @param size
2182
+ * @param type
2183
+ * @param stride
2184
+ * @param offset
2185
+ */
2186
+ protected void setSpecularAttribute(int vboId, int size, int type,
2187
+ int stride, int offset) {
2071
2188
  setAttributeVBO(specularLoc, vboId, size, type, true, stride, offset);
2072
2189
  }
2073
2190
 
2074
- /**
2075
- *
2076
- * @param vboId
2077
- * @param size
2078
- * @param type
2079
- * @param stride
2080
- * @param offset
2081
- */
2082
- protected void setEmissiveAttribute(int vboId, int size, int type,
2083
- int stride, int offset) {
2191
+ /**
2192
+ *
2193
+ * @param vboId
2194
+ * @param size
2195
+ * @param type
2196
+ * @param stride
2197
+ * @param offset
2198
+ */
2199
+ protected void setEmissiveAttribute(int vboId, int size, int type,
2200
+ int stride, int offset) {
2084
2201
  setAttributeVBO(emissiveLoc, vboId, size, type, true, stride, offset);
2085
2202
  }
2086
2203
 
2087
- /**
2088
- *
2089
- * @param vboId
2090
- * @param size
2091
- * @param type
2092
- * @param stride
2093
- * @param offset
2094
- */
2095
- protected void setShininessAttribute(int vboId, int size, int type,
2096
- int stride, int offset) {
2204
+ /**
2205
+ *
2206
+ * @param vboId
2207
+ * @param size
2208
+ * @param type
2209
+ * @param stride
2210
+ * @param offset
2211
+ */
2212
+ protected void setShininessAttribute(int vboId, int size, int type,
2213
+ int stride, int offset) {
2097
2214
  setAttributeVBO(shininessLoc, vboId, size, type, false, stride, offset);
2098
2215
  }
2099
2216
 
2100
- /**
2101
- *
2102
- * @param vboId
2103
- * @param size
2104
- * @param type
2105
- * @param stride
2106
- * @param offset
2107
- */
2108
- protected void setLineAttribute(int vboId, int size, int type,
2109
- int stride, int offset) {
2217
+ /**
2218
+ *
2219
+ * @param vboId
2220
+ * @param size
2221
+ * @param type
2222
+ * @param stride
2223
+ * @param offset
2224
+ */
2225
+ protected void setLineAttribute(int vboId, int size, int type,
2226
+ int stride, int offset) {
2110
2227
  setAttributeVBO(directionLoc, vboId, size, type, false, stride, offset);
2111
2228
  }
2112
2229
 
2113
- /**
2114
- *
2115
- * @param vboId
2116
- * @param size
2117
- * @param type
2118
- * @param stride
2119
- * @param offset
2120
- */
2121
- protected void setPointAttribute(int vboId, int size, int type,
2122
- int stride, int offset) {
2230
+ /**
2231
+ *
2232
+ * @param vboId
2233
+ * @param size
2234
+ * @param type
2235
+ * @param stride
2236
+ * @param offset
2237
+ */
2238
+ protected void setPointAttribute(int vboId, int size, int type,
2239
+ int stride, int offset) {
2123
2240
  setAttributeVBO(offsetLoc, vboId, size, type, false, stride, offset);
2124
2241
  }
2125
2242
 
2126
-
2127
2243
  // ***************************************************************************
2128
2244
  //
2129
2245
  // Class to store a user-specified value for a uniform parameter
2130
2246
  // in the shader
2131
-
2132
- /**
2133
- *
2134
- */
2247
+ /**
2248
+ *
2249
+ */
2135
2250
  protected static class UniformValue {
2136
- static final int INT1 = 0;
2137
- static final int INT2 = 1;
2138
- static final int INT3 = 2;
2139
- static final int INT4 = 3;
2140
- static final int FLOAT1 = 4;
2141
- static final int FLOAT2 = 5;
2142
- static final int FLOAT3 = 6;
2143
- static final int FLOAT4 = 7;
2144
- static final int INT1VEC = 8;
2145
- static final int INT2VEC = 9;
2146
- static final int INT3VEC = 10;
2147
- static final int INT4VEC = 11;
2251
+
2252
+ static final int INT1 = 0;
2253
+ static final int INT2 = 1;
2254
+ static final int INT3 = 2;
2255
+ static final int INT4 = 3;
2256
+ static final int FLOAT1 = 4;
2257
+ static final int FLOAT2 = 5;
2258
+ static final int FLOAT3 = 6;
2259
+ static final int FLOAT4 = 7;
2260
+ static final int INT1VEC = 8;
2261
+ static final int INT2VEC = 9;
2262
+ static final int INT3VEC = 10;
2263
+ static final int INT4VEC = 11;
2148
2264
  static final int FLOAT1VEC = 12;
2149
2265
  static final int FLOAT2VEC = 13;
2150
2266
  static final int FLOAT3VEC = 14;
2151
2267
  static final int FLOAT4VEC = 15;
2152
- static final int MAT2 = 16;
2153
- static final int MAT3 = 17;
2154
- static final int MAT4 = 18;
2268
+ static final int MAT2 = 16;
2269
+ static final int MAT3 = 17;
2270
+ static final int MAT4 = 18;
2155
2271
  static final int SAMPLER2D = 19;
2156
2272
 
2157
2273
  int type;