1
1
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
2
3
3
/*
4
- Part of the Processing project - http://processing.org
4
+ Processing OpenGL (c) 2011-2015 Andres Colubri
5
5
6
- Copyright (c) 2011-12 Ben Fry and Casey Reas
6
+ Part of the Processing project - http://processing.org
7
+ Copyright (c) 2001-04 Massachusetts Institute of Technology
8
+ Copyright (c) 2004-12 Ben Fry and Casey Reas
9
+ Copyright (c) 2012-15 The Processing Foundation
7
10
8
11
This library is free software; you can redistribute it and/or
9
12
modify it under the terms of the GNU Lesser General Public
10
- License as published by the Free Software Foundation; either
11
- version 2.1 of the License, or (at your option) any later version.
13
+ License version 2.1 as published by the Free Software Foundation.
12
14
13
15
This library is distributed in the hope that it will be useful,
14
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
21
Public License along with this library; if not, write to the
20
22
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21
23
Boston, MA 02111-1307 USA
22
- */
24
+ */
23
25
24
26
package processing .opengl ;
25
27
26
28
import processing .core .PApplet ;
27
29
import processing .core .PConstants ;
30
+ import processing .opengl .PGraphicsOpenGL .GLResourceFrameBuffer ;
28
31
29
32
import java .nio .IntBuffer ;
30
33
@@ -51,6 +54,7 @@ public class FrameBuffer implements PConstants {
51
54
public int glMultisample ;
52
55
public int width ;
53
56
public int height ;
57
+ private GLResourceFrameBuffer glres ;
54
58
55
59
protected int depthBits ;
56
60
protected int stencilBits ;
@@ -148,31 +152,6 @@ public class FrameBuffer implements PConstants {
148
152
}
149
153
150
154
151
- @ Override
152
- protected void finalize () throws Throwable {
153
- try {
154
- if (!screenFb ) {
155
- if (glFbo != 0 ) {
156
- PGraphicsOpenGL .finalizeFrameBufferObject (glFbo , context );
157
- }
158
- if (glDepth != 0 ) {
159
- PGraphicsOpenGL .finalizeRenderBufferObject (glDepth , context );
160
- }
161
- if (glStencil != 0 ) {
162
- PGraphicsOpenGL .finalizeRenderBufferObject (glStencil , context );
163
- }
164
- if (glMultisample != 0 ) {
165
- PGraphicsOpenGL .finalizeRenderBufferObject (glMultisample , context );
166
- }
167
- if (glDepthStencil != 0 ) {
168
- PGraphicsOpenGL .finalizeRenderBufferObject (glDepthStencil , context );
169
- }
170
- }
171
- } finally {
172
- super .finalize ();
173
- }
174
- }
175
-
176
155
public void clear () {
177
156
pg .pushFramebuffer ();
178
157
pg .setFramebuffer (this );
@@ -353,26 +332,27 @@ protected void allocate() {
353
332
dispose (); // Just in the case this object is being re-allocated.
354
333
355
334
context = pgl .getCurrentContext ();
335
+ glres = new GLResourceFrameBuffer (this );
356
336
357
337
if (screenFb ) {
358
338
glFbo = 0 ;
359
339
} else {
360
340
//create the FBO object...
361
- glFbo = PGraphicsOpenGL .createFrameBufferObject (context , pgl );
341
+ // glFbo = PGraphicsOpenGL.createFrameBufferObject(context, pgl);
362
342
363
343
// ... and then create the rest of the stuff.
364
344
if (multisample ) {
365
- createColorBufferMultisample ();
345
+ initColorBufferMultisample ();
366
346
}
367
347
368
348
if (packedDepthStencil ) {
369
- createPackedDepthStencilBuffer ();
349
+ initPackedDepthStencilBuffer ();
370
350
} else {
371
351
if (0 < depthBits ) {
372
- createDepthBuffer ();
352
+ initDepthBuffer ();
373
353
}
374
354
if (0 < stencilBits ) {
375
- createStencilBuffer ();
355
+ initStencilBuffer ();
376
356
}
377
357
}
378
358
}
@@ -381,27 +361,37 @@ protected void allocate() {
381
361
382
362
protected void dispose () {
383
363
if (screenFb ) return ;
384
-
385
- if (glFbo != 0 ) {
386
- PGraphicsOpenGL .finalizeFrameBufferObject (glFbo , context );
364
+ if (glres != null ) {
365
+ glres .dispose ();
387
366
glFbo = 0 ;
388
- }
389
- if (glDepth != 0 ) {
390
- PGraphicsOpenGL .finalizeRenderBufferObject (glDepth , context );
391
367
glDepth = 0 ;
392
- }
393
- if (glStencil != 0 ) {
394
- PGraphicsOpenGL .finalizeRenderBufferObject (glStencil , context );
395
368
glStencil = 0 ;
396
- }
397
- if (glMultisample != 0 ) {
398
- PGraphicsOpenGL .finalizeRenderBufferObject (glMultisample , context );
399
369
glMultisample = 0 ;
400
- }
401
- if (glDepthStencil != 0 ) {
402
- PGraphicsOpenGL .finalizeRenderBufferObject (glDepthStencil , context );
403
370
glDepthStencil = 0 ;
371
+ glres = null ;
404
372
}
373
+
374
+
375
+ // if (glFbo != 0) {
376
+ // PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context);
377
+ // glFbo = 0;
378
+ // }
379
+ // if (glDepth != 0) {
380
+ // PGraphicsOpenGL.finalizeRenderBufferObject(glDepth, context);
381
+ // glDepth = 0;
382
+ // }
383
+ // if (glStencil != 0) {
384
+ // PGraphicsOpenGL.finalizeRenderBufferObject(glStencil, context);
385
+ // glStencil = 0;
386
+ // }
387
+ // if (glMultisample != 0) {
388
+ // PGraphicsOpenGL.finalizeRenderBufferObject(glMultisample, context);
389
+ // glMultisample = 0;
390
+ // }
391
+ // if (glDepthStencil != 0) {
392
+ // PGraphicsOpenGL.finalizeRenderBufferObject(glDepthStencil, context);
393
+ // glDepthStencil = 0;
394
+ // }
405
395
}
406
396
407
397
@@ -410,17 +400,18 @@ protected boolean contextIsOutdated() {
410
400
411
401
boolean outdated = !pgl .contextIsCurrent (context );
412
402
if (outdated ) {
413
- PGraphicsOpenGL .removeFrameBufferObject (glFbo , context );
414
- PGraphicsOpenGL .removeRenderBufferObject (glDepth , context );
415
- PGraphicsOpenGL .removeRenderBufferObject (glStencil , context );
416
- PGraphicsOpenGL .removeRenderBufferObject (glDepthStencil , context );
417
- PGraphicsOpenGL .removeRenderBufferObject (glMultisample , context );
418
-
419
- glFbo = 0 ;
420
- glDepth = 0 ;
421
- glStencil = 0 ;
422
- glDepthStencil = 0 ;
423
- glMultisample = 0 ;
403
+ dispose ();
404
+ // PGraphicsOpenGL.removeFrameBufferObject(glFbo, context);
405
+ // PGraphicsOpenGL.removeRenderBufferObject(glDepth, context);
406
+ // PGraphicsOpenGL.removeRenderBufferObject(glStencil, context);
407
+ // PGraphicsOpenGL.removeRenderBufferObject(glDepthStencil, context);
408
+ // PGraphicsOpenGL.removeRenderBufferObject(glMultisample, context);
409
+ //
410
+ // glFbo = 0;
411
+ // glDepth = 0;
412
+ // glStencil = 0;
413
+ // glDepthStencil = 0;
414
+ // glMultisample = 0;
424
415
425
416
for (int i = 0 ; i < numColorBuffers ; i ++) {
426
417
colorBufferTex [i ] = null ;
@@ -430,13 +421,13 @@ protected boolean contextIsOutdated() {
430
421
}
431
422
432
423
433
- protected void createColorBufferMultisample () {
424
+ protected void initColorBufferMultisample () {
434
425
if (screenFb ) return ;
435
426
436
427
pg .pushFramebuffer ();
437
428
pg .setFramebuffer (this );
438
429
439
- glMultisample = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
430
+ // glMultisample = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
440
431
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glMultisample );
441
432
pgl .renderbufferStorageMultisample (PGL .RENDERBUFFER , nsamples ,
442
433
PGL .RGBA8 , width , height );
@@ -447,7 +438,7 @@ protected void createColorBufferMultisample() {
447
438
}
448
439
449
440
450
- protected void createPackedDepthStencilBuffer () {
441
+ protected void initPackedDepthStencilBuffer () {
451
442
if (screenFb ) return ;
452
443
453
444
if (width == 0 || height == 0 ) {
@@ -457,7 +448,7 @@ protected void createPackedDepthStencilBuffer() {
457
448
pg .pushFramebuffer ();
458
449
pg .setFramebuffer (this );
459
450
460
- glDepthStencil = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
451
+ // glDepthStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
461
452
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glDepthStencil );
462
453
463
454
if (multisample ) {
@@ -477,7 +468,7 @@ protected void createPackedDepthStencilBuffer() {
477
468
}
478
469
479
470
480
- protected void createDepthBuffer () {
471
+ protected void initDepthBuffer () {
481
472
if (screenFb ) return ;
482
473
483
474
if (width == 0 || height == 0 ) {
@@ -487,7 +478,7 @@ protected void createDepthBuffer() {
487
478
pg .pushFramebuffer ();
488
479
pg .setFramebuffer (this );
489
480
490
- glDepth = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
481
+ // glDepth = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
491
482
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glDepth );
492
483
493
484
int glConst = PGL .DEPTH_COMPONENT16 ;
@@ -513,7 +504,7 @@ protected void createDepthBuffer() {
513
504
}
514
505
515
506
516
- protected void createStencilBuffer () {
507
+ protected void initStencilBuffer () {
517
508
if (screenFb ) return ;
518
509
519
510
if (width == 0 || height == 0 ) {
@@ -523,7 +514,7 @@ protected void createStencilBuffer() {
523
514
pg .pushFramebuffer ();
524
515
pg .setFramebuffer (this );
525
516
526
- glStencil = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
517
+ // glStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
527
518
pgl .bindRenderbuffer (PGL .RENDERBUFFER , glStencil );
528
519
529
520
int glConst = PGL .STENCIL_INDEX1 ;
0 commit comments