From e93993364a2b9a0d451177920d3adf85691e7c2e Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Wed, 26 Oct 2011 03:30:17 +0000 Subject: [PATCH] * Fixed issue where additional render states in material would always have apply*** flags set to true, added workaround for old versions of material * RenderState now exports/imports apply*** flags git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8529 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/core/com/jme3/material/Material.java | 38 ++++++++++++++++--- .../core/com/jme3/material/RenderState.java | 26 ++++++++++++- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/engine/src/core/com/jme3/material/Material.java b/engine/src/core/com/jme3/material/Material.java index 1c6c8c3f8..4e8bb0abf 100644 --- a/engine/src/core/com/jme3/material/Material.java +++ b/engine/src/core/com/jme3/material/Material.java @@ -46,13 +46,17 @@ import com.jme3.light.Light; import com.jme3.light.LightList; import com.jme3.light.PointLight; import com.jme3.light.SpotLight; +import com.jme3.material.RenderState.BlendMode; +import com.jme3.material.RenderState.FaceCullMode; import com.jme3.material.TechniqueDef.LightMode; +import com.jme3.material.TechniqueDef.ShadowMode; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.math.Vector4f; import com.jme3.renderer.Caps; import com.jme3.renderer.RenderManager; import com.jme3.renderer.Renderer; +import com.jme3.renderer.queue.RenderQueue.Bucket; import com.jme3.scene.Geometry; import com.jme3.shader.Shader; import com.jme3.shader.Uniform; @@ -81,7 +85,8 @@ import java.util.logging.Logger; */ public class Material implements Asset, Cloneable, Savable, Comparable { - public static final int SAVABLE_VERSION = 1; + // Version #2: Fixed issue with RenderState.apply*** flags not getting exported + public static final int SAVABLE_VERSION = 2; private static final Logger logger = Logger.getLogger(Material.class.getName()); private static final RenderState additiveLight = new RenderState(); @@ -1048,8 +1053,16 @@ public class Material implements Asset, Cloneable, Savable, Comparable boolean enableVcolor = false; boolean separateTexCoord = false; - boolean applyDefaults = false; + boolean applyDefaultValues = false; + boolean guessRenderStateApply = false; + int ver = ic.getSavableVersion(Material.class); + if (ver < 1){ + applyDefaultValues = true; + } + if (ver < 2){ + guessRenderStateApply = true; + } if (im.getFormatVersion() == 0) { // Enable compatibility with old models if (defName.equalsIgnoreCase("Common/MatDefs/Misc/VertexColor.j3md")) { @@ -1072,9 +1085,7 @@ public class Material implements Asset, Cloneable, Savable, Comparable separateTexCoord = true; } } - applyDefaults = true; - }else if (ic.getSavableVersion(Material.class) == 0){ - applyDefaults = true; + assert applyDefaultValues && guessRenderStateApply; } def = (MaterialDef) im.getAssetManager().loadAsset(new AssetKey(defName)); @@ -1100,7 +1111,7 @@ public class Material implements Asset, Cloneable, Savable, Comparable paramValues.put(param.getName(), param); } - if (applyDefaults){ + if (applyDefaultValues){ // compatability with old versions where default vars were // not available for (MatParam param : def.getMaterialParams()){ @@ -1109,6 +1120,21 @@ public class Material implements Asset, Cloneable, Savable, Comparable } } } + if (guessRenderStateApply){ + // Try to guess values of "apply" render state based on defaults + // if value != default then set apply to true + additionalState.applyPolyOffset = additionalState.offsetEnabled; + additionalState.applyAlphaFallOff = additionalState.alphaTest; + additionalState.applyAlphaTest = additionalState.alphaTest; + additionalState.applyBlendMode = additionalState.blendMode != BlendMode.Off; + additionalState.applyColorWrite = !additionalState.colorWrite; + additionalState.applyCullMode = additionalState.cullMode != FaceCullMode.Back; + additionalState.applyDepthTest = !additionalState.depthTest; + additionalState.applyDepthWrite = !additionalState.depthWrite; + additionalState.applyPointSprite = additionalState.pointSprite; + additionalState.applyStencilTest = additionalState.stencilTest; + additionalState.applyWireFrame = additionalState.wireframe; + } if (enableVcolor) { setBoolean("VertexColor", true); } diff --git a/engine/src/core/com/jme3/material/RenderState.java b/engine/src/core/com/jme3/material/RenderState.java index 293323c86..7dd400801 100644 --- a/engine/src/core/com/jme3/material/RenderState.java +++ b/engine/src/core/com/jme3/material/RenderState.java @@ -324,7 +324,7 @@ public class RenderState implements Cloneable, Savable { StencilOperation backStencilDepthPassOperation = StencilOperation.Keep; TestFunction frontStencilFunction = TestFunction.Always; TestFunction backStencilFunction = TestFunction.Always; - + public void write(JmeExporter ex) throws IOException { OutputCapsule oc = ex.getCapsule(this); oc.write(pointSprite, "pointSprite", false); @@ -348,6 +348,19 @@ public class RenderState implements Cloneable, Savable { oc.write(backStencilDepthPassOperation, "backStencilDepthPassOperation", StencilOperation.Keep); oc.write(frontStencilFunction, "frontStencilFunction", TestFunction.Always); oc.write(backStencilFunction, "backStencilFunction", TestFunction.Always); + + // Only "additional render state" has them set to false by default + oc.write(applyPointSprite, "applyPointSprite", true); + oc.write(applyWireFrame, "applyWireFrame", true); + oc.write(applyCullMode, "applyCullMode", true); + oc.write(applyDepthWrite, "applyDepthWrite", true); + oc.write(applyDepthTest, "applyDepthTest", true); + oc.write(applyColorWrite, "applyColorWrite", true); + oc.write(applyBlendMode, "applyBlendMode", true); + oc.write(applyAlphaTest, "applyAlphaTest", true); + oc.write(applyAlphaFallOff, "applyAlphaFallOff", true); + oc.write(applyPolyOffset, "applyPolyOffset", true); + } public void read(JmeImporter im) throws IOException { @@ -373,6 +386,17 @@ public class RenderState implements Cloneable, Savable { backStencilDepthPassOperation = ic.readEnum("backStencilDepthPassOperation", StencilOperation.class, StencilOperation.Keep); frontStencilFunction = ic.readEnum("frontStencilFunction", TestFunction.class, TestFunction.Always); backStencilFunction = ic.readEnum("backStencilFunction", TestFunction.class, TestFunction.Always); + + applyPointSprite = ic.readBoolean("applyPointSprite", true); + applyWireFrame = ic.readBoolean("applyWireFrame", true); + applyCullMode = ic.readBoolean("applyCullMode", true); + applyDepthWrite = ic.readBoolean("applyDepthWrite", true); + applyDepthTest = ic.readBoolean("applyDepthTest", true); + applyColorWrite = ic.readBoolean("applyColorWrite", true); + applyBlendMode = ic.readBoolean("applyBlendMode", true); + applyAlphaTest = ic.readBoolean("applyAlphaTest", true); + applyAlphaFallOff = ic.readBoolean("applyAlphaFallOff", true); + applyPolyOffset = ic.readBoolean("applyPolyOffset", true); } /**