* 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
This commit is contained in:
parent
ae739ef441
commit
e93993364a
@ -46,13 +46,17 @@ import com.jme3.light.Light;
|
|||||||
import com.jme3.light.LightList;
|
import com.jme3.light.LightList;
|
||||||
import com.jme3.light.PointLight;
|
import com.jme3.light.PointLight;
|
||||||
import com.jme3.light.SpotLight;
|
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.LightMode;
|
||||||
|
import com.jme3.material.TechniqueDef.ShadowMode;
|
||||||
import com.jme3.math.Quaternion;
|
import com.jme3.math.Quaternion;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.math.Vector4f;
|
import com.jme3.math.Vector4f;
|
||||||
import com.jme3.renderer.Caps;
|
import com.jme3.renderer.Caps;
|
||||||
import com.jme3.renderer.RenderManager;
|
import com.jme3.renderer.RenderManager;
|
||||||
import com.jme3.renderer.Renderer;
|
import com.jme3.renderer.Renderer;
|
||||||
|
import com.jme3.renderer.queue.RenderQueue.Bucket;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.shader.Shader;
|
import com.jme3.shader.Shader;
|
||||||
import com.jme3.shader.Uniform;
|
import com.jme3.shader.Uniform;
|
||||||
@ -81,7 +85,8 @@ import java.util.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
public class Material implements Asset, Cloneable, Savable, Comparable<Material> {
|
public class Material implements Asset, Cloneable, Savable, Comparable<Material> {
|
||||||
|
|
||||||
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 Logger logger = Logger.getLogger(Material.class.getName());
|
||||||
private static final RenderState additiveLight = new RenderState();
|
private static final RenderState additiveLight = new RenderState();
|
||||||
@ -1048,8 +1053,16 @@ public class Material implements Asset, Cloneable, Savable, Comparable<Material>
|
|||||||
|
|
||||||
boolean enableVcolor = false;
|
boolean enableVcolor = false;
|
||||||
boolean separateTexCoord = 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) {
|
if (im.getFormatVersion() == 0) {
|
||||||
// Enable compatibility with old models
|
// Enable compatibility with old models
|
||||||
if (defName.equalsIgnoreCase("Common/MatDefs/Misc/VertexColor.j3md")) {
|
if (defName.equalsIgnoreCase("Common/MatDefs/Misc/VertexColor.j3md")) {
|
||||||
@ -1072,9 +1085,7 @@ public class Material implements Asset, Cloneable, Savable, Comparable<Material>
|
|||||||
separateTexCoord = true;
|
separateTexCoord = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
applyDefaults = true;
|
assert applyDefaultValues && guessRenderStateApply;
|
||||||
}else if (ic.getSavableVersion(Material.class) == 0){
|
|
||||||
applyDefaults = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def = (MaterialDef) im.getAssetManager().loadAsset(new AssetKey(defName));
|
def = (MaterialDef) im.getAssetManager().loadAsset(new AssetKey(defName));
|
||||||
@ -1100,7 +1111,7 @@ public class Material implements Asset, Cloneable, Savable, Comparable<Material>
|
|||||||
paramValues.put(param.getName(), param);
|
paramValues.put(param.getName(), param);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (applyDefaults){
|
if (applyDefaultValues){
|
||||||
// compatability with old versions where default vars were
|
// compatability with old versions where default vars were
|
||||||
// not available
|
// not available
|
||||||
for (MatParam param : def.getMaterialParams()){
|
for (MatParam param : def.getMaterialParams()){
|
||||||
@ -1109,6 +1120,21 @@ public class Material implements Asset, Cloneable, Savable, Comparable<Material>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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) {
|
if (enableVcolor) {
|
||||||
setBoolean("VertexColor", true);
|
setBoolean("VertexColor", true);
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
StencilOperation backStencilDepthPassOperation = StencilOperation.Keep;
|
StencilOperation backStencilDepthPassOperation = StencilOperation.Keep;
|
||||||
TestFunction frontStencilFunction = TestFunction.Always;
|
TestFunction frontStencilFunction = TestFunction.Always;
|
||||||
TestFunction backStencilFunction = TestFunction.Always;
|
TestFunction backStencilFunction = TestFunction.Always;
|
||||||
|
|
||||||
public void write(JmeExporter ex) throws IOException {
|
public void write(JmeExporter ex) throws IOException {
|
||||||
OutputCapsule oc = ex.getCapsule(this);
|
OutputCapsule oc = ex.getCapsule(this);
|
||||||
oc.write(pointSprite, "pointSprite", false);
|
oc.write(pointSprite, "pointSprite", false);
|
||||||
@ -348,6 +348,19 @@ public class RenderState implements Cloneable, Savable {
|
|||||||
oc.write(backStencilDepthPassOperation, "backStencilDepthPassOperation", StencilOperation.Keep);
|
oc.write(backStencilDepthPassOperation, "backStencilDepthPassOperation", StencilOperation.Keep);
|
||||||
oc.write(frontStencilFunction, "frontStencilFunction", TestFunction.Always);
|
oc.write(frontStencilFunction, "frontStencilFunction", TestFunction.Always);
|
||||||
oc.write(backStencilFunction, "backStencilFunction", 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 {
|
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);
|
backStencilDepthPassOperation = ic.readEnum("backStencilDepthPassOperation", StencilOperation.class, StencilOperation.Keep);
|
||||||
frontStencilFunction = ic.readEnum("frontStencilFunction", TestFunction.class, TestFunction.Always);
|
frontStencilFunction = ic.readEnum("frontStencilFunction", TestFunction.class, TestFunction.Always);
|
||||||
backStencilFunction = ic.readEnum("backStencilFunction", 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user