From 2915316e4536065a122fc87597e1cb1b9baa422f Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Mon, 17 Sep 2012 21:32:48 +0000 Subject: [PATCH] One can now have a block ForcedRenderState in a technique defnition. this renderstate if filled will be forced into the renderer when the technique is forced git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9749 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/material/plugins/J3MLoader.java | 13 ++++++++++- .../core/com/jme3/material/TechniqueDef.java | 10 ++++++++ .../core/com/jme3/renderer/RenderManager.java | 23 ++++++++++++------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/engine/src/core-plugins/com/jme3/material/plugins/J3MLoader.java b/engine/src/core-plugins/com/jme3/material/plugins/J3MLoader.java index 6da28a057..cdcade624 100644 --- a/engine/src/core-plugins/com/jme3/material/plugins/J3MLoader.java +++ b/engine/src/core-plugins/com/jme3/material/plugins/J3MLoader.java @@ -353,6 +353,15 @@ public class J3MLoader implements AssetLoader { renderState = null; } + private void readForcedRenderState(List renderStates) throws IOException{ + renderState = new RenderState(); + for (Statement statement : renderStates){ + readRenderStateStatement(statement.getLine()); + } + technique.setForcedRenderState(renderState); + renderState = null; + } + // [ ":" ] private void readDefine(String statement) throws IOException{ String[] split = statement.split(":"); @@ -384,8 +393,10 @@ public class J3MLoader implements AssetLoader { readShadowMode(statement.getLine()); }else if (split[0].equals("WorldParameters")){ readWorldParams(statement.getContents()); - }else if (split[0].equals("RenderState")){ + }else if (split[0].equals("RenderState")){ readRenderState(statement.getContents()); + }else if (split[0].equals("ForcedRenderState")){ + readForcedRenderState(statement.getContents()); }else if (split[0].equals("Defines")){ readDefines(statement.getContents()); }else{ diff --git a/engine/src/core/com/jme3/material/TechniqueDef.java b/engine/src/core/com/jme3/material/TechniqueDef.java index ee94a8c9d..072f35f25 100644 --- a/engine/src/core/com/jme3/material/TechniqueDef.java +++ b/engine/src/core/com/jme3/material/TechniqueDef.java @@ -113,6 +113,8 @@ public class TechniqueDef implements Savable { private boolean usesShaders; private RenderState renderState; + private RenderState forcedRenderState; + private LightMode lightMode = LightMode.Disable; private ShadowMode shadowMode = ShadowMode.Disable; @@ -376,6 +378,14 @@ public class TechniqueDef implements Savable { } } + public RenderState getForcedRenderState() { + return forcedRenderState; + } + + public void setForcedRenderState(RenderState forcedRenderState) { + this.forcedRenderState = forcedRenderState; + } + /** * Returns a list of world parameters that are used by this * technique definition. diff --git a/engine/src/core/com/jme3/renderer/RenderManager.java b/engine/src/core/com/jme3/renderer/RenderManager.java index e192c4555..5d69fc882 100644 --- a/engine/src/core/com/jme3/renderer/RenderManager.java +++ b/engine/src/core/com/jme3/renderer/RenderManager.java @@ -67,10 +67,8 @@ import java.util.logging.Logger; public class RenderManager { private static final Logger logger = Logger.getLogger(RenderManager.class.getName()); - private Renderer renderer; private UniformBindingManager uniformBindingManager = new UniformBindingManager(); - private ArrayList preViewPorts = new ArrayList(); private ArrayList viewPorts = new ArrayList(); private ArrayList postViewPorts = new ArrayList(); @@ -81,7 +79,6 @@ public class RenderManager { private boolean shader; private int viewX, viewY, viewWidth, viewHeight; private Matrix4f orthoMatrix = new Matrix4f(); - private String tmpTech; private boolean handleTranlucentBucket = true; @@ -447,7 +444,7 @@ public class RenderManager { renderer.setWorldMatrix(mat); } } - + /** * Internal use only. * Updates the given list of uniforms with {@link UniformBinding uniform bindings} @@ -502,9 +499,19 @@ public class RenderManager { if (g.getMaterial().getMaterialDef().getTechniqueDef(forcedTechnique) != null) { tmpTech = g.getMaterial().getActiveTechnique() != null ? g.getMaterial().getActiveTechnique().getDef().getName() : "Default"; g.getMaterial().selectTechnique(forcedTechnique, this); + //saving forcedRenderState for future calls + RenderState tmpRs = forcedRenderState; + if (g.getMaterial().getActiveTechnique().getDef().getForcedRenderState() != null) { + //forcing forced technique renderState + forcedRenderState = g.getMaterial().getActiveTechnique().getDef().getForcedRenderState(); + } // use geometry's material g.getMaterial().render(g, this); g.getMaterial().selectTechnique(tmpTech, this); + + //restoring forcedRenderState + forcedRenderState = tmpRs; + //Reverted this part from revision 6197 //If forcedTechnique does not exists, and frocedMaterial is not set, the geom MUST NOT be rendered } else if (forcedMaterial != null) { @@ -635,7 +642,7 @@ public class RenderManager { // check culling first. if (!scene.checkCulling(vp.getCamera())) { // move on to shadow-only render - if ((scene.getShadowMode() != RenderQueue.ShadowMode.Off || scene instanceof Node) && scene.getCullHint()!=Spatial.CullHint.Always) { + if ((scene.getShadowMode() != RenderQueue.ShadowMode.Off || scene instanceof Node) && scene.getCullHint() != Spatial.CullHint.Always) { renderShadow(scene, vp.getQueue()); } return; @@ -1006,19 +1013,19 @@ public class RenderManager { for (int i = 0; i < preViewPorts.size(); i++) { ViewPort vp = preViewPorts.get(i); - if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){ + if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive) { renderViewPort(vp, tpf); } } for (int i = 0; i < viewPorts.size(); i++) { ViewPort vp = viewPorts.get(i); - if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){ + if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive) { renderViewPort(vp, tpf); } } for (int i = 0; i < postViewPorts.size(); i++) { ViewPort vp = postViewPorts.get(i); - if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){ + if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive) { renderViewPort(vp, tpf); } }