diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index dbc6bf611..5fb50e191 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -957,7 +957,7 @@ public class PGL { backTexAttach.minFilter, backTexAttach.magFilter, backTexAttach.wrapS, backTexAttach.wrapT); tex.invertedY(true); - tex.colorBufferOf(pg); + tex.setAsColorBuffer(); pg.setCache(pg, tex); return tex; } else { @@ -967,7 +967,7 @@ public class PGL { fboWidth, fboHeight, NEAREST, NEAREST, CLAMP_TO_EDGE, CLAMP_TO_EDGE); tex.invertedY(true); - tex.colorBufferOf(pg); + tex.setAsColorBuffer(); pg.setCache(pg, tex); return tex; } @@ -983,7 +983,7 @@ public class PGL { frontTexAttach.minFilter, frontTexAttach.magFilter, frontTexAttach.wrapS, frontTexAttach.wrapT); tex.invertedY(true); - tex.colorBufferOf(pg); + tex.setAsColorBuffer(); return tex; } else { Texture tex = new Texture(); @@ -992,7 +992,7 @@ public class PGL { fboWidth, fboHeight, NEAREST, NEAREST, CLAMP_TO_EDGE, CLAMP_TO_EDGE); tex.invertedY(true); - tex.colorBufferOf(pg); + tex.setAsColorBuffer(); return tex; } } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 5732f8803..90299951e 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -667,13 +667,14 @@ public class PGraphicsOpenGL extends PGraphics { @Override protected void finalize() throws Throwable { try { + PApplet.println("finalize surface"); + deletePolyBuffers(); deleteLineBuffers(); deletePointBuffers(); deleteSurfaceTextures(); if (!primarySurface) { - PApplet.println("finalize offscreen surface"); if (offscreenFramebuffer != null) { offscreenFramebuffer.release(); offscreenFramebuffer = null; @@ -796,7 +797,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glTextureObjects.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " texture objects, " + glTextureObjects.size() + " remaining"); + PApplet.println("Deleted " + finalized.size() + " texture objects, " + glTextureObjects.size() + " remaining"); } protected static void removeTextureObject(int id, int context) { @@ -861,7 +862,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glVertexBuffers.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " vertex buffer objects, " + glVertexBuffers.size() + " remaining"); +// PApplet.println("Deleted " + finalized.size() + " vertex buffer objects, " + glVertexBuffers.size() + " remaining"); } protected static void removeVertexBufferObject(int id, int context) { @@ -928,7 +929,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glFrameBuffers.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " framebuffer objects, " + glFrameBuffers.size() + " remaining"); + PApplet.println("Deleted " + finalized.size() + " framebuffer objects, " + glFrameBuffers.size() + " remaining"); } protected static void removeFrameBufferObject(int id, int context) { @@ -993,7 +994,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glRenderBuffers.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " renderbuffer objects, " + glRenderBuffers.size() + " remaining"); + PApplet.println("Deleted " + finalized.size() + " renderbuffer objects, " + glRenderBuffers.size() + " remaining"); } protected static void removeRenderBufferObject(int id, int context) { @@ -1054,7 +1055,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glslPrograms.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " GLSL program objects, " + glslPrograms.size() + " remaining"); +// PApplet.println("Deleted " + finalized.size() + " GLSL program objects, " + glslPrograms.size() + " remaining"); } protected static void removeGLSLProgramObject(int id, int context) { @@ -1116,7 +1117,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glslVertexShaders.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " GLSL vertex shader objects, " + glslVertexShaders.size() + " remaining"); +// PApplet.println("Deleted " + finalized.size() + " GLSL vertex shader objects, " + glslVertexShaders.size() + " remaining"); } protected static void removeGLSLVertShaderObject(int id, int context) { @@ -1178,7 +1179,7 @@ public class PGraphicsOpenGL extends PGraphics { for (GLResource res : finalized) { glslFragmentShaders.remove(res); } - if (0 < finalized.size()) PApplet.println("Deleted " + finalized.size() + " GLSL fragment shader objects, " + glslFragmentShaders.size() + " remaining"); +// PApplet.println("Deleted " + finalized.size() + " GLSL fragment shader objects, " + glslFragmentShaders.size() + " remaining"); } protected static void removeGLSLFragShaderObject(int id, int context) { @@ -5301,13 +5302,13 @@ public class PGraphicsOpenGL extends PGraphics { sampling, mipmap); texture = new Texture(width, height, params); texture.invertedY(true); - texture.colorBufferOf(this); + texture.setAsColorBuffer(); pgPrimary.setCache(this, texture); if (!primarySurface) { ptexture = new Texture(width, height, params); ptexture.invertedY(true); - ptexture.colorBufferOf(this); + ptexture.setAsColorBuffer(); } } } @@ -5723,7 +5724,7 @@ public class PGraphicsOpenGL extends PGraphics { protected Texture addTexture(PImage img) { Texture.Parameters params = new Texture.Parameters(ARGB, textureSampling, - getHint(ENABLE_TEXTURE_MIPMAPS),textureWrap); + getHint(ENABLE_TEXTURE_MIPMAPS), textureWrap); return addTexture(img, params); } @@ -5736,7 +5737,7 @@ public class PGraphicsOpenGL extends PGraphics { if (img.parent == null) { img.parent = parent; } - Texture tex = new Texture(/*img.parent,*/ img.width, img.height, params); + Texture tex = new Texture(img.width, img.height, params); pgPrimary.setCache(img, tex); return tex; } diff --git a/core/src/processing/opengl/Texture.java b/core/src/processing/opengl/Texture.java index 227663660..2510d6fb6 100644 --- a/core/src/processing/opengl/Texture.java +++ b/core/src/processing/opengl/Texture.java @@ -80,7 +80,8 @@ public class Texture implements PConstants { protected PGL pgl; // The interface between Processing and OpenGL. protected int context; // The context that created this texture. - protected PGraphicsOpenGL pgDraw; // The main renderer is the color buffer of. + protected boolean isColorBuffer; // true if it is the color attachment of + // FrameBuffer object. protected boolean usingMipmaps; protected boolean usingRepeat; @@ -113,7 +114,7 @@ public class Texture implements PConstants { pgl = PGraphicsOpenGL.pgl; context = pgl.createEmptyContext(); - pgDraw = null; + isColorBuffer = false; glName = 0; } @@ -141,7 +142,7 @@ public class Texture implements PConstants { pgl = PGraphicsOpenGL.pgl; context = pgl.createEmptyContext(); - pgDraw = null; + isColorBuffer = false; glName = 0; @@ -152,6 +153,7 @@ public class Texture implements PConstants { @Override protected void finalize() throws Throwable { try { + PApplet.println("finalize texture"); if (glName != 0) { PGraphicsOpenGL.finalizeTextureObject(glName, context); } @@ -1240,13 +1242,13 @@ public class Texture implements PConstants { } - public void colorBufferOf(PGraphicsOpenGL pgDraw) { - this.pgDraw = pgDraw; + protected void setAsColorBuffer() { + isColorBuffer = true; } protected boolean isColorBuffer() { - return pgDraw != null; + return isColorBuffer; }