Hello everybody:
I’ve been working on my NormalGenerator http://www.jmonkeyengine.com/jmeforum/index.php?topic=5768.0(shameless advertisement ;)), and while toying with textures and RenderStates noticed something I think is a bug.
import com.jme.app.*;
import com.jme.math.*;
import com.jme.renderer.RenderContext;
import com.jme.renderer.Renderer;
import com.jme.scene.*;
import com.jme.scene.batch.*;
import com.jme.scene.shape.*;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jme.util.resource.ResourceLocatorTool;
import java.net.URL;
import java.nio.*;
import java.util.ArrayList;
/**
*
* @author Edgar A. Duenez-Guzman
*/
public class TestBug extends SimpleGame
{
private boolean flag = true;
/** Creates a new instance of TestNormalGenerator */
public TestBug()
{
super();
}
protected void simpleInitGame()
{
Box box1 = new Box( "Object1", new Vector3f( -1f, -1f, -1f ), new Vector3f( 1f, 1f, 1f ) );
box1.setLocalTranslation( -3.0f, 0, 0 );
rootNode.attachChild( box1 );
Box box2 = new Box( "Object2", new Vector3f( -1f, -1f, -1f ), new Vector3f( 1f, 1f, 1f ) );
box2.setLocalTranslation( 0.0f, 0, 0 );
rootNode.attachChild( box2 );
try {
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled( true );
ts.setTexture( TextureManager.loadTexture( TestBug.class.getResource( "jmetest/data/images/buttonback.png" ) ) );
box1.setRenderState( ts );
box1.updateRenderState();
} catch( Exception e ) { e.printStackTrace(); }
}
protected void simpleUpdate()
{
if( flag && timer.getTime() > 3000 )
{
flag = false;
Box box3 = new Box( "Object3", new Vector3f( -1f, -1f, -1f ), new Vector3f( 1f, 1f, 1f ) );
box3.setLocalTranslation( 0.0f, 3.0f, 0.0f );
try {
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled( true );
ts.setTexture( TextureManager.loadTexture( TestBug.class.getResource( "jmetest/data/images/Fieldstone.jpg" ) ) );
box3.setRenderState( ts );
box3.updateRenderState();
} catch( Exception e ) { e.printStackTrace(); }
rootNode.attachChild( box3 );
rootNode.updateRenderState(); //<
*************************
}
}
public static void main( String args[] )
{
TestBug t = new TestBug();
t.start();
}
}
The deal is this... the program creates 2 boxes, one with its own texture (and hence RenderState), I call updateRenderState on the box, and not on the rootNode because the state only modifies the box.
3 seconds later I create a third box with another texture and RenderState again calling updateRenderState only on this new object.
The bug is apparent if you comment the line marked with (too ;)) many asterisks on the code. (Or commenting it out, and pressing 't' twice to force a call to updateRenderState on the rootNode)
The point is that the texture changes to a darker version :-o. Not only that, but I think rootNode should not update anything (except geometric state perhaps).
Am I completely off? :?
Here are screenshots:

