propane 3.4.1-java → 3.7.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +1 -1
  6. data/CHANGELOG.md +9 -1
  7. data/Gemfile +2 -0
  8. data/README.md +9 -5
  9. data/Rakefile +10 -11
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +4 -2
  12. data/lib/propane/app.rb +2 -1
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +22 -23
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +10 -9
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +20 -14
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +2 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +2 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +2 -0
  33. data/library/simplex_noise/simplex_noise.rb +2 -0
  34. data/library/slider/slider.rb +23 -22
  35. data/library/vector_utils/vector_utils.rb +4 -0
  36. data/library/video_event/video_event.rb +2 -0
  37. data/pom.rb +37 -36
  38. data/pom.xml +6 -6
  39. data/propane.gemspec +12 -10
  40. data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
  41. data/src/main/java/monkstone/ColorUtil.java +1 -3
  42. data/src/main/java/monkstone/MathToolModule.java +10 -9
  43. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  44. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  45. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  46. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  47. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  48. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  51. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  52. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  53. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  54. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  55. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  56. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
  57. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  58. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  59. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  60. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  61. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  62. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  63. data/src/main/java/processing/awt/PSurfaceAWT.java +308 -208
  64. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  65. data/src/main/java/processing/core/PApplet.java +4225 -4855
  66. data/src/main/java/processing/core/PConstants.java +477 -447
  67. data/src/main/java/processing/core/PFont.java +914 -880
  68. data/src/main/java/processing/core/PGraphics.java +150 -134
  69. data/src/main/java/processing/core/PImage.java +275 -372
  70. data/src/main/java/processing/core/PMatrix.java +172 -159
  71. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  72. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  73. data/src/main/java/processing/core/PShape.java +2887 -2651
  74. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  75. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  76. data/src/main/java/processing/core/PStyle.java +40 -37
  77. data/src/main/java/processing/core/PSurface.java +139 -97
  78. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  79. data/src/main/java/processing/core/PVector.java +995 -963
  80. data/src/main/java/processing/core/ThinkDifferent.java +12 -8
  81. data/src/main/java/processing/data/DoubleDict.java +756 -710
  82. data/src/main/java/processing/data/DoubleList.java +749 -696
  83. data/src/main/java/processing/data/FloatDict.java +748 -702
  84. data/src/main/java/processing/data/FloatList.java +751 -697
  85. data/src/main/java/processing/data/IntDict.java +720 -673
  86. data/src/main/java/processing/data/IntList.java +699 -633
  87. data/src/main/java/processing/data/JSONArray.java +931 -873
  88. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  89. data/src/main/java/processing/data/JSONTokener.java +351 -341
  90. data/src/main/java/processing/data/LongDict.java +710 -663
  91. data/src/main/java/processing/data/LongList.java +701 -635
  92. data/src/main/java/processing/data/Sort.java +37 -41
  93. data/src/main/java/processing/data/StringDict.java +525 -486
  94. data/src/main/java/processing/data/StringList.java +626 -580
  95. data/src/main/java/processing/data/Table.java +3690 -3510
  96. data/src/main/java/processing/data/TableRow.java +182 -183
  97. data/src/main/java/processing/data/XML.java +957 -883
  98. data/src/main/java/processing/event/Event.java +87 -67
  99. data/src/main/java/processing/event/KeyEvent.java +48 -41
  100. data/src/main/java/processing/event/MouseEvent.java +88 -113
  101. data/src/main/java/processing/event/TouchEvent.java +10 -6
  102. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  103. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  104. data/src/main/java/processing/net/Client.java +20 -20
  105. data/src/main/java/processing/net/Server.java +9 -9
  106. data/src/main/java/processing/opengl/FontTexture.java +286 -266
  107. data/src/main/java/processing/opengl/FrameBuffer.java +389 -377
  108. data/src/main/java/processing/opengl/LinePath.java +132 -89
  109. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  110. data/src/main/java/processing/opengl/PGL.java +660 -567
  111. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  112. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  113. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  114. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  115. data/src/main/java/processing/opengl/PShader.java +369 -461
  116. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  117. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  118. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  119. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  120. data/test/create_test.rb +21 -20
  121. data/test/deglut_spec_test.rb +4 -2
  122. data/test/helper_methods_test.rb +49 -20
  123. data/test/math_tool_test.rb +39 -32
  124. data/test/native_folder.rb +47 -0
  125. data/test/respond_to_test.rb +3 -2
  126. data/test/sketches/key_event.rb +2 -2
  127. data/test/sketches/library/my_library/my_library.rb +3 -0
  128. data/test/test_helper.rb +2 -0
  129. data/test/vecmath_spec_test.rb +35 -22
  130. data/vendors/Rakefile +35 -40
  131. metadata +42 -22
  132. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  133. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  134. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  135. 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 java.io.IOException;
@@ -35,6 +38,8 @@ import java.util.regex.Pattern;
35
38
  import processing.core.PApplet;
36
39
  import processing.core.PConstants;
37
40
  import processing.core.PGraphics;
41
+ import processing.core.PImage;
42
+
38
43
 
39
44
  /**
40
45
  * Processing-OpenGL abstraction layer. Needs to be implemented by subclasses
@@ -47,112 +52,94 @@ public abstract class PGL {
47
52
  // ........................................................
48
53
 
49
54
  // Basic fields
50
- /**
51
- * The PGraphics and PApplet objects using this interface
52
- */
55
+
56
+ /** The PGraphics and PApplet objects using this interface */
53
57
  protected PGraphicsOpenGL graphics;
54
58
  protected PApplet sketch;
59
+ protected RenderCallback renderCallback;
55
60
 
56
- /**
57
- * OpenGL thread
58
- */
61
+ /** OpenGL thread */
59
62
  protected Thread glThread;
60
63
 
61
- /**
62
- * ID of the GL context associated to the surface *
63
- */
64
+ /** ID of the GL context associated to the surface **/
64
65
  protected int glContext;
65
66
 
66
- /**
67
- * true if this is the GL interface for a primary surface PGraphics
68
- */
67
+ /** true if this is the GL interface for a primary surface PGraphics */
69
68
  public boolean primaryPGL;
70
69
 
71
70
  // ........................................................
71
+
72
72
  // Parameters
73
- public static int REQUESTED_DEPTH_BITS = 24;
73
+
74
+ public static int REQUESTED_DEPTH_BITS = 24;
74
75
  public static int REQUESTED_STENCIL_BITS = 8;
75
- public static int REQUESTED_ALPHA_BITS = 8;
76
+ public static int REQUESTED_ALPHA_BITS = 8;
76
77
 
77
- /**
78
- * Switches between the use of regular and direct buffers.
79
- */
78
+ /** Switches between the use of regular and direct buffers. */
80
79
  protected static boolean USE_DIRECT_BUFFERS = true;
81
80
  protected static int MIN_DIRECT_BUFFER_SIZE = 1;
82
81
 
83
- /**
84
- * Enables/disables mipmap use.
85
- */
82
+ /** Enables/disables mipmap use. */
86
83
  protected static boolean MIPMAPS_ENABLED = true;
87
84
 
88
- /**
89
- * Initial sizes for arrays of input and tessellated data.
90
- */
91
- protected static int DEFAULT_IN_VERTICES = 64;
92
- protected static int DEFAULT_IN_EDGES = 128;
93
- protected static int DEFAULT_IN_TEXTURES = 64;
85
+ /** Initial sizes for arrays of input and tessellated data. */
86
+ protected static int DEFAULT_IN_VERTICES = 64;
87
+ protected static int DEFAULT_IN_EDGES = 128;
88
+ protected static int DEFAULT_IN_TEXTURES = 64;
94
89
  protected static int DEFAULT_TESS_VERTICES = 64;
95
- protected static int DEFAULT_TESS_INDICES = 128;
90
+ protected static int DEFAULT_TESS_INDICES = 128;
96
91
 
97
- /**
98
- * Maximum lights by default is 8, the minimum defined by OpenGL.
99
- */
92
+ /** Maximum lights by default is 8, the minimum defined by OpenGL. */
100
93
  protected static int MAX_LIGHTS = 8;
101
94
 
102
- /**
103
- * Maximum index value of a tessellated vertex. GLES restricts the vertex
95
+ /** Maximum index value of a tessellated vertex. GLES restricts the vertex
104
96
  * indices to be of type unsigned short. Since Java only supports signed
105
97
  * shorts as primitive type we have 2^15 = 32768 as the maximum number of
106
98
  * vertices that can be referred to within a single VBO.
107
99
  */
108
- protected final static int MAX_VERTEX_INDEX = 32767;
109
- protected static int MAX_VERTEX_INDEX1 = MAX_VERTEX_INDEX + 1;
110
-
111
- /**
112
- * Count of tessellated fill, line or point vertices that will trigger a flush
113
- * in the immediate mode. It doesn't necessarily be equal to
114
- * MAX_VERTEX_INDEX1, since the number of vertices can be effectively much
115
- * large since the renderer uses offsets to refer to vertices beyond the
116
- * MAX_VERTEX_INDEX limit.
100
+ protected static final int MAX_VERTEX_INDEX = 32767;
101
+ protected static final int MAX_VERTEX_INDEX1 = MAX_VERTEX_INDEX + 1;
102
+
103
+ /** Count of tessellated fill, line or point vertices that will
104
+ * trigger a flush in the immediate mode. It doesn't necessarily
105
+ * be equal to MAX_VERTEX_INDEX1, since the number of vertices can
106
+ * be effectively much large since the renderer uses offsets to
107
+ * refer to vertices beyond the MAX_VERTEX_INDEX limit.
117
108
  */
118
109
  protected static int FLUSH_VERTEX_COUNT = MAX_VERTEX_INDEX1;
119
110
 
120
- /**
121
- * Minimum/maximum dimensions of a texture used to hold font data.
122
- */
111
+ /** Minimum/maximum dimensions of a texture used to hold font data. */
123
112
  protected static int MIN_FONT_TEX_SIZE = 256;
124
113
  protected static int MAX_FONT_TEX_SIZE = 1024;
125
114
 
126
- /**
127
- * Minimum stroke weight needed to apply the full path stroking algorithm that
128
- * properly generates caps and joins.
115
+ /** Minimum stroke weight needed to apply the full path stroking
116
+ * algorithm that properly generates caps and joins.
129
117
  */
130
118
  protected static float MIN_CAPS_JOINS_WEIGHT = 2f;
131
119
 
132
- /**
133
- * Maximum length of linear paths to be stroked with the full algorithm that
134
- * generates accurate caps and joins.
120
+ /** Maximum length of linear paths to be stroked with the
121
+ * full algorithm that generates accurate caps and joins.
135
122
  */
136
123
  protected static int MAX_CAPS_JOINS_LENGTH = 5000;
137
124
 
138
- /**
139
- * Minimum array size to use arrayCopy method().
140
- */
125
+ /** Minimum array size to use arrayCopy method(). */
141
126
  protected static int MIN_ARRAYCOPY_SIZE = 2;
142
127
 
143
- /**
144
- * Factor used to displace the stroke vertices towards the camera in order to
145
- * make sure the lines are always on top of the fill geometry
146
- */
128
+ /** Factor used to displace the stroke vertices towards the camera in
129
+ * order to make sure the lines are always on top of the fill geometry */
147
130
  protected static float STROKE_DISPLACEMENT = 0.999f;
148
131
 
149
132
  // ........................................................
133
+
150
134
  // Variables to handle single-buffered situations (i.e.: Android)
135
+
151
136
  protected IntBuffer firstFrame;
152
137
  protected static boolean SINGLE_BUFFERED = false;
153
138
 
154
139
  // ........................................................
140
+
155
141
  // FBO layer
142
+
156
143
  protected boolean fboLayerEnabled = false;
157
144
  protected boolean fboLayerCreated = false;
158
145
  protected boolean fboLayerEnabledReq = false;
@@ -176,14 +163,25 @@ public abstract class PGL {
176
163
  protected int fboWidth, fboHeight;
177
164
  protected int backTex, frontTex;
178
165
 
179
- /**
180
- * Flags used to handle the creation of a separate front texture
181
- */
166
+ /** Flags used to handle the creation of a separate front texture */
182
167
  protected boolean usingFrontTex = false;
183
168
  protected boolean needSepFrontTex = false;
184
169
 
170
+ /**
171
+ * Defines if FBO Layer is allowed in the given environment.
172
+ * Using FBO can cause a fatal error during runtime for
173
+ * Intel HD Graphics 3000 chipsets (commonly used on older MacBooks)
174
+ * <a href="https://github.com/processing/processing/issues/4104">#4104</a>.
175
+ * Changed to private because needs to be accessed via isFboAllowed().
176
+ * <a href="https://github.com/processing/processing4/pull/76">#76</a> and
177
+ * <a href="https://github.com/processing/processing4/issues/50">#50</a>
178
+ */
179
+ private Boolean fboAllowed = true;
180
+
185
181
  // ........................................................
182
+
186
183
  // Texture rendering
184
+
187
185
  protected boolean loadedTex2DShader = false;
188
186
  protected int tex2DShaderProgram;
189
187
  protected int tex2DVertShader;
@@ -213,11 +211,11 @@ public abstract class PGL {
213
211
  };
214
212
  protected FloatBuffer texData;
215
213
 
216
- protected static final String SHADER_PREPROCESSOR_DIRECTIVE
217
- = "#ifdef GL_ES\n"
218
- + "precision mediump float;\n"
219
- + "precision mediump int;\n"
220
- + "#endif\n";
214
+ protected static final String SHADER_PREPROCESSOR_DIRECTIVE =
215
+ "#ifdef GL_ES\n" +
216
+ "precision mediump float;\n" +
217
+ "precision mediump int;\n" +
218
+ "#endif\n";
221
219
 
222
220
  protected static String[] texVertShaderSource = {
223
221
  "attribute vec2 position;",
@@ -234,7 +232,7 @@ public abstract class PGL {
234
232
  "uniform sampler2D texMap;",
235
233
  "varying vec2 vertTexCoord;",
236
234
  "void main() {",
237
- " gl_FragColor = texture2D(texMap, vertTexCoord.st);",
235
+ " gl_FragColor = texture2D(texMap, vertTexCoord.st);",
238
236
  "}"
239
237
  };
240
238
 
@@ -247,26 +245,26 @@ public abstract class PGL {
247
245
  "}"
248
246
  };
249
247
 
250
- /**
251
- * Which texturing targets are enabled
252
- */
253
- protected boolean[] texturingTargets = {false, false};
248
+ /** Which texturing targets are enabled */
249
+ protected boolean[] texturingTargets = { false, false };
254
250
 
255
- /**
256
- * Used to keep track of which textures are bound to each target
257
- */
251
+ /** Used to keep track of which textures are bound to each target */
258
252
  protected int maxTexUnits;
259
253
  protected int activeTexUnit = 0;
260
254
  protected int[][] boundTextures;
261
255
 
262
256
  // ........................................................
257
+
263
258
  // Framerate handling
259
+
264
260
  protected float targetFps = 60;
265
261
  protected float currentFps = 60;
266
262
  protected boolean setFps = false;
267
263
 
268
264
  // ........................................................
265
+
269
266
  // Utility buffers
267
+
270
268
  protected ByteBuffer byteBuffer;
271
269
  protected IntBuffer intBuffer;
272
270
  protected IntBuffer viewBuffer;
@@ -276,16 +274,14 @@ public abstract class PGL {
276
274
  protected ByteBuffer stencilBuffer;
277
275
 
278
276
  //........................................................
277
+
279
278
  // Rendering information
280
- /**
281
- * Used to register amount of geometry rendered in each frame.
282
- */
279
+
280
+ /** Used to register amount of geometry rendered in each frame. */
283
281
  protected int geomCount = 0;
284
282
  protected int pgeomCount;
285
283
 
286
- /**
287
- * Used to register calls to background.
288
- */
284
+ /** Used to register calls to background. */
289
285
  protected boolean clearColor = false;
290
286
  protected boolean pclearColor;
291
287
 
@@ -295,66 +291,66 @@ public abstract class PGL {
295
291
  protected boolean clearStencil = false;
296
292
  protected boolean pclearStencil;
297
293
 
294
+
298
295
  // ........................................................
296
+
299
297
  // Error messages
300
- public static final String WIKI
301
- = " Read http://wiki.processing.org/w/OpenGL_Issues for help.";
302
298
 
303
- public static final String FRAMEBUFFER_ERROR
304
- = "Framebuffer error (%1$s), rendering will probably not work as expected" + WIKI;
299
+ public static final String WIKI =
300
+ " Read http://wiki.processing.org/w/OpenGL_Issues for help.";
301
+
302
+ public static final String FRAMEBUFFER_ERROR =
303
+ "Framebuffer error (%1$s), rendering will probably not work as expected" + WIKI;
305
304
 
306
- public static final String MISSING_FBO_ERROR
307
- = "Framebuffer objects are not supported by this hardware (or driver)" + WIKI;
305
+ public static final String MISSING_FBO_ERROR =
306
+ "Framebuffer objects are not supported by this hardware (or driver)" + WIKI;
308
307
 
309
- public static final String MISSING_GLSL_ERROR
310
- = "GLSL shaders are not supported by this hardware (or driver)" + WIKI;
308
+ public static final String MISSING_GLSL_ERROR =
309
+ "GLSL shaders are not supported by this hardware (or driver)" + WIKI;
311
310
 
312
- public static final String MISSING_GLFUNC_ERROR
313
- = "GL function %1$s is not available on this hardware (or driver)" + WIKI;
311
+ public static final String MISSING_GLFUNC_ERROR =
312
+ "GL function %1$s is not available on this hardware (or driver)" + WIKI;
314
313
 
315
- public static final String UNSUPPORTED_GLPROF_ERROR
316
- = "Unsupported OpenGL profile.";
314
+ public static final String UNSUPPORTED_GLPROF_ERROR =
315
+ "Unsupported OpenGL profile.";
317
316
 
318
- public static final String TEXUNIT_ERROR
319
- = "Number of texture units not supported by this hardware (or driver)" + WIKI;
317
+ public static final String TEXUNIT_ERROR =
318
+ "Number of texture units not supported by this hardware (or driver)" + WIKI;
320
319
 
321
- public static final String NONPRIMARY_ERROR
322
- = "The renderer is trying to call a PGL function that can only be called on a primary PGL. "
323
- + "This is most likely due to a bug in the renderer's code, please report it with an "
324
- + "issue on Processing's github page https://github.com/processing/processing/issues?state=open "
325
- + "if using any of the built-in OpenGL renderers. If you are using a contributed "
326
- + "library, contact the library's developers.";
320
+ public static final String NONPRIMARY_ERROR =
321
+ "The renderer is trying to call a PGL function that can only be called on a primary PGL. " +
322
+ "This is most likely due to a bug in the renderer's code, please report it with an " +
323
+ "issue on Processing's github page https://github.com/processing/processing/issues?state=open " +
324
+ "if using any of the built-in OpenGL renderers. If you are using a contributed " +
325
+ "library, contact the library's developers.";
327
326
 
328
- protected static final String DEPTH_READING_NOT_ENABLED_ERROR
329
- = "Reading depth and stencil values from this multisampled buffer is not enabled. "
330
- + "You can enable it by calling hint(ENABLE_DEPTH_READING) once. "
331
- + "If your sketch becomes too slow, disable multisampling with noSmooth() instead.";
327
+ protected static final String DEPTH_READING_NOT_ENABLED_ERROR =
328
+ "Reading depth and stencil values from this multisampled buffer is not enabled. " +
329
+ "You can enable it by calling hint(ENABLE_DEPTH_READING) once. " +
330
+ "If your sketch becomes too slow, disable multisampling with noSmooth() instead.";
332
331
 
333
332
  // ........................................................
333
+
334
334
  // Constants
335
- /**
336
- * Size of different types in bytes
337
- */
338
- protected static int SIZEOF_SHORT = Short.SIZE / 8;
339
- protected static int SIZEOF_INT = Integer.SIZE / 8;
335
+
336
+ /** Size of different types in bytes */
337
+ protected static final int SIZEOF_SHORT = Short.SIZE / 8;
338
+ protected static int SIZEOF_INT = Integer.SIZE / 8;
340
339
  protected static int SIZEOF_FLOAT = Float.SIZE / 8;
341
- protected static int SIZEOF_BYTE = Byte.SIZE / 8;
340
+ protected static int SIZEOF_BYTE = Byte.SIZE / 8;
342
341
  protected static int SIZEOF_INDEX = SIZEOF_SHORT;
343
- protected static int INDEX_TYPE = 0x1403; // GL_UNSIGNED_SHORT
342
+ protected static int INDEX_TYPE = 0x1403; // GL_UNSIGNED_SHORT
344
343
 
345
- /**
346
- * Machine Epsilon for float precision.
347
- */
344
+ /** Machine Epsilon for float precision. */
348
345
  protected static float FLOAT_EPS = Float.MIN_VALUE;
349
346
  // Calculation of the Machine Epsilon for float precision. From:
350
347
  // http://en.wikipedia.org/wiki/Machine_epsilon#Approximation_using_Java
351
-
352
348
  static {
353
349
  float eps = 1.0f;
354
350
 
355
351
  do {
356
352
  eps /= 2.0f;
357
- } while ((float) (1.0 + (eps / 2.0)) != 1.0);
353
+ } while ((float)(1.0 + (eps / 2.0)) != 1.0);
358
354
 
359
355
  FLOAT_EPS = eps;
360
356
  }
@@ -363,13 +359,17 @@ public abstract class PGL {
363
359
  * Set to true if the host system is big endian (PowerPC, MIPS, SPARC), false
364
360
  * if little endian (x86 Intel for Mac or PC).
365
361
  */
366
- protected static boolean BIG_ENDIAN
367
- = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
362
+ protected static boolean BIG_ENDIAN =
363
+ ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
368
364
 
369
365
  // ........................................................
366
+
370
367
  // Present mode
368
+
371
369
  // ........................................................
370
+
372
371
  // Present mode
372
+
373
373
  protected boolean presentMode = false;
374
374
  protected boolean showStopButton = true;
375
375
  public float presentX;
@@ -396,13 +396,32 @@ public abstract class PGL {
396
396
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0,
397
397
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0};
398
398
 
399
+
399
400
  ///////////////////////////////////////////////////////////////
401
+
400
402
  // Initialization, finalization
403
+
404
+
401
405
  public PGL() {
406
+ this.renderCallback = () -> {};
402
407
  }
403
408
 
409
+
404
410
  public PGL(PGraphicsOpenGL pg) {
405
411
  this.graphics = pg;
412
+ this.renderCallback = () -> {};
413
+ initGraphics();
414
+ }
415
+
416
+
417
+ public PGL(PGraphicsOpenGL pg, RenderCallback newCallback) {
418
+ this.graphics = pg;
419
+ this.renderCallback = newCallback;
420
+ initGraphics();
421
+ }
422
+
423
+
424
+ private void initGraphics() {
406
425
  if (glColorTex == null) {
407
426
  glColorFbo = allocateIntBuffer(1);
408
427
  glColorTex = allocateIntBuffer(2);
@@ -422,14 +441,17 @@ public abstract class PGL {
422
441
  viewBuffer = allocateIntBuffer(4);
423
442
  }
424
443
 
444
+
425
445
  public void dispose() {
426
446
  destroyFBOLayer();
427
447
  }
428
448
 
449
+
429
450
  public void setPrimary(boolean primary) {
430
451
  primaryPGL = primary;
431
452
  }
432
453
 
454
+
433
455
  static public int smoothToSamples(int smooth) {
434
456
  switch (smooth) {
435
457
  case 0:
@@ -444,85 +466,105 @@ public abstract class PGL {
444
466
  }
445
467
  }
446
468
 
469
+
447
470
  abstract public Object getNative();
448
471
 
472
+
449
473
  abstract protected void setFrameRate(float fps);
450
474
 
475
+
451
476
  abstract protected void initSurface(int antialias);
452
477
 
478
+
453
479
  abstract protected void reinitSurface();
454
480
 
481
+
455
482
  abstract protected void registerListeners();
456
483
 
457
- protected int getReadFramebuffer() {
484
+
485
+ abstract protected PImage screenshot();
486
+
487
+
488
+ protected int getReadFramebuffer() {
458
489
  return fboLayerEnabled ? glColorFbo.get(0) : 0;
459
490
  }
460
491
 
461
- protected int getDrawFramebuffer() {
462
- if (fboLayerEnabled) {
463
- return 1 < numSamples ? glMultiFbo.get(0)
464
- : glColorFbo.get(0);
465
- } else {
466
- return 0;
467
- }
492
+
493
+ protected int getDrawFramebuffer() {
494
+ if (fboLayerEnabled) return 1 < numSamples ? glMultiFbo.get(0) :
495
+ glColorFbo.get(0);
496
+ else return 0;
468
497
  }
469
498
 
470
- protected int getDefaultDrawBuffer() {
499
+
500
+ protected int getDefaultDrawBuffer() {
471
501
  return fboLayerEnabled ? COLOR_ATTACHMENT0 : BACK;
472
502
  }
473
503
 
474
- protected int getDefaultReadBuffer() {
504
+
505
+ protected int getDefaultReadBuffer() {
475
506
  return fboLayerEnabled ? COLOR_ATTACHMENT0 : FRONT;
476
507
  }
477
508
 
478
- protected boolean isFBOBacked() {;
509
+
510
+ protected boolean isFBOBacked() {
479
511
  return fboLayerEnabled;
480
512
  }
481
513
 
514
+
482
515
  @Deprecated
483
516
  public void requestFBOLayer() {
484
517
  enableFBOLayer();
485
518
  }
486
519
 
520
+
487
521
  public void enableFBOLayer() {
488
522
  fboLayerEnabledReq = true;
489
523
  }
490
524
 
525
+
491
526
  public void disableFBOLayer() {
492
527
  fboLayerDisableReq = true;
493
528
  }
494
529
 
530
+
495
531
  public void resetFBOLayer() {
496
532
  fbolayerResetReq = true;
497
533
  }
498
534
 
535
+
499
536
  protected boolean isMultisampled() {
500
537
  return 1 < numSamples;
501
538
  }
502
539
 
540
+
503
541
  abstract protected int getDepthBits();
504
542
 
543
+
505
544
  abstract protected int getStencilBits();
506
545
 
546
+
507
547
  protected boolean getDepthTest() {
508
548
  intBuffer.rewind();
509
549
  getBooleanv(DEPTH_TEST, intBuffer);
510
- return intBuffer.get(0) != 0;
550
+ return intBuffer.get(0) == 0 ? false : true;
511
551
  }
512
552
 
553
+
513
554
  protected boolean getDepthWriteMask() {
514
555
  intBuffer.rewind();
515
556
  getBooleanv(DEPTH_WRITEMASK, intBuffer);
516
- return intBuffer.get(0) != 0;
557
+ return intBuffer.get(0) == 0 ? false : true;
517
558
  }
518
559
 
560
+
519
561
  protected Texture wrapBackTexture(Texture texture) {
520
562
  if (texture == null) {
521
563
  texture = new Texture(graphics);
522
564
  texture.init(graphics.width, graphics.height,
523
- glColorTex.get(backTex), TEXTURE_2D, RGBA,
524
- fboWidth, fboHeight, NEAREST, NEAREST,
525
- CLAMP_TO_EDGE, CLAMP_TO_EDGE);
565
+ glColorTex.get(backTex), TEXTURE_2D, RGBA,
566
+ fboWidth, fboHeight, NEAREST, NEAREST,
567
+ CLAMP_TO_EDGE, CLAMP_TO_EDGE);
526
568
  texture.invertedY(true);
527
569
  texture.colorBuffer(true);
528
570
  graphics.setCache(graphics, texture);
@@ -532,13 +574,14 @@ public abstract class PGL {
532
574
  return texture;
533
575
  }
534
576
 
535
- protected Texture wrapFrontTexture(Texture texture) {
577
+
578
+ protected Texture wrapFrontTexture(Texture texture) {
536
579
  if (texture == null) {
537
580
  texture = new Texture(graphics);
538
581
  texture.init(graphics.width, graphics.height,
539
- glColorTex.get(frontTex), TEXTURE_2D, RGBA,
540
- fboWidth, fboHeight, NEAREST, NEAREST,
541
- CLAMP_TO_EDGE, CLAMP_TO_EDGE);
582
+ glColorTex.get(frontTex), TEXTURE_2D, RGBA,
583
+ fboWidth, fboHeight, NEAREST, NEAREST,
584
+ CLAMP_TO_EDGE, CLAMP_TO_EDGE);
542
585
  texture.invertedY(true);
543
586
  texture.colorBuffer(true);
544
587
  } else {
@@ -547,6 +590,7 @@ public abstract class PGL {
547
590
  return texture;
548
591
  }
549
592
 
593
+
550
594
  protected void bindFrontTexture() {
551
595
  usingFrontTex = true;
552
596
  if (!texturingIsEnabled(TEXTURE_2D)) {
@@ -555,6 +599,7 @@ public abstract class PGL {
555
599
  bindTexture(TEXTURE_2D, glColorTex.get(frontTex));
556
600
  }
557
601
 
602
+
558
603
  protected void unbindFrontTexture() {
559
604
  if (textureIsBound(TEXTURE_2D, glColorTex.get(frontTex))) {
560
605
  // We don't want to unbind another texture
@@ -569,10 +614,9 @@ public abstract class PGL {
569
614
  }
570
615
  }
571
616
 
617
+
572
618
  protected void syncBackTexture() {
573
- if (usingFrontTex) {
574
- needSepFrontTex = true;
575
- }
619
+ if (usingFrontTex) needSepFrontTex = true;
576
620
  if (1 < numSamples) {
577
621
  bindFramebufferImpl(READ_FRAMEBUFFER, glMultiFbo.get(0));
578
622
  bindFramebufferImpl(DRAW_FRAMEBUFFER, glColorFbo.get(0));
@@ -581,15 +625,19 @@ public abstract class PGL {
581
625
  mask |= DEPTH_BUFFER_BIT | STENCIL_BUFFER_BIT;
582
626
  }
583
627
  blitFramebuffer(0, 0, fboWidth, fboHeight,
584
- 0, 0, fboWidth, fboHeight,
585
- mask, NEAREST);
628
+ 0, 0, fboWidth, fboHeight,
629
+ mask, NEAREST);
586
630
  }
587
631
  }
588
632
 
633
+
589
634
  abstract protected float getPixelScale();
590
635
 
591
636
  ///////////////////////////////////////////////////////////
637
+
592
638
  // Present mode
639
+
640
+
593
641
  public void initPresentMode(float x, float y, int stopColor) {
594
642
  presentMode = true;
595
643
  showStopButton = stopColor != 0;
@@ -599,28 +647,34 @@ public abstract class PGL {
599
647
  enableFBOLayer();
600
648
  }
601
649
 
650
+
602
651
  public boolean presentMode() {
603
652
  return presentMode;
604
653
  }
605
654
 
655
+
606
656
  public float presentX() {
607
657
  return presentX;
608
658
  }
609
659
 
660
+
610
661
  public float presentY() {
611
662
  return presentY;
612
663
  }
613
664
 
665
+
614
666
  public boolean insideStopButton(float x, float y) {
615
- if (!showStopButton) {
616
- return false;
617
- }
618
- return stopButtonX < x && x < stopButtonX + stopButtonWidth
619
- && -(closeButtonY + stopButtonHeight) < y && y < -closeButtonY;
667
+ if (!showStopButton) return false;
668
+ return stopButtonX < x && x < stopButtonX + stopButtonWidth &&
669
+ -(closeButtonY + stopButtonHeight) < y && y < -closeButtonY;
620
670
  }
621
671
 
672
+
622
673
  ///////////////////////////////////////////////////////////
674
+
623
675
  // Frame rendering
676
+
677
+
624
678
  protected void clearDepthStencil() {
625
679
  if (!pclearDepth && !pclearStencil) {
626
680
  depthMask(true);
@@ -637,8 +691,9 @@ public abstract class PGL {
637
691
  }
638
692
  }
639
693
 
694
+
640
695
  protected void clearBackground(float r, float g, float b, float a,
641
- boolean depth, boolean stencil) {
696
+ boolean depth, boolean stencil) {
642
697
  clearColor(r, g, b, a);
643
698
  if (depth && stencil) {
644
699
  clearDepth(1);
@@ -668,6 +723,7 @@ public abstract class PGL {
668
723
  }
669
724
  }
670
725
 
726
+
671
727
  protected void beginRender() {
672
728
  if (sketch == null) {
673
729
  sketch = graphics.parent;
@@ -706,7 +762,7 @@ public abstract class PGL {
706
762
  // Draw to the back texture
707
763
  bindFramebufferImpl(FRAMEBUFFER, glColorFbo.get(0));
708
764
  framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
709
- TEXTURE_2D, glColorTex.get(backTex), 0);
765
+ TEXTURE_2D, glColorTex.get(backTex), 0);
710
766
 
711
767
  if (1 < numSamples) {
712
768
  bindFramebufferImpl(FRAMEBUFFER, glMultiFbo.get(0));
@@ -727,18 +783,19 @@ public abstract class PGL {
727
783
  int x = 0;
728
784
  int y = 0;
729
785
  if (presentMode) {
730
- x = (int) presentX;
731
- y = (int) presentY;
786
+ x = (int)presentX;
787
+ y = (int)presentY;
732
788
  }
733
789
  float scale = getPixelScale();
734
790
  drawTexture(TEXTURE_2D, glColorTex.get(frontTex), fboWidth, fboHeight,
735
- x, y, graphics.width, graphics.height,
736
- 0, 0, (int) (scale * graphics.width), (int) (scale * graphics.height),
737
- 0, 0, graphics.width, graphics.height);
791
+ x, y, graphics.width, graphics.height,
792
+ 0, 0, (int)(scale * graphics.width), (int)(scale * graphics.height),
793
+ 0, 0, graphics.width, graphics.height);
738
794
  }
739
795
  }
740
796
  }
741
797
 
798
+
742
799
  protected void endRender(int windowColor) {
743
800
  if (fboLayerEnabled) {
744
801
  syncBackTexture();
@@ -747,7 +804,7 @@ public abstract class PGL {
747
804
  bindFramebufferImpl(FRAMEBUFFER, 0);
748
805
 
749
806
  if (presentMode) {
750
- float wa = ((windowColor >> 24) & 0xff) / 255.0f;
807
+ float wa = ((windowColor >> 24) & 0xff) / 255.0f;
751
808
  float wr = ((windowColor >> 16) & 0xff) / 255.0f;
752
809
  float wg = ((windowColor >> 8) & 0xff) / 255.0f;
753
810
  float wb = (windowColor & 0xff) / 255.0f;
@@ -769,17 +826,18 @@ public abstract class PGL {
769
826
  int[] color = new int[closeButtonPix.length];
770
827
  PApplet.arrayCopy(closeButtonPix, color);
771
828
 
829
+
772
830
  // Multiply the texture by the button color
773
831
  float ba = ((stopButtonColor >> 24) & 0xFF) / 255f;
774
832
  float br = ((stopButtonColor >> 16) & 0xFF) / 255f;
775
- float bg = ((stopButtonColor >> 8) & 0xFF) / 255f;
833
+ float bg = ((stopButtonColor >> 8) & 0xFF) / 255f;
776
834
  float bb = ((stopButtonColor) & 0xFF) / 255f;
777
835
  for (int i = 0; i < color.length; i++) {
778
836
  int c = closeButtonPix[i];
779
- int a = (int) (ba * ((c >> 24) & 0xFF));
780
- int r = (int) (br * ((c >> 16) & 0xFF));
781
- int g = (int) (bg * ((c >> 8) & 0xFF));
782
- int b = (int) (bb * ((c) & 0xFF));
837
+ int a = (int)(ba * ((c >> 24) & 0xFF));
838
+ int r = (int)(br * ((c >> 16) & 0xFF));
839
+ int g = (int)(bg * ((c >> 8) & 0xFF));
840
+ int b = (int)(bb * ((c) & 0xFF));
783
841
  color[i] = javaToNativeARGB((a << 24) | (r << 16) | (g << 8) | b);
784
842
  }
785
843
  IntBuffer buf = allocateIntBuffer(color);
@@ -787,10 +845,10 @@ public abstract class PGL {
787
845
  bindTexture(TEXTURE_2D, 0);
788
846
  }
789
847
  drawTexture(TEXTURE_2D, closeButtonTex.get(0), stopButtonWidth, stopButtonHeight,
790
- 0, 0, stopButtonX + stopButtonWidth, closeButtonY + stopButtonHeight,
791
- 0, stopButtonHeight, stopButtonWidth, 0,
792
- stopButtonX, closeButtonY, stopButtonX + stopButtonWidth, closeButtonY + stopButtonHeight);
793
- }
848
+ 0, 0, stopButtonX + stopButtonWidth, closeButtonY + stopButtonHeight,
849
+ 0, stopButtonHeight, stopButtonWidth, 0,
850
+ stopButtonX, closeButtonY, stopButtonX + stopButtonWidth, closeButtonY + stopButtonHeight);
851
+ }
794
852
  } else {
795
853
  clearDepth(1);
796
854
  clearColor(0, 0, 0, 0);
@@ -802,15 +860,15 @@ public abstract class PGL {
802
860
  int x = 0;
803
861
  int y = 0;
804
862
  if (presentMode) {
805
- x = (int) presentX;
806
- y = (int) presentY;
863
+ x = (int)presentX;
864
+ y = (int)presentY;
807
865
  }
808
866
  float scale = getPixelScale();
809
867
  drawTexture(TEXTURE_2D, glColorTex.get(backTex),
810
- fboWidth, fboHeight,
811
- x, y, graphics.width, graphics.height,
812
- 0, 0, (int) (scale * graphics.width), (int) (scale * graphics.height),
813
- 0, 0, graphics.width, graphics.height);
868
+ fboWidth, fboHeight,
869
+ x, y, graphics.width, graphics.height,
870
+ 0, 0, (int)(scale * graphics.width), (int)(scale * graphics.height),
871
+ 0, 0, graphics.width, graphics.height);
814
872
 
815
873
  // Swapping front and back textures.
816
874
  int temp = frontTex;
@@ -826,48 +884,60 @@ public abstract class PGL {
826
884
  saveFirstFrame();
827
885
  }
828
886
 
829
- if (!clearColor && 0 < sketch.frameCount || !sketch.isLooping()) {
830
- enableFBOLayer();
831
- if (SINGLE_BUFFERED) {
832
- createFBOLayer();
887
+ if (isFboAllowed()) {
888
+ if (!clearColor && 0 < sketch.frameCount || !sketch.isLooping()) {
889
+ enableFBOLayer();
890
+ if (SINGLE_BUFFERED) {
891
+ createFBOLayer();
892
+ }
833
893
  }
834
894
  }
835
895
  }
896
+
897
+ renderCallback.onRender();
836
898
  }
837
899
 
900
+
838
901
  protected abstract void getGL(PGL pgl);
839
902
 
903
+
840
904
  protected abstract boolean canDraw();
841
905
 
906
+
842
907
  protected abstract void requestFocus();
843
908
 
909
+
844
910
  protected abstract void requestDraw();
845
911
 
912
+
846
913
  protected abstract void swapBuffers();
847
914
 
848
- public boolean threadIsCurrent() {
915
+
916
+ public boolean threadIsCurrent() {
849
917
  return Thread.currentThread() == glThread;
850
918
  }
851
919
 
920
+
852
921
  public void setThread(Thread thread) {
853
922
  glThread = thread;
854
923
  }
855
924
 
856
- protected void beginGL() {
857
- }
858
925
 
859
- protected void endGL() {
860
- }
926
+ protected void beginGL() { }
927
+
928
+
929
+ protected void endGL() { }
930
+
861
931
 
862
932
  private void createFBOLayer() {
863
933
  float scale = getPixelScale();
864
934
 
865
935
  if (hasNpotTexSupport()) {
866
- fboWidth = (int) (scale * graphics.width);
867
- fboHeight = (int) (scale * graphics.height);
936
+ fboWidth = (int)(scale * graphics.width);
937
+ fboHeight = (int)(scale * graphics.height);
868
938
  } else {
869
- fboWidth = nextPowerOfTwo((int) (scale * graphics.width));
870
- fboHeight = nextPowerOfTwo((int) (scale * graphics.height));
939
+ fboWidth = nextPowerOfTwo((int)(scale * graphics.width));
940
+ fboHeight = nextPowerOfTwo((int)(scale * graphics.height));
871
941
  }
872
942
 
873
943
  if (hasFboMultisampleSupport()) {
@@ -890,7 +960,7 @@ public abstract class PGL {
890
960
  texParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
891
961
  texParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
892
962
  texImage2D(TEXTURE_2D, 0, RGBA, fboWidth, fboHeight, 0,
893
- RGBA, UNSIGNED_BYTE, null);
963
+ RGBA, UNSIGNED_BYTE, null);
894
964
  initTexture(TEXTURE_2D, RGBA, fboWidth, fboHeight, graphics.backgroundColor);
895
965
  }
896
966
  bindTexture(TEXTURE_2D, 0);
@@ -901,7 +971,7 @@ public abstract class PGL {
901
971
  genFramebuffers(1, glColorFbo);
902
972
  bindFramebufferImpl(FRAMEBUFFER, glColorFbo.get(0));
903
973
  framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0, TEXTURE_2D,
904
- glColorTex.get(backTex), 0);
974
+ glColorTex.get(backTex), 0);
905
975
 
906
976
  if (!multisample || graphics.getHint(PConstants.ENABLE_BUFFER_READING)) {
907
977
  // If not multisampled, this is the only depth and stencil buffer.
@@ -919,9 +989,9 @@ public abstract class PGL {
919
989
  genRenderbuffers(1, glMultiColor);
920
990
  bindRenderbuffer(RENDERBUFFER, glMultiColor.get(0));
921
991
  renderbufferStorageMultisample(RENDERBUFFER, numSamples,
922
- RGBA8, fboWidth, fboHeight);
992
+ RGBA8, fboWidth, fboHeight);
923
993
  framebufferRenderbuffer(FRAMEBUFFER, COLOR_ATTACHMENT0,
924
- RENDERBUFFER, glMultiColor.get(0));
994
+ RENDERBUFFER, glMultiColor.get(0));
925
995
 
926
996
  // Creating multisampled depth and stencil buffers
927
997
  createDepthAndStencilBuffer(true, depthBits, stencilBits, packed);
@@ -957,18 +1027,16 @@ public abstract class PGL {
957
1027
 
958
1028
  protected abstract void initFBOLayer();
959
1029
 
1030
+
960
1031
  protected void saveFirstFrame() {
961
1032
  firstFrame = allocateDirectIntBuffer(graphics.width * graphics.height);
962
- if (hasReadBuffer()) {
963
- readBuffer(BACK);
964
- }
1033
+ if (hasReadBuffer()) readBuffer(BACK);
965
1034
  readPixelsImpl(0, 0, graphics.width, graphics.height, RGBA, UNSIGNED_BYTE, firstFrame);
966
1035
  }
967
1036
 
1037
+
968
1038
  protected void restoreFirstFrame() {
969
- if (firstFrame == null) {
970
- return;
971
- }
1039
+ if (firstFrame == null) return;
972
1040
 
973
1041
  IntBuffer tex = allocateIntBuffer(1);
974
1042
  genTextures(1, tex);
@@ -976,11 +1044,11 @@ public abstract class PGL {
976
1044
  int w, h;
977
1045
  float scale = getPixelScale();
978
1046
  if (hasNpotTexSupport()) {
979
- w = (int) (scale * graphics.width);
980
- h = (int) (scale * graphics.height);
1047
+ w = (int)(scale * graphics.width);
1048
+ h = (int)(scale * graphics.height);
981
1049
  } else {
982
- w = nextPowerOfTwo((int) (scale * graphics.width));
983
- h = nextPowerOfTwo((int) (scale * graphics.height));
1050
+ w = nextPowerOfTwo((int)(scale * graphics.width));
1051
+ h = nextPowerOfTwo((int)(scale * graphics.height));
984
1052
  }
985
1053
 
986
1054
  bindTexture(TEXTURE_2D, tex.get(0));
@@ -992,9 +1060,9 @@ public abstract class PGL {
992
1060
  texSubImage2D(TEXTURE_2D, 0, 0, 0, graphics.width, graphics.height, RGBA, UNSIGNED_BYTE, firstFrame);
993
1061
 
994
1062
  drawTexture(TEXTURE_2D, tex.get(0), w, h,
995
- 0, 0, graphics.width, graphics.height,
996
- 0, 0, (int) (scale * graphics.width), (int) (scale * graphics.height),
997
- 0, 0, graphics.width, graphics.height);
1063
+ 0, 0, graphics.width, graphics.height,
1064
+ 0, 0, (int)(scale * graphics.width), (int)(scale * graphics.height),
1065
+ 0, 0, graphics.width, graphics.height);
998
1066
 
999
1067
  deleteTextures(1, tex);
1000
1068
  firstFrame.clear();
@@ -1018,26 +1086,27 @@ public abstract class PGL {
1018
1086
  fboLayerCreated = false;
1019
1087
  }
1020
1088
 
1089
+
1021
1090
  private void createDepthAndStencilBuffer(boolean multisample, int depthBits,
1022
- int stencilBits, boolean packed) {
1091
+ int stencilBits, boolean packed) {
1023
1092
  // Creating depth and stencil buffers
1024
1093
  if (packed && depthBits == 24 && stencilBits == 8) {
1025
1094
  // packed depth+stencil buffer
1026
- IntBuffer depthStencilBuf
1027
- = multisample ? glMultiDepthStencil : glDepthStencil;
1095
+ IntBuffer depthStencilBuf =
1096
+ multisample ? glMultiDepthStencil : glDepthStencil;
1028
1097
  genRenderbuffers(1, depthStencilBuf);
1029
1098
  bindRenderbuffer(RENDERBUFFER, depthStencilBuf.get(0));
1030
1099
  if (multisample) {
1031
1100
  renderbufferStorageMultisample(RENDERBUFFER, numSamples,
1032
- DEPTH24_STENCIL8, fboWidth, fboHeight);
1101
+ DEPTH24_STENCIL8, fboWidth, fboHeight);
1033
1102
  } else {
1034
1103
  renderbufferStorage(RENDERBUFFER, DEPTH24_STENCIL8,
1035
- fboWidth, fboHeight);
1104
+ fboWidth, fboHeight);
1036
1105
  }
1037
1106
  framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, RENDERBUFFER,
1038
- depthStencilBuf.get(0));
1107
+ depthStencilBuf.get(0));
1039
1108
  framebufferRenderbuffer(FRAMEBUFFER, STENCIL_ATTACHMENT, RENDERBUFFER,
1040
- depthStencilBuf.get(0));
1109
+ depthStencilBuf.get(0));
1041
1110
  } else {
1042
1111
  // separate depth and stencil buffers
1043
1112
  if (0 < depthBits) {
@@ -1061,13 +1130,13 @@ public abstract class PGL {
1061
1130
  bindRenderbuffer(RENDERBUFFER, depthBuf.get(0));
1062
1131
  if (multisample) {
1063
1132
  renderbufferStorageMultisample(RENDERBUFFER, numSamples,
1064
- depthComponent, fboWidth, fboHeight);
1133
+ depthComponent, fboWidth, fboHeight);
1065
1134
  } else {
1066
1135
  renderbufferStorage(RENDERBUFFER, depthComponent,
1067
- fboWidth, fboHeight);
1136
+ fboWidth, fboHeight);
1068
1137
  }
1069
1138
  framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT,
1070
- RENDERBUFFER, depthBuf.get(0));
1139
+ RENDERBUFFER, depthBuf.get(0));
1071
1140
  }
1072
1141
 
1073
1142
  if (0 < stencilBits) {
@@ -1091,33 +1160,43 @@ public abstract class PGL {
1091
1160
  bindRenderbuffer(RENDERBUFFER, stencilBuf.get(0));
1092
1161
  if (multisample) {
1093
1162
  renderbufferStorageMultisample(RENDERBUFFER, numSamples,
1094
- stencilIndex, fboWidth, fboHeight);
1163
+ stencilIndex, fboWidth, fboHeight);
1095
1164
  } else {
1096
1165
  renderbufferStorage(RENDERBUFFER, stencilIndex,
1097
- fboWidth, fboHeight);
1166
+ fboWidth, fboHeight);
1098
1167
  }
1099
1168
  framebufferRenderbuffer(FRAMEBUFFER, STENCIL_ATTACHMENT,
1100
- RENDERBUFFER, stencilBuf.get(0));
1169
+ RENDERBUFFER, stencilBuf.get(0));
1101
1170
  }
1102
1171
  }
1103
1172
  }
1104
1173
 
1174
+
1105
1175
  ///////////////////////////////////////////////////////////
1176
+
1106
1177
  // Context interface
1178
+
1179
+
1107
1180
  protected int createEmptyContext() {
1108
1181
  return -1;
1109
1182
  }
1110
1183
 
1184
+
1111
1185
  protected int getCurrentContext() {
1112
1186
  return glContext;
1113
1187
  }
1114
1188
 
1189
+
1115
1190
  ///////////////////////////////////////////////////////////
1191
+
1116
1192
  // Utility functions
1193
+
1194
+
1117
1195
  protected boolean contextIsCurrent(int other) {
1118
1196
  return other == -1 || other == glContext;
1119
1197
  }
1120
1198
 
1199
+
1121
1200
  protected void enableTexturing(int target) {
1122
1201
  if (target == TEXTURE_2D) {
1123
1202
  texturingTargets[0] = true;
@@ -1126,6 +1205,7 @@ public abstract class PGL {
1126
1205
  }
1127
1206
  }
1128
1207
 
1208
+
1129
1209
  protected void disableTexturing(int target) {
1130
1210
  if (target == TEXTURE_2D) {
1131
1211
  texturingTargets[0] = false;
@@ -1134,6 +1214,7 @@ public abstract class PGL {
1134
1214
  }
1135
1215
  }
1136
1216
 
1217
+
1137
1218
  protected boolean texturingIsEnabled(int target) {
1138
1219
  if (target == TEXTURE_2D) {
1139
1220
  return texturingTargets[0];
@@ -1144,10 +1225,9 @@ public abstract class PGL {
1144
1225
  }
1145
1226
  }
1146
1227
 
1228
+
1147
1229
  protected boolean textureIsBound(int target, int id) {
1148
- if (boundTextures == null) {
1149
- return false;
1150
- }
1230
+ if (boundTextures == null) return false;
1151
1231
 
1152
1232
  if (target == TEXTURE_2D) {
1153
1233
  return boundTextures[activeTexUnit][0] == id;
@@ -1158,12 +1238,14 @@ public abstract class PGL {
1158
1238
  }
1159
1239
  }
1160
1240
 
1241
+
1161
1242
  protected void initTexture(int target, int format, int width, int height) {
1162
1243
  initTexture(target, format, width, height, 0);
1163
1244
  }
1164
1245
 
1246
+
1165
1247
  protected void initTexture(int target, int format, int width, int height,
1166
- int initColor) {
1248
+ int initColor) {
1167
1249
  int[] glcolor = new int[16 * 16];
1168
1250
  Arrays.fill(glcolor, javaToNativeARGB(initColor));
1169
1251
  IntBuffer texels = allocateDirectIntBuffer(16 * 16);
@@ -1178,14 +1260,15 @@ public abstract class PGL {
1178
1260
  }
1179
1261
  }
1180
1262
 
1263
+
1181
1264
  protected void copyToTexture(int target, int format, int id, int x, int y,
1182
- int w, int h, int[] buffer) {
1265
+ int w, int h, int[] buffer) {
1183
1266
  copyToTexture(target, format, id, x, y, w, h, IntBuffer.wrap(buffer));
1184
1267
 
1185
1268
  }
1186
1269
 
1187
1270
  protected void copyToTexture(int target, int format, int id, int x, int y,
1188
- int w, int h, IntBuffer buffer) {
1271
+ int w, int h, IntBuffer buffer) {
1189
1272
  activeTexture(TEXTURE0);
1190
1273
  boolean enabledTex = false;
1191
1274
  if (!texturingIsEnabled(target)) {
@@ -1200,50 +1283,54 @@ public abstract class PGL {
1200
1283
  }
1201
1284
  }
1202
1285
 
1286
+
1203
1287
  /**
1204
1288
  * Not an approved function, this will change or be removed in the future.
1205
1289
  */
1206
1290
  public void drawTexture(int target, int id, int width, int height,
1207
- int X0, int Y0, int X1, int Y1) {
1291
+ int X0, int Y0, int X1, int Y1) {
1208
1292
  // If a texture is drawing on a viewport of the same size as its resolution,
1209
1293
  // the pixel factor is 1:1, so we override the surface's pixel factor.
1210
1294
  drawTexture(target, id, width, height,
1211
- 0, 0, width, height, 1,
1212
- X0, Y0, X1, Y1,
1213
- X0, Y0, X1, Y1);
1295
+ 0, 0, width, height, 1,
1296
+ X0, Y0, X1, Y1,
1297
+ X0, Y0, X1, Y1);
1214
1298
  }
1215
1299
 
1300
+
1216
1301
  /**
1217
1302
  * Not an approved function, this will change or be removed in the future.
1218
1303
  */
1219
- public void drawTexture(int target, int id, int texW, int texH,
1220
- int viewX, int viewY, int viewW, int viewH,
1221
- int texX0, int texY0, int texX1, int texY1,
1222
- int scrX0, int scrY0, int scrX1, int scrY1) {
1223
- int viewF = (int) getPixelScale();
1304
+ public void drawTexture(int target, int id,int texW, int texH,
1305
+ int viewX, int viewY, int viewW, int viewH,
1306
+ int texX0, int texY0, int texX1, int texY1,
1307
+ int scrX0, int scrY0, int scrX1, int scrY1) {
1308
+ int viewF = (int)getPixelScale();
1224
1309
  drawTexture(target, id, texW, texH,
1225
- viewX, viewY, viewW, viewH, viewF,
1226
- texX0, texY0, texX1, texY1,
1227
- scrX0, scrY0, scrX1, scrY1);
1310
+ viewX, viewY, viewW, viewH, viewF,
1311
+ texX0, texY0, texX1, texY1,
1312
+ scrX0, scrY0, scrX1, scrY1);
1228
1313
  }
1229
1314
 
1230
- public void drawTexture(int target, int id, int texW, int texH,
1231
- int viewX, int viewY, int viewW, int viewH, int viewF,
1232
- int texX0, int texY0, int texX1, int texY1,
1233
- int scrX0, int scrY0, int scrX1, int scrY1) {
1315
+
1316
+ public void drawTexture(int target, int id,int texW, int texH,
1317
+ int viewX, int viewY, int viewW, int viewH, int viewF,
1318
+ int texX0, int texY0, int texX1, int texY1,
1319
+ int scrX0, int scrY0, int scrX1, int scrY1) {
1234
1320
  if (target == TEXTURE_2D) {
1235
1321
  drawTexture2D(id, texW, texH,
1236
- viewX, viewY, viewW, viewH, viewF,
1237
- texX0, texY0, texX1, texY1,
1238
- scrX0, scrY0, scrX1, scrY1);
1322
+ viewX, viewY, viewW, viewH, viewF,
1323
+ texX0, texY0, texX1, texY1,
1324
+ scrX0, scrY0, scrX1, scrY1);
1239
1325
  } else if (target == TEXTURE_RECTANGLE) {
1240
1326
  drawTextureRect(id, texW, texH,
1241
- viewX, viewY, viewW, viewH, viewF,
1242
- texX0, texY0, texX1, texY1,
1243
- scrX0, scrY0, scrX1, scrY1);
1327
+ viewX, viewY, viewW, viewH, viewF,
1328
+ texX0, texY0, texX1, texY1,
1329
+ scrX0, scrY0, scrX1, scrY1);
1244
1330
  }
1245
1331
  }
1246
1332
 
1333
+
1247
1334
  protected PGL initTex2DShader() {
1248
1335
  PGL ppgl = primaryPGL ? this : graphics.getPrimaryPGL();
1249
1336
 
@@ -1278,10 +1365,11 @@ public abstract class PGL {
1278
1365
  return ppgl;
1279
1366
  }
1280
1367
 
1368
+
1281
1369
  protected void drawTexture2D(int id, int texW, int texH,
1282
- int viewX, int viewY, int viewW, int viewH, int viewF,
1283
- int texX0, int texY0, int texX1, int texY1,
1284
- int scrX0, int scrY0, int scrX1, int scrY1) {
1370
+ int viewX, int viewY, int viewW, int viewH, int viewF,
1371
+ int texX0, int texY0, int texX1, int texY1,
1372
+ int scrX0, int scrY0, int scrX1, int scrY1) {
1285
1373
  PGL ppgl = initTex2DShader();
1286
1374
 
1287
1375
  if (0 < ppgl.tex2DShaderProgram) {
@@ -1309,25 +1397,25 @@ public abstract class PGL {
1309
1397
  // Vertex coordinates of the textured quad are specified
1310
1398
  // in normalized screen space (-1, 1):
1311
1399
  // Corner 1
1312
- texCoords[0] = 2 * (float) scrX0 / viewW - 1;
1313
- texCoords[1] = 2 * (float) scrY0 / viewH - 1;
1314
- texCoords[2] = (float) texX0 / texW;
1315
- texCoords[3] = (float) texY0 / texH;
1400
+ texCoords[ 0] = 2 * (float)scrX0 / viewW - 1;
1401
+ texCoords[ 1] = 2 * (float)scrY0 / viewH - 1;
1402
+ texCoords[ 2] = (float)texX0 / texW;
1403
+ texCoords[ 3] = (float)texY0 / texH;
1316
1404
  // Corner 2
1317
- texCoords[4] = 2 * (float) scrX1 / viewW - 1;
1318
- texCoords[5] = 2 * (float) scrY0 / viewH - 1;
1319
- texCoords[6] = (float) texX1 / texW;
1320
- texCoords[7] = (float) texY0 / texH;
1405
+ texCoords[ 4] = 2 * (float)scrX1 / viewW - 1;
1406
+ texCoords[ 5] = 2 * (float)scrY0 / viewH - 1;
1407
+ texCoords[ 6] = (float)texX1 / texW;
1408
+ texCoords[ 7] = (float)texY0 / texH;
1321
1409
  // Corner 3
1322
- texCoords[8] = 2 * (float) scrX0 / viewW - 1;
1323
- texCoords[9] = 2 * (float) scrY1 / viewH - 1;
1324
- texCoords[10] = (float) texX0 / texW;
1325
- texCoords[11] = (float) texY1 / texH;
1410
+ texCoords[ 8] = 2 * (float)scrX0 / viewW - 1;
1411
+ texCoords[ 9] = 2 * (float)scrY1 / viewH - 1;
1412
+ texCoords[10] = (float)texX0 / texW;
1413
+ texCoords[11] = (float)texY1 / texH;
1326
1414
  // Corner 4
1327
- texCoords[12] = 2 * (float) scrX1 / viewW - 1;
1328
- texCoords[13] = 2 * (float) scrY1 / viewH - 1;
1329
- texCoords[14] = (float) texX1 / texW;
1330
- texCoords[15] = (float) texY1 / texH;
1415
+ texCoords[12] = 2 * (float)scrX1 / viewW - 1;
1416
+ texCoords[13] = 2 * (float)scrY1 / viewH - 1;
1417
+ texCoords[14] = (float)texX1 / texW;
1418
+ texCoords[15] = (float)texY1 / texH;
1331
1419
 
1332
1420
  texData.rewind();
1333
1421
  texData.put(texCoords);
@@ -1370,10 +1458,11 @@ public abstract class PGL {
1370
1458
  depthMask(depthMask);
1371
1459
 
1372
1460
  viewportImpl(viewBuffer.get(0), viewBuffer.get(1),
1373
- viewBuffer.get(2), viewBuffer.get(3));
1461
+ viewBuffer.get(2), viewBuffer.get(3));
1374
1462
  }
1375
1463
  }
1376
1464
 
1465
+
1377
1466
  protected PGL initTexRectShader() {
1378
1467
  PGL ppgl = primaryPGL ? this : graphics.getPrimaryPGL();
1379
1468
 
@@ -1386,7 +1475,7 @@ public abstract class PGL {
1386
1475
  ppgl.texRectFragShader = createShader(FRAGMENT_SHADER, fragSource);
1387
1476
  if (0 < ppgl.texRectVertShader && 0 < ppgl.texRectFragShader) {
1388
1477
  ppgl.texRectShaderProgram = createProgram(ppgl.texRectVertShader,
1389
- ppgl.texRectFragShader);
1478
+ ppgl.texRectFragShader);
1390
1479
  }
1391
1480
  if (0 < ppgl.texRectShaderProgram) {
1392
1481
  ppgl.texRectVertLoc = getAttribLocation(ppgl.texRectShaderProgram, "position");
@@ -1405,10 +1494,11 @@ public abstract class PGL {
1405
1494
  return ppgl;
1406
1495
  }
1407
1496
 
1497
+
1408
1498
  protected void drawTextureRect(int id, int texW, int texH,
1409
- int viewX, int viewY, int viewW, int viewH, int viewF,
1410
- int texX0, int texY0, int texX1, int texY1,
1411
- int scrX0, int scrY0, int scrX1, int scrY1) {
1499
+ int viewX, int viewY, int viewW, int viewH, int viewF,
1500
+ int texX0, int texY0, int texX1, int texY1,
1501
+ int scrX0, int scrY0, int scrX1, int scrY1) {
1412
1502
  PGL ppgl = initTexRectShader();
1413
1503
 
1414
1504
  if (texData == null) {
@@ -1440,23 +1530,23 @@ public abstract class PGL {
1440
1530
  // Vertex coordinates of the textured quad are specified
1441
1531
  // in normalized screen space (-1, 1):
1442
1532
  // Corner 1
1443
- texCoords[0] = 2 * (float) scrX0 / viewW - 1;
1444
- texCoords[1] = 2 * (float) scrY0 / viewH - 1;
1445
- texCoords[2] = texX0;
1446
- texCoords[3] = texY0;
1533
+ texCoords[ 0] = 2 * (float)scrX0 / viewW - 1;
1534
+ texCoords[ 1] = 2 * (float)scrY0 / viewH - 1;
1535
+ texCoords[ 2] = texX0;
1536
+ texCoords[ 3] = texY0;
1447
1537
  // Corner 2
1448
- texCoords[4] = 2 * (float) scrX1 / viewW - 1;
1449
- texCoords[5] = 2 * (float) scrY0 / viewH - 1;
1450
- texCoords[6] = texX1;
1451
- texCoords[7] = texY0;
1538
+ texCoords[ 4] = 2 * (float)scrX1 / viewW - 1;
1539
+ texCoords[ 5] = 2 * (float)scrY0 / viewH - 1;
1540
+ texCoords[ 6] = texX1;
1541
+ texCoords[ 7] = texY0;
1452
1542
  // Corner 3
1453
- texCoords[8] = 2 * (float) scrX0 / viewW - 1;
1454
- texCoords[9] = 2 * (float) scrY1 / viewH - 1;
1543
+ texCoords[ 8] = 2 * (float)scrX0 / viewW - 1;
1544
+ texCoords[ 9] = 2 * (float)scrY1 / viewH - 1;
1455
1545
  texCoords[10] = texX0;
1456
1546
  texCoords[11] = texY1;
1457
1547
  // Corner 4
1458
- texCoords[12] = 2 * (float) scrX1 / viewW - 1;
1459
- texCoords[13] = 2 * (float) scrY1 / viewH - 1;
1548
+ texCoords[12] = 2 * (float)scrX1 / viewW - 1;
1549
+ texCoords[13] = 2 * (float)scrY1 / viewH - 1;
1460
1550
  texCoords[14] = texX1;
1461
1551
  texCoords[15] = texY1;
1462
1552
 
@@ -1501,59 +1591,62 @@ public abstract class PGL {
1501
1591
  depthMask(depthMask);
1502
1592
 
1503
1593
  viewportImpl(viewBuffer.get(0), viewBuffer.get(1),
1504
- viewBuffer.get(2), viewBuffer.get(3));
1594
+ viewBuffer.get(2), viewBuffer.get(3));
1505
1595
  }
1506
1596
  }
1507
1597
 
1598
+
1508
1599
  protected int getColorValue(int scrX, int scrY) {
1509
1600
  if (colorBuffer == null) {
1510
1601
  colorBuffer = IntBuffer.allocate(1);
1511
1602
  }
1512
1603
  colorBuffer.rewind();
1513
1604
  readPixels(scrX, graphics.height - scrY - 1, 1, 1, RGBA, UNSIGNED_BYTE,
1514
- colorBuffer);
1605
+ colorBuffer);
1515
1606
  return colorBuffer.get();
1516
1607
  }
1517
1608
 
1609
+
1518
1610
  protected float getDepthValue(int scrX, int scrY) {
1519
1611
  if (depthBuffer == null) {
1520
1612
  depthBuffer = FloatBuffer.allocate(1);
1521
1613
  }
1522
1614
  depthBuffer.rewind();
1523
1615
  readPixels(scrX, graphics.height - scrY - 1, 1, 1, DEPTH_COMPONENT, FLOAT,
1524
- depthBuffer);
1616
+ depthBuffer);
1525
1617
  return depthBuffer.get(0);
1526
1618
  }
1527
1619
 
1620
+
1528
1621
  protected byte getStencilValue(int scrX, int scrY) {
1529
1622
  if (stencilBuffer == null) {
1530
1623
  stencilBuffer = ByteBuffer.allocate(1);
1531
1624
  }
1532
1625
  stencilBuffer.rewind();
1533
1626
  readPixels(scrX, graphics.height - scrY - 1, 1, 1, STENCIL_INDEX,
1534
- UNSIGNED_BYTE, stencilBuffer);
1627
+ UNSIGNED_BYTE, stencilBuffer);
1535
1628
  return stencilBuffer.get(0);
1536
1629
  }
1537
1630
 
1631
+
1538
1632
  protected static boolean isPowerOfTwo(int val) {
1539
1633
  return (val & (val - 1)) == 0;
1540
1634
  }
1541
1635
 
1636
+
1542
1637
  // bit shifting this might be more efficient
1543
1638
  protected static int nextPowerOfTwo(int val) {
1544
1639
  int ret = 1;
1545
- while (ret < val) {
1546
- ret <<= 1;
1547
- }
1640
+ while (ret < val) ret <<= 1;
1548
1641
  return ret;
1549
1642
  }
1550
1643
 
1644
+
1551
1645
  /**
1552
1646
  * Converts input native OpenGL value (RGBA on big endian, ABGR on little
1553
1647
  * endian) to Java ARGB.
1554
- *
1555
1648
  * @param color
1556
- * @return
1649
+ * @return
1557
1650
  */
1558
1651
  protected static int nativeToJavaARGB(int color) {
1559
1652
  if (BIG_ENDIAN) { // RGBA to ARGB
@@ -1564,15 +1657,12 @@ public abstract class PGL {
1564
1657
  }
1565
1658
  }
1566
1659
 
1660
+
1567
1661
  /**
1568
1662
  * Converts input array of native OpenGL values (RGBA on big endian, ABGR on
1569
1663
  * little endian) representing an image of width x height resolution to Java
1570
- * ARGB.It also rearranges the elements in the array so that the image is
1664
+ * ARGB. It also rearranges the elements in the array so that the image is
1571
1665
  * flipped vertically.
1572
- *
1573
- * @param pixels
1574
- * @param width
1575
- * @param height
1576
1666
  */
1577
1667
  protected static void nativeToJavaARGB(int[] pixels, int width, int height) {
1578
1668
  int index = 0;
@@ -1611,34 +1701,29 @@ public abstract class PGL {
1611
1701
  }
1612
1702
  }
1613
1703
 
1704
+
1614
1705
  /**
1615
1706
  * Converts input native OpenGL value (RGBA on big endian, ABGR on little
1616
- * endian) to Java RGB, so that the alpha component of the result is set to
1617
- * opaque (255).
1618
- *
1619
- * @param color
1620
- * @return
1707
+ * endian) to Java RGB, so that the alpha component of the result is set
1708
+ * to opaque (255).
1621
1709
  */
1622
1710
  protected static int nativeToJavaRGB(int color) {
1623
1711
  if (BIG_ENDIAN) { // RGBA to ARGB
1624
1712
  return (color >>> 8) | 0xFF000000;
1625
1713
  } else { // ABGR to ARGB
1626
1714
  int rb = color & 0x00FF00FF;
1627
- return 0xFF000000 | (rb << 16)
1628
- | (color & 0x0000FF00) | (rb >> 16);
1715
+ return 0xFF000000 | (rb << 16) |
1716
+ (color & 0x0000FF00) | (rb >> 16);
1629
1717
  }
1630
1718
  }
1631
1719
 
1720
+
1632
1721
  /**
1633
1722
  * Converts input array of native OpenGL values (RGBA on big endian, ABGR on
1634
1723
  * little endian) representing an image of width x height resolution to Java
1635
- * RGB, so that the alpha component of all pixels is set to opaque (255).It
1724
+ * RGB, so that the alpha component of all pixels is set to opaque (255). It
1636
1725
  * also rearranges the elements in the array so that the image is flipped
1637
1726
  * vertically.
1638
- *
1639
- * @param pixels
1640
- * @param width
1641
- * @param height
1642
1727
  */
1643
1728
  protected static void nativeToJavaRGB(int[] pixels, int width, int height) {
1644
1729
  int index = 0;
@@ -1653,10 +1738,10 @@ public abstract class PGL {
1653
1738
  } else { // ABGR to ARGB
1654
1739
  int rbi = pixi & 0x00FF00FF;
1655
1740
  int rby = pixy & 0x00FF00FF;
1656
- pixels[index] = 0xFF000000 | (rby << 16)
1657
- | (pixy & 0x0000FF00) | (rby >> 16);
1658
- pixels[yindex] = 0xFF000000 | (rbi << 16)
1659
- | (pixi & 0x0000FF00) | (rbi >> 16);
1741
+ pixels[index] = 0xFF000000 | (rby << 16) |
1742
+ (pixy & 0x0000FF00) | (rby >> 16);
1743
+ pixels[yindex] = 0xFF000000 | (rbi << 16) |
1744
+ (pixi & 0x0000FF00) | (rbi >> 16);
1660
1745
  }
1661
1746
  index++;
1662
1747
  yindex++;
@@ -1672,20 +1757,18 @@ public abstract class PGL {
1672
1757
  pixels[index] = (pixi >>> 8) | 0xFF000000;
1673
1758
  } else { // ABGR to ARGB
1674
1759
  int rbi = pixi & 0x00FF00FF;
1675
- pixels[index] = 0xFF000000 | (rbi << 16)
1676
- | (pixi & 0x000FF00) | (rbi >> 16);
1760
+ pixels[index] = 0xFF000000 | (rbi << 16) |
1761
+ (pixi & 0x000FF00) | (rbi >> 16);
1677
1762
  }
1678
1763
  index++;
1679
1764
  }
1680
1765
  }
1681
1766
  }
1682
1767
 
1768
+
1683
1769
  /**
1684
1770
  * Converts input Java ARGB value to native OpenGL format (RGBA on big endian,
1685
1771
  * BGRA on little endian).
1686
- *
1687
- * @param color
1688
- * @return
1689
1772
  */
1690
1773
  protected static int javaToNativeARGB(int color) {
1691
1774
  if (BIG_ENDIAN) { // ARGB to RGBA
@@ -1696,15 +1779,12 @@ public abstract class PGL {
1696
1779
  }
1697
1780
  }
1698
1781
 
1782
+
1699
1783
  /**
1700
1784
  * Converts input array of Java ARGB values representing an image of width x
1701
1785
  * height resolution to native OpenGL format (RGBA on big endian, BGRA on
1702
- * little endian).It also rearranges the elements in the array so that the
1786
+ * little endian). It also rearranges the elements in the array so that the
1703
1787
  * image is flipped vertically.
1704
- *
1705
- * @param pixels
1706
- * @param width
1707
- * @param height
1708
1788
  */
1709
1789
  protected static void javaToNativeARGB(int[] pixels, int width, int height) {
1710
1790
  int index = 0;
@@ -1746,9 +1826,8 @@ public abstract class PGL {
1746
1826
  /**
1747
1827
  * Converts input Java ARGB value to native OpenGL format (RGBA on big endian,
1748
1828
  * BGRA on little endian), setting alpha component to opaque (255).
1749
- *
1750
1829
  * @param color
1751
- * @return
1830
+ * @return
1752
1831
  */
1753
1832
  protected static int javaToNativeRGB(int color) {
1754
1833
  if (BIG_ENDIAN) { // ARGB to RGB
@@ -1759,16 +1838,13 @@ public abstract class PGL {
1759
1838
  }
1760
1839
  }
1761
1840
 
1841
+
1762
1842
  /**
1763
1843
  * Converts input array of Java ARGB values representing an image of width x
1764
1844
  * height resolution to native OpenGL format (RGBA on big endian, BGRA on
1765
1845
  * little endian), while setting alpha component of all pixels to opaque
1766
- * (255).It also rearranges the elements in the array so that the image is
1846
+ * (255). It also rearranges the elements in the array so that the image is
1767
1847
  * flipped vertically.
1768
- *
1769
- * @param pixels
1770
- * @param width
1771
- * @param height
1772
1848
  */
1773
1849
  protected static void javaToNativeRGB(int[] pixels, int width, int height) {
1774
1850
  int index = 0;
@@ -1783,10 +1859,10 @@ public abstract class PGL {
1783
1859
  } else { // ARGB to BGR
1784
1860
  int rbi = pixi & 0x00FF00FF;
1785
1861
  int rby = pixy & 0x00FF00FF;
1786
- pixels[index] = 0xFF000000 | (rby << 16)
1787
- | (pixy & 0x0000FF00) | (rby >> 16);
1788
- pixels[yindex] = 0xFF000000 | (rbi << 16)
1789
- | (pixi & 0x0000FF00) | (rbi >> 16);
1862
+ pixels[index] = 0xFF000000 | (rby << 16) |
1863
+ (pixy & 0x0000FF00) | (rby >> 16);
1864
+ pixels[yindex] = 0xFF000000 | (rbi << 16) |
1865
+ (pixi & 0x0000FF00) | (rbi >> 16);
1790
1866
  }
1791
1867
  index++;
1792
1868
  yindex++;
@@ -1802,14 +1878,15 @@ public abstract class PGL {
1802
1878
  pixels[index] = 0xFF | (pixi << 8);
1803
1879
  } else { // ARGB to BGR
1804
1880
  int rbi = pixi & 0x00FF00FF;
1805
- pixels[index] = 0xFF000000 | (rbi << 16)
1806
- | (pixi & 0x0000FF00) | (rbi >> 16);
1881
+ pixels[index] = 0xFF000000 | (rbi << 16) |
1882
+ (pixi & 0x0000FF00) | (rbi >> 16);
1807
1883
  }
1808
1884
  index++;
1809
1885
  }
1810
1886
  }
1811
1887
  }
1812
1888
 
1889
+
1813
1890
  protected static int qualityToSamples(int quality) {
1814
1891
  if (quality <= 1) {
1815
1892
  return 1;
@@ -1820,18 +1897,21 @@ public abstract class PGL {
1820
1897
  }
1821
1898
  }
1822
1899
 
1823
- abstract protected int getGLSLVersion();
1824
1900
 
1901
+ abstract protected int getGLSLVersion();
1825
1902
  abstract protected String getGLSLVersionSuffix();
1826
1903
 
1904
+
1827
1905
  protected String[] loadVertexShader(String filename) {
1828
1906
  return sketch.loadStrings(filename);
1829
1907
  }
1830
1908
 
1909
+
1831
1910
  protected String[] loadFragmentShader(String filename) {
1832
1911
  return sketch.loadStrings(filename);
1833
1912
  }
1834
1913
 
1914
+
1835
1915
  protected String[] loadFragmentShader(URL url) {
1836
1916
  try {
1837
1917
  return PApplet.loadStrings(url.openStream());
@@ -1841,6 +1921,7 @@ public abstract class PGL {
1841
1921
  return null;
1842
1922
  }
1843
1923
 
1924
+
1844
1925
  protected String[] loadVertexShader(URL url) {
1845
1926
  try {
1846
1927
  return PApplet.loadStrings(url.openStream());
@@ -1850,25 +1931,30 @@ public abstract class PGL {
1850
1931
  return null;
1851
1932
  }
1852
1933
 
1934
+
1853
1935
  protected String[] loadVertexShader(String filename, int version, String versionSuffix) {
1854
1936
  return loadVertexShader(filename);
1855
1937
  }
1856
1938
 
1939
+
1857
1940
  protected String[] loadFragmentShader(String filename, int version, String versionSuffix) {
1858
1941
  return loadFragmentShader(filename);
1859
1942
  }
1860
1943
 
1944
+
1861
1945
  protected String[] loadFragmentShader(URL url, int version, String versionSuffix) {
1862
1946
  return loadFragmentShader(url);
1863
1947
  }
1864
1948
 
1949
+
1865
1950
  protected String[] loadVertexShader(URL url, int version, String versionSuffix) {
1866
1951
  return loadVertexShader(url);
1867
1952
  }
1868
1953
 
1954
+
1869
1955
  protected static String[] preprocessFragmentSource(String[] fragSrc0,
1870
- int version,
1871
- String versionSuffix) {
1956
+ int version,
1957
+ String versionSuffix) {
1872
1958
  if (containsVersionDirective(fragSrc0)) {
1873
1959
  // The user knows what she or he is doing
1874
1960
  return fragSrc0;
@@ -1877,8 +1963,8 @@ public abstract class PGL {
1877
1963
  String[] fragSrc;
1878
1964
 
1879
1965
  if (version < 130) {
1880
- Pattern[] search = {};
1881
- String[] replace = {};
1966
+ Pattern[] search = { };
1967
+ String[] replace = { };
1882
1968
  int offset = 1;
1883
1969
 
1884
1970
  fragSrc = preprocessShaderSource(fragSrc0, search, replace, offset);
@@ -1887,14 +1973,14 @@ public abstract class PGL {
1887
1973
  // We need to replace 'texture' uniform by 'texMap' uniform and
1888
1974
  // 'textureXXX()' functions by 'texture()' functions. Order of these
1889
1975
  // replacements is important to prevent collisions between these two.
1890
- Pattern[] search = new Pattern[]{
1891
- Pattern.compile(String.format(GLSL_ID_REGEX, "varying|attribute")),
1892
- Pattern.compile(String.format(GLSL_ID_REGEX, "texture")),
1893
- Pattern.compile(String.format(GLSL_FN_REGEX, "texture2DRect|texture2D|texture3D|textureCube")),
1894
- Pattern.compile(String.format(GLSL_ID_REGEX, "gl_FragColor"))
1976
+ Pattern[] search = new Pattern[] {
1977
+ Pattern.compile(String.format(GLSL_ID_REGEX, "varying|attribute")),
1978
+ Pattern.compile(String.format(GLSL_ID_REGEX, "texture")),
1979
+ Pattern.compile(String.format(GLSL_FN_REGEX, "texture2DRect|texture2D|texture3D|textureCube")),
1980
+ Pattern.compile(String.format(GLSL_ID_REGEX, "gl_FragColor"))
1895
1981
  };
1896
- String[] replace = new String[]{
1897
- "in", "texMap", "texture", "_fragColor"
1982
+ String[] replace = new String[] {
1983
+ "in", "texMap", "texture", "_fragColor"
1898
1984
  };
1899
1985
  int offset = 2;
1900
1986
 
@@ -1911,8 +1997,8 @@ public abstract class PGL {
1911
1997
  }
1912
1998
 
1913
1999
  protected static String[] preprocessVertexSource(String[] vertSrc0,
1914
- int version,
1915
- String versionSuffix) {
2000
+ int version,
2001
+ String versionSuffix) {
1916
2002
  if (containsVersionDirective(vertSrc0)) {
1917
2003
  // The user knows what she or he is doing
1918
2004
  return vertSrc0;
@@ -1921,8 +2007,8 @@ public abstract class PGL {
1921
2007
  String[] vertSrc;
1922
2008
 
1923
2009
  if (version < 130) {
1924
- Pattern[] search = {};
1925
- String[] replace = {};
2010
+ Pattern[] search = { };
2011
+ String[] replace = { };
1926
2012
  int offset = 1;
1927
2013
 
1928
2014
  vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
@@ -1931,14 +2017,15 @@ public abstract class PGL {
1931
2017
  // We need to replace 'texture' uniform by 'texMap' uniform and
1932
2018
  // 'textureXXX()' functions by 'texture()' functions. Order of these
1933
2019
  // replacements is important to prevent collisions between these two.
1934
- Pattern[] search = new Pattern[]{
1935
- Pattern.compile(String.format(GLSL_ID_REGEX, "varying")),
1936
- Pattern.compile(String.format(GLSL_ID_REGEX, "attribute")),
1937
- Pattern.compile(String.format(GLSL_ID_REGEX, "texture")),
1938
- Pattern.compile(String.format(GLSL_FN_REGEX, "texture2DRect|texture2D|texture3D|textureCube"))
2020
+ Pattern[] search = new Pattern[] {
2021
+ Pattern.compile(String.format(GLSL_ID_REGEX, "varying")),
2022
+ Pattern.compile(String.format(GLSL_ID_REGEX, "attribute")),
2023
+ Pattern.compile(String.format(GLSL_ID_REGEX, "texture")),
2024
+ Pattern.compile(String.format(GLSL_FN_REGEX, "texture2DRect|texture2D|texture3D|textureCube"))
2025
+ };
2026
+ String[] replace = new String[] {
2027
+ "out", "in", "texMap", "texture",
1939
2028
  };
1940
- String[] replace = new String[]{
1941
- "out", "in", "texMap", "texture",};
1942
2029
  int offset = 1;
1943
2030
 
1944
2031
  vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
@@ -1948,14 +2035,16 @@ public abstract class PGL {
1948
2035
  return vertSrc;
1949
2036
  }
1950
2037
 
2038
+
1951
2039
  protected static final String GLSL_ID_REGEX = "(?<![0-9A-Z_a-z])(%s)(?![0-9A-Z_a-z]|\\s*\\()";
1952
2040
  protected static final String GLSL_FN_REGEX = "(?<![0-9A-Z_a-z])(%s)(?=\\s*\\()";
1953
2041
 
2042
+
1954
2043
  protected static String[] preprocessShaderSource(String[] src0,
1955
- Pattern[] search,
1956
- String[] replace,
1957
- int offset) {
1958
- String[] src = new String[src0.length + offset];
2044
+ Pattern[] search,
2045
+ String[] replace,
2046
+ int offset) {
2047
+ String[] src = new String[src0.length+offset];
1959
2048
  for (int i = 0; i < src0.length; i++) {
1960
2049
  String line = src0[i];
1961
2050
  int versionIndex = line.indexOf("#version");
@@ -1965,7 +2054,7 @@ public abstract class PGL {
1965
2054
  for (int j = 0; j < search.length; j++) {
1966
2055
  line = search[j].matcher(line).replaceAll(replace[j]);
1967
2056
  }
1968
- src[i + offset] = line;
2057
+ src[i+offset] = line;
1969
2058
  }
1970
2059
  return src;
1971
2060
  }
@@ -1998,6 +2087,7 @@ public abstract class PGL {
1998
2087
  return shader;
1999
2088
  }
2000
2089
 
2090
+
2001
2091
  protected int createProgram(int vertexShader, int fragmentShader) {
2002
2092
  int program = createProgram();
2003
2093
  if (program != 0) {
@@ -2014,55 +2104,58 @@ public abstract class PGL {
2014
2104
  return program;
2015
2105
  }
2016
2106
 
2107
+
2017
2108
  protected boolean compiled(int shader) {
2018
2109
  intBuffer.rewind();
2019
2110
  getShaderiv(shader, COMPILE_STATUS, intBuffer);
2020
2111
  return intBuffer.get(0) != 0;
2021
2112
  }
2022
2113
 
2114
+
2023
2115
  protected boolean linked(int program) {
2024
2116
  intBuffer.rewind();
2025
2117
  getProgramiv(program, LINK_STATUS, intBuffer);
2026
2118
  return intBuffer.get(0) != 0;
2027
2119
  }
2028
2120
 
2121
+
2029
2122
  protected int validateFramebuffer() {
2030
2123
  int status = checkFramebufferStatus(FRAMEBUFFER);
2031
2124
  if (status == FRAMEBUFFER_COMPLETE) {
2032
2125
  return 0;
2033
2126
  } else if (status == FRAMEBUFFER_UNDEFINED) {
2034
2127
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2035
- "framebuffer undefined"));
2128
+ "framebuffer undefined"));
2036
2129
  } else if (status == FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
2037
2130
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2038
- "incomplete attachment"));
2131
+ "incomplete attachment"));
2039
2132
  } else if (status == FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
2040
2133
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2041
- "incomplete missing attachment"));
2134
+ "incomplete missing attachment"));
2042
2135
  } else if (status == FRAMEBUFFER_INCOMPLETE_DIMENSIONS) {
2043
2136
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2044
- "incomplete dimensions"));
2137
+ "incomplete dimensions"));
2045
2138
  } else if (status == FRAMEBUFFER_INCOMPLETE_FORMATS) {
2046
2139
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2047
- "incomplete formats"));
2140
+ "incomplete formats"));
2048
2141
  } else if (status == FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) {
2049
2142
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2050
- "incomplete draw buffer"));
2143
+ "incomplete draw buffer"));
2051
2144
  } else if (status == FRAMEBUFFER_INCOMPLETE_READ_BUFFER) {
2052
2145
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2053
- "incomplete read buffer"));
2146
+ "incomplete read buffer"));
2054
2147
  } else if (status == FRAMEBUFFER_UNSUPPORTED) {
2055
2148
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2056
- "framebuffer unsupported"));
2149
+ "framebuffer unsupported"));
2057
2150
  } else if (status == FRAMEBUFFER_INCOMPLETE_MULTISAMPLE) {
2058
2151
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2059
- "incomplete multisample buffer"));
2152
+ "incomplete multisample buffer"));
2060
2153
  } else if (status == FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS) {
2061
2154
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2062
- "incomplete layer targets"));
2155
+ "incomplete layer targets"));
2063
2156
  } else {
2064
2157
  System.err.println(String.format(FRAMEBUFFER_ERROR,
2065
- "unknown error " + status));
2158
+ "unknown error " + status));
2066
2159
  }
2067
2160
  return status;
2068
2161
  }
@@ -2087,19 +2180,16 @@ public abstract class PGL {
2087
2180
  String[] nums = part.split("\\.");
2088
2181
  try {
2089
2182
  res[0] = Integer.parseInt(nums[0]);
2090
- } catch (NumberFormatException e) {
2091
- }
2183
+ } catch (NumberFormatException e) { }
2092
2184
  if (1 < nums.length) {
2093
2185
  try {
2094
2186
  res[1] = Integer.parseInt(nums[1]);
2095
- } catch (NumberFormatException e) {
2096
- }
2187
+ } catch (NumberFormatException e) { }
2097
2188
  }
2098
2189
  if (2 < nums.length) {
2099
2190
  try {
2100
2191
  res[2] = Integer.parseInt(nums[2]);
2101
- } catch (NumberFormatException e) {
2102
- }
2192
+ } catch (NumberFormatException e) { }
2103
2193
  }
2104
2194
  break;
2105
2195
  }
@@ -2107,20 +2197,22 @@ public abstract class PGL {
2107
2197
  return res;
2108
2198
  }
2109
2199
 
2200
+
2110
2201
  protected boolean hasFBOs() {
2111
2202
  // FBOs might still be available through extensions.
2112
2203
  int major = getGLVersion()[0];
2113
2204
  if (major < 2) {
2114
2205
  String ext = getString(EXTENSIONS);
2115
- return ext.contains("_framebuffer_object")
2116
- && ext.contains("_vertex_shader")
2117
- && ext.contains("_shader_objects")
2118
- && ext.contains("_shading_language");
2206
+ return ext.contains("_framebuffer_object") &&
2207
+ ext.contains("_vertex_shader") &&
2208
+ ext.contains("_shader_objects") &&
2209
+ ext.contains("_shading_language");
2119
2210
  } else {
2120
2211
  return true;
2121
2212
  }
2122
2213
  }
2123
2214
 
2215
+
2124
2216
  protected boolean hasShaders() {
2125
2217
  // GLSL might still be available through extensions. For instance,
2126
2218
  // GLContext.hasGLSL() gives false for older intel integrated chipsets on
@@ -2128,15 +2220,16 @@ public abstract class PGL {
2128
2220
  int major = getGLVersion()[0];
2129
2221
  if (major < 2) {
2130
2222
  String ext = getString(EXTENSIONS);
2131
- return ext.contains("_fragment_shader")
2132
- && ext.contains("_vertex_shader")
2133
- && ext.contains("_shader_objects")
2134
- && ext.contains("_shading_language");
2223
+ return ext.contains("_fragment_shader") &&
2224
+ ext.contains("_vertex_shader") &&
2225
+ ext.contains("_shader_objects") &&
2226
+ ext.contains("_shading_language");
2135
2227
  } else {
2136
2228
  return true;
2137
2229
  }
2138
2230
  }
2139
2231
 
2232
+
2140
2233
  protected boolean hasNpotTexSupport() {
2141
2234
  int major = getGLVersion()[0];
2142
2235
  if (major < 3) {
@@ -2151,6 +2244,7 @@ public abstract class PGL {
2151
2244
  }
2152
2245
  }
2153
2246
 
2247
+
2154
2248
  protected boolean hasAutoMipmapGenSupport() {
2155
2249
  int major = getGLVersion()[0];
2156
2250
  if (isES() && major >= 2) {
@@ -2163,6 +2257,7 @@ public abstract class PGL {
2163
2257
  }
2164
2258
  }
2165
2259
 
2260
+
2166
2261
  protected boolean hasFboMultisampleSupport() {
2167
2262
  int major = getGLVersion()[0];
2168
2263
  if (major < 3) {
@@ -2173,6 +2268,7 @@ public abstract class PGL {
2173
2268
  }
2174
2269
  }
2175
2270
 
2271
+
2176
2272
  protected boolean hasPackedDepthStencilSupport() {
2177
2273
  int major = getGLVersion()[0];
2178
2274
  if (major < 3) {
@@ -2183,6 +2279,7 @@ public abstract class PGL {
2183
2279
  }
2184
2280
  }
2185
2281
 
2282
+
2186
2283
  protected boolean hasAnisoSamplingSupport() {
2187
2284
  int major = getGLVersion()[0];
2188
2285
  if (isES() || major < 3) {
@@ -2193,6 +2290,7 @@ public abstract class PGL {
2193
2290
  }
2194
2291
  }
2195
2292
 
2293
+
2196
2294
  protected boolean hasSynchronization() {
2197
2295
  int[] version = getGLVersion();
2198
2296
  if (isES()) {
@@ -2201,6 +2299,7 @@ public abstract class PGL {
2201
2299
  return (version[0] > 3) || (version[0] == 3 && version[1] >= 2);
2202
2300
  }
2203
2301
 
2302
+
2204
2303
  protected boolean hasPBOs() {
2205
2304
  int[] version = getGLVersion();
2206
2305
  if (isES()) {
@@ -2209,6 +2308,7 @@ public abstract class PGL {
2209
2308
  return (version[0] > 2) || (version[0] == 2 && version[1] >= 1);
2210
2309
  }
2211
2310
 
2311
+
2212
2312
  protected boolean hasReadBuffer() {
2213
2313
  int[] version = getGLVersion();
2214
2314
  if (isES()) {
@@ -2217,6 +2317,7 @@ public abstract class PGL {
2217
2317
  return version[0] >= 2;
2218
2318
  }
2219
2319
 
2320
+
2220
2321
  protected boolean hasDrawBuffer() {
2221
2322
  int[] version = getGLVersion();
2222
2323
  if (isES()) {
@@ -2225,23 +2326,49 @@ public abstract class PGL {
2225
2326
  return version[0] >= 2;
2226
2327
  }
2227
2328
 
2329
+
2228
2330
  protected int maxSamples() {
2229
2331
  intBuffer.rewind();
2230
2332
  getIntegerv(MAX_SAMPLES, intBuffer);
2231
2333
  return intBuffer.get(0);
2232
2334
  }
2233
2335
 
2336
+
2234
2337
  protected int getMaxTexUnits() {
2235
2338
  intBuffer.rewind();
2236
2339
  getIntegerv(MAX_TEXTURE_IMAGE_UNITS, intBuffer);
2237
2340
  return intBuffer.get(0);
2238
2341
  }
2239
2342
 
2343
+
2344
+ public boolean isFboAllowed() {
2345
+ if (fboAllowed == null) {
2346
+ if (PApplet.platform == PConstants.MACOS) {
2347
+ try {
2348
+ String hardware = getString(PGL.RENDERER);
2349
+ if (hardware != null && hardware.contains("Intel HD Graphics 3000")) {
2350
+ fboAllowed = false;
2351
+ return false;
2352
+ }
2353
+ } catch (RuntimeException e) {
2354
+ System.err.println("Could not read renderer name. FBOs disabled. Reason: " + e);
2355
+ // disable for now, but will try again on next isFboAllowed() call
2356
+ return false;
2357
+ }
2358
+ }
2359
+ // all other scenarios allow for FBOs
2360
+ fboAllowed = true;
2361
+ }
2362
+ return fboAllowed;
2363
+ }
2364
+
2365
+
2240
2366
  protected static ByteBuffer allocateDirectByteBuffer(int size) {
2241
2367
  int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_BYTE;
2242
2368
  return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder());
2243
2369
  }
2244
2370
 
2371
+
2245
2372
  protected static ByteBuffer allocateByteBuffer(int size) {
2246
2373
  if (USE_DIRECT_BUFFERS) {
2247
2374
  return allocateDirectByteBuffer(size);
@@ -2250,6 +2377,7 @@ public abstract class PGL {
2250
2377
  }
2251
2378
  }
2252
2379
 
2380
+
2253
2381
  protected static ByteBuffer allocateByteBuffer(byte[] arr) {
2254
2382
  if (USE_DIRECT_BUFFERS) {
2255
2383
  ByteBuffer buf = allocateDirectByteBuffer(arr.length);
@@ -2261,8 +2389,9 @@ public abstract class PGL {
2261
2389
  }
2262
2390
  }
2263
2391
 
2392
+
2264
2393
  protected static ByteBuffer updateByteBuffer(ByteBuffer buf, byte[] arr,
2265
- boolean wrap) {
2394
+ boolean wrap) {
2266
2395
  if (USE_DIRECT_BUFFERS) {
2267
2396
  if (buf == null || buf.capacity() < arr.length) {
2268
2397
  buf = allocateDirectByteBuffer(arr.length);
@@ -2285,8 +2414,9 @@ public abstract class PGL {
2285
2414
  return buf;
2286
2415
  }
2287
2416
 
2417
+
2288
2418
  protected static void updateByteBuffer(ByteBuffer buf, byte[] arr,
2289
- int offset, int size) {
2419
+ int offset, int size) {
2290
2420
  if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) {
2291
2421
  buf.position(offset);
2292
2422
  buf.put(arr, offset, size);
@@ -2294,6 +2424,7 @@ public abstract class PGL {
2294
2424
  }
2295
2425
  }
2296
2426
 
2427
+
2297
2428
  protected static void getByteArray(ByteBuffer buf, byte[] arr) {
2298
2429
  if (!buf.hasArray() || buf.array() != arr) {
2299
2430
  buf.position(0);
@@ -2302,6 +2433,7 @@ public abstract class PGL {
2302
2433
  }
2303
2434
  }
2304
2435
 
2436
+
2305
2437
  protected static void putByteArray(ByteBuffer buf, byte[] arr) {
2306
2438
  if (!buf.hasArray() || buf.array() != arr) {
2307
2439
  buf.position(0);
@@ -2310,8 +2442,9 @@ public abstract class PGL {
2310
2442
  }
2311
2443
  }
2312
2444
 
2445
+
2313
2446
  protected static void fillByteBuffer(ByteBuffer buf, int i0, int i1,
2314
- byte val) {
2447
+ byte val) {
2315
2448
  int n = i1 - i0;
2316
2449
  byte[] temp = new byte[n];
2317
2450
  Arrays.fill(temp, 0, n, val);
@@ -2320,12 +2453,14 @@ public abstract class PGL {
2320
2453
  buf.rewind();
2321
2454
  }
2322
2455
 
2456
+
2323
2457
  protected static ShortBuffer allocateDirectShortBuffer(int size) {
2324
2458
  int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_SHORT;
2325
2459
  return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
2326
- asShortBuffer();
2460
+ asShortBuffer();
2327
2461
  }
2328
2462
 
2463
+
2329
2464
  protected static ShortBuffer allocateShortBuffer(int size) {
2330
2465
  if (USE_DIRECT_BUFFERS) {
2331
2466
  return allocateDirectShortBuffer(size);
@@ -2334,6 +2469,7 @@ public abstract class PGL {
2334
2469
  }
2335
2470
  }
2336
2471
 
2472
+
2337
2473
  protected static ShortBuffer allocateShortBuffer(short[] arr) {
2338
2474
  if (USE_DIRECT_BUFFERS) {
2339
2475
  ShortBuffer buf = allocateDirectShortBuffer(arr.length);
@@ -2345,8 +2481,9 @@ public abstract class PGL {
2345
2481
  }
2346
2482
  }
2347
2483
 
2484
+
2348
2485
  protected static ShortBuffer updateShortBuffer(ShortBuffer buf, short[] arr,
2349
- boolean wrap) {
2486
+ boolean wrap) {
2350
2487
  if (USE_DIRECT_BUFFERS) {
2351
2488
  if (buf == null || buf.capacity() < arr.length) {
2352
2489
  buf = allocateDirectShortBuffer(arr.length);
@@ -2369,8 +2506,9 @@ public abstract class PGL {
2369
2506
  return buf;
2370
2507
  }
2371
2508
 
2509
+
2372
2510
  protected static void updateShortBuffer(ShortBuffer buf, short[] arr,
2373
- int offset, int size) {
2511
+ int offset, int size) {
2374
2512
  if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) {
2375
2513
  buf.position(offset);
2376
2514
  buf.put(arr, offset, size);
@@ -2378,6 +2516,7 @@ public abstract class PGL {
2378
2516
  }
2379
2517
  }
2380
2518
 
2519
+
2381
2520
  protected static void getShortArray(ShortBuffer buf, short[] arr) {
2382
2521
  if (!buf.hasArray() || buf.array() != arr) {
2383
2522
  buf.position(0);
@@ -2386,6 +2525,7 @@ public abstract class PGL {
2386
2525
  }
2387
2526
  }
2388
2527
 
2528
+
2389
2529
  protected static void putShortArray(ShortBuffer buf, short[] arr) {
2390
2530
  if (!buf.hasArray() || buf.array() != arr) {
2391
2531
  buf.position(0);
@@ -2394,8 +2534,9 @@ public abstract class PGL {
2394
2534
  }
2395
2535
  }
2396
2536
 
2537
+
2397
2538
  protected static void fillShortBuffer(ShortBuffer buf, int i0, int i1,
2398
- short val) {
2539
+ short val) {
2399
2540
  int n = i1 - i0;
2400
2541
  short[] temp = new short[n];
2401
2542
  Arrays.fill(temp, 0, n, val);
@@ -2404,12 +2545,14 @@ public abstract class PGL {
2404
2545
  buf.rewind();
2405
2546
  }
2406
2547
 
2548
+
2407
2549
  protected static IntBuffer allocateDirectIntBuffer(int size) {
2408
2550
  int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_INT;
2409
2551
  return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
2410
- asIntBuffer();
2552
+ asIntBuffer();
2411
2553
  }
2412
2554
 
2555
+
2413
2556
  protected static IntBuffer allocateIntBuffer(int size) {
2414
2557
  if (USE_DIRECT_BUFFERS) {
2415
2558
  return allocateDirectIntBuffer(size);
@@ -2418,6 +2561,7 @@ public abstract class PGL {
2418
2561
  }
2419
2562
  }
2420
2563
 
2564
+
2421
2565
  protected static IntBuffer allocateIntBuffer(int[] arr) {
2422
2566
  if (USE_DIRECT_BUFFERS) {
2423
2567
  IntBuffer buf = allocateDirectIntBuffer(arr.length);
@@ -2429,8 +2573,9 @@ public abstract class PGL {
2429
2573
  }
2430
2574
  }
2431
2575
 
2576
+
2432
2577
  protected static IntBuffer updateIntBuffer(IntBuffer buf, int[] arr,
2433
- boolean wrap) {
2578
+ boolean wrap) {
2434
2579
  if (USE_DIRECT_BUFFERS) {
2435
2580
  if (buf == null || buf.capacity() < arr.length) {
2436
2581
  buf = allocateDirectIntBuffer(arr.length);
@@ -2453,14 +2598,16 @@ public abstract class PGL {
2453
2598
  return buf;
2454
2599
  }
2455
2600
 
2601
+
2456
2602
  protected static void updateIntBuffer(IntBuffer buf, int[] arr,
2457
- int offset, int size) {
2458
- if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) {
2459
- buf.position(offset);
2460
- buf.put(arr, offset, size);
2461
- buf.rewind();
2462
- }
2463
- }
2603
+ int offset, int size) {
2604
+ if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) {
2605
+ buf.position(offset);
2606
+ buf.put(arr, offset, size);
2607
+ buf.rewind();
2608
+ }
2609
+ }
2610
+
2464
2611
 
2465
2612
  protected static void getIntArray(IntBuffer buf, int[] arr) {
2466
2613
  if (!buf.hasArray() || buf.array() != arr) {
@@ -2470,6 +2617,7 @@ public abstract class PGL {
2470
2617
  }
2471
2618
  }
2472
2619
 
2620
+
2473
2621
  protected static void putIntArray(IntBuffer buf, int[] arr) {
2474
2622
  if (!buf.hasArray() || buf.array() != arr) {
2475
2623
  buf.position(0);
@@ -2478,6 +2626,7 @@ public abstract class PGL {
2478
2626
  }
2479
2627
  }
2480
2628
 
2629
+
2481
2630
  protected static void fillIntBuffer(IntBuffer buf, int i0, int i1, int val) {
2482
2631
  int n = i1 - i0;
2483
2632
  int[] temp = new int[n];
@@ -2487,12 +2636,14 @@ public abstract class PGL {
2487
2636
  buf.rewind();
2488
2637
  }
2489
2638
 
2639
+
2490
2640
  protected static FloatBuffer allocateDirectFloatBuffer(int size) {
2491
2641
  int bytes = PApplet.max(MIN_DIRECT_BUFFER_SIZE, size) * SIZEOF_FLOAT;
2492
2642
  return ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).
2493
- asFloatBuffer();
2643
+ asFloatBuffer();
2494
2644
  }
2495
2645
 
2646
+
2496
2647
  protected static FloatBuffer allocateFloatBuffer(int size) {
2497
2648
  if (USE_DIRECT_BUFFERS) {
2498
2649
  return allocateDirectFloatBuffer(size);
@@ -2501,6 +2652,7 @@ public abstract class PGL {
2501
2652
  }
2502
2653
  }
2503
2654
 
2655
+
2504
2656
  protected static FloatBuffer allocateFloatBuffer(float[] arr) {
2505
2657
  if (USE_DIRECT_BUFFERS) {
2506
2658
  FloatBuffer buf = allocateDirectFloatBuffer(arr.length);
@@ -2512,8 +2664,9 @@ public abstract class PGL {
2512
2664
  }
2513
2665
  }
2514
2666
 
2667
+
2515
2668
  protected static FloatBuffer updateFloatBuffer(FloatBuffer buf, float[] arr,
2516
- boolean wrap) {
2669
+ boolean wrap) {
2517
2670
  if (USE_DIRECT_BUFFERS) {
2518
2671
  if (buf == null || buf.capacity() < arr.length) {
2519
2672
  buf = allocateDirectFloatBuffer(arr.length);
@@ -2536,14 +2689,16 @@ public abstract class PGL {
2536
2689
  return buf;
2537
2690
  }
2538
2691
 
2692
+
2539
2693
  protected static void updateFloatBuffer(FloatBuffer buf, float[] arr,
2540
- int offset, int size) {
2541
- if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) {
2542
- buf.position(offset);
2543
- buf.put(arr, offset, size);
2544
- buf.rewind();
2545
- }
2546
- }
2694
+ int offset, int size) {
2695
+ if (USE_DIRECT_BUFFERS || (buf.hasArray() && buf.array() != arr)) {
2696
+ buf.position(offset);
2697
+ buf.put(arr, offset, size);
2698
+ buf.rewind();
2699
+ }
2700
+ }
2701
+
2547
2702
 
2548
2703
  protected static void getFloatArray(FloatBuffer buf, float[] arr) {
2549
2704
  if (!buf.hasArray() || buf.array() != arr) {
@@ -2553,6 +2708,7 @@ public abstract class PGL {
2553
2708
  }
2554
2709
  }
2555
2710
 
2711
+
2556
2712
  protected static void putFloatArray(FloatBuffer buf, float[] arr) {
2557
2713
  if (!buf.hasArray() || buf.array() != arr) {
2558
2714
  buf.position(0);
@@ -2561,8 +2717,9 @@ public abstract class PGL {
2561
2717
  }
2562
2718
  }
2563
2719
 
2720
+
2564
2721
  protected static void fillFloatBuffer(FloatBuffer buf, int i0, int i1,
2565
- float val) {
2722
+ float val) {
2566
2723
  int n = i1 - i0;
2567
2724
  float[] temp = new float[n];
2568
2725
  Arrays.fill(temp, 0, n, val);
@@ -2571,63 +2728,72 @@ public abstract class PGL {
2571
2728
  buf.rewind();
2572
2729
  }
2573
2730
 
2731
+
2574
2732
  // TODO: the next three functions shouldn't be here...
2575
2733
  // Uses 'Object' so that the API can be used w/ Android Typeface objects
2734
+
2576
2735
  abstract protected int getFontAscent(Object font);
2577
2736
 
2737
+
2578
2738
  abstract protected int getFontDescent(Object font);
2579
2739
 
2740
+
2580
2741
  abstract protected int getTextWidth(Object font, char[] buffer, int start, int stop);
2581
2742
 
2743
+
2582
2744
  abstract protected Object getDerivedFont(Object font, float size);
2583
2745
 
2584
2746
  ///////////////////////////////////////////////////////////
2747
+
2748
+ protected interface RenderCallback {
2749
+
2750
+ void onRender();
2751
+
2752
+ }
2753
+
2754
+ ///////////////////////////////////////////////////////////
2755
+
2585
2756
  // Tessellator interface
2757
+
2758
+
2586
2759
  protected abstract Tessellator createTessellator(TessellatorCallback callback);
2587
2760
 
2588
- protected interface Tessellator {
2589
2761
 
2762
+ protected interface Tessellator {
2590
2763
  public void setCallback(int flag);
2591
-
2592
2764
  public void setWindingRule(int rule);
2593
-
2594
2765
  public void setProperty(int property, int value);
2595
2766
 
2596
2767
  public void beginPolygon();
2597
-
2598
2768
  public void beginPolygon(Object data);
2599
-
2600
2769
  public void endPolygon();
2601
-
2602
2770
  public void beginContour();
2603
-
2604
2771
  public void endContour();
2605
-
2606
2772
  public void addVertex(double[] v);
2607
-
2608
2773
  public void addVertex(double[] v, int n, Object data);
2609
2774
  }
2610
2775
 
2611
- protected interface TessellatorCallback {
2612
2776
 
2777
+ protected interface TessellatorCallback {
2613
2778
  public void begin(int type);
2614
-
2615
2779
  public void end();
2616
-
2617
2780
  public void vertex(Object data);
2618
-
2619
2781
  public void combine(double[] coords, Object[] data,
2620
- float[] weight, Object[] outData);
2621
-
2782
+ float[] weight, Object[] outData);
2622
2783
  public void error(int errnum);
2623
2784
  }
2624
2785
 
2786
+
2625
2787
  protected String tessError(int err) {
2626
2788
  return "";
2627
2789
  }
2628
2790
 
2791
+
2629
2792
  ///////////////////////////////////////////////////////////
2793
+
2630
2794
  // FontOutline interface
2795
+
2796
+
2631
2797
  protected static boolean SHAPE_TEXT_SUPPORTED;
2632
2798
  protected static int SEG_MOVETO;
2633
2799
  protected static int SEG_LINETO;
@@ -2635,17 +2801,17 @@ public abstract class PGL {
2635
2801
  protected static int SEG_CUBICTO;
2636
2802
  protected static int SEG_CLOSE;
2637
2803
 
2804
+
2638
2805
  protected abstract FontOutline createFontOutline(char ch, Object font);
2639
2806
 
2640
- protected interface FontOutline {
2641
2807
 
2808
+ protected interface FontOutline {
2642
2809
  public boolean isDone();
2643
-
2644
2810
  public int currentSegment(float coords[]);
2645
-
2646
2811
  public void next();
2647
2812
  }
2648
2813
 
2814
+
2649
2815
  //////////////////////////////////////////////////////////////////////////////
2650
2816
  //
2651
2817
  // OpenGL ES 2.0 API, with a few additional functions for multisampling and
@@ -2665,7 +2831,9 @@ public abstract class PGL {
2665
2831
  // Also, keep in mind the note about the PGL constants below.
2666
2832
  //
2667
2833
  //////////////////////////////////////////////////////////////////////////////
2834
+
2668
2835
  ///////////////////////////////////////////////////////////
2836
+
2669
2837
  // Constants
2670
2838
  // Very important note: set the GL constants in your PGL subclass by using an
2671
2839
  // static initialization block as follows:
@@ -2678,6 +2846,7 @@ public abstract class PGL {
2678
2846
  // errors when the constants are accessed through PGL because they are not
2679
2847
  // overridden but hidden by the new declarations, and hence they keep their
2680
2848
  // initial values (all zeroes) when accessed through the superclass.
2849
+
2681
2850
  public static int FALSE;
2682
2851
  public static int TRUE;
2683
2852
 
@@ -2972,80 +3141,82 @@ public abstract class PGL {
2972
3141
  public static int CONDITION_SATISFIED;
2973
3142
 
2974
3143
  ///////////////////////////////////////////////////////////
3144
+
2975
3145
  // Special Functions
2976
- public abstract void flush();
2977
3146
 
3147
+ public abstract void flush();
2978
3148
  public abstract void finish();
2979
-
2980
3149
  public abstract void hint(int target, int hint);
2981
3150
 
2982
3151
  ///////////////////////////////////////////////////////////
3152
+
2983
3153
  // State and State Requests
2984
- public abstract void enable(int value);
2985
3154
 
3155
+ public abstract void enable(int value);
2986
3156
  public abstract void disable(int value);
2987
-
2988
3157
  public abstract void getBooleanv(int value, IntBuffer data);
2989
-
2990
3158
  public abstract void getIntegerv(int value, IntBuffer data);
2991
-
2992
3159
  public abstract void getFloatv(int value, FloatBuffer data);
2993
-
2994
3160
  public abstract boolean isEnabled(int value);
2995
3161
 
2996
- public abstract String getString(int name);
3162
+ /**
3163
+ * Get a configuration or status string from the underlying renderer.
3164
+ *
3165
+ * @param name The name or ID of the attribute to request.
3166
+ * @return The requested value as a string.
3167
+ * @throws GraphicsNotInitializedException Thrown if an attribute is requested that is not
3168
+ * available until graphics initialization before that initialization compeltes. For example,
3169
+ * if requesting a GL string before GL context is available.
3170
+ */
3171
+ public abstract String getString(int name) throws GraphicsNotInitializedException;
2997
3172
 
2998
3173
  ///////////////////////////////////////////////////////////
3174
+
2999
3175
  // Error Handling
3000
- public abstract int getError();
3001
3176
 
3177
+ public abstract int getError();
3002
3178
  public abstract String errorString(int err);
3003
3179
 
3004
3180
  //////////////////////////////////////////////////////////////////////////////
3181
+
3005
3182
  // Buffer Objects
3006
- public abstract void genBuffers(int n, IntBuffer buffers);
3007
3183
 
3184
+ public abstract void genBuffers(int n, IntBuffer buffers);
3008
3185
  public abstract void deleteBuffers(int n, IntBuffer buffers);
3009
-
3010
3186
  public abstract void bindBuffer(int target, int buffer);
3011
-
3012
3187
  public abstract void bufferData(int target, int size, Buffer data, int usage);
3013
-
3014
3188
  public abstract void bufferSubData(int target, int offset, int size, Buffer data);
3015
-
3016
3189
  public abstract void isBuffer(int buffer);
3017
-
3018
3190
  public abstract void getBufferParameteriv(int target, int value, IntBuffer data);
3019
-
3020
3191
  public abstract ByteBuffer mapBuffer(int target, int access);
3021
-
3022
3192
  public abstract ByteBuffer mapBufferRange(int target, int offset, int length, int access);
3023
-
3024
3193
  public abstract void unmapBuffer(int target);
3025
3194
 
3026
3195
  //////////////////////////////////////////////////////////////////////////////
3196
+
3027
3197
  // Synchronization
3028
- public abstract long fenceSync(int condition, int flags);
3029
3198
 
3199
+ public abstract long fenceSync(int condition, int flags);
3030
3200
  public abstract void deleteSync(long sync);
3031
-
3032
3201
  public abstract int clientWaitSync(long sync, int flags, long timeout);
3033
3202
 
3034
3203
  //////////////////////////////////////////////////////////////////////////////
3204
+
3035
3205
  // Viewport and Clipping
3036
- public abstract void depthRangef(float n, float f);
3037
3206
 
3207
+ public abstract void depthRangef(float n, float f);
3038
3208
  public abstract void viewport(int x, int y, int w, int h);
3039
-
3040
3209
  protected abstract void viewportImpl(int x, int y, int w, int h);
3041
3210
 
3042
3211
  //////////////////////////////////////////////////////////////////////////////
3212
+
3043
3213
  // Reading Pixels
3044
3214
  // This is a special case: because the renderer might be using an FBO even on
3045
3215
  // the main surface, some extra handling might be needed before and after
3046
3216
  // reading the pixels. To make this transparent to the user, the actual call
3047
3217
  // to glReadPixels() should be done in readPixelsImpl().
3048
- public void readPixels(int x, int y, int width, int height, int format, int type, Buffer buffer) {
3218
+
3219
+ public void readPixels(int x, int y, int width, int height, int format, int type, Buffer buffer){
3049
3220
  boolean multisampled = isMultisampled() || graphics.offscreenMultisample;
3050
3221
  boolean depthReadingEnabled = graphics.getHint(PConstants.ENABLE_BUFFER_READING);
3051
3222
  boolean depthRequested = format == STENCIL_INDEX || format == DEPTH_COMPONENT || format == DEPTH_STENCIL;
@@ -3060,7 +3231,7 @@ public abstract class PGL {
3060
3231
  graphics.endReadPixels();
3061
3232
  }
3062
3233
 
3063
- public void readPixels(int x, int y, int width, int height, int format, int type, long offset) {
3234
+ public void readPixels(int x, int y, int width, int height, int format, int type, long offset){
3064
3235
  boolean multisampled = isMultisampled() || graphics.offscreenMultisample;
3065
3236
  boolean depthReadingEnabled = graphics.getHint(PConstants.ENABLE_BUFFER_READING);
3066
3237
  boolean depthRequested = format == STENCIL_INDEX || format == DEPTH_COMPONENT || format == DEPTH_STENCIL;
@@ -3076,31 +3247,22 @@ public abstract class PGL {
3076
3247
  }
3077
3248
 
3078
3249
  protected abstract void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer);
3079
-
3080
3250
  protected abstract void readPixelsImpl(int x, int y, int width, int height, int format, int type, long offset);
3081
3251
 
3082
3252
  //////////////////////////////////////////////////////////////////////////////
3253
+
3083
3254
  // Vertices
3084
- public abstract void vertexAttrib1f(int index, float value);
3085
3255
 
3256
+ public abstract void vertexAttrib1f(int index, float value);
3086
3257
  public abstract void vertexAttrib2f(int index, float value0, float value1);
3087
-
3088
3258
  public abstract void vertexAttrib3f(int index, float value0, float value1, float value2);
3089
-
3090
3259
  public abstract void vertexAttrib4f(int index, float value0, float value1, float value2, float value3);
3091
-
3092
3260
  public abstract void vertexAttrib1fv(int index, FloatBuffer values);
3093
-
3094
3261
  public abstract void vertexAttrib2fv(int index, FloatBuffer values);
3095
-
3096
3262
  public abstract void vertexAttrib3fv(int index, FloatBuffer values);
3097
-
3098
3263
  public abstract void vertexAttrib4fv(int index, FloatBuffer values);
3099
-
3100
3264
  public abstract void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, int offset);
3101
-
3102
3265
  public abstract void enableVertexAttribArray(int index);
3103
-
3104
3266
  public abstract void disableVertexAttribArray(int index);
3105
3267
 
3106
3268
  public void drawArrays(int mode, int first, int count) {
@@ -3118,51 +3280,39 @@ public abstract class PGL {
3118
3280
  public abstract void drawElementsImpl(int mode, int count, int type, int offset);
3119
3281
 
3120
3282
  //////////////////////////////////////////////////////////////////////////////
3283
+
3121
3284
  // Rasterization
3122
- public abstract void lineWidth(float width);
3123
3285
 
3286
+ public abstract void lineWidth(float width);
3124
3287
  public abstract void frontFace(int dir);
3125
-
3126
3288
  public abstract void cullFace(int mode);
3127
-
3128
3289
  public abstract void polygonOffset(float factor, float units);
3129
3290
 
3130
3291
  //////////////////////////////////////////////////////////////////////////////
3292
+
3131
3293
  // Pixel Rectangles
3294
+
3132
3295
  public abstract void pixelStorei(int pname, int param);
3133
3296
 
3134
3297
  ///////////////////////////////////////////////////////////
3298
+
3135
3299
  // Texturing
3136
- public abstract void texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data);
3137
3300
 
3301
+ public abstract void texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data);
3138
3302
  public abstract void copyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border);
3139
-
3140
3303
  public abstract void texSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int type, Buffer data);
3141
-
3142
3304
  public abstract void copyTexSubImage2D(int target, int level, int xOffset, int yOffset, int x, int y, int width, int height);
3143
-
3144
3305
  public abstract void compressedTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int imageSize, Buffer data);
3145
-
3146
3306
  public abstract void compressedTexSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int imageSize, Buffer data);
3147
-
3148
3307
  public abstract void texParameteri(int target, int pname, int param);
3149
-
3150
3308
  public abstract void texParameterf(int target, int pname, float param);
3151
-
3152
3309
  public abstract void texParameteriv(int target, int pname, IntBuffer params);
3153
-
3154
3310
  public abstract void texParameterfv(int target, int pname, FloatBuffer params);
3155
-
3156
3311
  public abstract void generateMipmap(int target);
3157
-
3158
3312
  public abstract void genTextures(int n, IntBuffer textures);
3159
-
3160
3313
  public abstract void deleteTextures(int n, IntBuffer textures);
3161
-
3162
3314
  public abstract void getTexParameteriv(int target, int pname, IntBuffer params);
3163
-
3164
3315
  public abstract void getTexParameterfv(int target, int pname, FloatBuffer params);
3165
-
3166
3316
  public abstract boolean isTexture(int texture);
3167
3317
 
3168
3318
  // activeTexture() and bindTexture() have some extra logic to keep track of
@@ -3193,198 +3343,141 @@ public abstract class PGL {
3193
3343
  boundTextures[activeTexUnit][1] = texture;
3194
3344
  }
3195
3345
  }
3196
-
3197
3346
  protected abstract void bindTextureImpl(int target, int texture);
3198
3347
 
3199
3348
  ///////////////////////////////////////////////////////////
3349
+
3200
3350
  // Shaders and Programs
3201
- public abstract int createShader(int type);
3202
3351
 
3352
+ public abstract int createShader(int type);
3203
3353
  public abstract void shaderSource(int shader, String source);
3204
-
3205
3354
  public abstract void compileShader(int shader);
3206
-
3207
3355
  public abstract void releaseShaderCompiler();
3208
-
3209
3356
  public abstract void deleteShader(int shader);
3210
-
3211
3357
  public abstract void shaderBinary(int count, IntBuffer shaders, int binaryFormat, Buffer binary, int length);
3212
-
3213
3358
  public abstract int createProgram();
3214
-
3215
3359
  public abstract void attachShader(int program, int shader);
3216
-
3217
3360
  public abstract void detachShader(int program, int shader);
3218
-
3219
3361
  public abstract void linkProgram(int program);
3220
-
3221
3362
  public abstract void useProgram(int program);
3222
-
3223
3363
  public abstract void deleteProgram(int program);
3224
-
3225
3364
  public abstract String getActiveAttrib(int program, int index, IntBuffer size, IntBuffer type);
3226
-
3227
3365
  public abstract int getAttribLocation(int program, String name);
3228
-
3229
3366
  public abstract void bindAttribLocation(int program, int index, String name);
3230
-
3231
3367
  public abstract int getUniformLocation(int program, String name);
3232
-
3233
3368
  public abstract String getActiveUniform(int program, int index, IntBuffer size, IntBuffer type);
3234
-
3235
3369
  public abstract void uniform1i(int location, int value);
3236
-
3237
3370
  public abstract void uniform2i(int location, int value0, int value1);
3238
-
3239
3371
  public abstract void uniform3i(int location, int value0, int value1, int value2);
3240
-
3241
3372
  public abstract void uniform4i(int location, int value0, int value1, int value2, int value3);
3242
-
3243
3373
  public abstract void uniform1f(int location, float value);
3244
-
3245
3374
  public abstract void uniform2f(int location, float value0, float value1);
3246
-
3247
3375
  public abstract void uniform3f(int location, float value0, float value1, float value2);
3248
-
3249
3376
  public abstract void uniform4f(int location, float value0, float value1, float value2, float value3);
3250
-
3251
3377
  public abstract void uniform1iv(int location, int count, IntBuffer v);
3252
-
3253
3378
  public abstract void uniform2iv(int location, int count, IntBuffer v);
3254
-
3255
3379
  public abstract void uniform3iv(int location, int count, IntBuffer v);
3256
-
3257
3380
  public abstract void uniform4iv(int location, int count, IntBuffer v);
3258
-
3259
3381
  public abstract void uniform1fv(int location, int count, FloatBuffer v);
3260
-
3261
3382
  public abstract void uniform2fv(int location, int count, FloatBuffer v);
3262
-
3263
3383
  public abstract void uniform3fv(int location, int count, FloatBuffer v);
3264
-
3265
3384
  public abstract void uniform4fv(int location, int count, FloatBuffer v);
3266
-
3267
3385
  public abstract void uniformMatrix2fv(int location, int count, boolean transpose, FloatBuffer mat);
3268
-
3269
3386
  public abstract void uniformMatrix3fv(int location, int count, boolean transpose, FloatBuffer mat);
3270
-
3271
3387
  public abstract void uniformMatrix4fv(int location, int count, boolean transpose, FloatBuffer mat);
3272
-
3273
3388
  public abstract void validateProgram(int program);
3274
-
3275
3389
  public abstract boolean isShader(int shader);
3276
-
3277
3390
  public abstract void getShaderiv(int shader, int pname, IntBuffer params);
3278
-
3279
3391
  public abstract void getAttachedShaders(int program, int maxCount, IntBuffer count, IntBuffer shaders);
3280
-
3281
3392
  public abstract String getShaderInfoLog(int shader);
3282
-
3283
3393
  public abstract String getShaderSource(int shader);
3284
-
3285
3394
  public abstract void getShaderPrecisionFormat(int shaderType, int precisionType, IntBuffer range, IntBuffer precision);
3286
-
3287
3395
  public abstract void getVertexAttribfv(int index, int pname, FloatBuffer params);
3288
-
3289
3396
  public abstract void getVertexAttribiv(int index, int pname, IntBuffer params);
3290
-
3291
3397
  public abstract void getVertexAttribPointerv(int index, int pname, ByteBuffer data);
3292
-
3293
3398
  public abstract void getUniformfv(int program, int location, FloatBuffer params);
3294
-
3295
3399
  public abstract void getUniformiv(int program, int location, IntBuffer params);
3296
-
3297
3400
  public abstract boolean isProgram(int program);
3298
-
3299
3401
  public abstract void getProgramiv(int program, int pname, IntBuffer params);
3300
-
3301
3402
  public abstract String getProgramInfoLog(int program);
3302
3403
 
3303
3404
  ///////////////////////////////////////////////////////////
3405
+
3304
3406
  // Per-Fragment Operations
3305
- public abstract void scissor(int x, int y, int w, int h);
3306
3407
 
3408
+ public abstract void scissor(int x, int y, int w, int h);
3307
3409
  public abstract void sampleCoverage(float value, boolean invert);
3308
-
3309
3410
  public abstract void stencilFunc(int func, int ref, int mask);
3310
-
3311
3411
  public abstract void stencilFuncSeparate(int face, int func, int ref, int mask);
3312
-
3313
3412
  public abstract void stencilOp(int sfail, int dpfail, int dppass);
3314
-
3315
3413
  public abstract void stencilOpSeparate(int face, int sfail, int dpfail, int dppass);
3316
-
3317
3414
  public abstract void depthFunc(int func);
3318
-
3319
3415
  public abstract void blendEquation(int mode);
3320
-
3321
3416
  public abstract void blendEquationSeparate(int modeRGB, int modeAlpha);
3322
-
3323
3417
  public abstract void blendFunc(int src, int dst);
3324
-
3325
3418
  public abstract void blendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
3326
-
3327
3419
  public abstract void blendColor(float red, float green, float blue, float alpha);
3328
3420
 
3329
3421
  ///////////////////////////////////////////////////////////
3422
+
3330
3423
  // Whole Framebuffer Operations
3331
- public abstract void colorMask(boolean r, boolean g, boolean b, boolean a);
3332
3424
 
3425
+ public abstract void colorMask(boolean r, boolean g, boolean b, boolean a);
3333
3426
  public abstract void depthMask(boolean mask);
3334
-
3335
3427
  public abstract void stencilMask(int mask);
3336
-
3337
3428
  public abstract void stencilMaskSeparate(int face, int mask);
3338
-
3339
3429
  public abstract void clearColor(float r, float g, float b, float a);
3340
-
3341
3430
  public abstract void clearDepth(float d);
3342
-
3343
3431
  public abstract void clearStencil(int s);
3344
-
3345
3432
  public abstract void clear(int buf);
3346
3433
 
3347
3434
  ///////////////////////////////////////////////////////////
3435
+
3348
3436
  // Framebuffers Objects
3437
+
3349
3438
  public void bindFramebuffer(int target, int framebuffer) {
3350
3439
  graphics.beginBindFramebuffer(target, framebuffer);
3351
3440
  bindFramebufferImpl(target, framebuffer);
3352
3441
  graphics.endBindFramebuffer(target, framebuffer);
3353
3442
  }
3354
-
3355
3443
  protected abstract void bindFramebufferImpl(int target, int framebuffer);
3356
3444
 
3357
3445
  public abstract void deleteFramebuffers(int n, IntBuffer framebuffers);
3358
-
3359
3446
  public abstract void genFramebuffers(int n, IntBuffer framebuffers);
3360
-
3361
3447
  public abstract void bindRenderbuffer(int target, int renderbuffer);
3362
-
3363
3448
  public abstract void deleteRenderbuffers(int n, IntBuffer renderbuffers);
3364
-
3365
3449
  public abstract void genRenderbuffers(int n, IntBuffer renderbuffers);
3366
-
3367
3450
  public abstract void renderbufferStorage(int target, int internalFormat, int width, int height);
3368
-
3369
3451
  public abstract void framebufferRenderbuffer(int target, int attachment, int rendbuferfTarget, int renderbuffer);
3370
-
3371
3452
  public abstract void framebufferTexture2D(int target, int attachment, int texTarget, int texture, int level);
3372
-
3373
3453
  public abstract int checkFramebufferStatus(int target);
3374
-
3375
3454
  public abstract boolean isFramebuffer(int framebuffer);
3376
-
3377
3455
  public abstract void getFramebufferAttachmentParameteriv(int target, int attachment, int pname, IntBuffer params);
3378
-
3379
3456
  public abstract boolean isRenderbuffer(int renderbuffer);
3380
-
3381
3457
  public abstract void getRenderbufferParameteriv(int target, int pname, IntBuffer params);
3382
-
3383
3458
  public abstract void blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter);
3384
-
3385
3459
  public abstract void renderbufferStorageMultisample(int target, int samples, int format, int width, int height);
3386
-
3387
3460
  public abstract void readBuffer(int buf);
3388
-
3389
3461
  public abstract void drawBuffer(int buf);
3462
+
3463
+ ///////////////////////////////////////////////////////////
3464
+
3465
+ // Exceptions
3466
+
3467
+ /**
3468
+ * Exception for when attempting an operation requiring the graphics renderer, context, etc
3469
+ * to have been initialized before that initialization.
3470
+ */
3471
+ public class GraphicsNotInitializedException extends RuntimeException {
3472
+
3473
+ /**
3474
+ * Create a new exception indicating that an action could not be fulfilled because the rendering
3475
+ * context or equivalent is not ready.
3476
+ *
3477
+ * @param msg Further details about the issue.
3478
+ */
3479
+ public GraphicsNotInitializedException(String msg) {
3480
+ super(msg);
3481
+ }
3482
+ }
3390
3483
  }