material: refer to default technique via constant

cleanup_build_scripts
Kirill Vainer 9 years ago
parent fbcfbc0484
commit 2f26b34bd0
  1. 29
      jme3-core/src/main/java/com/jme3/material/Material.java
  2. 13
      jme3-core/src/main/java/com/jme3/material/TechniqueDef.java
  3. 4
      jme3-core/src/main/java/com/jme3/renderer/RenderManager.java
  4. 7
      jme3-core/src/test/java/com/jme3/renderer/OpaqueComparatorTest.java
  5. 2
      jme3-core/src/tools/java/jme3tools/shadercheck/ShaderCheck.java
  6. 3
      jme3-examples/src/main/java/jme3test/material/TestShaderNodes.java

@ -263,8 +263,14 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
// E.g. if user chose custom technique for one material but // E.g. if user chose custom technique for one material but
// uses default technique for other material, the materials // uses default technique for other material, the materials
// are not equal. // are not equal.
String thisDefName = this.technique != null ? this.technique.getDef().getName() : "Default"; String thisDefName = this.technique != null
String otherDefName = other.technique != null ? other.technique.getDef().getName() : "Default"; ? this.technique.getDef().getName()
: TechniqueDef.DEFAULT_TECHNIQUE_NAME;
String otherDefName = other.technique != null
? other.technique.getDef().getName()
: TechniqueDef.DEFAULT_TECHNIQUE_NAME;
if (!thisDefName.equals(otherDefName)) { if (!thisDefName.equals(otherDefName)) {
return false; return false;
} }
@ -693,23 +699,18 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
/** /**
* Select the technique to use for rendering this material. * Select the technique to use for rendering this material.
* <p> * <p>
* If <code>name</code> is "Default", then one of the
* {@link MaterialDef#getDefaultTechniques() default techniques}
* on the material will be selected. Otherwise, the named technique
* will be found in the material definition.
* <p>
* Any candidate technique for selection (either default or named) * Any candidate technique for selection (either default or named)
* must be verified to be compatible with the system, for that, the * must be verified to be compatible with the system, for that, the
* <code>renderManager</code> is queried for capabilities. * <code>renderManager</code> is queried for capabilities.
* *
* @param name The name of the technique to select, pass "Default" to * @param name The name of the technique to select, pass
* select one of the default techniques. * {@link TechniqueDef#DEFAULT_TECHNIQUE_NAME} to select one of the default
* techniques.
* @param renderManager The {@link RenderManager render manager} * @param renderManager The {@link RenderManager render manager}
* to query for capabilities. * to query for capabilities.
* *
* @throws IllegalArgumentException If "Default" is passed and no default * @throws IllegalArgumentException If no technique exists with the given
* techniques are available on the material definition, or if a name * name.
* is passed but there's no technique by that name.
* @throws UnsupportedOperationException If no candidate technique supports * @throws UnsupportedOperationException If no candidate technique supports
* the system capabilities. * the system capabilities.
*/ */
@ -839,7 +840,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
*/ */
public void preload(RenderManager renderManager) { public void preload(RenderManager renderManager) {
if (technique == null) { if (technique == null) {
selectTechnique("Default", renderManager); selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
} }
TechniqueDef techniqueDef = technique.getDef(); TechniqueDef techniqueDef = technique.getDef();
Renderer renderer = renderManager.getRenderer(); Renderer renderer = renderManager.getRenderer();
@ -939,7 +940,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
*/ */
public void render(Geometry geometry, LightList lights, RenderManager renderManager) { public void render(Geometry geometry, LightList lights, RenderManager renderManager) {
if (technique == null) { if (technique == null) {
selectTechnique("Default", renderManager); selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
} }
TechniqueDef techniqueDef = technique.getDef(); TechniqueDef techniqueDef = technique.getDef();

@ -53,6 +53,14 @@ public class TechniqueDef implements Savable {
*/ */
public static final int SAVABLE_VERSION = 1; public static final int SAVABLE_VERSION = 1;
/**
* The default technique name.
*
* The technique with this name is selected if no specific technique is
* requested by the user. Currently set to "Default".
*/
public static final String DEFAULT_TECHNIQUE_NAME = "Default";
/** /**
* Describes light rendering mode. * Describes light rendering mode.
*/ */
@ -132,7 +140,7 @@ public class TechniqueDef implements Savable {
public TechniqueDef(String name, int sortId){ public TechniqueDef(String name, int sortId){
this(); this();
this.sortId = sortId; this.sortId = sortId;
this.name = name == null ? "Default" : name; this.name = name == null ? TechniqueDef.DEFAULT_TECHNIQUE_NAME : name;
} }
/** /**
@ -157,7 +165,8 @@ public class TechniqueDef implements Savable {
/** /**
* Returns the name of this technique as specified in the J3MD file. * Returns the name of this technique as specified in the J3MD file.
* Default techniques have the name "Default". * Default
* techniques have the name {@link #DEFAULT_TECHNIQUE_NAME}.
* *
* @return the name of this technique * @return the name of this technique
*/ */

@ -582,7 +582,9 @@ public class RenderManager {
if (forcedTechnique != null) { if (forcedTechnique != null) {
MaterialDef matDef = g.getMaterial().getMaterialDef(); MaterialDef matDef = g.getMaterial().getMaterialDef();
if (matDef.getTechniqueDefs(forcedTechnique) != null) { if (matDef.getTechniqueDefs(forcedTechnique) != null) {
tmpTech = g.getMaterial().getActiveTechnique() != null ? g.getMaterial().getActiveTechnique().getDef().getName() : "Default"; tmpTech = g.getMaterial().getActiveTechnique() != null
? g.getMaterial().getActiveTechnique().getDef().getName()
: TechniqueDef.DEFAULT_TECHNIQUE_NAME;
g.getMaterial().selectTechnique(forcedTechnique, this); g.getMaterial().selectTechnique(forcedTechnique, this);
//saving forcedRenderState for future calls //saving forcedRenderState for future calls
RenderState tmpRs = forcedRenderState; RenderState tmpRs = forcedRenderState;

@ -33,6 +33,7 @@ package com.jme3.renderer;
import com.jme3.asset.AssetManager; import com.jme3.asset.AssetManager;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.material.TechniqueDef;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.renderer.queue.GeometryList; import com.jme3.renderer.queue.GeometryList;
import com.jme3.renderer.queue.OpaqueComparator; import com.jme3.renderer.queue.OpaqueComparator;
@ -92,7 +93,7 @@ public class OpaqueComparatorTest {
String techniqueName = materials[i].getActiveTechnique().getDef().getName(); String techniqueName = materials[i].getActiveTechnique().getDef().getName();
clonedMaterial.selectTechnique(techniqueName, renderManager); clonedMaterial.selectTechnique(techniqueName, renderManager);
} else { } else {
clonedMaterial.selectTechnique("Default", renderManager); clonedMaterial.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
} }
geom.setMaterial(clonedMaterial); geom.setMaterial(clonedMaterial);
@ -156,7 +157,7 @@ public class OpaqueComparatorTest {
Material lightingMatGlow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); Material lightingMatGlow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
lightingMatDefault.setName("TechDefault"); lightingMatDefault.setName("TechDefault");
lightingMatDefault.selectTechnique("Default", renderManager); lightingMatDefault.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
lightingPostShadow.setName("TechPostShad"); lightingPostShadow.setName("TechPostShad");
lightingPostShadow.selectTechnique("PostShadow", renderManager); lightingPostShadow.selectTechnique("PostShadow", renderManager);
@ -272,7 +273,7 @@ public class OpaqueComparatorTest {
tex2.getImage().setId(3); tex2.getImage().setId(3);
matBase1.setName("BASE"); matBase1.setName("BASE");
matBase1.selectTechnique("Default", renderManager); matBase1.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
matBase1.setBoolean("UseVertexColor", true); matBase1.setBoolean("UseVertexColor", true);
matBase1.setTexture("DiffuseMap", texBase); matBase1.setTexture("DiffuseMap", texBase);

@ -38,7 +38,7 @@ public class ShaderCheck {
MaterialDef def = (MaterialDef) assetManager.loadAsset(matdefName); MaterialDef def = (MaterialDef) assetManager.loadAsset(matdefName);
EnumSet<Caps> rendererCaps = EnumSet.noneOf(Caps.class); EnumSet<Caps> rendererCaps = EnumSet.noneOf(Caps.class);
rendererCaps.add(Caps.GLSL100); rendererCaps.add(Caps.GLSL100);
for (TechniqueDef techDef : def.getTechniqueDefs("Default")) { for (TechniqueDef techDef : def.getTechniqueDefs(TechniqueDef.DEFAULT_TECHNIQUE_NAME)) {
DefineList defines = techDef.createDefineList(); DefineList defines = techDef.createDefineList();
Shader shader = techDef.getShader(assetManager, rendererCaps, defines); Shader shader = techDef.getShader(assetManager, rendererCaps, defines);
for (Validator validator : validators) { for (Validator validator : validators) {

@ -3,6 +3,7 @@ package jme3test.material;
import com.jme3.app.SimpleApplication; import com.jme3.app.SimpleApplication;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.material.Technique; import com.jme3.material.Technique;
import com.jme3.material.TechniqueDef;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box; import com.jme3.scene.shape.Box;
@ -27,7 +28,7 @@ public class TestShaderNodes extends SimpleApplication {
Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg"); Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
Material mat = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md"); Material mat = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md");
mat.selectTechnique("Default", renderManager); mat.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
Technique t = mat.getActiveTechnique(); Technique t = mat.getActiveTechnique();
// for (Shader.ShaderSource shaderSource : t.getShader().getSources()) { // for (Shader.ShaderSource shaderSource : t.getShader().getSources()) {

Loading…
Cancel
Save