propane 3.4.2-java → 3.5.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +5 -1
- data/Gemfile +2 -0
- data/README.md +15 -3
- data/Rakefile +9 -10
- data/bin/propane +3 -1
- data/lib/propane.rb +2 -1
- data/lib/propane/app.rb +2 -1
- data/lib/propane/creators/sketch_class.rb +7 -1
- data/lib/propane/creators/sketch_factory.rb +4 -2
- data/lib/propane/creators/sketch_writer.rb +1 -0
- data/lib/propane/helper_methods.rb +22 -22
- data/lib/propane/helpers/numeric.rb +2 -0
- data/lib/propane/helpers/version_error.rb +1 -0
- data/lib/propane/library.rb +5 -1
- data/lib/propane/library_loader.rb +2 -0
- data/lib/propane/native_folder.rb +10 -9
- data/lib/propane/native_loader.rb +3 -0
- data/lib/propane/runner.rb +11 -5
- data/lib/propane/version.rb +2 -1
- data/library/boids/boids.rb +21 -11
- data/library/color_group/color_group.rb +2 -0
- data/library/control_panel/control_panel.rb +8 -5
- data/library/dxf/dxf.rb +2 -0
- data/library/file_chooser/chooser.rb +10 -9
- data/library/file_chooser/file_chooser.rb +10 -9
- data/library/library_proxy/library_proxy.rb +2 -0
- data/library/net/net.rb +2 -0
- data/library/simplex_noise/simplex_noise.rb +2 -0
- data/library/slider/slider.rb +23 -22
- data/library/vector_utils/vector_utils.rb +4 -0
- data/library/video_event/video_event.rb +2 -0
- data/pom.rb +46 -45
- data/pom.xml +4 -4
- data/propane.gemspec +8 -7
- data/src/main/java/monkstone/ColorUtil.java +1 -3
- data/src/main/java/monkstone/MathToolModule.java +1 -1
- data/src/main/java/monkstone/PropaneLibrary.java +2 -2
- data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
- data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +788 -283
- data/src/main/java/processing/awt/PImageAWT.java +260 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +56 -53
- data/src/main/java/processing/awt/PSurfaceAWT.java +309 -211
- data/src/main/java/processing/awt/ShimAWT.java +580 -0
- data/src/main/java/processing/core/PApplet.java +2877 -2098
- data/src/main/java/processing/core/PConstants.java +477 -447
- data/src/main/java/processing/core/PFont.java +930 -884
- data/src/main/java/processing/core/PGraphics.java +337 -309
- data/src/main/java/processing/core/PImage.java +1689 -1689
- data/src/main/java/processing/core/PMatrix.java +172 -159
- data/src/main/java/processing/core/PMatrix2D.java +456 -410
- data/src/main/java/processing/core/PMatrix3D.java +755 -735
- data/src/main/java/processing/core/PShape.java +2910 -2656
- data/src/main/java/processing/core/PShapeOBJ.java +97 -94
- data/src/main/java/processing/core/PShapeSVG.java +1656 -1462
- data/src/main/java/processing/core/PStyle.java +40 -37
- data/src/main/java/processing/core/PSurface.java +134 -97
- data/src/main/java/processing/core/PSurfaceNone.java +292 -218
- data/src/main/java/processing/core/PVector.java +991 -966
- data/src/main/java/processing/core/ThinkDifferent.java +12 -8
- data/src/main/java/processing/data/DoubleDict.java +756 -710
- data/src/main/java/processing/data/DoubleList.java +749 -696
- data/src/main/java/processing/data/FloatDict.java +748 -702
- data/src/main/java/processing/data/FloatList.java +751 -697
- data/src/main/java/processing/data/IntDict.java +720 -673
- data/src/main/java/processing/data/IntList.java +699 -633
- data/src/main/java/processing/data/JSONArray.java +931 -873
- data/src/main/java/processing/data/JSONObject.java +1262 -1165
- data/src/main/java/processing/data/JSONTokener.java +351 -341
- data/src/main/java/processing/data/LongDict.java +710 -663
- data/src/main/java/processing/data/LongList.java +701 -635
- data/src/main/java/processing/data/Sort.java +37 -41
- data/src/main/java/processing/data/StringDict.java +525 -486
- data/src/main/java/processing/data/StringList.java +626 -580
- data/src/main/java/processing/data/Table.java +3693 -3513
- data/src/main/java/processing/data/TableRow.java +182 -183
- data/src/main/java/processing/data/XML.java +954 -880
- data/src/main/java/processing/event/Event.java +87 -67
- data/src/main/java/processing/event/KeyEvent.java +48 -41
- data/src/main/java/processing/event/MouseEvent.java +87 -113
- data/src/main/java/processing/event/TouchEvent.java +10 -6
- data/src/main/java/processing/javafx/PSurfaceFX.java +26 -0
- data/src/main/java/processing/net/Client.java +20 -20
- data/src/main/java/processing/net/Server.java +9 -9
- data/src/main/java/processing/opengl/FontTexture.java +286 -266
- data/src/main/java/processing/opengl/FrameBuffer.java +390 -376
- data/src/main/java/processing/opengl/LinePath.java +130 -91
- data/src/main/java/processing/opengl/LineStroker.java +593 -582
- data/src/main/java/processing/opengl/PGL.java +645 -579
- data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
- data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12287 -12030
- data/src/main/java/processing/opengl/PJOGL.java +1743 -1672
- data/src/main/java/processing/opengl/PShader.java +345 -416
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4601 -4543
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1113 -1029
- data/src/main/java/processing/opengl/Texture.java +1489 -1401
- data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
- data/test/create_test.rb +21 -20
- data/test/deglut_spec_test.rb +4 -2
- data/test/helper_methods_test.rb +49 -20
- data/test/math_tool_test.rb +39 -32
- data/test/native_folder.rb +47 -0
- data/test/respond_to_test.rb +3 -2
- data/test/sketches/key_event.rb +2 -2
- data/test/sketches/library/my_library/my_library.rb +3 -0
- data/test/test_helper.rb +2 -0
- data/test/vecmath_spec_test.rb +35 -22
- data/vendors/Rakefile +28 -22
- metadata +13 -13
- data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
- 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,474 +31,485 @@ import processing.opengl.PGraphicsOpenGL.GLResourceFrameBuffer;
|
|
28
31
|
import java.nio.IntBuffer;
|
29
32
|
|
30
33
|
/**
|
31
|
-
* Encapsulates a Frame Buffer Object for offscreen rendering.
|
32
|
-
* onscreen == true, it represents the normal
|
33
|
-
* mechanism in OPENGL2 to return
|
34
|
-
*
|
35
|
-
* extension is
|
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.
|
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
|
+
|
58
|
+
protected int depthBits;
|
59
|
+
protected int stencilBits;
|
60
|
+
protected boolean packedDepthStencil;
|
61
|
+
|
62
|
+
protected boolean multisample;
|
63
|
+
protected int nsamples;
|
64
|
+
|
65
|
+
protected int numColorBuffers;
|
66
|
+
protected Texture[] colorBufferTex;
|
67
|
+
|
68
|
+
protected boolean screenFb;
|
69
|
+
protected boolean noDepth;
|
70
|
+
|
71
|
+
protected IntBuffer pixelBuffer;
|
72
|
+
|
73
|
+
|
74
|
+
FrameBuffer(PGraphicsOpenGL pg) {
|
75
|
+
this.pg = pg;
|
76
|
+
pgl = pg.pgl;
|
77
|
+
context = pgl.createEmptyContext();
|
78
|
+
}
|
79
|
+
|
80
|
+
|
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
|
+
}
|
40
134
|
|
41
|
-
|
42
|
-
protected PGL pgl;
|
43
|
-
protected int context; // The context that created this framebuffer.
|
135
|
+
screenFb = screen;
|
44
136
|
|
45
|
-
|
46
|
-
|
47
|
-
public int glStencil;
|
48
|
-
public int glDepthStencil;
|
49
|
-
public int glMultisample;
|
50
|
-
public int width;
|
51
|
-
public int height;
|
52
|
-
private GLResourceFrameBuffer glres;
|
137
|
+
allocate();
|
138
|
+
noDepth = false;
|
53
139
|
|
54
|
-
|
55
|
-
|
56
|
-
protected boolean packedDepthStencil;
|
140
|
+
pixelBuffer = null;
|
141
|
+
}
|
57
142
|
|
58
|
-
protected boolean multisample;
|
59
|
-
protected int nsamples;
|
60
143
|
|
61
|
-
|
62
|
-
|
144
|
+
FrameBuffer(PGraphicsOpenGL pg, int w, int h) {
|
145
|
+
this(pg, w, h, 1, 1, 0, 0, false, false);
|
146
|
+
}
|
63
147
|
|
64
|
-
protected boolean screenFb;
|
65
|
-
protected boolean noDepth;
|
66
148
|
|
67
|
-
|
149
|
+
FrameBuffer(PGraphicsOpenGL pg, int w, int h, boolean screen) {
|
150
|
+
this(pg, w, h, 1, 1, 0, 0, false, screen);
|
151
|
+
}
|
68
152
|
|
69
|
-
FrameBuffer(PGraphicsOpenGL pg) {
|
70
|
-
this.pg = pg;
|
71
|
-
pgl = pg.pgl;
|
72
|
-
context = pgl.createEmptyContext();
|
73
|
-
}
|
74
153
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
}
|
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
|
+
}
|
92
165
|
|
93
|
-
|
94
|
-
|
166
|
+
public void copyColor(FrameBuffer dest) {
|
167
|
+
copy(dest, PGL.COLOR_BUFFER_BIT);
|
168
|
+
}
|
95
169
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
} else {
|
100
|
-
multisample = false;
|
101
|
-
nsamples = 1;
|
102
|
-
}
|
170
|
+
public void copyDepth(FrameBuffer dest) {
|
171
|
+
copy(dest, PGL.DEPTH_BUFFER_BIT);
|
172
|
+
}
|
103
173
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
colorBufferTex[i] = null;
|
108
|
-
}
|
174
|
+
public void copyStencil(FrameBuffer dest) {
|
175
|
+
copy(dest, PGL.STENCIL_BUFFER_BIT);
|
176
|
+
}
|
109
177
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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
|
-
}
|
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
|
+
}
|
128
186
|
|
129
|
-
|
187
|
+
public void bind() {
|
188
|
+
pgl.bindFramebufferImpl(PGL.FRAMEBUFFER, glFbo);
|
189
|
+
}
|
130
190
|
|
131
|
-
|
132
|
-
|
191
|
+
public void disableDepthTest() {
|
192
|
+
noDepth = true;
|
193
|
+
}
|
133
194
|
|
134
|
-
|
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
|
+
}
|
135
203
|
}
|
204
|
+
}
|
136
205
|
|
137
|
-
|
138
|
-
|
139
|
-
|
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
|
+
}
|
140
212
|
|
141
|
-
|
142
|
-
|
213
|
+
public void getPixels(int[] pixels) {
|
214
|
+
if (pixelBuffer != null) {
|
215
|
+
pixelBuffer.get(pixels, 0, pixels.length);
|
216
|
+
pixelBuffer.rewind();
|
143
217
|
}
|
218
|
+
}
|
144
219
|
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
-
}
|
220
|
+
public IntBuffer getPixelBuffer() {
|
221
|
+
return pixelBuffer;
|
222
|
+
}
|
156
223
|
|
157
|
-
|
158
|
-
|
159
|
-
|
224
|
+
public boolean hasDepthBuffer() {
|
225
|
+
return 0 < depthBits;
|
226
|
+
}
|
160
227
|
|
161
|
-
|
162
|
-
|
163
|
-
|
228
|
+
public boolean hasStencilBuffer() {
|
229
|
+
return 0 < stencilBits;
|
230
|
+
}
|
164
231
|
|
165
|
-
|
166
|
-
|
232
|
+
public void setFBO(int id) {
|
233
|
+
if (screenFb) {
|
234
|
+
glFbo = id;
|
167
235
|
}
|
236
|
+
}
|
168
237
|
|
169
|
-
|
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
|
-
}
|
238
|
+
///////////////////////////////////////////////////////////
|
177
239
|
|
178
|
-
|
179
|
-
pgl.bindFramebufferImpl(PGL.FRAMEBUFFER, glFbo);
|
180
|
-
}
|
240
|
+
// Color buffer setters.
|
181
241
|
|
182
|
-
public void disableDepthTest() {
|
183
|
-
noDepth = true;
|
184
|
-
}
|
185
242
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
if (pg.getHint(ENABLE_DEPTH_TEST)) {
|
190
|
-
pgl.enable(PGL.DEPTH_TEST);
|
191
|
-
} else {
|
192
|
-
pgl.disable(PGL.DEPTH_TEST);
|
193
|
-
}
|
194
|
-
}
|
195
|
-
}
|
243
|
+
public void setColorBuffer(Texture tex) {
|
244
|
+
setColorBuffers(new Texture[] { tex }, 1);
|
245
|
+
}
|
196
246
|
|
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
|
-
}
|
205
247
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
}
|
211
|
-
}
|
248
|
+
public void setColorBuffers(Texture[] textures) {
|
249
|
+
setColorBuffers(textures, textures.length);
|
250
|
+
}
|
251
|
+
|
212
252
|
|
213
|
-
|
214
|
-
|
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.");
|
215
259
|
}
|
216
260
|
|
217
|
-
|
218
|
-
|
261
|
+
for (int i = 0; i < numColorBuffers; i++) {
|
262
|
+
colorBufferTex[i] = textures[i];
|
219
263
|
}
|
220
264
|
|
221
|
-
|
222
|
-
|
265
|
+
pg.pushFramebuffer();
|
266
|
+
pg.setFramebuffer(this);
|
267
|
+
|
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);
|
223
272
|
}
|
224
273
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
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);
|
229
278
|
}
|
230
279
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
280
|
+
pgl.validateFramebuffer();
|
281
|
+
|
282
|
+
pg.popFramebuffer();
|
283
|
+
}
|
284
|
+
|
285
|
+
|
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;
|
235
292
|
}
|
236
293
|
|
237
|
-
|
238
|
-
|
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);
|
239
300
|
}
|
301
|
+
pgl.validateFramebuffer();
|
240
302
|
|
241
|
-
|
242
|
-
|
243
|
-
return;
|
244
|
-
}
|
303
|
+
pg.popFramebuffer();
|
304
|
+
}
|
245
305
|
|
246
|
-
if (numColorBuffers != PApplet.min(n, textures.length)) {
|
247
|
-
throw new RuntimeException("Wrong number of textures to set the color "
|
248
|
-
+ "buffers.");
|
249
|
-
}
|
250
306
|
|
251
|
-
|
307
|
+
public int getDefaultReadBuffer() {
|
308
|
+
if (screenFb) {
|
309
|
+
return pgl.getDefaultReadBuffer();
|
310
|
+
} else {
|
311
|
+
return PGL.COLOR_ATTACHMENT0;
|
312
|
+
}
|
313
|
+
}
|
252
314
|
|
253
|
-
pg.pushFramebuffer();
|
254
|
-
pg.setFramebuffer(this);
|
255
315
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
316
|
+
public int getDefaultDrawBuffer() {
|
317
|
+
if (screenFb) {
|
318
|
+
return pgl.getDefaultDrawBuffer();
|
319
|
+
} else {
|
320
|
+
return PGL.COLOR_ATTACHMENT0;
|
321
|
+
}
|
322
|
+
}
|
261
323
|
|
262
|
-
for (int i = 0; i < numColorBuffers; i++) {
|
263
|
-
pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
|
264
|
-
colorBufferTex[i].glTarget,
|
265
|
-
colorBufferTex[i].glName, 0);
|
266
|
-
}
|
267
324
|
|
268
|
-
|
325
|
+
///////////////////////////////////////////////////////////
|
269
326
|
|
270
|
-
|
271
|
-
}
|
327
|
+
// Allocate/release framebuffer.
|
272
328
|
|
273
|
-
public void swapColorBuffers() {
|
274
|
-
for (int i = 0; i < numColorBuffers - 1; i++) {
|
275
|
-
int i1 = (i + 1);
|
276
|
-
Texture tmp = colorBufferTex[i];
|
277
|
-
colorBufferTex[i] = colorBufferTex[i1];
|
278
|
-
colorBufferTex[i1] = tmp;
|
279
|
-
}
|
280
329
|
|
281
|
-
|
282
|
-
|
283
|
-
for (int i = 0; i < numColorBuffers; i++) {
|
284
|
-
pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0 + i,
|
285
|
-
colorBufferTex[i].glTarget,
|
286
|
-
colorBufferTex[i].glName, 0);
|
287
|
-
}
|
288
|
-
pgl.validateFramebuffer();
|
330
|
+
protected void allocate() {
|
331
|
+
dispose(); // Just in the case this object is being re-allocated.
|
289
332
|
|
290
|
-
|
291
|
-
|
333
|
+
context = pgl.getCurrentContext();
|
334
|
+
glres = new GLResourceFrameBuffer(this); // create the FBO resources...
|
292
335
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
}
|
336
|
+
if (screenFb) {
|
337
|
+
glFbo = 0;
|
338
|
+
} else {
|
339
|
+
if (multisample) {
|
340
|
+
initColorBufferMultisample();
|
341
|
+
}
|
300
342
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
343
|
+
if (packedDepthStencil) {
|
344
|
+
initPackedDepthStencilBuffer();
|
345
|
+
} else {
|
346
|
+
if (0 < depthBits) {
|
347
|
+
initDepthBuffer();
|
306
348
|
}
|
307
|
-
|
308
|
-
|
309
|
-
///////////////////////////////////////////////////////////
|
310
|
-
// Allocate/release framebuffer.
|
311
|
-
protected void allocate() {
|
312
|
-
dispose(); // Just in the case this object is being re-allocated.
|
313
|
-
|
314
|
-
context = pgl.getCurrentContext();
|
315
|
-
glres = new GLResourceFrameBuffer(this); // create the FBO resources...
|
316
|
-
|
317
|
-
if (screenFb) {
|
318
|
-
glFbo = 0;
|
319
|
-
} else {
|
320
|
-
if (multisample) {
|
321
|
-
initColorBufferMultisample();
|
322
|
-
}
|
323
|
-
|
324
|
-
if (packedDepthStencil) {
|
325
|
-
initPackedDepthStencilBuffer();
|
326
|
-
} else {
|
327
|
-
if (0 < depthBits) {
|
328
|
-
initDepthBuffer();
|
329
|
-
}
|
330
|
-
if (0 < stencilBits) {
|
331
|
-
initStencilBuffer();
|
332
|
-
}
|
333
|
-
}
|
349
|
+
if (0 < stencilBits) {
|
350
|
+
initStencilBuffer();
|
334
351
|
}
|
352
|
+
}
|
335
353
|
}
|
354
|
+
}
|
336
355
|
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
glres = null;
|
349
|
-
}
|
356
|
+
|
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;
|
350
367
|
}
|
368
|
+
}
|
351
369
|
|
352
|
-
protected boolean contextIsOutdated() {
|
353
|
-
if (screenFb) {
|
354
|
-
return false;
|
355
|
-
}
|
356
370
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
371
|
+
protected boolean contextIsOutdated() {
|
372
|
+
if (screenFb) return false;
|
373
|
+
|
374
|
+
boolean outdated = !pgl.contextIsCurrent(context);
|
375
|
+
if (outdated) {
|
376
|
+
dispose();
|
377
|
+
for (int i = 0; i < numColorBuffers; i++) {
|
378
|
+
colorBufferTex[i] = null;
|
379
|
+
}
|
365
380
|
}
|
381
|
+
return outdated;
|
382
|
+
}
|
366
383
|
|
367
|
-
protected void initColorBufferMultisample() {
|
368
|
-
if (screenFb) {
|
369
|
-
return;
|
370
|
-
}
|
371
384
|
|
372
|
-
|
373
|
-
|
385
|
+
protected void initColorBufferMultisample() {
|
386
|
+
if (screenFb) return;
|
374
387
|
|
375
|
-
|
376
|
-
|
377
|
-
PGL.RGBA8, width, height);
|
378
|
-
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0,
|
379
|
-
PGL.RENDERBUFFER, glMultisample);
|
388
|
+
pg.pushFramebuffer();
|
389
|
+
pg.setFramebuffer(this);
|
380
390
|
|
381
|
-
|
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
396
|
|
384
|
-
|
385
|
-
|
386
|
-
return;
|
387
|
-
}
|
397
|
+
pg.popFramebuffer();
|
398
|
+
}
|
388
399
|
|
389
|
-
if (width == 0 || height == 0) {
|
390
|
-
throw new RuntimeException("PFramebuffer: size undefined.");
|
391
|
-
}
|
392
400
|
|
393
|
-
|
394
|
-
|
401
|
+
protected void initPackedDepthStencilBuffer() {
|
402
|
+
if (screenFb) return;
|
395
403
|
|
396
|
-
|
404
|
+
if (width == 0 || height == 0) {
|
405
|
+
throw new RuntimeException("PFramebuffer: size undefined.");
|
406
|
+
}
|
397
407
|
|
398
|
-
|
399
|
-
|
400
|
-
PGL.DEPTH24_STENCIL8, width, height);
|
401
|
-
} else {
|
402
|
-
pgl.renderbufferStorage(PGL.RENDERBUFFER, PGL.DEPTH24_STENCIL8,
|
403
|
-
width, height);
|
404
|
-
}
|
408
|
+
pg.pushFramebuffer();
|
409
|
+
pg.setFramebuffer(this);
|
405
410
|
|
406
|
-
|
407
|
-
PGL.RENDERBUFFER, glDepthStencil);
|
408
|
-
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
|
409
|
-
PGL.RENDERBUFFER, glDepthStencil);
|
411
|
+
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepthStencil);
|
410
412
|
|
411
|
-
|
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);
|
412
419
|
}
|
413
420
|
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
421
|
+
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
|
422
|
+
PGL.RENDERBUFFER, glDepthStencil);
|
423
|
+
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
|
424
|
+
PGL.RENDERBUFFER, glDepthStencil);
|
418
425
|
|
419
|
-
|
420
|
-
|
421
|
-
}
|
426
|
+
pg.popFramebuffer();
|
427
|
+
}
|
422
428
|
|
423
|
-
pg.pushFramebuffer();
|
424
|
-
pg.setFramebuffer(this);
|
425
|
-
|
426
|
-
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
|
427
|
-
|
428
|
-
int glConst = PGL.DEPTH_COMPONENT16;
|
429
|
-
switch (depthBits) {
|
430
|
-
case 16:
|
431
|
-
glConst = PGL.DEPTH_COMPONENT16;
|
432
|
-
break;
|
433
|
-
case 24:
|
434
|
-
glConst = PGL.DEPTH_COMPONENT24;
|
435
|
-
break;
|
436
|
-
case 32:
|
437
|
-
glConst = PGL.DEPTH_COMPONENT32;
|
438
|
-
break;
|
439
|
-
default:
|
440
|
-
break;
|
441
|
-
}
|
442
429
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
430
|
+
protected void initDepthBuffer() {
|
431
|
+
if (screenFb) return;
|
432
|
+
|
433
|
+
if (width == 0 || height == 0) {
|
434
|
+
throw new RuntimeException("PFramebuffer: size undefined.");
|
435
|
+
}
|
436
|
+
|
437
|
+
pg.pushFramebuffer();
|
438
|
+
pg.setFramebuffer(this);
|
449
439
|
|
450
|
-
|
451
|
-
PGL.RENDERBUFFER, glDepth);
|
440
|
+
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glDepth);
|
452
441
|
|
453
|
-
|
442
|
+
int glConst = PGL.DEPTH_COMPONENT16;
|
443
|
+
switch (depthBits) {
|
444
|
+
case 16:
|
445
|
+
glConst = PGL.DEPTH_COMPONENT16;
|
446
|
+
break;
|
447
|
+
case 24:
|
448
|
+
glConst = PGL.DEPTH_COMPONENT24;
|
449
|
+
break;
|
450
|
+
case 32:
|
451
|
+
glConst = PGL.DEPTH_COMPONENT32;
|
452
|
+
break;
|
453
|
+
default:
|
454
|
+
break;
|
454
455
|
}
|
455
456
|
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
457
|
+
if (multisample) {
|
458
|
+
pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
|
459
|
+
width, height);
|
460
|
+
} else {
|
461
|
+
pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
|
462
|
+
}
|
460
463
|
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
+
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
|
465
|
+
PGL.RENDERBUFFER, glDepth);
|
466
|
+
|
467
|
+
pg.popFramebuffer();
|
468
|
+
}
|
464
469
|
|
465
|
-
pg.pushFramebuffer();
|
466
|
-
pg.setFramebuffer(this);
|
467
|
-
|
468
|
-
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
|
469
|
-
|
470
|
-
int glConst = PGL.STENCIL_INDEX1;
|
471
|
-
switch (stencilBits) {
|
472
|
-
case 1:
|
473
|
-
glConst = PGL.STENCIL_INDEX1;
|
474
|
-
break;
|
475
|
-
case 4:
|
476
|
-
glConst = PGL.STENCIL_INDEX4;
|
477
|
-
break;
|
478
|
-
case 8:
|
479
|
-
glConst = PGL.STENCIL_INDEX8;
|
480
|
-
break;
|
481
|
-
default:
|
482
|
-
break;
|
483
|
-
}
|
484
|
-
if (multisample) {
|
485
|
-
pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
|
486
|
-
width, height);
|
487
|
-
} else {
|
488
|
-
pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
|
489
|
-
}
|
490
470
|
|
491
|
-
|
492
|
-
|
471
|
+
protected void initStencilBuffer() {
|
472
|
+
if (screenFb) return;
|
493
473
|
|
494
|
-
|
474
|
+
if (width == 0 || height == 0) {
|
475
|
+
throw new RuntimeException("PFramebuffer: size undefined.");
|
495
476
|
}
|
496
477
|
|
497
|
-
|
498
|
-
|
499
|
-
|
478
|
+
pg.pushFramebuffer();
|
479
|
+
pg.setFramebuffer(this);
|
480
|
+
|
481
|
+
pgl.bindRenderbuffer(PGL.RENDERBUFFER, glStencil);
|
482
|
+
|
483
|
+
int glConst = PGL.STENCIL_INDEX1;
|
484
|
+
switch (stencilBits) {
|
485
|
+
case 1:
|
486
|
+
glConst = PGL.STENCIL_INDEX1;
|
487
|
+
break;
|
488
|
+
case 4:
|
489
|
+
glConst = PGL.STENCIL_INDEX4;
|
490
|
+
break;
|
491
|
+
case 8:
|
492
|
+
glConst = PGL.STENCIL_INDEX8;
|
493
|
+
break;
|
494
|
+
default:
|
495
|
+
break;
|
500
496
|
}
|
497
|
+
if (multisample) {
|
498
|
+
pgl.renderbufferStorageMultisample(PGL.RENDERBUFFER, nsamples, glConst,
|
499
|
+
width, height);
|
500
|
+
} else {
|
501
|
+
pgl.renderbufferStorage(PGL.RENDERBUFFER, glConst, width, height);
|
502
|
+
}
|
503
|
+
|
504
|
+
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.STENCIL_ATTACHMENT,
|
505
|
+
PGL.RENDERBUFFER, glStencil);
|
506
|
+
|
507
|
+
pg.popFramebuffer();
|
508
|
+
}
|
509
|
+
|
510
|
+
|
511
|
+
protected void createPixelBuffer() {
|
512
|
+
pixelBuffer = IntBuffer.allocate(width * height);
|
513
|
+
pixelBuffer.rewind();
|
514
|
+
}
|
501
515
|
}
|