2525
2626import processing .core .PApplet ;
2727import processing .core .PConstants ;
28+ import processing .opengl .PGraphicsOpenGL .GLResourceFrameBuffer ;
2829
2930import java .nio .IntBuffer ;
3031
@@ -51,6 +52,7 @@ public class FrameBuffer implements PConstants {
5152 public int glMultisample ;
5253 public int width ;
5354 public int height ;
55+ private GLResourceFrameBuffer glres ;
5456
5557 protected int depthBits ;
5658 protected int stencilBits ;
@@ -148,30 +150,30 @@ public class FrameBuffer implements PConstants {
148150 }
149151
150152
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- }
153+ // @Override
154+ // protected void finalize() throws Throwable {
155+ // try {
156+ // if (!screenFb) {
157+ // if (glFbo != 0) {
158+ // PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context);
159+ // }
160+ // if (glDepth != 0) {
161+ // PGraphicsOpenGL.finalizeRenderBufferObject(glDepth, context);
162+ // }
163+ // if (glStencil != 0) {
164+ // PGraphicsOpenGL.finalizeRenderBufferObject(glStencil, context);
165+ // }
166+ // if (glMultisample != 0) {
167+ // PGraphicsOpenGL.finalizeRenderBufferObject(glMultisample, context);
168+ // }
169+ // if (glDepthStencil != 0) {
170+ // PGraphicsOpenGL.finalizeRenderBufferObject(glDepthStencil, context);
171+ // }
172+ // }
173+ // } finally {
174+ // super.finalize();
175+ // }
176+ // }
175177
176178 public void clear () {
177179 pg .pushFramebuffer ();
@@ -353,26 +355,27 @@ protected void allocate() {
353355 dispose (); // Just in the case this object is being re-allocated.
354356
355357 context = pgl .getCurrentContext ();
358+ glres = new GLResourceFrameBuffer (this );
356359
357360 if (screenFb ) {
358361 glFbo = 0 ;
359362 } else {
360363 //create the FBO object...
361- glFbo = PGraphicsOpenGL .createFrameBufferObject (context , pgl );
364+ // glFbo = PGraphicsOpenGL.createFrameBufferObject(context, pgl);
362365
363366 // ... and then create the rest of the stuff.
364367 if (multisample ) {
365- createColorBufferMultisample ();
368+ initColorBufferMultisample ();
366369 }
367370
368371 if (packedDepthStencil ) {
369- createPackedDepthStencilBuffer ();
372+ initPackedDepthStencilBuffer ();
370373 } else {
371374 if (0 < depthBits ) {
372- createDepthBuffer ();
375+ initDepthBuffer ();
373376 }
374377 if (0 < stencilBits ) {
375- createStencilBuffer ();
378+ initStencilBuffer ();
376379 }
377380 }
378381 }
@@ -381,27 +384,37 @@ protected void allocate() {
381384
382385 protected void dispose () {
383386 if (screenFb ) return ;
384-
385- if (glFbo != 0 ) {
386- PGraphicsOpenGL .finalizeFrameBufferObject (glFbo , context );
387+ if (glres != null ) {
388+ glres .dispose ();
387389 glFbo = 0 ;
388- }
389- if (glDepth != 0 ) {
390- PGraphicsOpenGL .finalizeRenderBufferObject (glDepth , context );
391390 glDepth = 0 ;
392- }
393- if (glStencil != 0 ) {
394- PGraphicsOpenGL .finalizeRenderBufferObject (glStencil , context );
395391 glStencil = 0 ;
396- }
397- if (glMultisample != 0 ) {
398- PGraphicsOpenGL .finalizeRenderBufferObject (glMultisample , context );
399392 glMultisample = 0 ;
400- }
401- if (glDepthStencil != 0 ) {
402- PGraphicsOpenGL .finalizeRenderBufferObject (glDepthStencil , context );
403393 glDepthStencil = 0 ;
394+ glres = null ;
404395 }
396+
397+
398+ // if (glFbo != 0) {
399+ // PGraphicsOpenGL.finalizeFrameBufferObject(glFbo, context);
400+ // glFbo = 0;
401+ // }
402+ // if (glDepth != 0) {
403+ // PGraphicsOpenGL.finalizeRenderBufferObject(glDepth, context);
404+ // glDepth = 0;
405+ // }
406+ // if (glStencil != 0) {
407+ // PGraphicsOpenGL.finalizeRenderBufferObject(glStencil, context);
408+ // glStencil = 0;
409+ // }
410+ // if (glMultisample != 0) {
411+ // PGraphicsOpenGL.finalizeRenderBufferObject(glMultisample, context);
412+ // glMultisample = 0;
413+ // }
414+ // if (glDepthStencil != 0) {
415+ // PGraphicsOpenGL.finalizeRenderBufferObject(glDepthStencil, context);
416+ // glDepthStencil = 0;
417+ // }
405418 }
406419
407420
@@ -410,17 +423,18 @@ protected boolean contextIsOutdated() {
410423
411424 boolean outdated = !pgl .contextIsCurrent (context );
412425 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 ;
426+ dispose ();
427+ // PGraphicsOpenGL.removeFrameBufferObject(glFbo, context);
428+ // PGraphicsOpenGL.removeRenderBufferObject(glDepth, context);
429+ // PGraphicsOpenGL.removeRenderBufferObject(glStencil, context);
430+ // PGraphicsOpenGL.removeRenderBufferObject(glDepthStencil, context);
431+ // PGraphicsOpenGL.removeRenderBufferObject(glMultisample, context);
432+ //
433+ // glFbo = 0;
434+ // glDepth = 0;
435+ // glStencil = 0;
436+ // glDepthStencil = 0;
437+ // glMultisample = 0;
424438
425439 for (int i = 0 ; i < numColorBuffers ; i ++) {
426440 colorBufferTex [i ] = null ;
@@ -430,13 +444,13 @@ protected boolean contextIsOutdated() {
430444 }
431445
432446
433- protected void createColorBufferMultisample () {
447+ protected void initColorBufferMultisample () {
434448 if (screenFb ) return ;
435449
436450 pg .pushFramebuffer ();
437451 pg .setFramebuffer (this );
438452
439- glMultisample = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
453+ // glMultisample = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
440454 pgl .bindRenderbuffer (PGL .RENDERBUFFER , glMultisample );
441455 pgl .renderbufferStorageMultisample (PGL .RENDERBUFFER , nsamples ,
442456 PGL .RGBA8 , width , height );
@@ -447,7 +461,7 @@ protected void createColorBufferMultisample() {
447461 }
448462
449463
450- protected void createPackedDepthStencilBuffer () {
464+ protected void initPackedDepthStencilBuffer () {
451465 if (screenFb ) return ;
452466
453467 if (width == 0 || height == 0 ) {
@@ -457,7 +471,7 @@ protected void createPackedDepthStencilBuffer() {
457471 pg .pushFramebuffer ();
458472 pg .setFramebuffer (this );
459473
460- glDepthStencil = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
474+ // glDepthStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
461475 pgl .bindRenderbuffer (PGL .RENDERBUFFER , glDepthStencil );
462476
463477 if (multisample ) {
@@ -477,7 +491,7 @@ protected void createPackedDepthStencilBuffer() {
477491 }
478492
479493
480- protected void createDepthBuffer () {
494+ protected void initDepthBuffer () {
481495 if (screenFb ) return ;
482496
483497 if (width == 0 || height == 0 ) {
@@ -487,7 +501,7 @@ protected void createDepthBuffer() {
487501 pg .pushFramebuffer ();
488502 pg .setFramebuffer (this );
489503
490- glDepth = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
504+ // glDepth = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
491505 pgl .bindRenderbuffer (PGL .RENDERBUFFER , glDepth );
492506
493507 int glConst = PGL .DEPTH_COMPONENT16 ;
@@ -513,7 +527,7 @@ protected void createDepthBuffer() {
513527 }
514528
515529
516- protected void createStencilBuffer () {
530+ protected void initStencilBuffer () {
517531 if (screenFb ) return ;
518532
519533 if (width == 0 || height == 0 ) {
@@ -523,7 +537,7 @@ protected void createStencilBuffer() {
523537 pg .pushFramebuffer ();
524538 pg .setFramebuffer (this );
525539
526- glStencil = PGraphicsOpenGL .createRenderBufferObject (context , pgl );
540+ // glStencil = PGraphicsOpenGL.createRenderBufferObject(context, pgl);
527541 pgl .bindRenderbuffer (PGL .RENDERBUFFER , glStencil );
528542
529543 int glConst = PGL .STENCIL_INDEX1 ;
0 commit comments