propane 2.9.0-java → 2.9.1-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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -0
  3. data/Rakefile +2 -3
  4. data/lib/.gitignore +1 -0
  5. data/lib/export.txt +2 -0
  6. data/lib/propane/version.rb +1 -1
  7. data/pom.rb +2 -49
  8. data/pom.xml +1 -64
  9. data/propane.gemspec +13 -10
  10. data/src/main/java/processing/awt/PGraphicsJava2D.java +29 -20
  11. data/src/main/java/processing/core/PApplet.java +12854 -12803
  12. data/src/main/java/processing/core/PGraphics.java +17 -22
  13. data/src/main/java/processing/core/PShape.java +42 -20
  14. data/src/main/java/processing/core/PShapeSVG.java +20 -5
  15. data/src/main/java/processing/core/PSurfaceNone.java +1 -4
  16. data/src/main/java/processing/data/DoubleDict.java +848 -0
  17. data/src/main/java/processing/data/DoubleList.java +928 -0
  18. data/src/main/java/processing/data/FloatDict.java +18 -2
  19. data/src/main/java/processing/data/FloatList.java +26 -2
  20. data/src/main/java/processing/data/IntDict.java +12 -3
  21. data/src/main/java/processing/data/IntList.java +24 -1
  22. data/src/main/java/processing/data/JSONObject.java +2 -2
  23. data/src/main/java/processing/data/LongDict.java +800 -0
  24. data/src/main/java/processing/data/LongList.java +937 -0
  25. data/src/main/java/processing/data/Sort.java +1 -1
  26. data/src/main/java/processing/data/StringDict.java +12 -3
  27. data/src/main/java/processing/data/StringList.java +25 -2
  28. data/src/main/java/processing/data/Table.java +16 -5
  29. data/src/main/java/processing/data/XML.java +8 -1
  30. data/src/main/java/processing/opengl/PGL.java +23 -16
  31. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13 -10
  32. data/src/main/java/processing/opengl/PJOGL.java +35 -12
  33. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +154 -0
  34. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +2 -2
  35. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +160 -0
  36. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +2 -2
  37. metadata +22 -13
@@ -41,6 +41,6 @@ public abstract class Sort implements Runnable {
41
41
 
42
42
 
43
43
  abstract public int size();
44
- abstract public float compare(int a, int b);
44
+ abstract public int compare(int a, int b);
45
45
  abstract public void swap(int a, int b);
46
46
  }
@@ -522,7 +522,7 @@ public class StringDict {
522
522
  }
523
523
 
524
524
  @Override
525
- public float compare(int a, int b) {
525
+ public int compare(int a, int b) {
526
526
  int diff = 0;
527
527
  if (useKeys) {
528
528
  diff = keys[a].compareToIgnoreCase(keys[b]);
@@ -571,8 +571,17 @@ public class StringDict {
571
571
 
572
572
 
573
573
  /**
574
- * Write tab-delimited entries out to
575
- * @param writer
574
+ * Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
575
+ */
576
+ public void save(File file) {
577
+ PrintWriter writer = PApplet.createWriter(file);
578
+ write(writer);
579
+ writer.close();
580
+ }
581
+
582
+
583
+ /**
584
+ * Write tab-delimited entries to a PrintWriter
576
585
  */
577
586
  public void write(PrintWriter writer) {
578
587
  for (int i = 0; i < count; i++) {
@@ -1,5 +1,7 @@
1
1
  package processing.data;
2
2
 
3
+ import java.io.File;
4
+ import java.io.PrintWriter;
3
5
  import java.util.Arrays;
4
6
  import java.util.Iterator;
5
7
  import java.util.Random;
@@ -514,8 +516,8 @@ public class StringList implements Iterable<String> {
514
516
  }
515
517
 
516
518
  @Override
517
- public float compare(int a, int b) {
518
- float diff = data[a].compareToIgnoreCase(data[b]);
519
+ public int compare(int a, int b) {
520
+ int diff = data[a].compareToIgnoreCase(data[b]);
519
521
  return reverse ? -diff : diff;
520
522
  }
521
523
 
@@ -756,6 +758,27 @@ public class StringList implements Iterable<String> {
756
758
  }
757
759
 
758
760
 
761
+ /**
762
+ * Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
763
+ */
764
+ public void save(File file) {
765
+ PrintWriter writer = PApplet.createWriter(file);
766
+ write(writer);
767
+ writer.close();
768
+ }
769
+
770
+
771
+ /**
772
+ * Write entries to a PrintWriter, one per line
773
+ */
774
+ public void write(PrintWriter writer) {
775
+ for (int i = 0; i < count; i++) {
776
+ writer.println(data[i]);
777
+ }
778
+ writer.flush();
779
+ }
780
+
781
+
759
782
  /**
760
783
  * Return this dictionary as a String in JSON format.
761
784
  */
@@ -4333,7 +4333,7 @@ public class Table {
4333
4333
  }
4334
4334
 
4335
4335
  @Override
4336
- public float compare(int index1, int index2) {
4336
+ public int compare(int index1, int index2) {
4337
4337
  int a = reverse ? order[index2] : order[index1];
4338
4338
  int b = reverse ? order[index1] : order[index2];
4339
4339
 
@@ -4341,13 +4341,24 @@ public class Table {
4341
4341
  case INT:
4342
4342
  return getInt(a, column) - getInt(b, column);
4343
4343
  case LONG:
4344
- return getLong(a, column) - getLong(b, column);
4344
+ long diffl = getLong(a, column) - getLong(b, column);
4345
+ return diffl == 0 ? 0 : (diffl < 0 ? -1 : 1);
4345
4346
  case FLOAT:
4346
- return getFloat(a, column) - getFloat(b, column);
4347
+ float difff = getFloat(a, column) - getFloat(b, column);
4348
+ return difff == 0 ? 0 : (difff < 0 ? -1 : 1);
4347
4349
  case DOUBLE:
4348
- return (float) (getDouble(a, column) - getDouble(b, column));
4350
+ double diffd = getDouble(a, column) - getDouble(b, column);
4351
+ return diffd == 0 ? 0 : (diffd < 0 ? -1 : 1);
4349
4352
  case STRING:
4350
- return getString(a, column).compareToIgnoreCase(getString(b, column));
4353
+ String string1 = getString(a, column);
4354
+ if (string1 == null) {
4355
+ string1 = ""; // avoid NPE when cells are left empty
4356
+ }
4357
+ String string2 = getString(b, column);
4358
+ if (string2 == null) {
4359
+ string2 = "";
4360
+ }
4361
+ return string1.compareToIgnoreCase(string2);
4351
4362
  case CATEGORY:
4352
4363
  return getInt(a, column) - getInt(b, column);
4353
4364
  default:
@@ -594,7 +594,14 @@ public class XML implements Serializable {
594
594
  children = null; // TODO not efficient
595
595
  }
596
596
 
597
-
597
+ /**
598
+ * Removes whitespace nodes.
599
+ * Those whitespace nodes are required to reconstruct the original XML's spacing and indentation.
600
+ * If you call this and use saveXML() your original spacing will be gone.
601
+ *
602
+ * @nowebref
603
+ * @brief Removes whitespace nodes
604
+ */
598
605
  public void trim() {
599
606
  try {
600
607
  XPathFactory xpathFactory = XPathFactory.newInstance();
@@ -1287,9 +1287,9 @@ public abstract class PGL {
1287
1287
  PGL ppgl = primaryPGL ? this : graphics.getPrimaryPGL();
1288
1288
 
1289
1289
  if (!ppgl.loadedTex2DShader || ppgl.tex2DShaderContext != ppgl.glContext) {
1290
- String[] preprocVertSrc = preprocessVertexSource(texVertShaderSource, getGLSLVersion());
1290
+ String[] preprocVertSrc = preprocessVertexSource(texVertShaderSource, getGLSLVersion(), getGLSLVersionSuffix());
1291
1291
  String vertSource = PApplet.join(preprocVertSrc, "\n");
1292
- String[] preprocFragSrc = preprocessFragmentSource(tex2DFragShaderSource, getGLSLVersion());
1292
+ String[] preprocFragSrc = preprocessFragmentSource(tex2DFragShaderSource, getGLSLVersion(), getGLSLVersionSuffix());
1293
1293
  String fragSource = PApplet.join(preprocFragSrc, "\n");
1294
1294
  ppgl.tex2DVertShader = createShader(VERTEX_SHADER, vertSource);
1295
1295
  ppgl.tex2DFragShader = createShader(FRAGMENT_SHADER, fragSource);
@@ -1419,9 +1419,9 @@ public abstract class PGL {
1419
1419
  PGL ppgl = primaryPGL ? this : graphics.getPrimaryPGL();
1420
1420
 
1421
1421
  if (!ppgl.loadedTexRectShader || ppgl.texRectShaderContext != ppgl.glContext) {
1422
- String[] preprocVertSrc = preprocessVertexSource(texVertShaderSource, getGLSLVersion());
1422
+ String[] preprocVertSrc = preprocessVertexSource(texVertShaderSource, getGLSLVersion(), getGLSLVersionSuffix());
1423
1423
  String vertSource = PApplet.join(preprocVertSrc, "\n");
1424
- String[] preprocFragSrc = preprocessFragmentSource(texRectFragShaderSource, getGLSLVersion());
1424
+ String[] preprocFragSrc = preprocessFragmentSource(texRectFragShaderSource, getGLSLVersion(), getGLSLVersionSuffix());
1425
1425
  String fragSource = PApplet.join(preprocFragSrc, "\n");
1426
1426
  ppgl.texRectVertShader = createShader(VERTEX_SHADER, vertSource);
1427
1427
  ppgl.texRectFragShader = createShader(FRAGMENT_SHADER, fragSource);
@@ -1848,6 +1848,7 @@ public abstract class PGL {
1848
1848
 
1849
1849
 
1850
1850
  abstract protected int getGLSLVersion();
1851
+ abstract protected String getGLSLVersionSuffix();
1851
1852
 
1852
1853
 
1853
1854
  protected String[] loadVertexShader(String filename) {
@@ -1880,28 +1881,29 @@ public abstract class PGL {
1880
1881
  }
1881
1882
 
1882
1883
 
1883
- protected String[] loadVertexShader(String filename, int version) {
1884
+ protected String[] loadVertexShader(String filename, int version, String versionSuffix) {
1884
1885
  return loadVertexShader(filename);
1885
1886
  }
1886
1887
 
1887
1888
 
1888
- protected String[] loadFragmentShader(String filename, int version) {
1889
+ protected String[] loadFragmentShader(String filename, int version, String versionSuffix) {
1889
1890
  return loadFragmentShader(filename);
1890
1891
  }
1891
1892
 
1892
1893
 
1893
- protected String[] loadFragmentShader(URL url, int version) {
1894
+ protected String[] loadFragmentShader(URL url, int version, String versionSuffix) {
1894
1895
  return loadFragmentShader(url);
1895
1896
  }
1896
1897
 
1897
1898
 
1898
- protected String[] loadVertexShader(URL url, int version) {
1899
+ protected String[] loadVertexShader(URL url, int version, String versionSuffix) {
1899
1900
  return loadVertexShader(url);
1900
1901
  }
1901
1902
 
1902
1903
 
1903
1904
  protected static String[] preprocessFragmentSource(String[] fragSrc0,
1904
- int version) {
1905
+ int version,
1906
+ String versionSuffix) {
1905
1907
  if (containsVersionDirective(fragSrc0)) {
1906
1908
  // The user knows what she or he is doing
1907
1909
  return fragSrc0;
@@ -1915,7 +1917,7 @@ public abstract class PGL {
1915
1917
  int offset = 1;
1916
1918
 
1917
1919
  fragSrc = preprocessShaderSource(fragSrc0, search, replace, offset);
1918
- fragSrc[0] = "#version " + version;
1920
+ fragSrc[0] = "#version " + version + versionSuffix;
1919
1921
  } else {
1920
1922
  // We need to replace 'texture' uniform by 'texMap' uniform and
1921
1923
  // 'textureXXX()' functions by 'texture()' functions. Order of these
@@ -1932,15 +1934,20 @@ public abstract class PGL {
1932
1934
  int offset = 2;
1933
1935
 
1934
1936
  fragSrc = preprocessShaderSource(fragSrc0, search, replace, offset);
1935
- fragSrc[0] = "#version " + version;
1936
- fragSrc[1] = "out vec4 _fragColor;";
1937
+ fragSrc[0] = "#version " + version + versionSuffix;
1938
+ if (" es".equals(versionSuffix)) {
1939
+ fragSrc[1] = "out mediump vec4 _fragColor;";
1940
+ } else {
1941
+ fragSrc[1] = "out vec4 _fragColor;";
1942
+ }
1937
1943
  }
1938
1944
 
1939
1945
  return fragSrc;
1940
1946
  }
1941
1947
 
1942
1948
  protected static String[] preprocessVertexSource(String[] vertSrc0,
1943
- int version) {
1949
+ int version,
1950
+ String versionSuffix) {
1944
1951
  if (containsVersionDirective(vertSrc0)) {
1945
1952
  // The user knows what she or he is doing
1946
1953
  return vertSrc0;
@@ -1954,7 +1961,7 @@ public abstract class PGL {
1954
1961
  int offset = 1;
1955
1962
 
1956
1963
  vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
1957
- vertSrc[0] = "#version " + version;
1964
+ vertSrc[0] = "#version " + version + versionSuffix;
1958
1965
  } else {
1959
1966
  // We need to replace 'texture' uniform by 'texMap' uniform and
1960
1967
  // 'textureXXX()' functions by 'texture()' functions. Order of these
@@ -1971,7 +1978,7 @@ public abstract class PGL {
1971
1978
  int offset = 1;
1972
1979
 
1973
1980
  vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
1974
- vertSrc[0] = "#version " + version;
1981
+ vertSrc[0] = "#version " + version + versionSuffix;
1975
1982
  }
1976
1983
 
1977
1984
  return vertSrc;
@@ -2225,7 +2232,7 @@ public abstract class PGL {
2225
2232
 
2226
2233
  protected boolean hasAnisoSamplingSupport() {
2227
2234
  int major = getGLVersion()[0];
2228
- if (major < 3) {
2235
+ if (isES() || major < 3) {
2229
2236
  String ext = getString(EXTENSIONS);
2230
2237
  return -1 < ext.indexOf("_texture_filter_anisotropic");
2231
2238
  } else {
@@ -1561,13 +1561,14 @@ public class PGraphicsOpenGL extends PGraphics {
1561
1561
  }
1562
1562
  pgl.depthFunc(PGL.LEQUAL);
1563
1563
 
1564
- if (OPENGL_RENDERER.equals("VideoCore IV HW")) {
1565
- // Broadcom's VC IV driver is unhappy with either of these
1566
- // ignore for now
1564
+ if (pgl.isES()) {
1565
+ // neither GL_MULTISAMPLE nor GL_POLYGON_SMOOTH are part of GLES2 or GLES3
1567
1566
  } else if (smooth < 1) {
1568
1567
  pgl.disable(PGL.MULTISAMPLE);
1569
1568
  } else if (1 <= smooth) {
1570
1569
  pgl.enable(PGL.MULTISAMPLE);
1570
+ }
1571
+ if (!pgl.isES()) {
1571
1572
  pgl.disable(PGL.POLYGON_SMOOTH);
1572
1573
  }
1573
1574
 
@@ -6775,16 +6776,14 @@ public class PGraphicsOpenGL extends PGraphics {
6775
6776
  // quality = temp;
6776
6777
  // }
6777
6778
  }
6778
- if (OPENGL_RENDERER.equals("VideoCore IV HW")) {
6779
- // Broadcom's VC IV driver is unhappy with either of these
6780
- // ignore for now
6779
+ if (pgl.isES()) {
6780
+ // neither GL_MULTISAMPLE nor GL_POLYGON_SMOOTH are part of GLES2 or GLES3
6781
6781
  } else if (smooth < 1) {
6782
6782
  pgl.disable(PGL.MULTISAMPLE);
6783
6783
  } else if (1 <= smooth) {
6784
6784
  pgl.enable(PGL.MULTISAMPLE);
6785
6785
  }
6786
- // work around runtime exceptions in Broadcom's VC IV driver
6787
- if (false == OPENGL_RENDERER.equals("VideoCore IV HW")) {
6786
+ if (!pgl.isES()) {
6788
6787
  pgl.disable(PGL.POLYGON_SMOOTH);
6789
6788
  }
6790
6789
 
@@ -6895,8 +6894,12 @@ public class PGraphicsOpenGL extends PGraphics {
6895
6894
 
6896
6895
  // overwrite the default shaders with vendor specific versions
6897
6896
  // if needed
6898
- if (OPENGL_RENDERER.equals("VideoCore IV HW") || // Broadcom's binary driver for Raspberry Pi
6899
- OPENGL_RENDERER.contains("VC4")) { // Mesa driver for same hardware
6897
+ if (OPENGL_RENDERER.equals("VideoCore IV HW")) { // Broadcom's binary driver for Raspberry Pi
6898
+ defLightShaderVertURL =
6899
+ PGraphicsOpenGL.class.getResource("/processing/opengl/shaders/LightVert-brcm.glsl");
6900
+ defTexlightShaderVertURL =
6901
+ PGraphicsOpenGL.class.getResource("/processing/opengl/shaders/TexLightVert-brcm.glsl");
6902
+ } else if (OPENGL_RENDERER.contains("VC4")) { // Mesa driver for same hardware
6900
6903
  defLightShaderVertURL =
6901
6904
  PGraphicsOpenGL.class.getResource("/processing/opengl/shaders/LightVert-vc4.glsl");
6902
6905
  defTexlightShaderVertURL =
@@ -503,6 +503,7 @@ public class PJOGL extends PGL {
503
503
  return ((Font) font).deriveFont(size);
504
504
  }
505
505
 
506
+
506
507
  @Override
507
508
  protected int getGLSLVersion() {
508
509
  VersionNumber vn = context.getGLSLVersionNumber();
@@ -510,49 +511,60 @@ public class PJOGL extends PGL {
510
511
  }
511
512
 
512
513
 
514
+ @Override
515
+ protected String getGLSLVersionSuffix() {
516
+ VersionNumber vn = context.getGLSLVersionNumber();
517
+ if (context.isGLESProfile() && 1 < vn.getMajor()) {
518
+ return " es";
519
+ } else {
520
+ return "";
521
+ }
522
+ }
523
+
524
+
513
525
  @Override
514
526
  protected String[] loadVertexShader(String filename) {
515
- return loadVertexShader(filename, getGLSLVersion());
527
+ return loadVertexShader(filename, getGLSLVersion(), getGLSLVersionSuffix());
516
528
  }
517
529
 
518
530
 
519
531
  @Override
520
532
  protected String[] loadFragmentShader(String filename) {
521
- return loadFragmentShader(filename, getGLSLVersion());
533
+ return loadFragmentShader(filename, getGLSLVersion(), getGLSLVersionSuffix());
522
534
  }
523
535
 
524
536
 
525
537
  @Override
526
538
  protected String[] loadVertexShader(URL url) {
527
- return loadVertexShader(url, getGLSLVersion());
539
+ return loadVertexShader(url, getGLSLVersion(), getGLSLVersionSuffix());
528
540
  }
529
541
 
530
542
 
531
543
  @Override
532
544
  protected String[] loadFragmentShader(URL url) {
533
- return loadFragmentShader(url, getGLSLVersion());
545
+ return loadFragmentShader(url, getGLSLVersion(), getGLSLVersionSuffix());
534
546
  }
535
547
 
536
548
 
537
549
  @Override
538
- protected String[] loadFragmentShader(String filename, int version) {
550
+ protected String[] loadFragmentShader(String filename, int version, String versionSuffix) {
539
551
  String[] fragSrc0 = sketch.loadStrings(filename);
540
- return preprocessFragmentSource(fragSrc0, version);
552
+ return preprocessFragmentSource(fragSrc0, version, versionSuffix);
541
553
  }
542
554
 
543
555
 
544
556
  @Override
545
- protected String[] loadVertexShader(String filename, int version) {
557
+ protected String[] loadVertexShader(String filename, int version, String versionSuffix) {
546
558
  String[] vertSrc0 = sketch.loadStrings(filename);
547
- return preprocessVertexSource(vertSrc0, version);
559
+ return preprocessVertexSource(vertSrc0, version, versionSuffix);
548
560
  }
549
561
 
550
562
 
551
563
  @Override
552
- protected String[] loadFragmentShader(URL url, int version) {
564
+ protected String[] loadFragmentShader(URL url, int version, String versionSuffix) {
553
565
  try {
554
566
  String[] fragSrc0 = PApplet.loadStrings(url.openStream());
555
- return preprocessFragmentSource(fragSrc0, version);
567
+ return preprocessFragmentSource(fragSrc0, version, versionSuffix);
556
568
  } catch (IOException e) {
557
569
  PGraphics.showException("Cannot load fragment shader " + url.getFile());
558
570
  }
@@ -561,10 +573,10 @@ public class PJOGL extends PGL {
561
573
 
562
574
 
563
575
  @Override
564
- protected String[] loadVertexShader(URL url, int version) {
576
+ protected String[] loadVertexShader(URL url, int version, String versionSuffix) {
565
577
  try {
566
578
  String[] vertSrc0 = PApplet.loadStrings(url.openStream());
567
- return preprocessVertexSource(vertSrc0, version);
579
+ return preprocessVertexSource(vertSrc0, version, versionSuffix);
568
580
  } catch (IOException e) {
569
581
  PGraphics.showException("Cannot load vertex shader " + url.getFile());
570
582
  }
@@ -1926,6 +1938,8 @@ public class PJOGL extends PGL {
1926
1938
  gl2x.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
1927
1939
  } else if (gl3 != null) {
1928
1940
  gl3.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
1941
+ } else if (gl3es3 != null) {
1942
+ gl3es3.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
1929
1943
  } else {
1930
1944
  throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glBlitFramebuffer()"));
1931
1945
  }
@@ -1937,6 +1951,8 @@ public class PJOGL extends PGL {
1937
1951
  gl2x.glRenderbufferStorageMultisample(target, samples, format, width, height);
1938
1952
  } else if (gl3 != null) {
1939
1953
  gl3.glRenderbufferStorageMultisample(target, samples, format, width, height);
1954
+ } else if (gl3es3 != null) {
1955
+ gl3es3.glRenderbufferStorageMultisample(target, samples, format, width, height);
1940
1956
  } else {
1941
1957
  throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glRenderbufferStorageMultisample()"));
1942
1958
  }
@@ -1948,6 +1964,8 @@ public class PJOGL extends PGL {
1948
1964
  gl2x.glReadBuffer(buf);
1949
1965
  } else if (gl3 != null) {
1950
1966
  gl3.glReadBuffer(buf);
1967
+ } else if (gl3es3 != null) {
1968
+ gl3es3.glReadBuffer(buf);
1951
1969
  } else {
1952
1970
  throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glReadBuffer()"));
1953
1971
  }
@@ -1959,6 +1977,11 @@ public class PJOGL extends PGL {
1959
1977
  gl2x.glDrawBuffer(buf);
1960
1978
  } else if (gl3 != null) {
1961
1979
  gl3.glDrawBuffer(buf);
1980
+ } else if (gl3es3 != null) {
1981
+ IntBuffer intBuffer = IntBuffer.allocate(1);
1982
+ intBuffer.put(buf);
1983
+ intBuffer.rewind();
1984
+ gl3es3.glDrawBuffers(1, intBuffer);
1962
1985
  } else {
1963
1986
  throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glDrawBuffer()"));
1964
1987
  }
@@ -0,0 +1,154 @@
1
+ /*
2
+ Part of the Processing project - http://processing.org
3
+
4
+ Copyright (c) 2012-15 The Processing Foundation
5
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
6
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ uniform mat4 modelviewMatrix;
24
+ uniform mat4 transformMatrix;
25
+ uniform mat3 normalMatrix;
26
+
27
+ uniform int lightCount;
28
+ uniform vec4 lightPosition[8];
29
+ uniform vec3 lightNormal[8];
30
+ uniform vec3 lightAmbient[8];
31
+ uniform vec3 lightDiffuse[8];
32
+ uniform vec3 lightSpecular[8];
33
+ uniform vec3 lightFalloff[8];
34
+ uniform vec2 lightSpot[8];
35
+
36
+ attribute vec4 position;
37
+ attribute vec4 color;
38
+ attribute vec3 normal;
39
+
40
+ attribute vec4 ambient;
41
+ attribute vec4 specular;
42
+ attribute vec4 emissive;
43
+ attribute float shininess;
44
+
45
+ varying vec4 vertColor;
46
+ varying vec4 backVertColor;
47
+
48
+ const float zero_float = 0.0;
49
+ const float one_float = 1.0;
50
+ const vec3 zero_vec3 = vec3(0.0);
51
+ const vec3 minus_one_vec3 = vec3(0.0-1.0);
52
+
53
+ float falloffFactor(vec3 lightPos, vec3 vertPos, vec3 coeff) {
54
+ vec3 lpv = lightPos - vertPos;
55
+ vec3 dist = vec3(one_float);
56
+ dist.z = dot(lpv, lpv);
57
+ dist.y = sqrt(dist.z);
58
+ return one_float / dot(dist, coeff);
59
+ }
60
+
61
+ float spotFactor(vec3 lightPos, vec3 vertPos, vec3 lightNorm, float minCos, float spotExp) {
62
+ vec3 lpv = normalize(lightPos - vertPos);
63
+ vec3 nln = minus_one_vec3 * lightNorm;
64
+ float spotCos = dot(nln, lpv);
65
+ return spotCos <= minCos ? zero_float : pow(spotCos, spotExp);
66
+ }
67
+
68
+ float lambertFactor(vec3 lightDir, vec3 vecNormal) {
69
+ return max(zero_float, dot(lightDir, vecNormal));
70
+ }
71
+
72
+ float blinnPhongFactor(vec3 lightDir, vec3 vertPos, vec3 vecNormal, float shine) {
73
+ vec3 np = normalize(vertPos);
74
+ vec3 ldp = normalize(lightDir - np);
75
+ return pow(max(zero_float, dot(ldp, vecNormal)), shine);
76
+ }
77
+
78
+ void main() {
79
+ // Vertex in clip coordinates
80
+ gl_Position = transformMatrix * position;
81
+
82
+ // Vertex in eye coordinates
83
+ vec3 ecVertex = vec3(modelviewMatrix * position);
84
+
85
+ // Normal vector in eye coordinates
86
+ vec3 ecNormal = normalize(normalMatrix * normal);
87
+ vec3 ecNormalInv = ecNormal * minus_one_vec3;
88
+
89
+ // Light calculations
90
+ vec3 totalAmbient = vec3(0, 0, 0);
91
+
92
+ vec3 totalFrontDiffuse = vec3(0, 0, 0);
93
+ vec3 totalFrontSpecular = vec3(0, 0, 0);
94
+
95
+ vec3 totalBackDiffuse = vec3(0, 0, 0);
96
+ vec3 totalBackSpecular = vec3(0, 0, 0);
97
+
98
+ // prevent register allocation failure by limiting ourselves to
99
+ // two lights for now
100
+ for (int i = 0; i < 2; i++) {
101
+ if (lightCount == i) break;
102
+
103
+ vec3 lightPos = lightPosition[i].xyz;
104
+ bool isDir = lightPosition[i].w < one_float;
105
+ float spotCos = lightSpot[i].x;
106
+ float spotExp = lightSpot[i].y;
107
+
108
+ vec3 lightDir;
109
+ float falloff;
110
+ float spotf;
111
+
112
+ if (isDir) {
113
+ falloff = one_float;
114
+ lightDir = minus_one_vec3 * lightNormal[i];
115
+ } else {
116
+ falloff = falloffFactor(lightPos, ecVertex, lightFalloff[i]);
117
+ lightDir = normalize(lightPos - ecVertex);
118
+ }
119
+
120
+ spotf = spotExp > zero_float ? spotFactor(lightPos, ecVertex, lightNormal[i],
121
+ spotCos, spotExp)
122
+ : one_float;
123
+
124
+ if (any(greaterThan(lightAmbient[i], zero_vec3))) {
125
+ totalAmbient += lightAmbient[i] * falloff;
126
+ }
127
+
128
+ if (any(greaterThan(lightDiffuse[i], zero_vec3))) {
129
+ totalFrontDiffuse += lightDiffuse[i] * falloff * spotf *
130
+ lambertFactor(lightDir, ecNormal);
131
+ totalBackDiffuse += lightDiffuse[i] * falloff * spotf *
132
+ lambertFactor(lightDir, ecNormalInv);
133
+ }
134
+
135
+ if (any(greaterThan(lightSpecular[i], zero_vec3))) {
136
+ totalFrontSpecular += lightSpecular[i] * falloff * spotf *
137
+ blinnPhongFactor(lightDir, ecVertex, ecNormal, shininess);
138
+ totalBackSpecular += lightSpecular[i] * falloff * spotf *
139
+ blinnPhongFactor(lightDir, ecVertex, ecNormalInv, shininess);
140
+ }
141
+ }
142
+
143
+ // Calculating final color as result of all lights (plus emissive term).
144
+ // Transparency is determined exclusively by the diffuse component.
145
+ vertColor = vec4(totalAmbient, 0) * ambient +
146
+ vec4(totalFrontDiffuse, 1) * color +
147
+ vec4(totalFrontSpecular, 0) * specular +
148
+ vec4(emissive.rgb, 0);
149
+
150
+ backVertColor = vec4(totalAmbient, 0) * ambient +
151
+ vec4(totalBackDiffuse, 1) * color +
152
+ vec4(totalBackSpecular, 0) * specular +
153
+ vec4(emissive.rgb, 0);
154
+ }