28
28
import processing .core .PConstants ;
29
29
import processing .opengl .PGraphicsOpenGL .GLResourceFrameBuffer ;
30
30
31
- import java .lang .ref .WeakReference ;
32
31
import java .nio .IntBuffer ;
33
32
34
33
/**
43
42
*/
44
43
45
44
public class FrameBuffer implements PConstants {
46
- protected WeakReference < PGraphicsOpenGL > pg ;
45
+ protected PGraphicsOpenGL pg ;
47
46
protected PGL pgl ;
48
47
protected int context ; // The context that created this framebuffer.
49
48
@@ -73,7 +72,7 @@ public class FrameBuffer implements PConstants {
73
72
74
73
75
74
FrameBuffer (PGraphicsOpenGL pg ) {
76
- this .pg = new WeakReference < PGraphicsOpenGL >( pg ) ;
75
+ this .pg = pg ;
77
76
pgl = pg .pgl ;
78
77
context = pgl .createEmptyContext ();
79
78
}
@@ -153,17 +152,15 @@ public class FrameBuffer implements PConstants {
153
152
154
153
155
154
public void clear () {
156
- PGraphicsOpenGL g = pg .get ();
157
- if (g == null ) return ;
158
- g .pushFramebuffer ();
159
- g .setFramebuffer (this );
155
+ pg .pushFramebuffer ();
156
+ pg .setFramebuffer (this );
160
157
pgl .clearDepth (1 );
161
158
pgl .clearStencil (0 );
162
159
pgl .clearColor (0 , 0 , 0 , 0 );
163
160
pgl .clear (PGL .DEPTH_BUFFER_BIT |
164
161
PGL .STENCIL_BUFFER_BIT |
165
162
PGL .COLOR_BUFFER_BIT );
166
- g .popFramebuffer ();
163
+ pg .popFramebuffer ();
167
164
}
168
165
169
166
public void copyColor (FrameBuffer dest ) {
@@ -179,14 +176,12 @@ public void copyStencil(FrameBuffer dest) {
179
176
}
180
177
181
178
public void copy (FrameBuffer dest , int mask ) {
182
- PGraphicsOpenGL g = pg .get ();
183
- if (g == null ) return ;
184
179
pgl .bindFramebufferImpl (PGL .READ_FRAMEBUFFER , this .glFbo );
185
180
pgl .bindFramebufferImpl (PGL .DRAW_FRAMEBUFFER , dest .glFbo );
186
181
pgl .blitFramebuffer (0 , 0 , this .width , this .height ,
187
182
0 , 0 , dest .width , dest .height , mask , PGL .NEAREST );
188
- pgl .bindFramebufferImpl (PGL .READ_FRAMEBUFFER , g .getCurrentFB ().glFbo );
189
- pgl .bindFramebufferImpl (PGL .DRAW_FRAMEBUFFER , g .getCurrentFB ().glFbo );
183
+ pgl .bindFramebufferImpl (PGL .READ_FRAMEBUFFER , pg .getCurrentFB ().glFbo );
184
+ pgl .bindFramebufferImpl (PGL .DRAW_FRAMEBUFFER , pg .getCurrentFB ().glFbo );
190
185
}
191
186
192
187
public void bind () {
@@ -198,11 +193,9 @@ public void disableDepthTest() {
198
193
}
199
194
200
195
public void finish () {
201
- PGraphicsOpenGL g = pg .get ();
202
- if (g == null ) return ;
203
196
if (noDepth ) {
204
197
// No need to clear depth buffer because depth testing was disabled.
205
- if (g .getHint (ENABLE_DEPTH_TEST )) {
198
+ if (pg .getHint (ENABLE_DEPTH_TEST )) {
206
199
pgl .enable (PGL .DEPTH_TEST );
207
200
} else {
208
201
pgl .disable (PGL .DEPTH_TEST );
@@ -258,8 +251,6 @@ public void setColorBuffers(Texture[] textures) {
258
251
259
252
260
253
public void setColorBuffers (Texture [] textures , int n ) {
261
- PGraphicsOpenGL g = pg .get ();
262
- if (g == null ) return ;
263
254
if (screenFb ) return ;
264
255
265
256
if (numColorBuffers != PApplet .min (n , textures .length )) {
@@ -271,8 +262,8 @@ public void setColorBuffers(Texture[] textures, int n) {
271
262
colorBufferTex [i ] = textures [i ];
272
263
}
273
264
274
- g .pushFramebuffer ();
275
- g .setFramebuffer (this );
265
+ pg .pushFramebuffer ();
266
+ pg .setFramebuffer (this );
276
267
277
268
// Making sure nothing is attached.
278
269
for (int i = 0 ; i < numColorBuffers ; i ++) {
@@ -288,31 +279,28 @@ public void setColorBuffers(Texture[] textures, int n) {
288
279
289
280
pgl .validateFramebuffer ();
290
281
291
- g .popFramebuffer ();
282
+ pg .popFramebuffer ();
292
283
}
293
284
294
285
295
286
public void swapColorBuffers () {
296
- PGraphicsOpenGL g = pg .get ();
297
- if (g == null ) return ;
298
-
299
287
for (int i = 0 ; i < numColorBuffers - 1 ; i ++) {
300
288
int i1 = (i + 1 );
301
289
Texture tmp = colorBufferTex [i ];
302
290
colorBufferTex [i ] = colorBufferTex [i1 ];
303
291
colorBufferTex [i1 ] = tmp ;
304
292
}
305
293
306
- g .pushFramebuffer ();
307
- g .setFramebuffer (this );
294
+ pg .pushFramebuffer ();
295
+ pg .setFramebuffer (this );
308
296
for (int i = 0 ; i < numColorBuffers ; i ++) {
309
297
pgl .framebufferTexture2D (PGL .FRAMEBUFFER , PGL .COLOR_ATTACHMENT0 + i ,
310
298
colorBufferTex [i ].glTarget ,
311
299
colorBufferTex [i ].glName , 0 );
312
300
}
313
301
pgl .validateFramebuffer ();
314
302
315
- g .popFramebuffer ();
303
+ pg .popFramebuffer ();
316
304
}
317
305
318
306
@@ -433,12 +421,10 @@ protected boolean contextIsOutdated() {
433
421
434
422
435
423
protected void initColorBufferMultisample () {
436
- PGraphicsOpenGL g = pg .get ();
437
- if (g == null ) return ;
438
424
if (screenFb ) return ;
439
425
440
- g .pushFramebuffer ();
441
- g .setFramebuffer (this );
426
+ pg .pushFramebuffer ();
427
+ pg .setFramebuffer (this );
442
428
443
429
// glMultisample = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
444
430
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glMultisample );
@@ -447,21 +433,19 @@ protected void initColorBufferMultisample() {
447
433
pgl .framebufferRenderbuffer (PGL .FRAMEBUFFER , PGL .COLOR_ATTACHMENT0 ,
448
434
PGL .RENDERBUFFER , glMultisample );
449
435
450
- g .popFramebuffer ();
436
+ pg .popFramebuffer ();
451
437
}
452
438
453
439
454
440
protected void initPackedDepthStencilBuffer () {
455
- PGraphicsOpenGL g = pg .get ();
456
- if (g == null ) return ;
457
441
if (screenFb ) return ;
458
442
459
443
if (width == 0 || height == 0 ) {
460
444
throw new RuntimeException ("PFramebuffer: size undefined." );
461
445
}
462
446
463
- g .pushFramebuffer ();
464
- g .setFramebuffer (this );
447
+ pg .pushFramebuffer ();
448
+ pg .setFramebuffer (this );
465
449
466
450
// glDepthStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
467
451
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glDepthStencil );
@@ -479,21 +463,19 @@ protected void initPackedDepthStencilBuffer() {
479
463
pgl .framebufferRenderbuffer (PGL .FRAMEBUFFER , PGL .STENCIL_ATTACHMENT ,
480
464
PGL .RENDERBUFFER , glDepthStencil );
481
465
482
- g .popFramebuffer ();
466
+ pg .popFramebuffer ();
483
467
}
484
468
485
469
486
470
protected void initDepthBuffer () {
487
- PGraphicsOpenGL g = pg .get ();
488
- if (g == null ) return ;
489
471
if (screenFb ) return ;
490
472
491
473
if (width == 0 || height == 0 ) {
492
474
throw new RuntimeException ("PFramebuffer: size undefined." );
493
475
}
494
476
495
- g .pushFramebuffer ();
496
- g .setFramebuffer (this );
477
+ pg .pushFramebuffer ();
478
+ pg .setFramebuffer (this );
497
479
498
480
// glDepth = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
499
481
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glDepth );
@@ -517,21 +499,19 @@ protected void initDepthBuffer() {
517
499
pgl .framebufferRenderbuffer (PGL .FRAMEBUFFER , PGL .DEPTH_ATTACHMENT ,
518
500
PGL .RENDERBUFFER , glDepth );
519
501
520
- g .popFramebuffer ();
502
+ pg .popFramebuffer ();
521
503
}
522
504
523
505
524
506
protected void initStencilBuffer () {
525
- PGraphicsOpenGL g = pg .get ();
526
- if (g == null ) return ;
527
507
if (screenFb ) return ;
528
508
529
509
if (width == 0 || height == 0 ) {
530
510
throw new RuntimeException ("PFramebuffer: size undefined." );
531
511
}
532
512
533
- g .pushFramebuffer ();
534
- g .setFramebuffer (this );
513
+ pg .pushFramebuffer ();
514
+ pg .setFramebuffer (this );
535
515
536
516
// glStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
537
517
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glStencil );
@@ -554,7 +534,7 @@ protected void initStencilBuffer() {
554
534
pgl .framebufferRenderbuffer (PGL .FRAMEBUFFER , PGL .STENCIL_ATTACHMENT ,
555
535
PGL .RENDERBUFFER , glStencil );
556
536
557
- g .popFramebuffer ();
537
+ pg .popFramebuffer ();
558
538
}
559
539
560
540
0 commit comments