propane 3.4.0-java → 3.7.0.pre-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +2 -2
  6. data/CHANGELOG.md +12 -0
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +10 -11
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +6 -4
  12. data/lib/propane/app.rb +20 -10
  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 +23 -24
  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 +14 -6
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +28 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +6 -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 +7 -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 +4 -1
  37. data/pom.rb +37 -36
  38. data/pom.xml +7 -7
  39. data/propane.gemspec +16 -12
  40. data/src/main/java/monkstone/ColorUtil.java +13 -1
  41. data/src/main/java/monkstone/MathToolModule.java +253 -203
  42. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  43. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  44. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  45. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  46. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  47. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  48. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  51. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  52. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  53. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  54. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  55. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -3
  56. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  57. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  58. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  59. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  60. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  61. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  62. data/src/main/java/processing/awt/PSurfaceAWT.java +309 -209
  63. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  64. data/src/main/java/processing/core/PApplet.java +4510 -4503
  65. data/src/main/java/processing/core/PConstants.java +477 -447
  66. data/src/main/java/processing/core/PFont.java +914 -880
  67. data/src/main/java/processing/core/PGraphics.java +193 -177
  68. data/src/main/java/processing/core/PImage.java +611 -309
  69. data/src/main/java/processing/core/PMatrix.java +172 -159
  70. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  71. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  72. data/src/main/java/processing/core/PShape.java +2888 -2652
  73. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  74. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  75. data/src/main/java/processing/core/PStyle.java +40 -37
  76. data/src/main/java/processing/core/PSurface.java +139 -97
  77. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  78. data/src/main/java/processing/core/PVector.java +997 -965
  79. data/src/main/java/processing/core/ThinkDifferent.java +15 -13
  80. data/src/main/java/processing/data/DoubleDict.java +756 -710
  81. data/src/main/java/processing/data/DoubleList.java +749 -696
  82. data/src/main/java/processing/data/FloatDict.java +748 -702
  83. data/src/main/java/processing/data/FloatList.java +751 -697
  84. data/src/main/java/processing/data/IntDict.java +720 -673
  85. data/src/main/java/processing/data/IntList.java +699 -633
  86. data/src/main/java/processing/data/JSONArray.java +931 -873
  87. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  88. data/src/main/java/processing/data/JSONTokener.java +351 -341
  89. data/src/main/java/processing/data/LongDict.java +710 -663
  90. data/src/main/java/processing/data/LongList.java +701 -635
  91. data/src/main/java/processing/data/Sort.java +37 -41
  92. data/src/main/java/processing/data/StringDict.java +525 -486
  93. data/src/main/java/processing/data/StringList.java +626 -580
  94. data/src/main/java/processing/data/Table.java +3690 -3510
  95. data/src/main/java/processing/data/TableRow.java +182 -183
  96. data/src/main/java/processing/data/XML.java +957 -883
  97. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  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 +744 -0
  105. data/src/main/java/processing/net/Server.java +388 -0
  106. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  107. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  108. data/src/main/java/processing/opengl/LinePath.java +547 -500
  109. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  110. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  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 +1266 -1257
  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 +33 -62
  131. metadata +56 -48
  132. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  133. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  134. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  135. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  136. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  137. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  138. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  139. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  140. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  141. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  142. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  143. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  144. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  145. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  146. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  147. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  148. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  149. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  150. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  151. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  152. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  153. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  154. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  155. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,3 +1,5 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
1
3
  /*
2
4
  Part of the Processing project - http://processing.org
3
5
 
@@ -18,7 +20,8 @@
18
20
  Public License along with this library; if not, write to the
19
21
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
22
  Boston, MA 02111-1307 USA
21
- */
23
+ */
24
+
22
25
  package processing.opengl;
23
26
 
24
27
  import processing.core.PApplet;
@@ -28,464 +31,483 @@ import processing.opengl.PGraphicsOpenGL.GLResourceFrameBuffer;
28
31
  import java.nio.IntBuffer;
29
32
 
30
33
  /**
31
- * Encapsulates a Frame Buffer Object for offscreen rendering. When created with
32
- * onscreen == true, it represents the normal framebuffer. Needed by the stack
33
- * mechanism in OPENGL2 to return to onscreen rendering after a sequence of
34
- * pushFramebuffer calls. It transparently handles the situations when the FBO
35
- * extension is not available.
34
+ * Encapsulates a Frame Buffer Object for offscreen rendering.
35
+ * When created with onscreen == true, it represents the normal
36
+ * framebuffer. Needed by the stack mechanism in OPENGL2 to return
37
+ * to onscreen rendering after a sequence of pushFramebuffer calls.
38
+ * It transparently handles the situations when the FBO extension is
39
+ * not available.
36
40
  *
37
41
  * By Andres Colubri.
38
42
  */
43
+
39
44
  public class FrameBuffer implements PConstants {
45
+ protected PGraphicsOpenGL pg;
46
+ protected PGL pgl;
47
+ protected int context; // The context that created this framebuffer.
40
48
 
41
- protected PGraphicsOpenGL pg;
42
- protected PGL pgl;
43
- protected int context; // The context that created this framebuffer.
49
+ public int glFbo;
50
+ public int glDepth;
51
+ public int glStencil;
52
+ public int glDepthStencil;
53
+ public int glMultisample;
54
+ public int width;
55
+ public int height;
56
+ private GLResourceFrameBuffer glres;
44
57
 
45
- public int glFbo;
46
- public int glDepth;
47
- public int glStencil;
48
- public int glDepthStencil;
49
- public int glMultisample;
50
- public int width;
51
- public int height;
52
- private GLResourceFrameBuffer glres;
58
+ protected int depthBits;
59
+ protected int stencilBits;
60
+ protected boolean packedDepthStencil;
53
61
 
54
- protected int depthBits;
55
- protected int stencilBits;
56
- protected boolean packedDepthStencil;
62
+ protected boolean multisample;
63
+ protected int nsamples;
64
+
65
+ protected int numColorBuffers;
66
+ protected Texture[] colorBufferTex;
57
67
 
58
- protected boolean multisample;
59
- protected int nsamples;
68
+ protected boolean screenFb;
69
+ protected boolean noDepth;
70
+
71
+ protected IntBuffer pixelBuffer;
60
72
 
61
- protected int numColorBuffers;
62
- protected Texture[] colorBufferTex;
63
73
 
64
- protected boolean screenFb;
65
- protected boolean noDepth;
74
+ FrameBuffer(PGraphicsOpenGL pg) {
75
+ this.pg = pg;
76
+ pgl = pg.pgl;
77
+ context = pgl.createEmptyContext();
78
+ }
66
79
 
67
- protected IntBuffer pixelBuffer;
68
80
 
69
- FrameBuffer(PGraphicsOpenGL pg) {
70
- this.pg = pg;
71
- pgl = pg.pgl;
72
- context = pgl.createEmptyContext();
73
- }
81
+ FrameBuffer(PGraphicsOpenGL pg, int w, int h, int samples, int colorBuffers,
82
+ int depthBits, int stencilBits, boolean packedDepthStencil,
83
+ boolean screen) {
84
+ this(pg);
85
+
86
+ glFbo = 0;
87
+ glDepth = 0;
88
+ glStencil = 0;
89
+ glDepthStencil = 0;
90
+ glMultisample = 0;
91
+
92
+ if (screen) {
93
+ // If this framebuffer is used to represent a on-screen buffer,
94
+ // then it doesn't make it sense for it to have multisampling,
95
+ // color, depth or stencil buffers.
96
+ depthBits = stencilBits = samples = colorBuffers = 0;
97
+ }
98
+
99
+ width = w;
100
+ height = h;
101
+
102
+ if (1 < samples) {
103
+ multisample = true;
104
+ nsamples = samples;
105
+ } else {
106
+ multisample = false;
107
+ nsamples = 1;
108
+ }
109
+
110
+ numColorBuffers = colorBuffers;
111
+ colorBufferTex = new Texture[numColorBuffers];
112
+ for (int i = 0; i < numColorBuffers; i++) {
113
+ colorBufferTex[i] = null;
114
+ }
115
+
116
+ if (depthBits < 1 && stencilBits < 1) {
117
+ this.depthBits = 0;
118
+ this.stencilBits = 0;
119
+ this.packedDepthStencil = false;
120
+ } else {
121
+ if (packedDepthStencil) {
122
+ // When combined depth/stencil format is required, the depth and stencil
123
+ // bits are overriden and the 24/8 combination for a 32 bits surface is
124
+ // used.
125
+ this.depthBits = 24;
126
+ this.stencilBits = 8;
127
+ this.packedDepthStencil = true;
128
+ } else {
129
+ this.depthBits = depthBits;
130
+ this.stencilBits = stencilBits;
131
+ this.packedDepthStencil = false;
132
+ }
133
+ }
134
+
135
+ screenFb = screen;
136
+
137
+ allocate();
138
+ noDepth = false;
139
+
140
+ pixelBuffer = null;
141
+ }
142
+
74
143
 
75
- FrameBuffer(PGraphicsOpenGL pg, int w, int h, int samples, int colorBuffers,
76
- int depthBits, int stencilBits, boolean packedDepthStencil,
77
- boolean screen) {
78
- this(pg);
79
-
80
- glFbo = 0;
81
- glDepth = 0;
82
- glStencil = 0;
83
- glDepthStencil = 0;
84
- glMultisample = 0;
85
-
86
- if (screen) {
87
- // If this framebuffer is used to represent a on-screen buffer,
88
- // then it doesn't make it sense for it to have multisampling,
89
- // color, depth or stencil buffers.
90
- depthBits = stencilBits = samples = colorBuffers = 0;
91
- }
144
+ FrameBuffer(PGraphicsOpenGL pg, int w, int h) {
145
+ this(pg, w, h, 1, 1, 0, 0, false, false);
146
+ }
92
147
 
93
- width = w;
94
- height = h;
95
148
 
96
- if (1 < samples) {
97
- multisample = true;
98
- nsamples = samples;
99
- } else {
100
- multisample = false;
101
- nsamples = 1;
102
- }
149
+ FrameBuffer(PGraphicsOpenGL pg, int w, int h, boolean screen) {
150
+ this(pg, w, h, 1, 1, 0, 0, false, screen);
151
+ }
103
152
 
104
- numColorBuffers = colorBuffers;
105
- colorBufferTex = new Texture[numColorBuffers];
106
- for (int i = 0; i < numColorBuffers; i++) {
107
- colorBufferTex[i] = null;
108
- }
109
153
 
110
- if (depthBits < 1 && stencilBits < 1) {
111
- this.depthBits = 0;
112
- this.stencilBits = 0;
113
- this.packedDepthStencil = false;
114
- } else {
115
- if (packedDepthStencil) {
116
- // When combined depth/stencil format is required, the depth and stencil
117
- // bits are overriden and the 24/8 combination for a 32 bits surface is
118
- // used.
119
- this.depthBits = 24;
120
- this.stencilBits = 8;
121
- this.packedDepthStencil = true;
122
- } else {
123
- this.depthBits = depthBits;
124
- this.stencilBits = stencilBits;
125
- this.packedDepthStencil = false;
126
- }
127
- }
154
+ public void clear() {
155
+ pg.pushFramebuffer();
156
+ pg.setFramebuffer(this);
157
+ pgl.clearDepth(1);
158
+ pgl.clearStencil(0);
159
+ pgl.clearColor(0, 0, 0, 0);
160
+ pgl.clear(PGL.DEPTH_BUFFER_BIT |
161
+ PGL.STENCIL_BUFFER_BIT |
162
+ PGL.COLOR_BUFFER_BIT);
163
+ pg.popFramebuffer();
164
+ }
128
165
 
129
- screenFb = screen;
166
+ public void copyColor(FrameBuffer dest) {
167
+ copy(dest, PGL.COLOR_BUFFER_BIT);
168
+ }
130
169
 
131
- allocate();
132
- noDepth = false;
170
+ public void copyDepth(FrameBuffer dest) {
171
+ copy(dest, PGL.DEPTH_BUFFER_BIT);
172
+ }
133
173
 
134
- pixelBuffer = null;
135
- }
174
+ public void copyStencil(FrameBuffer dest) {
175
+ copy(dest, PGL.STENCIL_BUFFER_BIT);
176
+ }
136
177
 
137
- FrameBuffer(PGraphicsOpenGL pg, int w, int h) {
138
- this(pg, w, h, 1, 1, 0, 0, false, false);
139
- }
178
+ public void copy(FrameBuffer dest, int mask) {
179
+ pgl.bindFramebufferImpl(PGL.READ_FRAMEBUFFER, this.glFbo);
180
+ pgl.bindFramebufferImpl(PGL.DRAW_FRAMEBUFFER, dest.glFbo);
181
+ pgl.blitFramebuffer(0, 0, this.width, this.height,
182
+ 0, 0, dest.width, dest.height, mask, PGL.NEAREST);
183
+ pgl.bindFramebufferImpl(PGL.READ_FRAMEBUFFER, pg.getCurrentFB().glFbo);
184
+ pgl.bindFramebufferImpl(PGL.DRAW_FRAMEBUFFER, pg.getCurrentFB().glFbo);
185
+ }
140
186
 
141
- FrameBuffer(PGraphicsOpenGL pg, int w, int h, boolean screen) {
142
- this(pg, w, h, 1, 1, 0, 0, false, screen);
143
- }
187
+ public void bind() {
188
+ pgl.bindFramebufferImpl(PGL.FRAMEBUFFER, glFbo);
189
+ }
144
190
 
145
- public void clear() {
146
- pg.pushFramebuffer();
147
- pg.setFramebuffer(this);
148
- pgl.clearDepth(1);
149
- pgl.clearStencil(0);
150
- pgl.clearColor(0, 0, 0, 0);
151
- pgl.clear(PGL.DEPTH_BUFFER_BIT
152
- | PGL.STENCIL_BUFFER_BIT
153
- | PGL.COLOR_BUFFER_BIT);
154
- pg.popFramebuffer();
155
- }
191
+ public void disableDepthTest() {
192
+ noDepth = true;
193
+ }
156
194
 
157
- public void copyColor(FrameBuffer dest) {
158
- copy(dest, PGL.COLOR_BUFFER_BIT);
195
+ public void finish() {
196
+ if (noDepth) {
197
+ // No need to clear depth buffer because depth testing was disabled.
198
+ if (pg.getHint(ENABLE_DEPTH_TEST)) {
199
+ pgl.enable(PGL.DEPTH_TEST);
200
+ } else {
201
+ pgl.disable(PGL.DEPTH_TEST);
202
+ }
159
203
  }
204
+ }
160
205
 
161
- public void copyDepth(FrameBuffer dest) {
162
- copy(dest, PGL.DEPTH_BUFFER_BIT);
163
- }
206
+ public void readPixels() {
207
+ if (pixelBuffer == null) createPixelBuffer();
208
+ pixelBuffer.rewind();
209
+ pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE,
210
+ pixelBuffer);
211
+ }
164
212
 
165
- public void copyStencil(FrameBuffer dest) {
166
- copy(dest, PGL.STENCIL_BUFFER_BIT);
213
+ public void getPixels(int[] pixels) {
214
+ if (pixelBuffer != null) {
215
+ pixelBuffer.get(pixels, 0, pixels.length);
216
+ pixelBuffer.rewind();
167
217
  }
218
+ }
168
219
 
169
- public void copy(FrameBuffer dest, int mask) {
170
- pgl.bindFramebufferImpl(PGL.READ_FRAMEBUFFER, this.glFbo);
171
- pgl.bindFramebufferImpl(PGL.DRAW_FRAMEBUFFER, dest.glFbo);
172
- pgl.blitFramebuffer(0, 0, this.width, this.height,
173
- 0, 0, dest.width, dest.height, mask, PGL.NEAREST);
174
- pgl.bindFramebufferImpl(PGL.READ_FRAMEBUFFER, pg.getCurrentFB().glFbo);
175
- pgl.bindFramebufferImpl(PGL.DRAW_FRAMEBUFFER, pg.getCurrentFB().glFbo);
176
- }
220
+ public IntBuffer getPixelBuffer() {
221
+ return pixelBuffer;
222
+ }
177
223
 
178
- public void bind() {
179
- pgl.bindFramebufferImpl(PGL.FRAMEBUFFER, glFbo);
180
- }
224
+ public boolean hasDepthBuffer() {
225
+ return 0 < depthBits;
226
+ }
181
227
 
182
- public void disableDepthTest() {
183
- noDepth = true;
184
- }
228
+ public boolean hasStencilBuffer() {
229
+ return 0 < stencilBits;
230
+ }
185
231
 
186
- public void finish() {
187
- if (noDepth) {
188
- // No need to clear depth buffer because depth testing was disabled.
189
- if (pg.getHint(ENABLE_DEPTH_TEST)) {
190
- pgl.enable(PGL.DEPTH_TEST);
191
- } else {
192
- pgl.disable(PGL.DEPTH_TEST);
193
- }
194
- }
232
+ public void setFBO(int id) {
233
+ if (screenFb) {
234
+ glFbo = id;
195
235
  }
236
+ }
196
237
 
197
- public void readPixels() {
198
- if (pixelBuffer == null) {
199
- createPixelBuffer();
200
- }
201
- pixelBuffer.rewind();
202
- pgl.readPixels(0, 0, width, height, PGL.RGBA, PGL.UNSIGNED_BYTE,
203
- pixelBuffer);
204
- }
238
+ ///////////////////////////////////////////////////////////
205
239
 
206
- public void getPixels(int[] pixels) {
207
- if (pixelBuffer != null) {
208
- pixelBuffer.get(pixels, 0, pixels.length);
209
- pixelBuffer.rewind();
210
- }
211
- }
240
+ // Color buffer setters.
212
241
 
213
- public IntBuffer getPixelBuffer() {
214
- return pixelBuffer;
215
- }
216
242
 
217
- public boolean hasDepthBuffer() {
218
- return 0 < depthBits;
219
- }
243
+ public void setColorBuffer(Texture tex) {
244
+ setColorBuffers(new Texture[] { tex }, 1);
245
+ }
220
246
 
221
- public boolean hasStencilBuffer() {
222
- return 0 < stencilBits;
223
- }
224
247
 
225
- public void setFBO(int id) {
226
- if (screenFb) {
227
- glFbo = id;
228
- }
229
- }
248
+ public void setColorBuffers(Texture[] textures) {
249
+ setColorBuffers(textures, textures.length);
250
+ }
230
251
 
231
- ///////////////////////////////////////////////////////////
232
- // Color buffer setters.
233
- public void setColorBuffer(Texture tex) {
234
- setColorBuffers(new Texture[]{tex}, 1);
235
- }
236
252
 
237
- public void setColorBuffers(Texture[] textures) {
238
- setColorBuffers(textures, textures.length);
253
+ public void setColorBuffers(Texture[] textures, int n) {
254
+ if (screenFb) return;
255
+
256
+ if (numColorBuffers != PApplet.min(n, textures.length)) {
257
+ throw new RuntimeException("Wrong number of textures to set the color " +
258
+ "buffers.");
239
259
  }
240
260
 
241
- public void setColorBuffers(Texture[] textures, int n) {
242
- if (screenFb) {
243
- return;
244
- }
261
+ System.arraycopy(textures, 0, colorBufferTex, 0, numColorBuffers);
245
262
 
246
- if (numColorBuffers != PApplet.min(n, textures.length)) {
247
- throw new RuntimeException("Wrong number of textures to set the color "
248
- + "buffers.");
249
- }
263
+ pg.pushFramebuffer();
264
+ pg.setFramebuffer(this);
250
265
 
251
- for (int i = 0; i < numColorBuffers; i++) {
252
- colorBufferTex[i] = textures[i];
253
- }
266
+ // Making sure nothing is attached.
267
+ for (int i = 0; i < numColorBuffers; i++) {
268
+ pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
269
+ PGL.TEXTURE_2D, 0, 0);
270
+ }
254
271
 
255
- pg.pushFramebuffer();
256
- pg.setFramebuffer(this);
272
+ for (int i = 0; i < numColorBuffers; i++) {
273
+ pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
274
+ colorBufferTex[i].glTarget,
275
+ colorBufferTex[i].glName, 0);
276
+ }
257
277
 
258
- // Making sure nothing is attached.
259
- for (int i = 0; i < numColorBuffers; i++) {
260
- pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
261
- PGL.TEXTURE_2D, 0, 0);
262
- }
278
+ pgl.validateFramebuffer();
263
279
 
264
- for (int i = 0; i < numColorBuffers; i++) {
265
- pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
266
- colorBufferTex[i].glTarget,
267
- colorBufferTex[i].glName, 0);
268
- }
280
+ pg.popFramebuffer();
281
+ }
269
282
 
270
- pgl.validateFramebuffer();
271
283
 
272
- pg.popFramebuffer();
284
+ public void swapColorBuffers() {
285
+ for (int i = 0; i < numColorBuffers - 1; i++) {
286
+ int i1 = (i + 1);
287
+ Texture tmp = colorBufferTex[i];
288
+ colorBufferTex[i] = colorBufferTex[i1];
289
+ colorBufferTex[i1] = tmp;
273
290
  }
274
291
 
275
- public void swapColorBuffers() {
276
- for (int i = 0; i < numColorBuffers - 1; i++) {
277
- int i1 = (i + 1);
278
- Texture tmp = colorBufferTex[i];
279
- colorBufferTex[i] = colorBufferTex[i1];
280
- colorBufferTex[i1] = tmp;
281
- }
292
+ pg.pushFramebuffer();
293
+ pg.setFramebuffer(this);
294
+ for (int i = 0; i < numColorBuffers; i++) {
295
+ pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
296
+ colorBufferTex[i].glTarget,
297
+ colorBufferTex[i].glName, 0);
298
+ }
299
+ pgl.validateFramebuffer();
282
300
 
283
- pg.pushFramebuffer();
284
- pg.setFramebuffer(this);
285
- for (int i = 0; i < numColorBuffers; i++) {
286
- pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
287
- colorBufferTex[i].glTarget,
288
- colorBufferTex[i].glName, 0);
289
- }
290
- pgl.validateFramebuffer();
301
+ pg.popFramebuffer();
302
+ }
291
303
 
292
- pg.popFramebuffer();
293
- }
294
304
 
295
- public int getDefaultReadBuffer() {
296
- if (screenFb) {
297
- return pgl.getDefaultReadBuffer();
298
- } else {
299
- return PGL.COLOR_ATTACHMENT0;
300
- }
305
+ public int getDefaultReadBuffer() {
306
+ if (screenFb) {
307
+ return pgl.getDefaultReadBuffer();
308
+ } else {
309
+ return PGL.COLOR_ATTACHMENT0;
301
310
  }
311
+ }
302
312
 
303
- public int getDefaultDrawBuffer() {
304
- if (screenFb) {
305
- return pgl.getDefaultDrawBuffer();
306
- } else {
307
- return PGL.COLOR_ATTACHMENT0;
308
- }
309
- }
310
313
 
311
- ///////////////////////////////////////////////////////////
312
- // Allocate/release framebuffer.
313
- protected void allocate() {
314
- dispose(); // Just in the case this object is being re-allocated.
315
-
316
- context = pgl.getCurrentContext();
317
- glres = new GLResourceFrameBuffer(this); // create the FBO resources...
318
-
319
- if (screenFb) {
320
- glFbo = 0;
321
- } else {
322
- if (multisample) {
323
- initColorBufferMultisample();
324
- }
325
-
326
- if (packedDepthStencil) {
327
- initPackedDepthStencilBuffer();
328
- } else {
329
- if (0 < depthBits) {
330
- initDepthBuffer();
331
- }
332
- if (0 < stencilBits) {
333
- initStencilBuffer();
334
- }
335
- }
336
- }
314
+ public int getDefaultDrawBuffer() {
315
+ if (screenFb) {
316
+ return pgl.getDefaultDrawBuffer();
317
+ } else {
318
+ return PGL.COLOR_ATTACHMENT0;
337
319
  }
320
+ }
321
+
322
+
323
+ ///////////////////////////////////////////////////////////
324
+
325
+ // Allocate/release framebuffer.
326
+
327
+
328
+ protected final void allocate() {
329
+ dispose(); // Just in the case this object is being re-allocated.
330
+
331
+ context = pgl.getCurrentContext();
332
+ glres = new GLResourceFrameBuffer(this); // create the FBO resources...
338
333
 
339
- protected void dispose() {
340
- if (screenFb) {
341
- return;
334
+ if (screenFb) {
335
+ glFbo = 0;
336
+ } else {
337
+ if (multisample) {
338
+ initColorBufferMultisample();
339
+ }
340
+
341
+ if (packedDepthStencil) {
342
+ initPackedDepthStencilBuffer();
343
+ } else {
344
+ if (0 < depthBits) {
345
+ initDepthBuffer();
342
346
  }
343
- if (glres != null) {
344
- glres.dispose();
345
- glFbo = 0;
346
- glDepth = 0;
347
- glStencil = 0;
348
- glMultisample = 0;
349
- glDepthStencil = 0;
350
- glres = null;
347
+ if (0 < stencilBits) {
348
+ initStencilBuffer();
351
349
  }
350
+ }
352
351
  }
352
+ }
353
353
 
354
- protected boolean contextIsOutdated() {
355
- if (screenFb) {
356
- return false;
357
- }
358
354
 
359
- boolean outdated = !pgl.contextIsCurrent(context);
360
- if (outdated) {
361
- dispose();
362
- for (int i = 0; i < numColorBuffers; i++) {
363
- colorBufferTex[i] = null;
364
- }
365
- }
366
- return outdated;
355
+ protected void dispose() {
356
+ if (screenFb) return;
357
+ if (glres != null) {
358
+ glres.dispose();
359
+ glFbo = 0;
360
+ glDepth = 0;
361
+ glStencil = 0;
362
+ glMultisample = 0;
363
+ glDepthStencil = 0;
364
+ glres = null;
367
365
  }
366
+ }
368
367
 
369
- protected void initColorBufferMultisample() {
370
- if (screenFb) {
371
- return;
372
- }
373
-
374
- pg.pushFramebuffer();
375
- pg.setFramebuffer(this);
376
368
 
377
- pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
378
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
379
- PGL.RGBA8, width, height);
380
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0,
381
- PGL.RENDERBUFFER, glMultisample);
369
+ protected boolean contextIsOutdated() {
370
+ if (screenFb) return false;
382
371
 
383
- pg.popFramebuffer();
372
+ boolean outdated = !pgl.contextIsCurrent(context);
373
+ if (outdated) {
374
+ dispose();
375
+ for (int i = 0; i < numColorBuffers; i++) {
376
+ colorBufferTex[i] = null;
377
+ }
384
378
  }
379
+ return outdated;
380
+ }
385
381
 
386
- protected void initPackedDepthStencilBuffer() {
387
- if (screenFb) {
388
- return;
389
- }
390
382
 
391
- if (width == 0 || height == 0) {
392
- throw new RuntimeException("PFramebuffer: size undefined.");
393
- }
383
+ protected void initColorBufferMultisample() {
384
+ if (screenFb) return;
394
385
 
395
- pg.pushFramebuffer();
396
- pg.setFramebuffer(this);
386
+ pg.pushFramebuffer();
387
+ pg.setFramebuffer(this);
397
388
 
398
- pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
389
+ pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
390
+ pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
391
+ PGL.RGBA8, width, height);
392
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0,
393
+ PGL.RENDERBUFFER, glMultisample);
399
394
 
400
- if (multisample) {
401
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
402
- PGL.DEPTH24_STENCIL8, width, height);
403
- } else {
404
- pgl.renderbufferStorage(PGL.RENDERBUFFER, PGL.DEPTH24_STENCIL8,
405
- width, height);
406
- }
395
+ pg.popFramebuffer();
396
+ }
407
397
 
408
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
409
- PGL.RENDERBUFFER, glDepthStencil);
410
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
411
- PGL.RENDERBUFFER, glDepthStencil);
412
398
 
413
- pg.popFramebuffer();
399
+ protected void initPackedDepthStencilBuffer() {
400
+ if (screenFb) return;
401
+
402
+ if (width == 0 || height == 0) {
403
+ throw new RuntimeException("PFramebuffer: size undefined.");
414
404
  }
415
405
 
416
- protected void initDepthBuffer() {
417
- if (screenFb) {
418
- return;
419
- }
406
+ pg.pushFramebuffer();
407
+ pg.setFramebuffer(this);
420
408
 
421
- if (width == 0 || height == 0) {
422
- throw new RuntimeException("PFramebuffer: size undefined.");
423
- }
409
+ pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
424
410
 
425
- pg.pushFramebuffer();
426
- pg.setFramebuffer(this);
411
+ if (multisample) {
412
+ pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
413
+ PGL.DEPTH24_STENCIL8, width, height);
414
+ } else {
415
+ pgl.renderbufferStorage(PGL.RENDERBUFFER, PGL.DEPTH24_STENCIL8,
416
+ width, height);
417
+ }
427
418
 
428
- pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
419
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
420
+ PGL.RENDERBUFFER, glDepthStencil);
421
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
422
+ PGL.RENDERBUFFER, glDepthStencil);
429
423
 
430
- int glConst = PGL.DEPTH_COMPONENT16;
431
- if (depthBits == 16) {
432
- glConst = PGL.DEPTH_COMPONENT16;
433
- } else if (depthBits == 24) {
434
- glConst = PGL.DEPTH_COMPONENT24;
435
- } else if (depthBits == 32) {
436
- glConst = PGL.DEPTH_COMPONENT32;
437
- }
424
+ pg.popFramebuffer();
425
+ }
438
426
 
439
- if (multisample) {
440
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
441
- width, height);
442
- } else {
443
- pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
444
- }
445
427
 
446
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
447
- PGL.RENDERBUFFER, glDepth);
428
+ protected void initDepthBuffer() {
429
+ if (screenFb) return;
448
430
 
449
- pg.popFramebuffer();
431
+ if (width == 0 || height == 0) {
432
+ throw new RuntimeException("PFramebuffer: size undefined.");
450
433
  }
451
434
 
452
- protected void initStencilBuffer() {
453
- if (screenFb) {
454
- return;
455
- }
435
+ pg.pushFramebuffer();
436
+ pg.setFramebuffer(this);
456
437
 
457
- if (width == 0 || height == 0) {
458
- throw new RuntimeException("PFramebuffer: size undefined.");
459
- }
438
+ pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
460
439
 
461
- pg.pushFramebuffer();
462
- pg.setFramebuffer(this);
440
+ int glConst = PGL.DEPTH_COMPONENT16;
441
+ switch (depthBits) {
442
+ case 16:
443
+ glConst = PGL.DEPTH_COMPONENT16;
444
+ break;
445
+ case 24:
446
+ glConst = PGL.DEPTH_COMPONENT24;
447
+ break;
448
+ case 32:
449
+ glConst = PGL.DEPTH_COMPONENT32;
450
+ break;
451
+ default:
452
+ break;
453
+ }
463
454
 
464
- pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
455
+ if (multisample) {
456
+ pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
457
+ width, height);
458
+ } else {
459
+ pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
460
+ }
465
461
 
466
- int glConst = PGL.STENCIL_INDEX1;
467
- if (stencilBits == 1) {
468
- glConst = PGL.STENCIL_INDEX1;
469
- } else if (stencilBits == 4) {
470
- glConst = PGL.STENCIL_INDEX4;
471
- } else if (stencilBits == 8) {
472
- glConst = PGL.STENCIL_INDEX8;
473
- }
474
- if (multisample) {
475
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
476
- width, height);
477
- } else {
478
- pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
479
- }
462
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
463
+ PGL.RENDERBUFFER, glDepth);
480
464
 
481
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
482
- PGL.RENDERBUFFER, glStencil);
465
+ pg.popFramebuffer();
466
+ }
483
467
 
484
- pg.popFramebuffer();
468
+
469
+ protected void initStencilBuffer() {
470
+ if (screenFb) return;
471
+
472
+ if (width == 0 || height == 0) {
473
+ throw new RuntimeException("PFramebuffer: size undefined.");
485
474
  }
486
475
 
487
- protected void createPixelBuffer() {
488
- pixelBuffer = IntBuffer.allocate(width * height);
489
- pixelBuffer.rewind();
476
+ pg.pushFramebuffer();
477
+ pg.setFramebuffer(this);
478
+
479
+ pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
480
+
481
+ int glConst = PGL.STENCIL_INDEX1;
482
+ switch (stencilBits) {
483
+ case 1:
484
+ glConst = PGL.STENCIL_INDEX1;
485
+ break;
486
+ case 4:
487
+ glConst = PGL.STENCIL_INDEX4;
488
+ break;
489
+ case 8:
490
+ glConst = PGL.STENCIL_INDEX8;
491
+ break;
492
+ default:
493
+ break;
494
+ }
495
+ if (multisample) {
496
+ pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
497
+ width, height);
498
+ } else {
499
+ pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
490
500
  }
501
+
502
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
503
+ PGL.RENDERBUFFER, glStencil);
504
+
505
+ pg.popFramebuffer();
506
+ }
507
+
508
+
509
+ protected void createPixelBuffer() {
510
+ pixelBuffer = IntBuffer.allocate(width * height);
511
+ pixelBuffer.rewind();
512
+ }
491
513
  }