Render Passes and GameStates

I almost posted these classes in user code, but started thinking I just replicated the Render Pass behavior in an odd way.  :oops:



I need some clarification on Render Passes and GameStates.  I couldn't find much info on successfully using them together - so I hammered out a RenderPassStandardGame and RenderPassGameState.



I needed a GameState that used the ORTHO queue to appear underneath another state using OPAQUE & TRANSPARENT…  All the info I found on z orders and whatnot said that the ORTHO needed to be in a pass rendered before the other, but nothing I searched through mentioned how to go about this within GameStates. 



The classes I put together let me set a "level" on the state and then all the states get put into passes and rendered in order from lowest level to highest.  Am I heading in the right direction, or was that a waste of time?    :?

i think u can use a render pass manager to achieve that. but i might be wrong though~



just call manager.add(urPass); in the order u want the scene to be rendered should do it.

Check the jME test TestPassNode in the cvs… that should clarify things. GameStates are like root nodes, so everything you see there should apply to them as well.

duenez said:

Check the jME test TestPassNode in the cvs... that should clarify things. GameStates are like root nodes, so everything you see there should apply to them as well.


Thanks for the tip - I'd never looked at PassNode or PassNodeState before.  :)

However I think we may be talking apples and oranges here.  Apples being StandardGame and oranges being SimplePassGame. My main reason for creating this thread was to see if anyone had already addressed controlling the rendering order of GameStates in a much more elegant fashion.

To my knowledge this hasn't been fully addressed yet for StandardGame, and I haven't had the need for it in my own development yet.



If you find any thing hindering you in StandardGame let me know and I'll make the appropriate changes.

Thanks darkfrog!



I'm going to try putting together some examples of what I'm attempting to do later today.

OK - the challenge is to make the multicolored boxes appear above the sphere but under the cube.  My current approach to solving this seems cumbersome, so I'm eager to see alternatives. :slight_smile:



package game.state.order.test;

import com.jmex.game.StandardGame;
import com.jmex.game.state.DebugGameState;
import com.jmex.game.state.GameStateManager;

public class main {

   /**
    * @param args
    */
   public static void main(String[] args) {
   
      StandardGame game = new StandardGame("order test");
      game.getSettings().setWidth(1680);
      game.getSettings().setHeight(1050);
      game.getSettings().setDepth(32);
      game.getSettings().setFullscreen(true);
      game.start();
      
      GameStateManager manager = GameStateManager.getInstance();
      
      SphereState sphere = new SphereState();
      manager.attachChild(sphere);
      
      OrthoBoxes ortho = new OrthoBoxes();
      manager.attachChild(ortho);
            
      CubeState cube = new CubeState();
      manager.attachChild(cube);
      
      DebugGameState debug = new DebugGameState();
      manager.attachChild(debug);
      
      debug.setActive(true);
      ortho.setActive(true);
      sphere.setActive(true);
      cube.setActive(true);
      
   }
   

}




package game.state.order.test;

import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.Renderer;
import com.jme.scene.shape.Box;
import com.jme.scene.state.LightState;
import com.jme.system.DisplaySystem;
import com.jmex.game.state.BasicGameState;

public class OrthoBoxes extends BasicGameState {

   public OrthoBoxes() {
      super("ortho queue");
      
      rootNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
      rootNode.setLightCombineMode(LightState.OFF);
      
      int width  = DisplaySystem.getDisplaySystem().getWidth();
      int height = DisplaySystem.getDisplaySystem().getHeight();
      float x,y,z = 0;
      
      for(int i =0; i < 25; i++) {
         
         x = width * FastMath.rand.nextFloat();
         y = height * FastMath.rand.nextFloat();
         
         Box b = new Box("random box "+(i+1),Vector3f.ZERO,10,10,0);
         Vector3f tmp = new Vector3f(x,y,z);
         b.setLocalTranslation( tmp);
         
         /*** this doesn't work in ortho queue?
         b.setModelBound(new BoundingBox());
         b.updateModelBound();
         ***/
         
         b.setRandomColors();
         b.updateRenderState();
         
         rootNode.attachChild(b);
         
      }
      
      rootNode.updateRenderState();
      
   }

}




package game.state.order.test;

import com.jme.bounding.BoundingBox;
import com.jme.renderer.Renderer;
import com.jme.scene.shape.Sphere;
import com.jmex.game.state.BasicGameState;

public class SphereState extends BasicGameState {

   public SphereState() {
      super("sphere");
      
      Sphere s = new Sphere("sphere",12,12,5);
      //s.setRandomColors();
      s.setModelBound(new BoundingBox());
      s.updateModelBound();
      rootNode.attachChild(s);
      rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
      
      rootNode.updateRenderState();
      
   }

}




package game.state.order.test;

import com.jme.bounding.BoundingBox;
import com.jme.math.Vector3f;
import com.jme.renderer.Renderer;
import com.jme.scene.shape.Box;
import com.jmex.game.state.BasicGameState;

public class CubeState extends BasicGameState {

   public CubeState() {
      super("cube");
      
      Box b = new Box("sphere",Vector3f.ZERO,8,8,8);
      b.setLocalTranslation(new Vector3f(15,15,15));
      b.setModelBound(new BoundingBox());
      b.updateModelBound();
      rootNode.attachChild(b);
      rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
      
      rootNode.updateRenderState();
      
   }

}

This sounds related to the problems I'm having…



I saw the GameState tutorial that Darkfrog posted, and I liked the modularity of the GameState architecture. So I made a game with a couple game states and set up a StandardGame that let you switch between states with a key press. All was good.



Then I saw the TestIsland, and liked the graphics. I don't really understand what a "PassGame" is but I figured I could steal the code and put it into my game. I made a TerrainManager that does everything that test island does. I pass it a MyGameState object.  I put all sorts of code in my game state object that was happening in the SimplePassGame and superclasses.  My game state became sort of like a game object that is encapsulated by the StandardGame. I make calls to it in update and render etc.  It holds a camera, a timer, a PassManager, a reference to the DisplaySystem…



I pass the gamestate into my terrain manager, and the terrain manager builds the island and the water, using gamestate's rootnode and camera and passmanager and stuff.



It renders, but the terrain is semi-transparent. I can't figure out why.  There was a lot of crap to copy around so it is possible I forgot something, but this code seems to be the important part:



        /**

        * Create a ZBuffer to display pixels closest to the camera above

        * farther ones.

        */

        ZBufferState buf = display.getRenderer().createZBufferState();

        buf.setEnabled( true );

        buf.setFunction( ZBufferState.CF_LEQUAL );

        rootNode.setRenderState( buf );



This code was originally in BaseSimpleGame's initGame method. I put it into MyGameState's init method.  It gets called when the gamestate is made. 

I'm sure that I just have a fundamental misunderstanding of how all this is working.



If somebody would like to toss out an explanation of why what I'm doing is a horrible horrible idea, I'd be happy to hear it :stuck_out_tongue:

darkfrog said:

To my knowledge this hasn't been fully addressed yet for StandardGame, and I haven't had the need for it in my own development yet.

If you find any thing hindering you in StandardGame let me know and I'll make the appropriate changes.


Actually, I think we do need it. I had to disable the use of render pass manager with a bloom pass because it interferred with the substance game state.