propane 3.1.0.pre-java → 3.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/wrapper/maven-wrapper.properties +1 -0
  3. data/CHANGELOG.md +1 -5
  4. data/README.md +23 -12
  5. data/Rakefile +23 -12
  6. data/lib/propane/helpers/version_error.rb +6 -0
  7. data/lib/propane/runner.rb +12 -0
  8. data/lib/propane/version.rb +1 -1
  9. data/library/slider/slider.rb +1 -1
  10. data/mvnw +234 -0
  11. data/mvnw.cmd +145 -0
  12. data/pom.xml +28 -27
  13. data/propane.gemspec +2 -2
  14. data/src/main/java/japplemenubar/JAppleMenuBar.java +41 -47
  15. data/src/main/java/monkstone/ColorUtil.java +1 -1
  16. data/src/main/java/monkstone/MathToolModule.java +12 -11
  17. data/src/main/java/monkstone/PropaneLibrary.java +9 -10
  18. data/src/main/java/monkstone/core/LibraryProxy.java +124 -113
  19. data/src/main/java/monkstone/fastmath/Deglut.java +86 -89
  20. data/src/main/java/monkstone/filechooser/Chooser.java +7 -13
  21. data/src/main/java/monkstone/noise/SimplexNoise.java +0 -1
  22. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +4 -4
  23. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  24. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +9 -9
  25. data/src/main/java/monkstone/slider/SimpleSlider.java +0 -9
  26. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +11 -13
  27. data/src/main/java/monkstone/slider/Slider.java +1 -1
  28. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  29. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  30. data/src/main/java/monkstone/slider/WheelHandler.java +8 -9
  31. data/src/main/java/monkstone/vecmath/AppRender.java +2 -2
  32. data/src/main/java/monkstone/vecmath/ShapeRender.java +2 -2
  33. data/src/main/java/monkstone/vecmath/package-info.java +2 -2
  34. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
  35. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  36. data/src/main/java/monkstone/videoevent/VideoInterface.java +11 -5
  37. data/src/main/java/monkstone/videoevent/package-info.java +2 -2
  38. data/src/main/java/processing/awt/PGraphicsJava2D.java +1742 -2243
  39. data/src/main/java/processing/awt/PShapeJava2D.java +268 -270
  40. data/src/main/java/processing/awt/PSurfaceAWT.java +821 -920
  41. data/src/main/java/processing/core/DesktopHandler.java +94 -0
  42. data/src/main/java/processing/core/PApplet.java +14170 -14082
  43. data/src/main/java/processing/core/PConstants.java +447 -473
  44. data/src/main/java/processing/core/PFont.java +867 -873
  45. data/src/main/java/processing/core/PGraphics.java +7193 -7428
  46. data/src/main/java/processing/core/PImage.java +3051 -3117
  47. data/src/main/java/processing/core/PMatrix.java +159 -172
  48. data/src/main/java/processing/core/PMatrix2D.java +403 -444
  49. data/src/main/java/processing/core/PMatrix3D.java +735 -749
  50. data/src/main/java/processing/core/PShape.java +2651 -2793
  51. data/src/main/java/processing/core/PShapeOBJ.java +415 -422
  52. data/src/main/java/processing/core/PShapeSVG.java +1466 -1475
  53. data/src/main/java/processing/core/PStyle.java +37 -40
  54. data/src/main/java/processing/core/PSurface.java +98 -103
  55. data/src/main/java/processing/core/PSurfaceNone.java +208 -236
  56. data/src/main/java/processing/core/PVector.java +961 -990
  57. data/src/main/java/processing/data/DoubleDict.java +709 -753
  58. data/src/main/java/processing/data/DoubleList.java +695 -748
  59. data/src/main/java/processing/data/FloatDict.java +702 -746
  60. data/src/main/java/processing/data/FloatList.java +697 -751
  61. data/src/main/java/processing/data/IntDict.java +673 -718
  62. data/src/main/java/processing/data/IntList.java +633 -699
  63. data/src/main/java/processing/data/JSONArray.java +873 -931
  64. data/src/main/java/processing/data/JSONObject.java +1165 -1262
  65. data/src/main/java/processing/data/JSONTokener.java +341 -351
  66. data/src/main/java/processing/data/LongDict.java +662 -707
  67. data/src/main/java/processing/data/LongList.java +634 -700
  68. data/src/main/java/processing/data/Sort.java +41 -37
  69. data/src/main/java/processing/data/StringDict.java +486 -522
  70. data/src/main/java/processing/data/StringList.java +580 -624
  71. data/src/main/java/processing/data/Table.java +3508 -3686
  72. data/src/main/java/processing/data/TableRow.java +183 -182
  73. data/src/main/java/processing/data/XML.java +883 -957
  74. data/src/main/java/processing/event/Event.java +66 -87
  75. data/src/main/java/processing/event/KeyEvent.java +41 -48
  76. data/src/main/java/processing/event/MouseEvent.java +93 -103
  77. data/src/main/java/processing/event/TouchEvent.java +6 -10
  78. data/src/main/java/processing/javafx/PGraphicsFX2D.java +5 -69
  79. data/src/main/java/processing/javafx/PSurfaceFX.java +2 -7
  80. data/src/main/java/processing/opengl/FontTexture.java +270 -290
  81. data/src/main/java/processing/opengl/FrameBuffer.java +363 -375
  82. data/src/main/java/processing/opengl/LinePath.java +500 -543
  83. data/src/main/java/processing/opengl/LineStroker.java +582 -593
  84. data/src/main/java/processing/opengl/PGL.java +2881 -2904
  85. data/src/main/java/processing/opengl/PGraphics2D.java +315 -408
  86. data/src/main/java/processing/opengl/PGraphics3D.java +72 -107
  87. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12043 -12230
  88. data/src/main/java/processing/opengl/PJOGL.java +1681 -1745
  89. data/src/main/java/processing/opengl/PShader.java +1257 -1260
  90. data/src/main/java/processing/opengl/PShapeOpenGL.java +4599 -4662
  91. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1030 -1047
  92. data/src/main/java/processing/opengl/Texture.java +1397 -1462
  93. data/src/main/java/processing/opengl/VertexBuffer.java +55 -57
  94. data/src/main/resources/icon/icon-1024.png +0 -0
  95. data/src/main/resources/icon/icon-128.png +0 -0
  96. data/src/main/resources/icon/icon-16.png +0 -0
  97. data/src/main/resources/icon/icon-256.png +0 -0
  98. data/src/main/resources/icon/icon-32.png +0 -0
  99. data/src/main/resources/icon/icon-48.png +0 -0
  100. data/src/main/resources/icon/icon-512.png +0 -0
  101. data/src/main/resources/icon/icon-64.png +0 -0
  102. data/vendors/Rakefile +1 -1
  103. metadata +12 -8
  104. data/src/main/java/processing/core/ThinkDifferent.java +0 -70
@@ -1,5 +1,3 @@
1
- /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
-
3
1
  /*
4
2
  Part of the Processing project - http://processing.org
5
3
 
@@ -20,8 +18,7 @@
20
18
  Public License along with this library; if not, write to the
21
19
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
20
  Boston, MA 02111-1307 USA
23
- */
24
-
21
+ */
25
22
  package processing.opengl;
26
23
 
27
24
  import processing.core.PApplet;
@@ -31,473 +28,464 @@ import processing.opengl.PGraphicsOpenGL.GLResourceFrameBuffer;
31
28
  import java.nio.IntBuffer;
32
29
 
33
30
  /**
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.
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.
40
36
  *
41
37
  * By Andres Colubri.
42
38
  */
43
-
44
39
  public class FrameBuffer implements PConstants {
45
- protected PGraphicsOpenGL pg;
46
- protected PGL pgl;
47
- protected int context; // The context that created this framebuffer.
48
-
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;
57
40
 
58
- protected int depthBits;
59
- protected int stencilBits;
60
- protected boolean packedDepthStencil;
41
+ protected PGraphicsOpenGL pg;
42
+ protected PGL pgl;
43
+ protected int context; // The context that created this framebuffer.
61
44
 
62
- protected boolean multisample;
63
- protected int nsamples;
64
-
65
- protected int numColorBuffers;
66
- protected Texture[] colorBufferTex;
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;
67
53
 
68
- protected boolean screenFb;
69
- protected boolean noDepth;
70
-
71
- protected IntBuffer pixelBuffer;
54
+ protected int depthBits;
55
+ protected int stencilBits;
56
+ protected boolean packedDepthStencil;
72
57
 
58
+ protected boolean multisample;
59
+ protected int nsamples;
73
60
 
74
- FrameBuffer(PGraphicsOpenGL pg) {
75
- this.pg = pg;
76
- pgl = pg.pgl;
77
- context = pgl.createEmptyContext();
78
- }
61
+ protected int numColorBuffers;
62
+ protected Texture[] colorBufferTex;
79
63
 
64
+ protected boolean screenFb;
65
+ protected boolean noDepth;
80
66
 
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
-
143
-
144
- FrameBuffer(PGraphicsOpenGL pg, int w, int h) {
145
- this(pg, w, h, 1, 1, 0, 0, false, false);
146
- }
147
-
148
-
149
- FrameBuffer(PGraphicsOpenGL pg, int w, int h, boolean screen) {
150
- this(pg, w, h, 1, 1, 0, 0, false, screen);
151
- }
67
+ protected IntBuffer pixelBuffer;
152
68
 
69
+ FrameBuffer(PGraphicsOpenGL pg) {
70
+ this.pg = pg;
71
+ pgl = pg.pgl;
72
+ context = pgl.createEmptyContext();
73
+ }
153
74
 
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
- }
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
+ }
165
92
 
166
- public void copyColor(FrameBuffer dest) {
167
- copy(dest, PGL.COLOR_BUFFER_BIT);
168
- }
93
+ width = w;
94
+ height = h;
169
95
 
170
- public void copyDepth(FrameBuffer dest) {
171
- copy(dest, PGL.DEPTH_BUFFER_BIT);
172
- }
96
+ if (1 < samples) {
97
+ multisample = true;
98
+ nsamples = samples;
99
+ } else {
100
+ multisample = false;
101
+ nsamples = 1;
102
+ }
173
103
 
174
- public void copyStencil(FrameBuffer dest) {
175
- copy(dest, PGL.STENCIL_BUFFER_BIT);
176
- }
104
+ numColorBuffers = colorBuffers;
105
+ colorBufferTex = new Texture[numColorBuffers];
106
+ for (int i = 0; i < numColorBuffers; i++) {
107
+ colorBufferTex[i] = null;
108
+ }
177
109
 
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
- }
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
+ }
186
128
 
187
- public void bind() {
188
- pgl.bindFramebufferImpl(PGL.FRAMEBUFFER, glFbo);
189
- }
129
+ screenFb = screen;
190
130
 
191
- public void disableDepthTest() {
192
- noDepth = true;
193
- }
131
+ allocate();
132
+ noDepth = false;
194
133
 
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
- }
134
+ pixelBuffer = null;
203
135
  }
204
- }
205
136
 
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
- }
212
-
213
- public void getPixels(int[] pixels) {
214
- if (pixelBuffer != null) {
215
- pixelBuffer.get(pixels, 0, pixels.length);
216
- pixelBuffer.rewind();
137
+ FrameBuffer(PGraphicsOpenGL pg, int w, int h) {
138
+ this(pg, w, h, 1, 1, 0, 0, false, false);
217
139
  }
218
- }
219
-
220
- public IntBuffer getPixelBuffer() {
221
- return pixelBuffer;
222
- }
223
140
 
224
- public boolean hasDepthBuffer() {
225
- return 0 < depthBits;
226
- }
227
-
228
- public boolean hasStencilBuffer() {
229
- return 0 < stencilBits;
230
- }
231
-
232
- public void setFBO(int id) {
233
- if (screenFb) {
234
- glFbo = id;
141
+ FrameBuffer(PGraphicsOpenGL pg, int w, int h, boolean screen) {
142
+ this(pg, w, h, 1, 1, 0, 0, false, screen);
235
143
  }
236
- }
237
-
238
- ///////////////////////////////////////////////////////////
239
-
240
- // Color buffer setters.
241
-
242
144
 
243
- public void setColorBuffer(Texture tex) {
244
- setColorBuffers(new Texture[] { tex }, 1);
245
- }
246
-
247
-
248
- public void setColorBuffers(Texture[] textures) {
249
- setColorBuffers(textures, textures.length);
250
- }
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
+ }
251
156
 
157
+ public void copyColor(FrameBuffer dest) {
158
+ copy(dest, PGL.COLOR_BUFFER_BIT);
159
+ }
252
160
 
253
- public void setColorBuffers(Texture[] textures, int n) {
254
- if (screenFb) return;
161
+ public void copyDepth(FrameBuffer dest) {
162
+ copy(dest, PGL.DEPTH_BUFFER_BIT);
163
+ }
255
164
 
256
- if (numColorBuffers != PApplet.min(n, textures.length)) {
257
- throw new RuntimeException("Wrong number of textures to set the color " +
258
- "buffers.");
165
+ public void copyStencil(FrameBuffer dest) {
166
+ copy(dest, PGL.STENCIL_BUFFER_BIT);
259
167
  }
260
168
 
261
- for (int i = 0; i < numColorBuffers; i++) {
262
- colorBufferTex[i] = textures[i];
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);
263
176
  }
264
177
 
265
- pg.pushFramebuffer();
266
- pg.setFramebuffer(this);
178
+ public void bind() {
179
+ pgl.bindFramebufferImpl(PGL.FRAMEBUFFER, glFbo);
180
+ }
267
181
 
268
- // Making sure nothing is attached.
269
- for (int i = 0; i < numColorBuffers; i++) {
270
- pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
271
- PGL.TEXTURE_2D, 0, 0);
182
+ public void disableDepthTest() {
183
+ noDepth = true;
272
184
  }
273
185
 
274
- for (int i = 0; i < numColorBuffers; i++) {
275
- pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
276
- colorBufferTex[i].glTarget,
277
- colorBufferTex[i].glName, 0);
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
+ }
278
195
  }
279
196
 
280
- pgl.validateFramebuffer();
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
+ }
281
205
 
282
- pg.popFramebuffer();
283
- }
206
+ public void getPixels(int[] pixels) {
207
+ if (pixelBuffer != null) {
208
+ pixelBuffer.get(pixels, 0, pixels.length);
209
+ pixelBuffer.rewind();
210
+ }
211
+ }
284
212
 
213
+ public IntBuffer getPixelBuffer() {
214
+ return pixelBuffer;
215
+ }
285
216
 
286
- public void swapColorBuffers() {
287
- for (int i = 0; i < numColorBuffers - 1; i++) {
288
- int i1 = (i + 1);
289
- Texture tmp = colorBufferTex[i];
290
- colorBufferTex[i] = colorBufferTex[i1];
291
- colorBufferTex[i1] = tmp;
217
+ public boolean hasDepthBuffer() {
218
+ return 0 < depthBits;
292
219
  }
293
220
 
294
- pg.pushFramebuffer();
295
- pg.setFramebuffer(this);
296
- for (int i = 0; i < numColorBuffers; i++) {
297
- pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
298
- colorBufferTex[i].glTarget,
299
- colorBufferTex[i].glName, 0);
221
+ public boolean hasStencilBuffer() {
222
+ return 0 < stencilBits;
300
223
  }
301
- pgl.validateFramebuffer();
302
224
 
303
- pg.popFramebuffer();
304
- }
225
+ public void setFBO(int id) {
226
+ if (screenFb) {
227
+ glFbo = id;
228
+ }
229
+ }
305
230
 
231
+ ///////////////////////////////////////////////////////////
232
+ // Color buffer setters.
233
+ public void setColorBuffer(Texture tex) {
234
+ setColorBuffers(new Texture[]{tex}, 1);
235
+ }
306
236
 
307
- public int getDefaultReadBuffer() {
308
- if (screenFb) {
309
- return pgl.getDefaultReadBuffer();
310
- } else {
311
- return PGL.COLOR_ATTACHMENT0;
237
+ public void setColorBuffers(Texture[] textures) {
238
+ setColorBuffers(textures, textures.length);
312
239
  }
313
- }
314
240
 
241
+ public void setColorBuffers(Texture[] textures, int n) {
242
+ if (screenFb) {
243
+ return;
244
+ }
315
245
 
316
- public int getDefaultDrawBuffer() {
317
- if (screenFb) {
318
- return pgl.getDefaultDrawBuffer();
319
- } else {
320
- return PGL.COLOR_ATTACHMENT0;
321
- }
322
- }
246
+ if (numColorBuffers != PApplet.min(n, textures.length)) {
247
+ throw new RuntimeException("Wrong number of textures to set the color "
248
+ + "buffers.");
249
+ }
323
250
 
251
+ for (int i = 0; i < numColorBuffers; i++) {
252
+ colorBufferTex[i] = textures[i];
253
+ }
324
254
 
325
- ///////////////////////////////////////////////////////////
255
+ pg.pushFramebuffer();
256
+ pg.setFramebuffer(this);
326
257
 
327
- // Allocate/release framebuffer.
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
+ }
328
263
 
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
+ }
329
269
 
330
- protected void allocate() {
331
- dispose(); // Just in the case this object is being re-allocated.
270
+ pgl.validateFramebuffer();
332
271
 
333
- context = pgl.getCurrentContext();
334
- glres = new GLResourceFrameBuffer(this); // create the FBO resources...
272
+ pg.popFramebuffer();
273
+ }
335
274
 
336
- if (screenFb) {
337
- glFbo = 0;
338
- } else {
339
- if (multisample) {
340
- initColorBufferMultisample();
341
- }
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
+ }
342
282
 
343
- if (packedDepthStencil) {
344
- initPackedDepthStencilBuffer();
345
- } else {
346
- if (0 < depthBits) {
347
- initDepthBuffer();
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);
348
289
  }
349
- if (0 < stencilBits) {
350
- initStencilBuffer();
290
+ pgl.validateFramebuffer();
291
+
292
+ pg.popFramebuffer();
293
+ }
294
+
295
+ public int getDefaultReadBuffer() {
296
+ if (screenFb) {
297
+ return pgl.getDefaultReadBuffer();
298
+ } else {
299
+ return PGL.COLOR_ATTACHMENT0;
351
300
  }
352
- }
353
301
  }
354
- }
355
302
 
303
+ public int getDefaultDrawBuffer() {
304
+ if (screenFb) {
305
+ return pgl.getDefaultDrawBuffer();
306
+ } else {
307
+ return PGL.COLOR_ATTACHMENT0;
308
+ }
309
+ }
356
310
 
357
- protected void dispose() {
358
- if (screenFb) return;
359
- if (glres != null) {
360
- glres.dispose();
361
- glFbo = 0;
362
- glDepth = 0;
363
- glStencil = 0;
364
- glMultisample = 0;
365
- glDepthStencil = 0;
366
- glres = null;
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
+ }
367
337
  }
368
- }
369
338
 
339
+ protected void dispose() {
340
+ if (screenFb) {
341
+ return;
342
+ }
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;
351
+ }
352
+ }
370
353
 
371
- protected boolean contextIsOutdated() {
372
- if (screenFb) return false;
354
+ protected boolean contextIsOutdated() {
355
+ if (screenFb) {
356
+ return false;
357
+ }
373
358
 
374
- boolean outdated = !pgl.contextIsCurrent(context);
375
- if (outdated) {
376
- dispose();
377
- for (int i = 0; i < numColorBuffers; i++) {
378
- colorBufferTex[i] = null;
379
- }
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;
380
367
  }
381
- return outdated;
382
- }
383
368
 
369
+ protected void initColorBufferMultisample() {
370
+ if (screenFb) {
371
+ return;
372
+ }
384
373
 
385
- protected void initColorBufferMultisample() {
386
- if (screenFb) return;
374
+ pg.pushFramebuffer();
375
+ pg.setFramebuffer(this);
387
376
 
388
- pg.pushFramebuffer();
389
- pg.setFramebuffer(this);
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);
390
382
 
391
- pgl.bindRenderbuffer(PGL.RENDERBUFFER, glMultisample);
392
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
393
- PGL.RGBA8, width, height);
394
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0,
395
- PGL.RENDERBUFFER, glMultisample);
383
+ pg.popFramebuffer();
384
+ }
396
385
 
397
- pg.popFramebuffer();
398
- }
386
+ protected void initPackedDepthStencilBuffer() {
387
+ if (screenFb) {
388
+ return;
389
+ }
399
390
 
391
+ if (width == 0 || height == 0) {
392
+ throw new RuntimeException("PFramebuffer: size undefined.");
393
+ }
400
394
 
401
- protected void initPackedDepthStencilBuffer() {
402
- if (screenFb) return;
395
+ pg.pushFramebuffer();
396
+ pg.setFramebuffer(this);
403
397
 
404
- if (width == 0 || height == 0) {
405
- throw new RuntimeException("PFramebuffer: size undefined.");
406
- }
398
+ pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
407
399
 
408
- pg.pushFramebuffer();
409
- pg.setFramebuffer(this);
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
+ }
410
407
 
411
- pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
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
412
 
413
- if (multisample) {
414
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples,
415
- PGL.DEPTH24_STENCIL8, width, height);
416
- } else {
417
- pgl.renderbufferStorage(PGL.RENDERBUFFER, PGL.DEPTH24_STENCIL8,
418
- width, height);
413
+ pg.popFramebuffer();
419
414
  }
420
415
 
421
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
422
- PGL.RENDERBUFFER, glDepthStencil);
423
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
424
- PGL.RENDERBUFFER, glDepthStencil);
425
-
426
- pg.popFramebuffer();
427
- }
416
+ protected void initDepthBuffer() {
417
+ if (screenFb) {
418
+ return;
419
+ }
428
420
 
421
+ if (width == 0 || height == 0) {
422
+ throw new RuntimeException("PFramebuffer: size undefined.");
423
+ }
429
424
 
430
- protected void initDepthBuffer() {
431
- if (screenFb) return;
425
+ pg.pushFramebuffer();
426
+ pg.setFramebuffer(this);
432
427
 
433
- if (width == 0 || height == 0) {
434
- throw new RuntimeException("PFramebuffer: size undefined.");
435
- }
428
+ pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
436
429
 
437
- pg.pushFramebuffer();
438
- pg.setFramebuffer(this);
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
+ }
439
438
 
440
- pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
439
+ if (multisample) {
440
+ pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
441
+ width, height);
442
+ } else {
443
+ pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
444
+ }
441
445
 
442
- int glConst = PGL.DEPTH_COMPONENT16;
443
- if (depthBits == 16) {
444
- glConst = PGL.DEPTH_COMPONENT16;
445
- } else if (depthBits == 24) {
446
- glConst = PGL.DEPTH_COMPONENT24;
447
- } else if (depthBits == 32) {
448
- glConst = PGL.DEPTH_COMPONENT32;
449
- }
446
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
447
+ PGL.RENDERBUFFER, glDepth);
450
448
 
451
- if (multisample) {
452
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
453
- width, height);
454
- } else {
455
- pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
449
+ pg.popFramebuffer();
456
450
  }
457
451
 
458
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
459
- PGL.RENDERBUFFER, glDepth);
460
-
461
- pg.popFramebuffer();
462
- }
452
+ protected void initStencilBuffer() {
453
+ if (screenFb) {
454
+ return;
455
+ }
463
456
 
457
+ if (width == 0 || height == 0) {
458
+ throw new RuntimeException("PFramebuffer: size undefined.");
459
+ }
464
460
 
465
- protected void initStencilBuffer() {
466
- if (screenFb) return;
461
+ pg.pushFramebuffer();
462
+ pg.setFramebuffer(this);
467
463
 
468
- if (width == 0 || height == 0) {
469
- throw new RuntimeException("PFramebuffer: size undefined.");
470
- }
464
+ pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
471
465
 
472
- pg.pushFramebuffer();
473
- pg.setFramebuffer(this);
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
+ }
474
480
 
475
- pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
481
+ pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
482
+ PGL.RENDERBUFFER, glStencil);
476
483
 
477
- int glConst = PGL.STENCIL_INDEX1;
478
- if (stencilBits == 1) {
479
- glConst = PGL.STENCIL_INDEX1;
480
- } else if (stencilBits == 4) {
481
- glConst = PGL.STENCIL_INDEX4;
482
- } else if (stencilBits == 8) {
483
- glConst = PGL.STENCIL_INDEX8;
484
- }
485
- if (multisample) {
486
- pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
487
- width, height);
488
- } else {
489
- pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
484
+ pg.popFramebuffer();
490
485
  }
491
486
 
492
- pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
493
- PGL.RENDERBUFFER, glStencil);
494
-
495
- pg.popFramebuffer();
496
- }
497
-
498
-
499
- protected void createPixelBuffer() {
500
- pixelBuffer = IntBuffer.allocate(width * height);
501
- pixelBuffer.rewind();
502
- }
487
+ protected void createPixelBuffer() {
488
+ pixelBuffer = IntBuffer.allocate(width * height);
489
+ pixelBuffer.rewind();
490
+ }
503
491
  }