propane 3.4.2-java → 3.5.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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +5 -1
  5. data/Gemfile +2 -0
  6. data/README.md +15 -3
  7. data/Rakefile +9 -10
  8. data/bin/propane +3 -1
  9. data/lib/propane.rb +2 -1
  10. data/lib/propane/app.rb +2 -1
  11. data/lib/propane/creators/sketch_class.rb +7 -1
  12. data/lib/propane/creators/sketch_factory.rb +4 -2
  13. data/lib/propane/creators/sketch_writer.rb +1 -0
  14. data/lib/propane/helper_methods.rb +22 -22
  15. data/lib/propane/helpers/numeric.rb +2 -0
  16. data/lib/propane/helpers/version_error.rb +1 -0
  17. data/lib/propane/library.rb +5 -1
  18. data/lib/propane/library_loader.rb +2 -0
  19. data/lib/propane/native_folder.rb +10 -9
  20. data/lib/propane/native_loader.rb +3 -0
  21. data/lib/propane/runner.rb +11 -5
  22. data/lib/propane/version.rb +2 -1
  23. data/library/boids/boids.rb +21 -11
  24. data/library/color_group/color_group.rb +2 -0
  25. data/library/control_panel/control_panel.rb +8 -5
  26. data/library/dxf/dxf.rb +2 -0
  27. data/library/file_chooser/chooser.rb +10 -9
  28. data/library/file_chooser/file_chooser.rb +10 -9
  29. data/library/library_proxy/library_proxy.rb +2 -0
  30. data/library/net/net.rb +2 -0
  31. data/library/simplex_noise/simplex_noise.rb +2 -0
  32. data/library/slider/slider.rb +23 -22
  33. data/library/vector_utils/vector_utils.rb +4 -0
  34. data/library/video_event/video_event.rb +2 -0
  35. data/pom.rb +46 -45
  36. data/pom.xml +4 -4
  37. data/propane.gemspec +8 -7
  38. data/src/main/java/monkstone/ColorUtil.java +1 -3
  39. data/src/main/java/monkstone/MathToolModule.java +1 -1
  40. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  41. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  42. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  43. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  44. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  45. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  46. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  47. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  48. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  49. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  50. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  51. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  52. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  53. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
  54. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  55. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  56. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  57. data/src/main/java/processing/awt/PGraphicsJava2D.java +788 -283
  58. data/src/main/java/processing/awt/PImageAWT.java +260 -0
  59. data/src/main/java/processing/awt/PShapeJava2D.java +56 -53
  60. data/src/main/java/processing/awt/PSurfaceAWT.java +309 -211
  61. data/src/main/java/processing/awt/ShimAWT.java +580 -0
  62. data/src/main/java/processing/core/PApplet.java +2877 -2098
  63. data/src/main/java/processing/core/PConstants.java +477 -447
  64. data/src/main/java/processing/core/PFont.java +930 -884
  65. data/src/main/java/processing/core/PGraphics.java +337 -309
  66. data/src/main/java/processing/core/PImage.java +1689 -1689
  67. data/src/main/java/processing/core/PMatrix.java +172 -159
  68. data/src/main/java/processing/core/PMatrix2D.java +456 -410
  69. data/src/main/java/processing/core/PMatrix3D.java +755 -735
  70. data/src/main/java/processing/core/PShape.java +2910 -2656
  71. data/src/main/java/processing/core/PShapeOBJ.java +97 -94
  72. data/src/main/java/processing/core/PShapeSVG.java +1656 -1462
  73. data/src/main/java/processing/core/PStyle.java +40 -37
  74. data/src/main/java/processing/core/PSurface.java +134 -97
  75. data/src/main/java/processing/core/PSurfaceNone.java +292 -218
  76. data/src/main/java/processing/core/PVector.java +991 -966
  77. data/src/main/java/processing/core/ThinkDifferent.java +12 -8
  78. data/src/main/java/processing/data/DoubleDict.java +756 -710
  79. data/src/main/java/processing/data/DoubleList.java +749 -696
  80. data/src/main/java/processing/data/FloatDict.java +748 -702
  81. data/src/main/java/processing/data/FloatList.java +751 -697
  82. data/src/main/java/processing/data/IntDict.java +720 -673
  83. data/src/main/java/processing/data/IntList.java +699 -633
  84. data/src/main/java/processing/data/JSONArray.java +931 -873
  85. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  86. data/src/main/java/processing/data/JSONTokener.java +351 -341
  87. data/src/main/java/processing/data/LongDict.java +710 -663
  88. data/src/main/java/processing/data/LongList.java +701 -635
  89. data/src/main/java/processing/data/Sort.java +37 -41
  90. data/src/main/java/processing/data/StringDict.java +525 -486
  91. data/src/main/java/processing/data/StringList.java +626 -580
  92. data/src/main/java/processing/data/Table.java +3693 -3513
  93. data/src/main/java/processing/data/TableRow.java +182 -183
  94. data/src/main/java/processing/data/XML.java +954 -880
  95. data/src/main/java/processing/event/Event.java +87 -67
  96. data/src/main/java/processing/event/KeyEvent.java +48 -41
  97. data/src/main/java/processing/event/MouseEvent.java +87 -113
  98. data/src/main/java/processing/event/TouchEvent.java +10 -6
  99. data/src/main/java/processing/javafx/PSurfaceFX.java +26 -0
  100. data/src/main/java/processing/net/Client.java +20 -20
  101. data/src/main/java/processing/net/Server.java +9 -9
  102. data/src/main/java/processing/opengl/FontTexture.java +286 -266
  103. data/src/main/java/processing/opengl/FrameBuffer.java +390 -376
  104. data/src/main/java/processing/opengl/LinePath.java +130 -91
  105. data/src/main/java/processing/opengl/LineStroker.java +593 -582
  106. data/src/main/java/processing/opengl/PGL.java +645 -579
  107. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  108. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  109. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12287 -12030
  110. data/src/main/java/processing/opengl/PJOGL.java +1743 -1672
  111. data/src/main/java/processing/opengl/PShader.java +345 -416
  112. data/src/main/java/processing/opengl/PShapeOpenGL.java +4601 -4543
  113. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1113 -1029
  114. data/src/main/java/processing/opengl/Texture.java +1489 -1401
  115. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  116. data/test/create_test.rb +21 -20
  117. data/test/deglut_spec_test.rb +4 -2
  118. data/test/helper_methods_test.rb +49 -20
  119. data/test/math_tool_test.rb +39 -32
  120. data/test/native_folder.rb +47 -0
  121. data/test/respond_to_test.rb +3 -2
  122. data/test/sketches/key_event.rb +2 -2
  123. data/test/sketches/library/my_library/my_library.rb +3 -0
  124. data/test/test_helper.rb +2 -0
  125. data/test/vecmath_spec_test.rb +35 -22
  126. data/vendors/Rakefile +28 -22
  127. metadata +13 -13
  128. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  129. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  130. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  131. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,3 +1,5 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
1
3
  /*
2
4
  Part of the Processing project - http://processing.org
3
5
 
@@ -18,7 +20,8 @@
18
20
  Public License along with this library; if not, write to the
19
21
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
22
  Boston, MA 02111-1307 USA
21
- */
23
+ */
24
+
22
25
  package processing.opengl;
23
26
 
24
27
  import processing.core.*;
@@ -30,49 +33,48 @@ import java.nio.IntBuffer;
30
33
  import java.util.HashMap;
31
34
 
32
35
  /**
33
- * This class encapsulates a GLSL shader program, including a vertex and a
34
- * fragment shader. Based on the GLSLShader class from GLGraphics, which in turn
35
- * was originally based in the code by JohnG:
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:
36
39
  * http://processing.org/discourse/beta/num_1159494801.html
37
40
  *
38
41
  * @webref rendering:shaders
39
42
  */
40
43
  public class PShader implements PConstants {
41
-
42
- static protected final int POINT = 0;
43
- static protected final int LINE = 1;
44
- static protected final int POLY = 2;
45
- static protected final int COLOR = 3;
46
- static protected final int LIGHT = 4;
47
- static protected final int TEXTURE = 5;
44
+ static protected final int POINT = 0;
45
+ static protected final int LINE = 1;
46
+ static protected final int POLY = 2;
47
+ static protected final int COLOR = 3;
48
+ static protected final int LIGHT = 4;
49
+ static protected final int TEXTURE = 5;
48
50
  static protected final int TEXLIGHT = 6;
49
51
 
50
- static protected String pointShaderAttrRegexp
51
- = "attribute *vec2 *offset";
52
- static protected String pointShaderInRegexp
53
- = "in *vec2 *offset;";
54
- static protected String lineShaderAttrRegexp
55
- = "attribute *vec4 *direction";
56
- static protected String lineShaderInRegexp
57
- = "in *vec4 *direction";
58
- static protected String pointShaderDefRegexp
59
- = "#define *PROCESSING_POINT_SHADER";
60
- static protected String lineShaderDefRegexp
61
- = "#define *PROCESSING_LINE_SHADER";
62
- static protected String colorShaderDefRegexp
63
- = "#define *PROCESSING_COLOR_SHADER";
64
- static protected String lightShaderDefRegexp
65
- = "#define *PROCESSING_LIGHT_SHADER";
66
- static protected String texShaderDefRegexp
67
- = "#define *PROCESSING_TEXTURE_SHADER";
68
- static protected String texlightShaderDefRegexp
69
- = "#define *PROCESSING_TEXLIGHT_SHADER";
70
- static protected String polyShaderDefRegexp
71
- = "#define *PROCESSING_POLYGON_SHADER";
72
- static protected String triShaderAttrRegexp
73
- = "#define *PROCESSING_TRIANGLES_SHADER";
74
- static protected String quadShaderAttrRegexp
75
- = "#define *PROCESSING_QUADS_SHADER";
52
+ static protected String pointShaderAttrRegexp =
53
+ "attribute *vec2 *offset";
54
+ static protected String pointShaderInRegexp =
55
+ "in *vec2 *offset;";
56
+ static protected String lineShaderAttrRegexp =
57
+ "attribute *vec4 *direction";
58
+ static protected String lineShaderInRegexp =
59
+ "in *vec4 *direction";
60
+ static protected String pointShaderDefRegexp =
61
+ "#define *PROCESSING_POINT_SHADER";
62
+ static protected String lineShaderDefRegexp =
63
+ "#define *PROCESSING_LINE_SHADER";
64
+ static protected String colorShaderDefRegexp =
65
+ "#define *PROCESSING_COLOR_SHADER";
66
+ static protected String lightShaderDefRegexp =
67
+ "#define *PROCESSING_LIGHT_SHADER";
68
+ static protected String texShaderDefRegexp =
69
+ "#define *PROCESSING_TEXTURE_SHADER";
70
+ static protected String texlightShaderDefRegexp =
71
+ "#define *PROCESSING_TEXLIGHT_SHADER";
72
+ static protected String polyShaderDefRegexp =
73
+ "#define *PROCESSING_POLYGON_SHADER";
74
+ static protected String triShaderAttrRegexp =
75
+ "#define *PROCESSING_TRIANGLES_SHADER";
76
+ static protected String quadShaderAttrRegexp =
77
+ "#define *PROCESSING_QUADS_SHADER";
76
78
 
77
79
  protected PApplet parent;
78
80
  // The main renderer associated to the parent PApplet.
@@ -183,16 +185,19 @@ public class PShader implements PConstants {
183
185
  type = -1;
184
186
  }
185
187
 
188
+
186
189
  public PShader(PApplet parent) {
187
190
  this();
188
191
  this.parent = parent;
189
- primaryPG = (PGraphicsOpenGL) parent.g;
192
+ primaryPG = (PGraphicsOpenGL)parent.g;
190
193
  pgl = primaryPG.pgl;
191
194
  context = pgl.createEmptyContext();
192
195
  }
193
196
 
197
+
194
198
  /**
195
- * Creates a shader program using the specified vertex and fragment shaders.
199
+ * Creates a shader program using the specified vertex and fragment
200
+ * shaders.
196
201
  *
197
202
  * @param parent the parent program
198
203
  * @param vertFilename name of the vertex shader
@@ -200,7 +205,7 @@ public class PShader implements PConstants {
200
205
  */
201
206
  public PShader(PApplet parent, String vertFilename, String fragFilename) {
202
207
  this.parent = parent;
203
- primaryPG = (PGraphicsOpenGL) parent.g;
208
+ primaryPG = (PGraphicsOpenGL)parent.g;
204
209
  pgl = primaryPG.pgl;
205
210
 
206
211
  this.vertexURL = null;
@@ -225,21 +230,21 @@ public class PShader implements PConstants {
225
230
  type = fragType;
226
231
  } else if (fragType == -1) {
227
232
  type = vertType;
228
- } else if (fragType == vertType) {
233
+ } else if (fragType == vertType) {
229
234
  type = vertType;
230
235
  } else {
231
236
  PGraphics.showWarning(PGraphicsOpenGL.INCONSISTENT_SHADER_TYPES);
232
237
  }
233
238
  }
234
239
 
240
+
235
241
  /**
236
- * @param parent
237
242
  * @param vertURL network location of the vertex shader
238
243
  * @param fragURL network location of the fragment shader
239
244
  */
240
245
  public PShader(PApplet parent, URL vertURL, URL fragURL) {
241
246
  this.parent = parent;
242
- primaryPG = (PGraphicsOpenGL) parent.g;
247
+ primaryPG = (PGraphicsOpenGL)parent.g;
243
248
  pgl = primaryPG.pgl;
244
249
 
245
250
  this.vertexURL = vertURL;
@@ -264,7 +269,7 @@ public class PShader implements PConstants {
264
269
  type = fragType;
265
270
  } else if (fragType == -1) {
266
271
  type = vertType;
267
- } else if (fragType == vertType) {
272
+ } else if (fragType == vertType) {
268
273
  type = vertType;
269
274
  } else {
270
275
  PGraphics.showWarning(PGraphicsOpenGL.INCONSISTENT_SHADER_TYPES);
@@ -273,7 +278,7 @@ public class PShader implements PConstants {
273
278
 
274
279
  public PShader(PApplet parent, String[] vertSource, String[] fragSource) {
275
280
  this.parent = parent;
276
- primaryPG = (PGraphicsOpenGL) parent.g;
281
+ primaryPG = (PGraphicsOpenGL)parent.g;
277
282
  pgl = primaryPG.pgl;
278
283
 
279
284
  this.vertexURL = null;
@@ -298,32 +303,37 @@ public class PShader implements PConstants {
298
303
  type = fragType;
299
304
  } else if (fragType == -1) {
300
305
  type = vertType;
301
- } else if (fragType == vertType) {
306
+ } else if (fragType == vertType) {
302
307
  type = vertType;
303
308
  } else {
304
309
  PGraphics.showWarning(PGraphicsOpenGL.INCONSISTENT_SHADER_TYPES);
305
310
  }
306
311
  }
307
312
 
313
+
308
314
  public void setVertexShader(String vertFilename) {
309
315
  this.vertexFilename = vertFilename;
310
316
  vertexShaderSource = pgl.loadVertexShader(vertFilename);
311
317
  }
312
318
 
319
+
313
320
  public void setVertexShader(URL vertURL) {
314
321
  this.vertexURL = vertURL;
315
322
  vertexShaderSource = pgl.loadVertexShader(vertURL);
316
323
  }
317
324
 
325
+
318
326
  public void setVertexShader(String[] vertSource) {
319
327
  vertexShaderSource = vertSource;
320
328
  }
321
329
 
330
+
322
331
  public void setFragmentShader(String fragFilename) {
323
332
  this.fragmentFilename = fragFilename;
324
333
  fragmentShaderSource = pgl.loadFragmentShader(fragFilename);
325
334
  }
326
335
 
336
+
327
337
  public void setFragmentShader(URL fragURL) {
328
338
  this.fragmentURL = fragURL;
329
339
  fragmentShaderSource = pgl.loadFragmentShader(fragURL);
@@ -333,6 +343,7 @@ public class PShader implements PConstants {
333
343
  fragmentShaderSource = fragSource;
334
344
  }
335
345
 
346
+
336
347
  /**
337
348
  * Initializes (if needed) and binds the shader program.
338
349
  */
@@ -345,18 +356,15 @@ public class PShader implements PConstants {
345
356
  bindTextures();
346
357
  }
347
358
 
348
- if (hasType()) {
349
- bindTyped();
350
- }
359
+ if (hasType()) bindTyped();
351
360
  }
352
361
 
362
+
353
363
  /**
354
364
  * Unbinds the shader program.
355
365
  */
356
366
  public void unbind() {
357
- if (hasType()) {
358
- unbindTyped();
359
- }
367
+ if (hasType()) unbindTyped();
360
368
 
361
369
  if (bound) {
362
370
  unbindTextures();
@@ -365,10 +373,10 @@ public class PShader implements PConstants {
365
373
  }
366
374
  }
367
375
 
376
+
368
377
  /**
369
378
  * Returns true if the shader is bound, false otherwise.
370
- *
371
- * @return
379
+ * @return
372
380
  */
373
381
  public boolean bound() {
374
382
  return bound;
@@ -381,94 +389,88 @@ public class PShader implements PConstants {
381
389
  * @param x first component of the variable to modify
382
390
  */
383
391
  public void set(String name, int x) {
384
- setUniformImpl(name, UniformValue.INT1, new int[]{x});
392
+ setUniformImpl(name, UniformValue.INT1, new int[] { x });
385
393
  }
386
394
 
387
395
  /**
388
- * @param name
389
- * @param x
390
- * @param y second component of the variable to modify. The variable has to be
391
- * declared with an array/vector type in the shader (i.e.: int[2], vec2)
396
+ * @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)
392
397
  */
393
398
  public void set(String name, int x, int y) {
394
- setUniformImpl(name, UniformValue.INT2, new int[]{x, y});
399
+ setUniformImpl(name, UniformValue.INT2, new int[] { x, y });
395
400
  }
396
401
 
397
402
  /**
398
- * @param name
399
- * @param x
400
- * @param y
401
- * @param z third component of the variable to modify. The variable has to be
402
- * declared with an array/vector type in the shader (i.e.: int[3], vec3)
403
+ * @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)
403
404
  */
404
405
  public void set(String name, int x, int y, int z) {
405
- setUniformImpl(name, UniformValue.INT3, new int[]{x, y, z});
406
+ setUniformImpl(name, UniformValue.INT3, new int[] { x, y, z });
406
407
  }
407
408
 
408
409
  /**
409
- * @param name
410
- * @param x
411
- * @param y
412
- * @param z
413
- * @param w fourth component of the variable to modify. The variable has to be
414
- * declared with an array/vector type in the shader (i.e.: int[4], vec4)
410
+ * @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)
415
411
  */
416
412
  public void set(String name, int x, int y, int z, int w) {
417
- setUniformImpl(name, UniformValue.INT4, new int[]{x, y, z, w});
413
+ setUniformImpl(name, UniformValue.INT4, new int[] { x, y, z, w });
418
414
  }
419
415
 
416
+
420
417
  public void set(String name, float x) {
421
- setUniformImpl(name, UniformValue.FLOAT1, new float[]{x});
418
+ setUniformImpl(name, UniformValue.FLOAT1, new float[] { x });
422
419
  }
423
420
 
421
+
424
422
  public void set(String name, float x, float y) {
425
- setUniformImpl(name, UniformValue.FLOAT2, new float[]{x, y});
423
+ setUniformImpl(name, UniformValue.FLOAT2, new float[] { x, y });
426
424
  }
427
425
 
426
+
428
427
  public void set(String name, float x, float y, float z) {
429
- setUniformImpl(name, UniformValue.FLOAT3, new float[]{x, y, z});
428
+ setUniformImpl(name, UniformValue.FLOAT3, new float[] { x, y, z });
430
429
  }
431
430
 
431
+
432
432
  public void set(String name, float x, float y, float z, float w) {
433
- setUniformImpl(name, UniformValue.FLOAT4, new float[]{x, y, z, w});
433
+ setUniformImpl(name, UniformValue.FLOAT4, new float[] { x, y, z, w });
434
434
  }
435
435
 
436
436
  /**
437
- * @param name
438
- * @param vec modifies all the components of an array/vector uniform variable.
439
- * PVector can only be used if the type of the variable is vec3.
437
+ * @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.
440
438
  */
441
439
  public void set(String name, PVector vec) {
442
440
  setUniformImpl(name, UniformValue.FLOAT3,
443
- new float[]{vec.x, vec.y, vec.z});
441
+ new float[] { vec.x, vec.y, vec.z });
444
442
  }
445
443
 
444
+
446
445
  public void set(String name, boolean x) {
447
- setUniformImpl(name, UniformValue.INT1, new int[]{(x) ? 1 : 0});
446
+ setUniformImpl(name, UniformValue.INT1, new int[] { (x)?1:0 });
448
447
  }
449
448
 
449
+
450
450
  public void set(String name, boolean x, boolean y) {
451
451
  setUniformImpl(name, UniformValue.INT2,
452
- new int[]{(x) ? 1 : 0, (y) ? 1 : 0});
452
+ new int[] { (x)?1:0, (y)?1:0 });
453
453
  }
454
454
 
455
+
455
456
  public void set(String name, boolean x, boolean y, boolean z) {
456
457
  setUniformImpl(name, UniformValue.INT3,
457
- new int[]{(x) ? 1 : 0, (y) ? 1 : 0, (z) ? 1 : 0});
458
+ new int[] { (x)?1:0, (y)?1:0, (z)?1:0 });
458
459
  }
459
460
 
461
+
460
462
  public void set(String name, boolean x, boolean y, boolean z, boolean w) {
461
463
  setUniformImpl(name, UniformValue.INT4,
462
- new int[]{(x) ? 1 : 0, (y) ? 1 : 0, (z) ? 1 : 0, (w) ? 1 : 0});
464
+ new int[] { (x)?1:0, (y)?1:0, (z)?1:0, (w)?1:0 });
463
465
  }
464
466
 
467
+
465
468
  public void set(String name, int[] vec) {
466
469
  set(name, vec, 1);
467
470
  }
468
471
 
472
+
469
473
  /**
470
- * @param name
471
- * @param vec
472
474
  * @param ncoords number of coordinates per element, max 4
473
475
  */
474
476
  public void set(String name, int[] vec, int ncoords) {
@@ -481,17 +483,19 @@ public class PShader implements PConstants {
481
483
  } else if (ncoords == 4) {
482
484
  setUniformImpl(name, UniformValue.INT4VEC, vec);
483
485
  } else if (4 < ncoords) {
484
- PGraphics.showWarning("Only up to 4 coordinates per element are "
485
- + "supported.");
486
+ PGraphics.showWarning("Only up to 4 coordinates per element are " +
487
+ "supported.");
486
488
  } else {
487
489
  PGraphics.showWarning("Wrong number of coordinates: it is negative!");
488
490
  }
489
491
  }
490
492
 
493
+
491
494
  public void set(String name, float[] vec) {
492
495
  set(name, vec, 1);
493
496
  }
494
497
 
498
+
495
499
  public void set(String name, float[] vec, int ncoords) {
496
500
  if (ncoords == 1) {
497
501
  setUniformImpl(name, UniformValue.FLOAT1VEC, vec);
@@ -502,84 +506,86 @@ public class PShader implements PConstants {
502
506
  } else if (ncoords == 4) {
503
507
  setUniformImpl(name, UniformValue.FLOAT4VEC, vec);
504
508
  } else if (4 < ncoords) {
505
- PGraphics.showWarning("Only up to 4 coordinates per element are "
506
- + "supported.");
509
+ PGraphics.showWarning("Only up to 4 coordinates per element are " +
510
+ "supported.");
507
511
  } else {
508
512
  PGraphics.showWarning("Wrong number of coordinates: it is negative!");
509
513
  }
510
514
  }
511
515
 
516
+
512
517
  public void set(String name, boolean[] vec) {
513
518
  set(name, vec, 1);
514
519
  }
515
520
 
521
+
516
522
  public void set(String name, boolean[] boolvec, int ncoords) {
517
523
  int[] vec = new int[boolvec.length];
518
524
  for (int i = 0; i < boolvec.length; i++) {
519
- vec[i] = (boolvec[i]) ? 1 : 0;
525
+ vec[i] = (boolvec[i])?1:0;
520
526
  }
521
527
  set(name, vec, ncoords);
522
528
  }
523
529
 
530
+
524
531
  /**
525
- * @param name
526
532
  * @param mat matrix of values
527
533
  */
528
534
  public void set(String name, PMatrix2D mat) {
529
- float[] matv = {mat.m00, mat.m01,
530
- mat.m10, mat.m11};
535
+ float[] matv = { mat.m00, mat.m01,
536
+ mat.m10, mat.m11 };
531
537
  setUniformImpl(name, UniformValue.MAT2, matv);
532
538
  }
533
539
 
540
+
534
541
  public void set(String name, PMatrix3D mat) {
535
542
  set(name, mat, false);
536
543
  }
537
544
 
538
545
  /**
539
- * @param name
540
- * @param mat
541
546
  * @param use3x3 enforces the matrix is 3 x 3
542
547
  */
543
548
  public void set(String name, PMatrix3D mat, boolean use3x3) {
544
549
  if (use3x3) {
545
- float[] matv = {mat.m00, mat.m01, mat.m02,
546
- mat.m10, mat.m11, mat.m12,
547
- mat.m20, mat.m21, mat.m22};
550
+ float[] matv = { mat.m00, mat.m01, mat.m02,
551
+ mat.m10, mat.m11, mat.m12,
552
+ mat.m20, mat.m21, mat.m22 };
548
553
  setUniformImpl(name, UniformValue.MAT3, matv);
549
554
  } else {
550
- float[] matv = {mat.m00, mat.m01, mat.m02, mat.m03,
551
- mat.m10, mat.m11, mat.m12, mat.m13,
552
- mat.m20, mat.m21, mat.m22, mat.m23,
553
- mat.m30, mat.m31, mat.m32, mat.m33};
555
+ float[] matv = { mat.m00, mat.m01, mat.m02, mat.m03,
556
+ mat.m10, mat.m11, mat.m12, mat.m13,
557
+ mat.m20, mat.m21, mat.m22, mat.m23,
558
+ mat.m30, mat.m31, mat.m32, mat.m33 };
554
559
  setUniformImpl(name, UniformValue.MAT4, matv);
555
560
  }
556
561
  }
557
562
 
558
563
  /**
559
- * @param name
560
- * @param tex sets the sampler uniform variable to read from this image
561
- * texture
564
+ * @param tex sets the sampler uniform variable to read from this image texture
562
565
  */
563
566
  public void set(String name, PImage tex) {
564
567
  setUniformImpl(name, UniformValue.SAMPLER2D, tex);
565
568
  }
566
569
 
570
+
567
571
  /**
568
572
  * Extra initialization method that can be used by subclasses, called after
569
- * compiling and attaching the vertex and fragment shaders, and before linking
570
- * the shader program.
573
+ * compiling and attaching the vertex and fragment shaders, and before
574
+ * linking the shader program.
571
575
  *
572
576
  */
573
577
  protected void setup() {
574
578
  }
575
579
 
580
+
576
581
  protected void draw(int idxId, int count, int offset) {
577
582
  pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, idxId);
578
583
  pgl.drawElements(PGL.TRIANGLES, count, PGL.INDEX_TYPE,
579
- offset * PGL.SIZEOF_INDEX);
584
+ offset * PGL.SIZEOF_INDEX);
580
585
  pgl.bindBuffer(PGL.ELEMENT_ARRAY_BUFFER, 0);
581
586
  }
582
587
 
588
+
583
589
  /**
584
590
  * Returns the ID location of the attribute parameter given its name.
585
591
  *
@@ -591,6 +597,7 @@ public class PShader implements PConstants {
591
597
  return pgl.getAttribLocation(glProgram, name);
592
598
  }
593
599
 
600
+
594
601
  /**
595
602
  * Returns the ID location of the uniform parameter given its name.
596
603
  *
@@ -602,38 +609,44 @@ public class PShader implements PConstants {
602
609
  return pgl.getUniformLocation(glProgram, name);
603
610
  }
604
611
 
612
+
605
613
  protected void setAttributeVBO(int loc, int vboId, int size, int type,
606
- boolean normalized, int stride, int offset) {
614
+ boolean normalized, int stride, int offset) {
607
615
  if (-1 < loc) {
608
616
  pgl.bindBuffer(PGL.ARRAY_BUFFER, vboId);
609
617
  pgl.vertexAttribPointer(loc, size, type, normalized, stride, offset);
610
618
  }
611
619
  }
612
620
 
621
+
613
622
  protected void setUniformValue(int loc, int x) {
614
623
  if (-1 < loc) {
615
624
  pgl.uniform1i(loc, x);
616
625
  }
617
626
  }
618
627
 
628
+
619
629
  protected void setUniformValue(int loc, int x, int y) {
620
630
  if (-1 < loc) {
621
631
  pgl.uniform2i(loc, x, y);
622
632
  }
623
633
  }
624
634
 
635
+
625
636
  protected void setUniformValue(int loc, int x, int y, int z) {
626
637
  if (-1 < loc) {
627
638
  pgl.uniform3i(loc, x, y, z);
628
639
  }
629
640
  }
630
641
 
642
+
631
643
  protected void setUniformValue(int loc, int x, int y, int z, int w) {
632
644
  if (-1 < loc) {
633
645
  pgl.uniform4i(loc, x, y, z, w);
634
646
  }
635
647
  }
636
648
 
649
+
637
650
  protected void setUniformValue(int loc, float x) {
638
651
  if (-1 < loc) {
639
652
  pgl.uniform1f(loc, x);
@@ -646,20 +659,23 @@ public class PShader implements PConstants {
646
659
  }
647
660
  }
648
661
 
662
+
649
663
  protected void setUniformValue(int loc, float x, float y, float z) {
650
664
  if (-1 < loc) {
651
665
  pgl.uniform3f(loc, x, y, z);
652
666
  }
653
667
  }
654
668
 
669
+
655
670
  protected void setUniformValue(int loc, float x, float y, float z, float w) {
656
671
  if (-1 < loc) {
657
672
  pgl.uniform4f(loc, x, y, z, w);
658
673
  }
659
674
  }
660
675
 
676
+
661
677
  protected void setUniformVector(int loc, int[] vec, int ncoords,
662
- int length) {
678
+ int length) {
663
679
  if (-1 < loc) {
664
680
  updateIntBuffer(vec);
665
681
  switch (ncoords) {
@@ -681,8 +697,9 @@ public class PShader implements PConstants {
681
697
  }
682
698
  }
683
699
 
700
+
684
701
  protected void setUniformVector(int loc, float[] vec, int ncoords,
685
- int length) {
702
+ int length) {
686
703
  if (-1 < loc) {
687
704
  updateFloatBuffer(vec);
688
705
  switch (ncoords) {
@@ -704,6 +721,7 @@ public class PShader implements PConstants {
704
721
  }
705
722
  }
706
723
 
724
+
707
725
  protected void setUniformMatrix(int loc, float[] mat) {
708
726
  if (-1 < loc) {
709
727
  updateFloatBuffer(mat);
@@ -723,6 +741,7 @@ public class PShader implements PConstants {
723
741
  }
724
742
  }
725
743
 
744
+
726
745
  protected void setUniformTex(int loc, Texture tex) {
727
746
  if (texUnits != null) {
728
747
  Integer unit = texUnits.get(loc);
@@ -735,6 +754,7 @@ public class PShader implements PConstants {
735
754
  }
736
755
  }
737
756
 
757
+
738
758
  protected void setUniformImpl(String name, int type, Object value) {
739
759
  if (uniformValues == null) {
740
760
  uniformValues = new HashMap<>();
@@ -742,176 +762,120 @@ public class PShader implements PConstants {
742
762
  uniformValues.put(name, new UniformValue(type, value));
743
763
  }
744
764
 
765
+
745
766
  protected void consumeUniforms() {
746
767
  if (uniformValues != null && 0 < uniformValues.size()) {
747
768
  int unit = 0;
748
- for (String name : uniformValues.keySet()) {
769
+ for (String name: uniformValues.keySet()) {
749
770
  int loc = getUniformLoc(name);
750
771
  if (loc == -1) {
751
- PGraphics.showWarning("The shader doesn't have a uniform called \""
752
- + name + "\" OR the uniform was removed during "
753
- + "compilation because it was unused.");
772
+ PGraphics.showWarning("The shader doesn't have a uniform called \"" +
773
+ name + "\" OR the uniform was removed during " +
774
+ "compilation because it was unused.");
754
775
  continue;
755
776
  }
756
777
  UniformValue val = uniformValues.get(name);
757
- switch (val.type) {
758
- case UniformValue.INT1:
759
- {
760
- int[] v = ((int[]) val.value);
761
- pgl.uniform1i(loc, v[0]);
762
- break;
763
- }
764
- case UniformValue.INT2:
765
- {
766
- int[] v = ((int[]) val.value);
767
- pgl.uniform2i(loc, v[0], v[1]);
768
- break;
769
- }
770
- case UniformValue.INT3:
771
- {
772
- int[] v = ((int[]) val.value);
773
- pgl.uniform3i(loc, v[0], v[1], v[2]);
774
- break;
775
- }
776
- case UniformValue.INT4:
777
- {
778
- int[] v = ((int[]) val.value);
779
- pgl.uniform4i(loc, v[0], v[1], v[2], v[3]);
780
- break;
781
- }
782
- case UniformValue.FLOAT1:
783
- {
784
- float[] v = ((float[]) val.value);
785
- pgl.uniform1f(loc, v[0]);
786
- break;
787
- }
788
- case UniformValue.FLOAT2:
789
- {
790
- float[] v = ((float[]) val.value);
791
- pgl.uniform2f(loc, v[0], v[1]);
792
- break;
793
- }
794
- case UniformValue.FLOAT3:
795
- {
796
- float[] v = ((float[]) val.value);
797
- pgl.uniform3f(loc, v[0], v[1], v[2]);
798
- break;
799
- }
800
- case UniformValue.FLOAT4:
801
- {
802
- float[] v = ((float[]) val.value);
803
- pgl.uniform4f(loc, v[0], v[1], v[2], v[3]);
804
- break;
805
- }
806
- case UniformValue.INT1VEC:
807
- {
808
- int[] v = ((int[]) val.value);
809
- updateIntBuffer(v);
810
- pgl.uniform1iv(loc, v.length, intBuffer);
811
- break;
812
- }
813
- case UniformValue.INT2VEC:
814
- {
815
- int[] v = ((int[]) val.value);
816
- updateIntBuffer(v);
817
- pgl.uniform2iv(loc, v.length / 2, intBuffer);
818
- break;
819
- }
820
- case UniformValue.INT3VEC:
821
- {
822
- int[] v = ((int[]) val.value);
823
- updateIntBuffer(v);
824
- pgl.uniform3iv(loc, v.length / 3, intBuffer);
825
- break;
826
- }
827
- case UniformValue.INT4VEC:
828
- {
829
- int[] v = ((int[]) val.value);
830
- updateIntBuffer(v);
831
- pgl.uniform4iv(loc, v.length / 4, intBuffer);
832
- break;
833
- }
834
- case UniformValue.FLOAT1VEC:
835
- {
836
- float[] v = ((float[]) val.value);
837
- updateFloatBuffer(v);
838
- pgl.uniform1fv(loc, v.length, floatBuffer);
839
- break;
840
- }
841
- case UniformValue.FLOAT2VEC:
842
- {
843
- float[] v = ((float[]) val.value);
844
- updateFloatBuffer(v);
845
- pgl.uniform2fv(loc, v.length / 2, floatBuffer);
846
- break;
847
- }
848
- case UniformValue.FLOAT3VEC:
849
- {
850
- float[] v = ((float[]) val.value);
851
- updateFloatBuffer(v);
852
- pgl.uniform3fv(loc, v.length / 3, floatBuffer);
853
- break;
854
- }
855
- case UniformValue.FLOAT4VEC:
856
- {
857
- float[] v = ((float[]) val.value);
858
- updateFloatBuffer(v);
859
- pgl.uniform4fv(loc, v.length / 4, floatBuffer);
860
- break;
861
- }
862
- case UniformValue.MAT2:
863
- {
864
- float[] v = ((float[]) val.value);
865
- updateFloatBuffer(v);
866
- pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
867
- break;
868
- }
869
- case UniformValue.MAT3:
870
- {
871
- float[] v = ((float[]) val.value);
872
- updateFloatBuffer(v);
873
- pgl.uniformMatrix3fv(loc, 1, false, floatBuffer);
874
- break;
875
- }
876
- case UniformValue.MAT4:
877
- {
878
- float[] v = ((float[]) val.value);
879
- updateFloatBuffer(v);
880
- pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
881
- break;
882
- }
883
- case UniformValue.SAMPLER2D:
884
- PImage img = (PImage) val.value;
885
- Texture tex = currentPG.getTexture(img);
886
- if (textures == null) {
887
- textures = new HashMap<>();
888
- } textures.put(loc, tex);
889
- if (texUnits == null) {
890
- texUnits = new HashMap<>();
891
- } if (texUnits.containsKey(loc)) {
892
- unit = texUnits.get(loc);
893
- pgl.uniform1i(loc, unit);
894
- } else {
895
- texUnits.put(loc, unit);
896
- pgl.uniform1i(loc, unit);
897
- } unit++;
898
- break;
899
- default:
900
- break;
778
+ if (val.type == UniformValue.INT1) {
779
+ int[] v = ((int[])val.value);
780
+ pgl.uniform1i(loc, v[0]);
781
+ } else if (val.type == UniformValue.INT2) {
782
+ int[] v = ((int[])val.value);
783
+ pgl.uniform2i(loc, v[0], v[1]);
784
+ } else if (val.type == UniformValue.INT3) {
785
+ int[] v = ((int[])val.value);
786
+ pgl.uniform3i(loc, v[0], v[1], v[2]);
787
+ } else if (val.type == UniformValue.INT4) {
788
+ int[] v = ((int[])val.value);
789
+ pgl.uniform4i(loc, v[0], v[1], v[2], v[3]);
790
+ } else if (val.type == UniformValue.FLOAT1) {
791
+ float[] v = ((float[])val.value);
792
+ pgl.uniform1f(loc, v[0]);
793
+ } else if (val.type == UniformValue.FLOAT2) {
794
+ float[] v = ((float[])val.value);
795
+ pgl.uniform2f(loc, v[0], v[1]);
796
+ } else if (val.type == UniformValue.FLOAT3) {
797
+ float[] v = ((float[])val.value);
798
+ pgl.uniform3f(loc, v[0], v[1], v[2]);
799
+ } else if (val.type == UniformValue.FLOAT4) {
800
+ float[] v = ((float[])val.value);
801
+ pgl.uniform4f(loc, v[0], v[1], v[2], v[3]);
802
+ } else if (val.type == UniformValue.INT1VEC) {
803
+ int[] v = ((int[])val.value);
804
+ updateIntBuffer(v);
805
+ pgl.uniform1iv(loc, v.length, intBuffer);
806
+ } else if (val.type == UniformValue.INT2VEC) {
807
+ int[] v = ((int[])val.value);
808
+ updateIntBuffer(v);
809
+ pgl.uniform2iv(loc, v.length / 2, intBuffer);
810
+ } else if (val.type == UniformValue.INT3VEC) {
811
+ int[] v = ((int[])val.value);
812
+ updateIntBuffer(v);
813
+ pgl.uniform3iv(loc, v.length / 3, intBuffer);
814
+ } else if (val.type == UniformValue.INT4VEC) {
815
+ int[] v = ((int[])val.value);
816
+ updateIntBuffer(v);
817
+ pgl.uniform4iv(loc, v.length / 4, intBuffer);
818
+ } else if (val.type == UniformValue.FLOAT1VEC) {
819
+ float[] v = ((float[])val.value);
820
+ updateFloatBuffer(v);
821
+ pgl.uniform1fv(loc, v.length, floatBuffer);
822
+ } else if (val.type == UniformValue.FLOAT2VEC) {
823
+ float[] v = ((float[])val.value);
824
+ updateFloatBuffer(v);
825
+ pgl.uniform2fv(loc, v.length / 2, floatBuffer);
826
+ } else if (val.type == UniformValue.FLOAT3VEC) {
827
+ float[] v = ((float[])val.value);
828
+ updateFloatBuffer(v);
829
+ pgl.uniform3fv(loc, v.length / 3, floatBuffer);
830
+ } else if (val.type == UniformValue.FLOAT4VEC) {
831
+ float[] v = ((float[])val.value);
832
+ updateFloatBuffer(v);
833
+ pgl.uniform4fv(loc, v.length / 4, floatBuffer);
834
+ } else if (val.type == UniformValue.MAT2) {
835
+ float[] v = ((float[])val.value);
836
+ updateFloatBuffer(v);
837
+ pgl.uniformMatrix2fv(loc, 1, false, floatBuffer);
838
+ } else if (val.type == UniformValue.MAT3) {
839
+ float[] v = ((float[])val.value);
840
+ updateFloatBuffer(v);
841
+ pgl.uniformMatrix3fv(loc, 1, false, floatBuffer);
842
+ } else if (val.type == UniformValue.MAT4) {
843
+ float[] v = ((float[])val.value);
844
+ updateFloatBuffer(v);
845
+ pgl.uniformMatrix4fv(loc, 1, false, floatBuffer);
846
+ } else if (val.type == UniformValue.SAMPLER2D) {
847
+ PImage img = (PImage)val.value;
848
+ Texture tex = currentPG.getTexture(img);
849
+
850
+ if (textures == null) textures = new HashMap<>();
851
+ textures.put(loc, tex);
852
+
853
+ if (texUnits == null) texUnits = new HashMap<>();
854
+ if (texUnits.containsKey(loc)) {
855
+ unit = texUnits.get(loc);
856
+ pgl.uniform1i(loc, unit);
857
+ } else {
858
+ texUnits.put(loc, unit);
859
+ pgl.uniform1i(loc, unit);
860
+ }
861
+ unit++;
901
862
  }
902
863
  }
903
864
  uniformValues.clear();
904
865
  }
905
866
  }
906
867
 
868
+
907
869
  protected void updateIntBuffer(int[] vec) {
908
870
  intBuffer = PGL.updateIntBuffer(intBuffer, vec, false);
909
871
  }
910
872
 
873
+
911
874
  protected void updateFloatBuffer(float[] vec) {
912
875
  floatBuffer = PGL.updateFloatBuffer(floatBuffer, vec, false);
913
876
  }
914
877
 
878
+
915
879
  protected void bindTextures() {
916
880
  if (textures != null && texUnits != null) {
917
881
  textures.keySet().forEach((loc) -> {
@@ -927,6 +891,7 @@ public class PShader implements PConstants {
927
891
  }
928
892
  }
929
893
 
894
+
930
895
  protected void unbindTextures() {
931
896
  if (textures != null && texUnits != null) {
932
897
  textures.keySet().forEach((loc) -> {
@@ -943,6 +908,7 @@ public class PShader implements PConstants {
943
908
  }
944
909
  }
945
910
 
911
+
946
912
  public void init() {
947
913
  if (glProgram == 0 || contextIsOutdated()) {
948
914
  create();
@@ -959,11 +925,13 @@ public class PShader implements PConstants {
959
925
  }
960
926
  }
961
927
 
928
+
962
929
  protected void create() {
963
930
  context = pgl.getCurrentContext();
964
931
  glres = new GLResourceShader(this);
965
932
  }
966
933
 
934
+
967
935
  protected boolean compile() {
968
936
  boolean vertRes = true;
969
937
  if (hasVertexShader()) {
@@ -982,23 +950,25 @@ public class PShader implements PConstants {
982
950
  return vertRes && fragRes;
983
951
  }
984
952
 
953
+
985
954
  protected void validate() {
986
955
  pgl.getProgramiv(glProgram, PGL.LINK_STATUS, intBuffer);
987
956
  boolean linked = intBuffer.get(0) != 0;
988
957
  if (!linked) {
989
- PGraphics.showException("Cannot link shader program:\n"
990
- + pgl.getProgramInfoLog(glProgram));
958
+ PGraphics.showException("Cannot link shader program:\n" +
959
+ pgl.getProgramInfoLog(glProgram));
991
960
  }
992
961
 
993
962
  pgl.validateProgram(glProgram);
994
963
  pgl.getProgramiv(glProgram, PGL.VALIDATE_STATUS, intBuffer);
995
964
  boolean validated = intBuffer.get(0) != 0;
996
965
  if (!validated) {
997
- PGraphics.showException("Cannot validate shader program:\n"
998
- + pgl.getProgramInfoLog(glProgram));
966
+ PGraphics.showException("Cannot validate shader program:\n" +
967
+ pgl.getProgramInfoLog(glProgram));
999
968
  }
1000
969
  }
1001
970
 
971
+
1002
972
  protected boolean contextIsOutdated() {
1003
973
  boolean outdated = !pgl.contextIsCurrent(context);
1004
974
  if (outdated) {
@@ -1007,16 +977,20 @@ public class PShader implements PConstants {
1007
977
  return outdated;
1008
978
  }
1009
979
 
980
+
981
+
1010
982
  protected boolean hasVertexShader() {
1011
983
  return vertexShaderSource != null && 0 < vertexShaderSource.length;
1012
984
  }
1013
985
 
986
+
1014
987
  protected boolean hasFragmentShader() {
1015
988
  return fragmentShaderSource != null && 0 < fragmentShaderSource.length;
1016
989
  }
1017
990
 
991
+
1018
992
  /**
1019
- * @return
993
+ * @param shaderSource a string containing the shader's code
1020
994
  */
1021
995
  protected boolean compileVertexShader() {
1022
996
  pgl.shaderSource(glVertex, PApplet.join(vertexShaderSource, "\n"));
@@ -1025,14 +999,15 @@ public class PShader implements PConstants {
1025
999
  pgl.getShaderiv(glVertex, PGL.COMPILE_STATUS, intBuffer);
1026
1000
  boolean compiled = intBuffer.get(0) != 0;
1027
1001
  if (!compiled) {
1028
- PGraphics.showException("Cannot compile vertex shader:\n"
1029
- + pgl.getShaderInfoLog(glVertex));
1002
+ PGraphics.showException("Cannot compile vertex shader:\n" +
1003
+ pgl.getShaderInfoLog(glVertex));
1030
1004
  return false;
1031
1005
  } else {
1032
1006
  return true;
1033
1007
  }
1034
1008
  }
1035
1009
 
1010
+
1036
1011
  /**
1037
1012
  * @return
1038
1013
  */
@@ -1043,14 +1018,15 @@ public class PShader implements PConstants {
1043
1018
  pgl.getShaderiv(glFragment, PGL.COMPILE_STATUS, intBuffer);
1044
1019
  boolean compiled = intBuffer.get(0) != 0;
1045
1020
  if (!compiled) {
1046
- PGraphics.showException("Cannot compile fragment shader:\n"
1047
- + pgl.getShaderInfoLog(glFragment));
1021
+ PGraphics.showException("Cannot compile fragment shader:\n" +
1022
+ pgl.getShaderInfoLog(glFragment));
1048
1023
  return false;
1049
1024
  } else {
1050
1025
  return true;
1051
1026
  }
1052
1027
  }
1053
1028
 
1029
+
1054
1030
  protected void dispose() {
1055
1031
  if (glres != null) {
1056
1032
  glres.dispose();
@@ -1061,71 +1037,78 @@ public class PShader implements PConstants {
1061
1037
  }
1062
1038
  }
1063
1039
 
1040
+
1064
1041
  static protected int getShaderType(String[] source, int defaultType) {
1065
1042
  for (String source1 : source) {
1066
1043
  String line = source1.trim();
1067
- if (PApplet.match(line, colorShaderDefRegexp) != null) {
1044
+ if (PApplet.match(line, colorShaderDefRegexp) != null)
1068
1045
  return PShader.COLOR;
1069
- } else if (PApplet.match(line, lightShaderDefRegexp) != null) {
1046
+ else if (PApplet.match(line, lightShaderDefRegexp) != null)
1070
1047
  return PShader.LIGHT;
1071
- } else if (PApplet.match(line, texShaderDefRegexp) != null) {
1048
+ else if (PApplet.match(line, texShaderDefRegexp) != null)
1072
1049
  return PShader.TEXTURE;
1073
- } else if (PApplet.match(line, texlightShaderDefRegexp) != null) {
1050
+ else if (PApplet.match(line, texlightShaderDefRegexp) != null)
1074
1051
  return PShader.TEXLIGHT;
1075
- } else if (PApplet.match(line, polyShaderDefRegexp) != null) {
1052
+ else if (PApplet.match(line, polyShaderDefRegexp) != null)
1076
1053
  return PShader.POLY;
1077
- } else if (PApplet.match(line, triShaderAttrRegexp) != null) {
1054
+ else if (PApplet.match(line, triShaderAttrRegexp) != null)
1078
1055
  return PShader.POLY;
1079
- } else if (PApplet.match(line, quadShaderAttrRegexp) != null) {
1056
+ else if (PApplet.match(line, quadShaderAttrRegexp) != null)
1080
1057
  return PShader.POLY;
1081
- } else if (PApplet.match(line, pointShaderDefRegexp) != null) {
1058
+ else if (PApplet.match(line, pointShaderDefRegexp) != null)
1082
1059
  return PShader.POINT;
1083
- } else if (PApplet.match(line, lineShaderDefRegexp) != null) {
1060
+ else if (PApplet.match(line, lineShaderDefRegexp) != null)
1084
1061
  return PShader.LINE;
1085
- } else if (PApplet.match(line, pointShaderAttrRegexp) != null) {
1062
+ else if (PApplet.match(line, pointShaderAttrRegexp) != null)
1086
1063
  return PShader.POINT;
1087
- } else if (PApplet.match(line, pointShaderInRegexp) != null) {
1064
+ else if (PApplet.match(line, pointShaderInRegexp) != null)
1088
1065
  return PShader.POINT;
1089
- } else if (PApplet.match(line, lineShaderAttrRegexp) != null) {
1066
+ else if (PApplet.match(line, lineShaderAttrRegexp) != null)
1090
1067
  return PShader.LINE;
1091
- } else if (PApplet.match(line, lineShaderInRegexp) != null) {
1068
+ else if (PApplet.match(line, lineShaderInRegexp) != null)
1092
1069
  return PShader.LINE;
1093
- }
1094
1070
  }
1095
1071
  return defaultType;
1096
1072
  }
1097
1073
 
1074
+
1098
1075
  // ***************************************************************************
1099
1076
  //
1100
1077
  // Processing specific
1078
+
1079
+
1101
1080
  protected int getType() {
1102
1081
  return type;
1103
1082
  }
1104
1083
 
1084
+
1105
1085
  protected void setType(int type) {
1106
1086
  this.type = type;
1107
1087
  }
1108
1088
 
1089
+
1109
1090
  protected boolean hasType() {
1110
1091
  return POINT <= type && type <= TEXLIGHT;
1111
1092
  }
1112
1093
 
1094
+
1113
1095
  protected boolean isPointShader() {
1114
1096
  return type == POINT;
1115
1097
  }
1116
1098
 
1099
+
1117
1100
  protected boolean isLineShader() {
1118
1101
  return type == LINE;
1119
1102
  }
1120
1103
 
1104
+
1121
1105
  protected boolean isPolyShader() {
1122
1106
  return POLY <= type && type <= TEXLIGHT;
1123
1107
  }
1124
1108
 
1109
+
1125
1110
  protected boolean checkPolyType(int type) {
1126
- if (getType() == PShader.POLY) {
1127
- return true;
1128
- }
1111
+ if (getType() == PShader.POLY) return true;
1129
1112
 
1130
1113
  if (getType() != type) {
1131
1114
  switch (type) {
@@ -1150,23 +1133,22 @@ public class PShader implements PConstants {
1150
1133
  return true;
1151
1134
  }
1152
1135
 
1136
+
1153
1137
  protected int getLastTexUnit() {
1154
1138
  return texUnits == null ? -1 : texUnits.size() - 1;
1155
1139
  }
1156
1140
 
1141
+
1157
1142
  protected void setRenderer(PGraphicsOpenGL pg) {
1158
1143
  this.currentPG = pg;
1159
1144
  }
1160
1145
 
1146
+
1161
1147
  protected void loadAttributes() {
1162
- if (loadedAttributes) {
1163
- return;
1164
- }
1148
+ if (loadedAttributes) return;
1165
1149
 
1166
1150
  vertexLoc = getAttributeLoc("vertex");
1167
- if (vertexLoc == -1) {
1168
- vertexLoc = getAttributeLoc("position");
1169
- }
1151
+ if (vertexLoc == -1) vertexLoc = getAttributeLoc("position");
1170
1152
 
1171
1153
  colorLoc = getAttributeLoc("color");
1172
1154
  texCoordLoc = getAttributeLoc("texCoord");
@@ -1187,24 +1169,20 @@ public class PShader implements PConstants {
1187
1169
  loadedAttributes = true;
1188
1170
  }
1189
1171
 
1172
+
1190
1173
  protected void loadUniforms() {
1191
- if (loadedUniforms) {
1192
- return;
1193
- }
1174
+ if (loadedUniforms) return;
1194
1175
  transformMatLoc = getUniformLoc("transform");
1195
- if (transformMatLoc == -1) {
1176
+ if (transformMatLoc == -1)
1196
1177
  transformMatLoc = getUniformLoc("transformMatrix");
1197
- }
1198
1178
 
1199
1179
  modelviewMatLoc = getUniformLoc("modelview");
1200
- if (modelviewMatLoc == -1) {
1180
+ if (modelviewMatLoc == -1)
1201
1181
  modelviewMatLoc = getUniformLoc("modelviewMatrix");
1202
- }
1203
1182
 
1204
1183
  projectionMatLoc = getUniformLoc("projection");
1205
- if (projectionMatLoc == -1) {
1184
+ if (projectionMatLoc == -1)
1206
1185
  projectionMatLoc = getUniformLoc("projectionMatrix");
1207
- }
1208
1186
 
1209
1187
  viewportLoc = getUniformLoc("viewport");
1210
1188
  resolutionLoc = getUniformLoc("resolution");
@@ -1234,6 +1212,7 @@ public class PShader implements PConstants {
1234
1212
  loadedUniforms = true;
1235
1213
  }
1236
1214
 
1215
+
1237
1216
  protected void setCommonUniforms() {
1238
1217
  if (-1 < transformMatLoc) {
1239
1218
  currentPG.updateGLProjmodelview();
@@ -1274,6 +1253,7 @@ public class PShader implements PConstants {
1274
1253
  }
1275
1254
  }
1276
1255
 
1256
+
1277
1257
  protected void bindTyped() {
1278
1258
  if (currentPG == null) {
1279
1259
  setRenderer(primaryPG.getCurrentPG());
@@ -1282,36 +1262,20 @@ public class PShader implements PConstants {
1282
1262
  }
1283
1263
  setCommonUniforms();
1284
1264
 
1285
- if (-1 < vertexLoc) {
1286
- pgl.enableVertexAttribArray(vertexLoc);
1287
- }
1288
- if (-1 < colorLoc) {
1289
- pgl.enableVertexAttribArray(colorLoc);
1290
- }
1291
- if (-1 < texCoordLoc) {
1292
- pgl.enableVertexAttribArray(texCoordLoc);
1293
- }
1294
- if (-1 < normalLoc) {
1295
- pgl.enableVertexAttribArray(normalLoc);
1296
- }
1265
+ if (-1 < vertexLoc) pgl.enableVertexAttribArray(vertexLoc);
1266
+ if (-1 < colorLoc) pgl.enableVertexAttribArray(colorLoc);
1267
+ if (-1 < texCoordLoc) pgl.enableVertexAttribArray(texCoordLoc);
1268
+ if (-1 < normalLoc) pgl.enableVertexAttribArray(normalLoc);
1297
1269
 
1298
1270
  if (-1 < normalMatLoc) {
1299
1271
  currentPG.updateGLNormal();
1300
1272
  setUniformMatrix(normalMatLoc, currentPG.glNormal);
1301
1273
  }
1302
1274
 
1303
- if (-1 < ambientLoc) {
1304
- pgl.enableVertexAttribArray(ambientLoc);
1305
- }
1306
- if (-1 < specularLoc) {
1307
- pgl.enableVertexAttribArray(specularLoc);
1308
- }
1309
- if (-1 < emissiveLoc) {
1310
- pgl.enableVertexAttribArray(emissiveLoc);
1311
- }
1312
- if (-1 < shininessLoc) {
1313
- pgl.enableVertexAttribArray(shininessLoc);
1314
- }
1275
+ if (-1 < ambientLoc) pgl.enableVertexAttribArray(ambientLoc);
1276
+ if (-1 < specularLoc) pgl.enableVertexAttribArray(specularLoc);
1277
+ if (-1 < emissiveLoc) pgl.enableVertexAttribArray(emissiveLoc);
1278
+ if (-1 < shininessLoc) pgl.enableVertexAttribArray(shininessLoc);
1315
1279
 
1316
1280
  int count = currentPG.lightCount;
1317
1281
  setUniformValue(lightCountLoc, count);
@@ -1322,21 +1286,17 @@ public class PShader implements PConstants {
1322
1286
  setUniformVector(lightDiffuseLoc, currentPG.lightDiffuse, 3, count);
1323
1287
  setUniformVector(lightSpecularLoc, currentPG.lightSpecular, 3, count);
1324
1288
  setUniformVector(lightFalloffLoc, currentPG.lightFalloffCoefficients,
1325
- 3, count);
1289
+ 3, count);
1326
1290
  setUniformVector(lightSpotLoc, currentPG.lightSpotParameters, 2, count);
1327
1291
  }
1328
1292
 
1329
- if (-1 < directionLoc) {
1330
- pgl.enableVertexAttribArray(directionLoc);
1331
- }
1293
+ if (-1 < directionLoc) pgl.enableVertexAttribArray(directionLoc);
1332
1294
 
1333
- if (-1 < offsetLoc) {
1334
- pgl.enableVertexAttribArray(offsetLoc);
1335
- }
1295
+ if (-1 < offsetLoc) pgl.enableVertexAttribArray(offsetLoc);
1336
1296
 
1337
1297
  if (-1 < perspectiveLoc) {
1338
- if (currentPG.getHint(ENABLE_STROKE_PERSPECTIVE)
1339
- && currentPG.nonOrthoProjection()) {
1298
+ if (currentPG.getHint(ENABLE_STROKE_PERSPECTIVE) &&
1299
+ currentPG.nonOrthoProjection()) {
1340
1300
  setUniformValue(perspectiveLoc, 1);
1341
1301
  } else {
1342
1302
  setUniformValue(perspectiveLoc, 0);
@@ -1358,13 +1318,9 @@ public class PShader implements PConstants {
1358
1318
  }
1359
1319
 
1360
1320
  protected void unbindTyped() {
1361
- if (-1 < offsetLoc) {
1362
- pgl.disableVertexAttribArray(offsetLoc);
1363
- }
1321
+ if (-1 < offsetLoc) pgl.disableVertexAttribArray(offsetLoc);
1364
1322
 
1365
- if (-1 < directionLoc) {
1366
- pgl.disableVertexAttribArray(directionLoc);
1367
- }
1323
+ if (-1 < directionLoc) pgl.disableVertexAttribArray(directionLoc);
1368
1324
 
1369
1325
  if (-1 < textureLoc && texture != null) {
1370
1326
  pgl.activeTexture(PGL.TEXTURE0 + texUnit);
@@ -1373,31 +1329,15 @@ public class PShader implements PConstants {
1373
1329
  texture = null;
1374
1330
  }
1375
1331
 
1376
- if (-1 < ambientLoc) {
1377
- pgl.disableVertexAttribArray(ambientLoc);
1378
- }
1379
- if (-1 < specularLoc) {
1380
- pgl.disableVertexAttribArray(specularLoc);
1381
- }
1382
- if (-1 < emissiveLoc) {
1383
- pgl.disableVertexAttribArray(emissiveLoc);
1384
- }
1385
- if (-1 < shininessLoc) {
1386
- pgl.disableVertexAttribArray(shininessLoc);
1387
- }
1332
+ if (-1 < ambientLoc) pgl.disableVertexAttribArray(ambientLoc);
1333
+ if (-1 < specularLoc) pgl.disableVertexAttribArray(specularLoc);
1334
+ if (-1 < emissiveLoc) pgl.disableVertexAttribArray(emissiveLoc);
1335
+ if (-1 < shininessLoc) pgl.disableVertexAttribArray(shininessLoc);
1388
1336
 
1389
- if (-1 < vertexLoc) {
1390
- pgl.disableVertexAttribArray(vertexLoc);
1391
- }
1392
- if (-1 < colorLoc) {
1393
- pgl.disableVertexAttribArray(colorLoc);
1394
- }
1395
- if (-1 < texCoordLoc) {
1396
- pgl.disableVertexAttribArray(texCoordLoc);
1397
- }
1398
- if (-1 < normalLoc) {
1399
- pgl.disableVertexAttribArray(normalLoc);
1400
- }
1337
+ if (-1 < vertexLoc) pgl.disableVertexAttribArray(vertexLoc);
1338
+ if (-1 < colorLoc) pgl.disableVertexAttribArray(colorLoc);
1339
+ if (-1 < texCoordLoc) pgl.disableVertexAttribArray(texCoordLoc);
1340
+ if (-1 < normalLoc) pgl.disableVertexAttribArray(normalLoc);
1401
1341
 
1402
1342
  if (-1 < ppixelsLoc) {
1403
1343
  pgl.enableFBOLayer();
@@ -1414,29 +1354,29 @@ public class PShader implements PConstants {
1414
1354
 
1415
1355
  float scaleu = 1;
1416
1356
  float scalev = 1;
1417
- float dispu = 0;
1418
- float dispv = 0;
1357
+ float dispu = 0;
1358
+ float dispv = 0;
1419
1359
 
1420
1360
  if (tex != null) {
1421
1361
  if (tex.invertedX()) {
1422
1362
  scaleu = -1;
1423
- dispu = 1;
1363
+ dispu = 1;
1424
1364
  }
1425
1365
 
1426
1366
  if (tex.invertedY()) {
1427
1367
  scalev = -1;
1428
- dispv = 1;
1368
+ dispv = 1;
1429
1369
  }
1430
1370
 
1431
1371
  scaleu *= tex.maxTexcoordU();
1432
- dispu *= tex.maxTexcoordU();
1372
+ dispu *= tex.maxTexcoordU();
1433
1373
  scalev *= tex.maxTexcoordV();
1434
- dispv *= tex.maxTexcoordV();
1374
+ dispv *= tex.maxTexcoordV();
1435
1375
 
1436
1376
  setUniformValue(texOffsetLoc, 1.0f / tex.width, 1.0f / tex.height);
1437
1377
 
1438
1378
  if (-1 < textureLoc) {
1439
- texUnit = -1 < ppixelsUnit ? ppixelsUnit + 1 : getLastTexUnit() + 1;
1379
+ texUnit = -1 < ppixelsUnit ? ppixelsUnit + 1 : getLastTexUnit() + 1;
1440
1380
  setUniformValue(textureLoc, texUnit);
1441
1381
  pgl.activeTexture(PGL.TEXTURE0 + texUnit);
1442
1382
  tex.bind();
@@ -1447,26 +1387,15 @@ public class PShader implements PConstants {
1447
1387
  if (tcmat == null) {
1448
1388
  tcmat = new float[16];
1449
1389
  }
1450
- tcmat[0] = scaleu;
1451
- tcmat[4] = 0;
1452
- tcmat[8] = 0;
1453
- tcmat[12] = dispu;
1454
- tcmat[1] = 0;
1455
- tcmat[5] = scalev;
1456
- tcmat[9] = 0;
1457
- tcmat[13] = dispv;
1458
- tcmat[2] = 0;
1459
- tcmat[6] = 0;
1460
- tcmat[10] = 0;
1461
- tcmat[14] = 0;
1462
- tcmat[3] = 0;
1463
- tcmat[7] = 0;
1464
- tcmat[11] = 0;
1465
- tcmat[15] = 0;
1390
+ tcmat[0] = scaleu; tcmat[4] = 0; tcmat[ 8] = 0; tcmat[12] = dispu;
1391
+ tcmat[1] = 0; tcmat[5] = scalev; tcmat[ 9] = 0; tcmat[13] = dispv;
1392
+ tcmat[2] = 0; tcmat[6] = 0; tcmat[10] = 0; tcmat[14] = 0;
1393
+ tcmat[3] = 0; tcmat[7] = 0; tcmat[11] = 0; tcmat[15] = 0;
1466
1394
  setUniformMatrix(texMatrixLoc, tcmat);
1467
1395
  }
1468
1396
  }
1469
1397
 
1398
+
1470
1399
  protected boolean supportsTexturing() {
1471
1400
  return -1 < textureLoc;
1472
1401
  }
@@ -1484,85 +1413,85 @@ public class PShader implements PConstants {
1484
1413
  }
1485
1414
 
1486
1415
  protected boolean accessLightAttribs() {
1487
- return -1 < ambientLoc || -1 < specularLoc || -1 < emissiveLoc
1488
- || -1 < shininessLoc;
1416
+ return -1 < ambientLoc || -1 < specularLoc || -1 < emissiveLoc ||
1417
+ -1 < shininessLoc;
1489
1418
  }
1490
1419
 
1491
1420
  protected void setVertexAttribute(int vboId, int size, int type,
1492
- int stride, int offset) {
1421
+ int stride, int offset) {
1493
1422
  setAttributeVBO(vertexLoc, vboId, size, type, false, stride, offset);
1494
1423
  }
1495
1424
 
1496
1425
  protected void setColorAttribute(int vboId, int size, int type,
1497
- int stride, int offset) {
1426
+ int stride, int offset) {
1498
1427
  setAttributeVBO(colorLoc, vboId, size, type, true, stride, offset);
1499
1428
  }
1500
1429
 
1501
1430
  protected void setNormalAttribute(int vboId, int size, int type,
1502
- int stride, int offset) {
1431
+ int stride, int offset) {
1503
1432
  setAttributeVBO(normalLoc, vboId, size, type, false, stride, offset);
1504
1433
  }
1505
1434
 
1506
1435
  protected void setTexcoordAttribute(int vboId, int size, int type,
1507
- int stride, int offset) {
1436
+ int stride, int offset) {
1508
1437
  setAttributeVBO(texCoordLoc, vboId, size, type, false, stride, offset);
1509
1438
  }
1510
1439
 
1511
1440
  protected void setAmbientAttribute(int vboId, int size, int type,
1512
- int stride, int offset) {
1441
+ int stride, int offset) {
1513
1442
  setAttributeVBO(ambientLoc, vboId, size, type, true, stride, offset);
1514
1443
  }
1515
1444
 
1516
1445
  protected void setSpecularAttribute(int vboId, int size, int type,
1517
- int stride, int offset) {
1446
+ int stride, int offset) {
1518
1447
  setAttributeVBO(specularLoc, vboId, size, type, true, stride, offset);
1519
1448
  }
1520
1449
 
1521
1450
  protected void setEmissiveAttribute(int vboId, int size, int type,
1522
- int stride, int offset) {
1451
+ int stride, int offset) {
1523
1452
  setAttributeVBO(emissiveLoc, vboId, size, type, true, stride, offset);
1524
1453
  }
1525
1454
 
1526
1455
  protected void setShininessAttribute(int vboId, int size, int type,
1527
- int stride, int offset) {
1456
+ int stride, int offset) {
1528
1457
  setAttributeVBO(shininessLoc, vboId, size, type, false, stride, offset);
1529
1458
  }
1530
1459
 
1531
1460
  protected void setLineAttribute(int vboId, int size, int type,
1532
- int stride, int offset) {
1461
+ int stride, int offset) {
1533
1462
  setAttributeVBO(directionLoc, vboId, size, type, false, stride, offset);
1534
1463
  }
1535
1464
 
1536
1465
  protected void setPointAttribute(int vboId, int size, int type,
1537
- int stride, int offset) {
1466
+ int stride, int offset) {
1538
1467
  setAttributeVBO(offsetLoc, vboId, size, type, false, stride, offset);
1539
1468
  }
1540
1469
 
1470
+
1541
1471
  // ***************************************************************************
1542
1472
  //
1543
1473
  // Class to store a user-specified value for a uniform parameter
1544
1474
  // in the shader
1545
1475
  protected static class UniformValue {
1546
-
1547
- static final int INT1 = 0;
1548
- static final int INT2 = 1;
1549
- static final int INT3 = 2;
1550
- static final int INT4 = 3;
1551
- static final int FLOAT1 = 4;
1552
- static final int FLOAT2 = 5;
1553
- static final int FLOAT3 = 6;
1554
- static final int FLOAT4 = 7;
1555
- static final int INT1VEC = 8;
1556
- static final int INT2VEC = 9;
1557
- static final int INT3VEC = 10;
1558
- static final int INT4VEC = 11;
1476
+ static final int INT1 = 0;
1477
+ static final int INT2 = 1;
1478
+ static final int INT3 = 2;
1479
+ static final int INT4 = 3;
1480
+ static final int FLOAT1 = 4;
1481
+ static final int FLOAT2 = 5;
1482
+ static final int FLOAT3 = 6;
1483
+ static final int FLOAT4 = 7;
1484
+ static final int INT1VEC = 8;
1485
+ static final int INT2VEC = 9;
1486
+ static final int INT3VEC = 10;
1487
+ static final int INT4VEC = 11;
1559
1488
  static final int FLOAT1VEC = 12;
1560
1489
  static final int FLOAT2VEC = 13;
1561
1490
  static final int FLOAT3VEC = 14;
1562
1491
  static final int FLOAT4VEC = 15;
1563
- static final int MAT2 = 16;
1564
- static final int MAT3 = 17;
1565
- static final int MAT4 = 18;
1492
+ static final int MAT2 = 16;
1493
+ static final int MAT3 = 17;
1494
+ static final int MAT4 = 18;
1566
1495
  static final int SAMPLER2D = 19;
1567
1496
 
1568
1497
  int type;