From 147ff8796d8cf37bc493a63ddaf4f0aca69471f2 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Sat, 4 Jan 2014 14:16:24 +0000 Subject: [PATCH] - Made the FilterPostProcessor cleanup delete framebuffers and textures form memory. - Changed the way the filter porcessor handle the rendering of the filter; depth right is not disabled anymore when it sjouldn't alowing a filter to output depth with gl_FragDepth if needed git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10955 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/post/filters/BloomFilter.java | 8 +++++++ .../jme3/post/filters/CartoonEdgeFilter.java | 7 ++++++ .../com/jme3/post/ssao/SSAOFilter.java | 5 ++++ .../com/jme3/water/WaterFilter.java | 6 +++++ engine/src/core/com/jme3/post/Filter.java | 7 +++++- .../com/jme3/post/FilterPostProcessor.java | 24 +++++++++++++------ 6 files changed, 49 insertions(+), 8 deletions(-) diff --git a/engine/src/core-effects/com/jme3/post/filters/BloomFilter.java b/engine/src/core-effects/com/jme3/post/filters/BloomFilter.java index 2207f30c0..778111a3c 100644 --- a/engine/src/core-effects/com/jme3/post/filters/BloomFilter.java +++ b/engine/src/core-effects/com/jme3/post/filters/BloomFilter.java @@ -40,6 +40,7 @@ import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.post.Filter; import com.jme3.renderer.RenderManager; +import com.jme3.renderer.Renderer; import com.jme3.renderer.ViewPort; import com.jme3.renderer.queue.RenderQueue; import com.jme3.texture.Image.Format; @@ -216,6 +217,13 @@ public class BloomFilter extends Filter { } } + @Override + protected void cleanUpFilter(Renderer r) { + if (glowMode != GlowMode.Scene) { + preGlowPass.cleanup(r); + } + } + /** * returns the bloom intensity * @return diff --git a/engine/src/core-effects/com/jme3/post/filters/CartoonEdgeFilter.java b/engine/src/core-effects/com/jme3/post/filters/CartoonEdgeFilter.java index da1830d93..8308c8a46 100644 --- a/engine/src/core-effects/com/jme3/post/filters/CartoonEdgeFilter.java +++ b/engine/src/core-effects/com/jme3/post/filters/CartoonEdgeFilter.java @@ -105,6 +105,13 @@ public class CartoonEdgeFilter extends Filter { material.setColor("EdgeColor", edgeColor); } + @Override + protected void cleanUpFilter(Renderer r) { + normalPass.cleanup(r); + } + + + /** * Return the depth sensitivity
* for more details see {@link #setDepthSensitivity(float depthSensitivity)} diff --git a/engine/src/core-effects/com/jme3/post/ssao/SSAOFilter.java b/engine/src/core-effects/com/jme3/post/ssao/SSAOFilter.java index 260b733b6..75d6b1c86 100644 --- a/engine/src/core-effects/com/jme3/post/ssao/SSAOFilter.java +++ b/engine/src/core-effects/com/jme3/post/ssao/SSAOFilter.java @@ -188,6 +188,11 @@ public class SSAOFilter extends Filter { } + @Override + protected void cleanUpFilter(Renderer r) { + normalPass.cleanup(r); + } + /** * Return the bias
* see {@link #setBias(float bias)} diff --git a/engine/src/core-effects/com/jme3/water/WaterFilter.java b/engine/src/core-effects/com/jme3/water/WaterFilter.java index d11c0c33b..14c9b4f2f 100644 --- a/engine/src/core-effects/com/jme3/water/WaterFilter.java +++ b/engine/src/core-effects/com/jme3/water/WaterFilter.java @@ -44,6 +44,7 @@ import com.jme3.post.Filter; import com.jme3.post.Filter.Pass; import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; +import com.jme3.renderer.Renderer; import com.jme3.renderer.ViewPort; import com.jme3.scene.Node; import com.jme3.scene.Spatial; @@ -282,6 +283,11 @@ public class WaterFilter extends Filter { } + @Override + protected void cleanUpFilter(Renderer r) { + reflectionPass.cleanup(r); + } + @Override public void write(JmeExporter ex) throws IOException { super.write(ex); diff --git a/engine/src/core/com/jme3/post/Filter.java b/engine/src/core/com/jme3/post/Filter.java index ed246f6b3..e1da6accd 100644 --- a/engine/src/core/com/jme3/post/Filter.java +++ b/engine/src/core/com/jme3/post/Filter.java @@ -191,6 +191,11 @@ public abstract class Filter implements Savable { } public void cleanup(Renderer r) { + r.deleteFrameBuffer(renderFrameBuffer); + r.deleteImage(renderedTexture.getImage()); + if(depthTexture!=null){ + r.deleteImage(depthTexture.getImage()); + } } } @@ -437,4 +442,4 @@ public abstract class Filter implements Savable { protected void setProcessor(FilterPostProcessor proc) { processor = proc; } -} + } diff --git a/engine/src/core/com/jme3/post/FilterPostProcessor.java b/engine/src/core/com/jme3/post/FilterPostProcessor.java index 637f393f2..0c0b627af 100644 --- a/engine/src/core/com/jme3/post/FilterPostProcessor.java +++ b/engine/src/core/com/jme3/post/FilterPostProcessor.java @@ -181,18 +181,20 @@ public class FilterPostProcessor implements SceneProcessor, Savable { viewPort.getCamera().resize(originalWidth, originalHeight, false); viewPort.getCamera().setViewPort(left, right, bottom, top); viewPort.getCamera().update(); - renderManager.setCamera( viewPort.getCamera(), false); + renderManager.setCamera( viewPort.getCamera(), false); + if (mat.getAdditionalRenderState().isDepthWrite()) { + mat.getAdditionalRenderState().setDepthTest(false); + mat.getAdditionalRenderState().setDepthWrite(false); + } }else{ viewPort.getCamera().resize(buff.getWidth(), buff.getHeight(), false); viewPort.getCamera().setViewPort(0, 1, 0, 1); viewPort.getCamera().update(); renderManager.setCamera( viewPort.getCamera(), false); + mat.getAdditionalRenderState().setDepthTest(true); + mat.getAdditionalRenderState().setDepthWrite(true); } - if (mat.getAdditionalRenderState().isDepthWrite()) { - mat.getAdditionalRenderState().setDepthTest(false); - mat.getAdditionalRenderState().setDepthWrite(false); - } fsQuad.setMaterial(mat); fsQuad.updateGeometricState(); @@ -292,7 +294,7 @@ public class FilterPostProcessor implements SceneProcessor, Savable { } renderFilterChain(renderer, sceneBuffer); renderer.setFrameBuffer(outputBuffer); - + //viewport can be null if no filters are enabled if (viewPort != null) { renderManager.setCamera(viewPort.getCamera(), false); @@ -375,6 +377,14 @@ public class FilterPostProcessor implements SceneProcessor, Savable { viewPort.getCamera().setViewPort(left, right, bottom, top); viewPort.setOutputFrameBuffer(outputBuffer); viewPort = null; + renderManager.getRenderer().deleteFrameBuffer(renderFrameBuffer); + if(depthTexture!=null){ + renderManager.getRenderer().deleteImage(depthTexture.getImage()); + } + renderManager.getRenderer().deleteImage(filterTexture.getImage()); + if(renderFrameBufferMS != null){ + renderManager.getRenderer().deleteFrameBuffer(renderFrameBufferMS); + } for (Filter filter : filters) { filter.cleanup(renderer); } @@ -549,4 +559,4 @@ public class FilterPostProcessor implements SceneProcessor, Savable { viewPort.setOutputFrameBuffer(renderFrameBuffer); } } -} + }