From ffce10b8daf5fe976741e652527ab57d0acb5b7f Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Fri, 21 Oct 2011 23:01:34 +0000 Subject: [PATCH] * Added AwtPanel.attachTo() argument that allows attaching panel to main framebuffer instead of replacing it on the viewports git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8481 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../renderer/android/OGLESShaderRenderer.java | 3 +++ .../src/android/com/jme3/system/JmeSystem.java | 6 ------ engine/src/core/com/jme3/renderer/Renderer.java | 8 ++++++++ engine/src/core/com/jme3/system/JmeVersion.java | 11 +---------- .../src/core/com/jme3/system/NullRenderer.java | 3 +++ .../desktop/com/jme3/system/awt/AwtPanel.java | 17 +++++++++++++---- .../jme3/renderer/lwjgl/LwjglGL1Renderer.java | 3 +++ .../com/jme3/renderer/lwjgl/LwjglRenderer.java | 9 +++++++++ engine/src/test/jme3test/awt/TestAwtPanels.java | 4 ++-- 9 files changed, 42 insertions(+), 22 deletions(-) diff --git a/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java b/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java index 4ecc8b094..33d5161dd 100644 --- a/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java +++ b/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java @@ -1567,6 +1567,9 @@ public class OGLESShaderRenderer implements Renderer { } */ + public void setMainFrameBufferOverride(FrameBuffer fb){ + } + public void setFrameBuffer(FrameBuffer fb) { if (verboseLogging) { logger.warning("setFrameBuffer is not supported."); diff --git a/engine/src/android/com/jme3/system/JmeSystem.java b/engine/src/android/com/jme3/system/JmeSystem.java index a173e5437..bffcb20c5 100644 --- a/engine/src/android/com/jme3/system/JmeSystem.java +++ b/engine/src/android/com/jme3/system/JmeSystem.java @@ -5,13 +5,7 @@ import android.content.res.Resources; import com.jme3.util.AndroidLogHandler; import com.jme3.asset.AndroidAssetManager; import com.jme3.asset.AssetManager; -import com.jme3.audio.AudioNode; -import com.jme3.audio.AudioData; -import com.jme3.audio.AudioParam; import com.jme3.audio.AudioRenderer; -import com.jme3.audio.Environment; -import com.jme3.audio.Listener; -import com.jme3.audio.ListenerParam; import com.jme3.audio.android.AndroidAudioRenderer; //import com.jme3.audio.DummyAudioRenderer; import com.jme3.system.JmeContext.Type; diff --git a/engine/src/core/com/jme3/renderer/Renderer.java b/engine/src/core/com/jme3/renderer/Renderer.java index 75f4674d8..6e366ab18 100644 --- a/engine/src/core/com/jme3/renderer/Renderer.java +++ b/engine/src/core/com/jme3/renderer/Renderer.java @@ -206,6 +206,14 @@ public interface Renderer { * Sets the framebuffer that will be drawn to. */ public void setFrameBuffer(FrameBuffer fb); + + /** + * Set the framebuffer that will be set instead of the main framebuffer + * when a call to setFrameBuffer(null) is made. + * + * @param fb + */ + public void setMainFrameBufferOverride(FrameBuffer fb); /** * Reads the pixels currently stored in the specified framebuffer diff --git a/engine/src/core/com/jme3/system/JmeVersion.java b/engine/src/core/com/jme3/system/JmeVersion.java index 7ae9dfbf8..95d021fbd 100644 --- a/engine/src/core/com/jme3/system/JmeVersion.java +++ b/engine/src/core/com/jme3/system/JmeVersion.java @@ -1,14 +1,5 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package com.jme3.system; -/** - * - * @author normenhansen - */ public class JmeVersion { - public static final String FULL_NAME = "jMonkeyEngine 3.0beta"; - + public static final String FULL_NAME = "jMonkeyEngine 3.0.0 Beta"; } diff --git a/engine/src/core/com/jme3/system/NullRenderer.java b/engine/src/core/com/jme3/system/NullRenderer.java index 181d88da9..2b1d82122 100644 --- a/engine/src/core/com/jme3/system/NullRenderer.java +++ b/engine/src/core/com/jme3/system/NullRenderer.java @@ -113,6 +113,9 @@ public class NullRenderer implements Renderer { public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth) { } + public void setMainFrameBufferOverride(FrameBuffer fb) { + } + public void setFrameBuffer(FrameBuffer fb) { } diff --git a/engine/src/desktop/com/jme3/system/awt/AwtPanel.java b/engine/src/desktop/com/jme3/system/awt/AwtPanel.java index e84d4743a..d80e24792 100644 --- a/engine/src/desktop/com/jme3/system/awt/AwtPanel.java +++ b/engine/src/desktop/com/jme3/system/awt/AwtPanel.java @@ -13,7 +13,6 @@ import java.awt.BufferCapabilities; import java.awt.Canvas; import java.awt.Graphics; import java.awt.Graphics2D; -import java.awt.Image; import java.awt.ImageCapabilities; import java.awt.RenderingHints; import java.awt.event.ComponentAdapter; @@ -30,6 +29,8 @@ import java.util.concurrent.atomic.AtomicBoolean; public class AwtPanel extends Canvas implements SceneProcessor { + private boolean attachAsMain = false; + private BufferedImage img; private FrameBuffer fb; private ByteBuffer byteBuf; @@ -186,7 +187,7 @@ public class AwtPanel extends Canvas implements SceneProcessor { return paintMode != PaintMode.OnRequest && showing.get(); } - public void attachTo(ViewPort ... vps){ + public void attachTo(boolean overrideMainFramebuffer, ViewPort ... vps){ if (viewPorts.size() > 0){ for (ViewPort vp : viewPorts){ vp.setOutputFrameBuffer(null); @@ -196,6 +197,8 @@ public class AwtPanel extends Canvas implements SceneProcessor { viewPorts.addAll(Arrays.asList(vps)); viewPorts.get(viewPorts.size()-1).addProcessor(this); + + this.attachAsMain = overrideMainFramebuffer; } public void initialize(RenderManager rm, ViewPort vp) { @@ -214,6 +217,10 @@ public class AwtPanel extends Canvas implements SceneProcessor { fb.setDepthBuffer(Format.Depth); fb.setColorBuffer(Format.RGB8); + if (attachAsMain){ + rm.getRenderer().setMainFrameBufferOverride(fb); + } + synchronized (lock){ img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); } @@ -227,7 +234,9 @@ public class AwtPanel extends Canvas implements SceneProcessor { transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); for (ViewPort vp : viewPorts){ - vp.setOutputFrameBuffer(fb); + if (!attachAsMain){ + vp.setOutputFrameBuffer(fb); + } vp.getCamera().resize(width, height, true); // NOTE: Hack alert. This is done ONLY for custom framebuffers. @@ -255,7 +264,7 @@ public class AwtPanel extends Canvas implements SceneProcessor { } public void postFrame(FrameBuffer out) { - if (out != fb){ + if (!attachAsMain && out != fb){ throw new IllegalStateException("Why did you change the output framebuffer?"); } diff --git a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java index ecd016e67..e8c572f04 100644 --- a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java +++ b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java @@ -1158,6 +1158,9 @@ public class LwjglGL1Renderer implements GL1Renderer { public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth) { } + public void setMainFrameBufferOverride(FrameBuffer fb){ + } + public void setFrameBuffer(FrameBuffer fb) { } diff --git a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java index d57a228ae..bb7866f5f 100644 --- a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java +++ b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java @@ -147,6 +147,7 @@ public class LwjglRenderer implements Renderer { private int maxDepthTexSamples; private boolean tdc; private FrameBuffer lastFb = null; + private FrameBuffer mainFbOverride = null; private final Statistics statistics = new Statistics(); private int vpX, vpY, vpW, vpH; private int clipX, clipY, clipW, clipH; @@ -1527,8 +1528,16 @@ public class LwjglRenderer implements Renderer { } return samplePositions; } + + public void setMainFrameBufferOverride(FrameBuffer fb){ + mainFbOverride = fb; + } public void setFrameBuffer(FrameBuffer fb) { + if (fb == null && mainFbOverride != null){ + fb = mainFbOverride; + } + if (lastFb == fb) { if (fb == null || !fb.isUpdateNeeded()){ return; diff --git a/engine/src/test/jme3test/awt/TestAwtPanels.java b/engine/src/test/jme3test/awt/TestAwtPanels.java index a49dcea40..2c67867bd 100644 --- a/engine/src/test/jme3test/awt/TestAwtPanels.java +++ b/engine/src/test/jme3test/awt/TestAwtPanels.java @@ -81,8 +81,8 @@ public class TestAwtPanels extends SimpleApplication { geom.setMaterial(mat); rootNode.attachChild(geom); - panel.attachTo(viewPort); + panel.attachTo(true, viewPort); guiViewPort.setClearFlags(true, true, true); - panel2.attachTo(guiViewPort); + panel2.attachTo(false, guiViewPort); } }