diff --git a/jme3-core/src/main/java/com/jme3/material/Material.java b/jme3-core/src/main/java/com/jme3/material/Material.java index 8874c5e58d..1352fa393b 100644 --- a/jme3-core/src/main/java/com/jme3/material/Material.java +++ b/jme3-core/src/main/java/com/jme3/material/Material.java @@ -907,22 +907,23 @@ private BindUnits updateShaderMaterialParameters(Renderer renderer, Shader shade private void updateRenderState(Geometry geometry, RenderManager renderManager, Renderer renderer, TechniqueDef techniqueDef) { + RenderState finalRenderState; if (renderManager.getForcedRenderState() != null) { - mergedRenderState.copyFrom(renderManager.getForcedRenderState()); + finalRenderState = mergedRenderState.copyFrom(renderManager.getForcedRenderState()); } else if (techniqueDef.getRenderState() != null) { - mergedRenderState.copyFrom(RenderState.DEFAULT); - techniqueDef.getRenderState().copyMergedTo(additionalState, mergedRenderState); + finalRenderState = mergedRenderState.copyFrom(RenderState.DEFAULT); + finalRenderState = techniqueDef.getRenderState().copyMergedTo(additionalState, finalRenderState); } else { - mergedRenderState.copyFrom(RenderState.DEFAULT); - RenderState.DEFAULT.copyMergedTo(additionalState, mergedRenderState); + finalRenderState = mergedRenderState.copyFrom(RenderState.DEFAULT); + finalRenderState = RenderState.DEFAULT.copyMergedTo(additionalState, finalRenderState); } // test if the face cull mode should be flipped before render - if (mergedRenderState.isFaceCullFlippable() && isNormalsBackward(geometry.getWorldScale())) { - mergedRenderState.flipFaceCull(); + if (finalRenderState.isFaceCullFlippable() && isNormalsBackward(geometry.getWorldScale())) { + finalRenderState.flipFaceCull(); } - renderer.applyRenderState(mergedRenderState); + renderer.applyRenderState(finalRenderState); } - + /** * Returns true if the geometry world scale indicates that normals will be backward. * @param scalar geometry world scale diff --git a/jme3-core/src/main/java/com/jme3/material/RenderState.java b/jme3-core/src/main/java/com/jme3/material/RenderState.java index 69bba188f7..c49744db1e 100644 --- a/jme3-core/src/main/java/com/jme3/material/RenderState.java +++ b/jme3-core/src/main/java/com/jme3/material/RenderState.java @@ -1692,7 +1692,7 @@ public void set(RenderState state) { * This method is more precise than {@link #set(com.jme3.material.RenderState)}. * @param state state to copy from */ - public void copyFrom(RenderState state) { + public RenderState copyFrom(RenderState state) { this.applyBlendMode = state.applyBlendMode; this.applyColorWrite = state.applyColorWrite; this.applyCullMode = state.applyCullMode; @@ -1734,6 +1734,7 @@ public void copyFrom(RenderState state) { this.sfactorRGB = state.sfactorRGB; this.stencilTest = state.stencilTest; this.wireframe = state.wireframe; + return this; } @Override