40
40
*/
41
41
42
42
public class FrameBuffer implements PConstants {
43
+ protected PGraphicsOpenGL pg ;
43
44
protected PGL pgl ;
44
45
protected int context ; // The context that created this framebuffer.
45
46
@@ -67,16 +68,17 @@ public class FrameBuffer implements PConstants {
67
68
protected IntBuffer pixelBuffer ;
68
69
69
70
70
- FrameBuffer () {
71
- pgl = PGraphicsOpenGL .pgl ;
71
+ FrameBuffer (PGraphicsOpenGL pg ) {
72
+ this .pg = pg ;
73
+ pgl = pg .pgl ;
72
74
context = pgl .createEmptyContext ();
73
75
}
74
76
75
77
76
- FrameBuffer (int w , int h , int samples , int colorBuffers ,
77
- int depthBits , int stencilBits , boolean packedDepthStencil ,
78
- boolean screen ) {
79
- this ();
78
+ FrameBuffer (PGraphicsOpenGL pg , int w , int h , int samples , int colorBuffers ,
79
+ int depthBits , int stencilBits , boolean packedDepthStencil ,
80
+ boolean screen ) {
81
+ this (pg );
80
82
81
83
glFbo = 0 ;
82
84
glDepth = 0 ;
@@ -136,13 +138,13 @@ public class FrameBuffer implements PConstants {
136
138
}
137
139
138
140
139
- FrameBuffer (int w , int h ) {
140
- this (w , h , 1 , 1 , 0 , 0 , false , false );
141
+ FrameBuffer (PGraphicsOpenGL pg , int w , int h ) {
142
+ this (pg , w , h , 1 , 1 , 0 , 0 , false , false );
141
143
}
142
144
143
145
144
- FrameBuffer (int w , int h , boolean screen ) {
145
- this (w , h , 1 , 1 , 0 , 0 , false , screen );
146
+ FrameBuffer (PGraphicsOpenGL pg , int w , int h , boolean screen ) {
147
+ this (pg , w , h , 1 , 1 , 0 , 0 , false , screen );
146
148
}
147
149
148
150
@@ -172,25 +174,36 @@ protected void finalize() throws Throwable {
172
174
}
173
175
174
176
public void clear () {
175
- PGraphicsOpenGL .pushFramebuffer ();
176
- PGraphicsOpenGL .setFramebuffer (this );
177
+ pg .pushFramebuffer ();
178
+ pg .setFramebuffer (this );
177
179
pgl .clearDepth (1 );
178
180
pgl .clearStencil (0 );
179
181
pgl .clearColor (0 , 0 , 0 , 0 );
180
182
pgl .clear (PGL .DEPTH_BUFFER_BIT |
181
183
PGL .STENCIL_BUFFER_BIT |
182
184
PGL .COLOR_BUFFER_BIT );
183
- PGraphicsOpenGL .popFramebuffer ();
185
+ pg .popFramebuffer ();
184
186
}
185
187
186
- public void copy (FrameBuffer dest , FrameBuffer current ) {
188
+ public void copyColor (FrameBuffer dest ) {
189
+ copy (dest , PGL .COLOR_BUFFER_BIT );
190
+ }
191
+
192
+ public void copyDepth (FrameBuffer dest ) {
193
+ copy (dest , PGL .DEPTH_BUFFER_BIT );
194
+ }
195
+
196
+ public void copyStencil (FrameBuffer dest ) {
197
+ copy (dest , PGL .STENCIL_BUFFER_BIT );
198
+ }
199
+
200
+ public void copy (FrameBuffer dest , int mask ) {
187
201
pgl .bindFramebuffer (PGL .READ_FRAMEBUFFER , this .glFbo );
188
202
pgl .bindFramebuffer (PGL .DRAW_FRAMEBUFFER , dest .glFbo );
189
203
pgl .blitFramebuffer (0 , 0 , this .width , this .height ,
190
- 0 , 0 , dest .width , dest .height ,
191
- PGL .COLOR_BUFFER_BIT , PGL .NEAREST );
192
- pgl .bindFramebuffer (PGL .READ_FRAMEBUFFER , current .glFbo );
193
- pgl .bindFramebuffer (PGL .DRAW_FRAMEBUFFER , current .glFbo );
204
+ 0 , 0 , dest .width , dest .height , mask , PGL .NEAREST );
205
+ pgl .bindFramebuffer (PGL .READ_FRAMEBUFFER , pg .getCurrentFB ().glFbo );
206
+ pgl .bindFramebuffer (PGL .DRAW_FRAMEBUFFER , pg .getCurrentFB ().glFbo );
194
207
}
195
208
196
209
public void bind () {
@@ -201,7 +214,7 @@ public void disableDepthTest() {
201
214
noDepth = true ;
202
215
}
203
216
204
- public void finish (PGraphicsOpenGL pg ) {
217
+ public void finish () {
205
218
if (noDepth ) {
206
219
// No need to clear depth buffer because depth testing was disabled.
207
220
if (pg .getHint (ENABLE_DEPTH_TEST )) {
@@ -271,8 +284,8 @@ public void setColorBuffers(Texture[] textures, int n) {
271
284
colorBufferTex [i ] = textures [i ];
272
285
}
273
286
274
- PGraphicsOpenGL .pushFramebuffer ();
275
- PGraphicsOpenGL .setFramebuffer (this );
287
+ pg .pushFramebuffer ();
288
+ pg .setFramebuffer (this );
276
289
277
290
// Making sure nothing is attached.
278
291
for (int i = 0 ; i < numColorBuffers ; i ++) {
@@ -288,7 +301,7 @@ public void setColorBuffers(Texture[] textures, int n) {
288
301
289
302
pgl .validateFramebuffer ();
290
303
291
- PGraphicsOpenGL .popFramebuffer ();
304
+ pg .popFramebuffer ();
292
305
}
293
306
294
307
@@ -300,16 +313,16 @@ public void swapColorBuffers() {
300
313
colorBufferTex [i1 ] = tmp ;
301
314
}
302
315
303
- PGraphicsOpenGL .pushFramebuffer ();
304
- PGraphicsOpenGL .setFramebuffer (this );
316
+ pg .pushFramebuffer ();
317
+ pg .setFramebuffer (this );
305
318
for (int i = 0 ; i < numColorBuffers ; i ++) {
306
319
pgl .framebufferTexture2D (PGL .FRAMEBUFFER , PGL .COLOR_ATTACHMENT0 + i ,
307
320
colorBufferTex [i ].glTarget ,
308
321
colorBufferTex [i ].glName , 0 );
309
322
}
310
323
pgl .validateFramebuffer ();
311
324
312
- PGraphicsOpenGL .popFramebuffer ();
325
+ pg .popFramebuffer ();
313
326
}
314
327
315
328
@@ -345,7 +358,7 @@ protected void allocate() {
345
358
glFbo = 0 ;
346
359
} else {
347
360
//create the FBO object...
348
- glFbo = PGraphicsOpenGL .createFrameBufferObject (context );
361
+ glFbo = PGraphicsOpenGL .createFrameBufferObject (context , pgl );
349
362
350
363
// ... and then create the rest of the stuff.
351
364
if (multisample ) {
@@ -420,17 +433,17 @@ protected boolean contextIsOutdated() {
420
433
protected void createColorBufferMultisample () {
421
434
if (screenFb ) return ;
422
435
423
- PGraphicsOpenGL .pushFramebuffer ();
424
- PGraphicsOpenGL .setFramebuffer (this );
436
+ pg .pushFramebuffer ();
437
+ pg .setFramebuffer (this );
425
438
426
- glMultisample = PGraphicsOpenGL .createRenderBufferObject (context );
439
+ glMultisample = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
427
440
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glMultisample );
428
441
pgl .renderbufferStorageMultisample (PGL .RENDERBUFFER , nsamples ,
429
442
PGL .RGBA8 , width , height );
430
443
pgl .framebufferRenderbuffer (PGL .FRAMEBUFFER , PGL .COLOR_ATTACHMENT0 ,
431
444
PGL .RENDERBUFFER , glMultisample );
432
445
433
- PGraphicsOpenGL .popFramebuffer ();
446
+ pg .popFramebuffer ();
434
447
}
435
448
436
449
@@ -441,10 +454,10 @@ protected void createPackedDepthStencilBuffer() {
441
454
throw new RuntimeException ("PFramebuffer: size undefined." );
442
455
}
443
456
444
- PGraphicsOpenGL .pushFramebuffer ();
445
- PGraphicsOpenGL .setFramebuffer (this );
457
+ pg .pushFramebuffer ();
458
+ pg .setFramebuffer (this );
446
459
447
- glDepthStencil = PGraphicsOpenGL .createRenderBufferObject (context );
460
+ glDepthStencil = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
448
461
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glDepthStencil );
449
462
450
463
if (multisample ) {
@@ -460,7 +473,7 @@ protected void createPackedDepthStencilBuffer() {
460
473
pgl .framebufferRenderbuffer (PGL .FRAMEBUFFER , PGL .STENCIL_ATTACHMENT ,
461
474
PGL .RENDERBUFFER , glDepthStencil );
462
475
463
- PGraphicsOpenGL .popFramebuffer ();
476
+ pg .popFramebuffer ();
464
477
}
465
478
466
479
@@ -471,10 +484,10 @@ protected void createDepthBuffer() {
471
484
throw new RuntimeException ("PFramebuffer: size undefined." );
472
485
}
473
486
474
- PGraphicsOpenGL .pushFramebuffer ();
475
- PGraphicsOpenGL .setFramebuffer (this );
487
+ pg .pushFramebuffer ();
488
+ pg .setFramebuffer (this );
476
489
477
- glDepth = PGraphicsOpenGL .createRenderBufferObject (context );
490
+ glDepth = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
478
491
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glDepth );
479
492
480
493
int glConst = PGL .DEPTH_COMPONENT16 ;
@@ -496,7 +509,7 @@ protected void createDepthBuffer() {
496
509
pgl .framebufferRenderbuffer (PGL .FRAMEBUFFER , PGL .DEPTH_ATTACHMENT ,
497
510
PGL .RENDERBUFFER , glDepth );
498
511
499
- PGraphicsOpenGL .popFramebuffer ();
512
+ pg .popFramebuffer ();
500
513
}
501
514
502
515
@@ -507,10 +520,10 @@ protected void createStencilBuffer() {
507
520
throw new RuntimeException ("PFramebuffer: size undefined." );
508
521
}
509
522
510
- PGraphicsOpenGL .pushFramebuffer ();
511
- PGraphicsOpenGL .setFramebuffer (this );
523
+ pg .pushFramebuffer ();
524
+ pg .setFramebuffer (this );
512
525
513
- glStencil = PGraphicsOpenGL .createRenderBufferObject (context );
526
+ glStencil = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
514
527
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glStencil );
515
528
516
529
int glConst = PGL .STENCIL_INDEX1 ;
@@ -531,7 +544,7 @@ protected void createStencilBuffer() {
531
544
pgl .framebufferRenderbuffer (PGL .FRAMEBUFFER , PGL .STENCIL_ATTACHMENT ,
532
545
PGL .RENDERBUFFER , glStencil );
533
546
534
- PGraphicsOpenGL .popFramebuffer ();
547
+ pg .popFramebuffer ();
535
548
}
536
549
537
550
0 commit comments