Enable/disable viewport

Sometimes there is a RTT usecase for a still image.

How about adding setEnabled() method to ViewPort?



[patch]

Index: src/core/com/jme3/renderer/RenderManager.java

===================================================================

— src/core/com/jme3/renderer/RenderManager.java (revision 6688)

+++ src/core/com/jme3/renderer/RenderManager.java (working copy)

@@ -681,6 +681,9 @@

}



public void renderViewPort(ViewPort vp, float tpf) {

  •   if (!vp.isEnabled()) {<br />
    
  •   	return;<br />
    
  •   }<br />
    

List<SceneProcessor> processors = vp.getProcessors();

if (processors.size() == 0) {

processors = null;

Index: src/core/com/jme3/renderer/ViewPort.java

===================================================================

— src/core/com/jme3/renderer/ViewPort.java (revision 6688)

+++ src/core/com/jme3/renderer/ViewPort.java (working copy)

@@ -52,6 +52,7 @@

protected final ColorRGBA backColor = new ColorRGBA(0,0,0,0);

protected boolean clearEnabled = false;

protected boolean clearDepth = true, clearColor = true, clearStencil = true;

  • private boolean enabled = true;



    public ViewPort(String name, Camera cam) {

    this.name = name;

    @@ -153,5 +154,13 @@

    public ColorRGBA getBackgroundColor(){

    return backColor;

    }

    +
  • public void setEnabled(boolean enable) {
  •    this.enabled = enable;<br />
    
  • }

    +
  • public boolean isEnabled() {
  •    return enabled;<br />
    
  • }



    }

    Index: src/test/jme3test/post/TestRenderToTexture.java

    ===================================================================

    — src/test/jme3test/post/TestRenderToTexture.java (revision 6688)

    +++ src/test/jme3test/post/TestRenderToTexture.java (working copy)

    @@ -33,6 +33,9 @@

    package jme3test.post;



    import com.jme3.app.SimpleApplication;

    +import com.jme3.input.KeyInput;

    +import com.jme3.input.controls.ActionListener;

    +import com.jme3.input.controls.KeyTrigger;

    import com.jme3.material.Material;

    import com.jme3.math.ColorRGBA;

    import com.jme3.math.FastMath;

    @@ -50,10 +53,12 @@

    /**
  • This test renders a scene to a texture, then displays the texture on a cube.

    */

    -public class TestRenderToTexture extends SimpleApplication {

    +public class TestRenderToTexture extends SimpleApplication implements ActionListener {


  • private static final String TOGGLE_UPDATE = "Toggle Update";

    private Geometry offBox;

    private float angle = 0;
  • private ViewPort offView;



    public static void main(String[] args){

    TestRenderToTexture app = new TestRenderToTexture();

    @@ -63,8 +68,7 @@

    public Texture setupOffscreenView(){

    Camera offCamera = new Camera(512, 512);


  •    // create a pre-view. a view that is rendered before the main view<br />
    
  •    ViewPort offView = renderManager.createPreView(&quot;Offscreen View&quot;, offCamera);<br />
    
  •    offView = renderManager.createPreView(&quot;Offscreen View&quot;, offCamera);<br />
    

offView.setClearEnabled(true);

offView.setBackgroundColor(ColorRGBA.DarkGray);



@@ -114,6 +118,8 @@

mat.setTexture("ColorMap", offTex);

quad.setMaterial(mat);

rootNode.attachChild(quad);

  •    inputManager.addMapping(TOGGLE_UPDATE, new KeyTrigger(KeyInput.KEY_SPACE));<br />
    
  •    inputManager.addListener(this, TOGGLE_UPDATE);<br />
    

}



@Override

@@ -128,5 +134,12 @@

offBox.updateGeometricState();

}


  • @Override
  • public void onAction(String name, boolean isPressed, float tpf) {
  •    if (name.equals(TOGGLE_UPDATE) &amp;&amp; isPressed) {<br />
    
  •        offView.setEnabled(!offView.isEnabled());<br />
    
  •    }<br />
    
  • }

    +



    }



    [/patch]

That I could use!



I’d much prefer this solution than query a node for the viewport name and disable it when it’s hidden. So much easier to have it as a class-scope variable and enable/disable it when needed.

yep nice

committed in svn. rev 6700

Thanks!



I’ll test it out tomorrow and report if there are any obvious issues.