material: refer to default technique via constant
This commit is contained in:
parent
fbcfbc0484
commit
2f26b34bd0
jme3-core/src
main/java/com/jme3
test/java/com/jme3/renderer
tools/java/jme3tools/shadercheck
jme3-examples/src/main/java/jme3test/material
@ -263,8 +263,14 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
|
||||
// E.g. if user chose custom technique for one material but
|
||||
// uses default technique for other material, the materials
|
||||
// are not equal.
|
||||
String thisDefName = this.technique != null ? this.technique.getDef().getName() : "Default";
|
||||
String otherDefName = other.technique != null ? other.technique.getDef().getName() : "Default";
|
||||
String thisDefName = this.technique != null
|
||||
? 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)) {
|
||||
return false;
|
||||
}
|
||||
@ -693,23 +699,18 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
|
||||
/**
|
||||
* Select the technique to use for rendering this material.
|
||||
* <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)
|
||||
* must be verified to be compatible with the system, for that, the
|
||||
* <code>renderManager</code> is queried for capabilities.
|
||||
*
|
||||
* @param name The name of the technique to select, pass "Default" to
|
||||
* select one of the default techniques.
|
||||
* @param name The name of the technique to select, pass
|
||||
* {@link TechniqueDef#DEFAULT_TECHNIQUE_NAME} to select one of the default
|
||||
* techniques.
|
||||
* @param renderManager The {@link RenderManager render manager}
|
||||
* to query for capabilities.
|
||||
*
|
||||
* @throws IllegalArgumentException If "Default" is passed and no default
|
||||
* techniques are available on the material definition, or if a name
|
||||
* is passed but there's no technique by that name.
|
||||
* @throws IllegalArgumentException If no technique exists with the given
|
||||
* name.
|
||||
* @throws UnsupportedOperationException If no candidate technique supports
|
||||
* the system capabilities.
|
||||
*/
|
||||
@ -839,7 +840,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
|
||||
*/
|
||||
public void preload(RenderManager renderManager) {
|
||||
if (technique == null) {
|
||||
selectTechnique("Default", renderManager);
|
||||
selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
|
||||
}
|
||||
TechniqueDef techniqueDef = technique.getDef();
|
||||
Renderer renderer = renderManager.getRenderer();
|
||||
@ -939,7 +940,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
|
||||
*/
|
||||
public void render(Geometry geometry, LightList lights, RenderManager renderManager) {
|
||||
if (technique == null) {
|
||||
selectTechnique("Default", renderManager);
|
||||
selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
|
||||
}
|
||||
|
||||
TechniqueDef techniqueDef = technique.getDef();
|
||||
|
@ -53,6 +53,14 @@ public class TechniqueDef implements Savable {
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@ -132,7 +140,7 @@ public class TechniqueDef implements Savable {
|
||||
public TechniqueDef(String name, int sortId){
|
||||
this();
|
||||
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.
|
||||
* Default techniques have the name "Default".
|
||||
* Default
|
||||
* techniques have the name {@link #DEFAULT_TECHNIQUE_NAME}.
|
||||
*
|
||||
* @return the name of this technique
|
||||
*/
|
||||
|
@ -582,7 +582,9 @@ public class RenderManager {
|
||||
if (forcedTechnique != null) {
|
||||
MaterialDef matDef = g.getMaterial().getMaterialDef();
|
||||
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);
|
||||
//saving forcedRenderState for future calls
|
||||
RenderState tmpRs = forcedRenderState;
|
||||
|
@ -33,6 +33,7 @@ package com.jme3.renderer;
|
||||
|
||||
import com.jme3.asset.AssetManager;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.TechniqueDef;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.renderer.queue.GeometryList;
|
||||
import com.jme3.renderer.queue.OpaqueComparator;
|
||||
@ -92,7 +93,7 @@ public class OpaqueComparatorTest {
|
||||
String techniqueName = materials[i].getActiveTechnique().getDef().getName();
|
||||
clonedMaterial.selectTechnique(techniqueName, renderManager);
|
||||
} else {
|
||||
clonedMaterial.selectTechnique("Default", renderManager);
|
||||
clonedMaterial.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
|
||||
}
|
||||
|
||||
geom.setMaterial(clonedMaterial);
|
||||
@ -156,7 +157,7 @@ public class OpaqueComparatorTest {
|
||||
Material lightingMatGlow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
|
||||
|
||||
lightingMatDefault.setName("TechDefault");
|
||||
lightingMatDefault.selectTechnique("Default", renderManager);
|
||||
lightingMatDefault.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
|
||||
|
||||
lightingPostShadow.setName("TechPostShad");
|
||||
lightingPostShadow.selectTechnique("PostShadow", renderManager);
|
||||
@ -272,7 +273,7 @@ public class OpaqueComparatorTest {
|
||||
tex2.getImage().setId(3);
|
||||
|
||||
matBase1.setName("BASE");
|
||||
matBase1.selectTechnique("Default", renderManager);
|
||||
matBase1.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
|
||||
matBase1.setBoolean("UseVertexColor", true);
|
||||
matBase1.setTexture("DiffuseMap", texBase);
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class ShaderCheck {
|
||||
MaterialDef def = (MaterialDef) assetManager.loadAsset(matdefName);
|
||||
EnumSet<Caps> rendererCaps = EnumSet.noneOf(Caps.class);
|
||||
rendererCaps.add(Caps.GLSL100);
|
||||
for (TechniqueDef techDef : def.getTechniqueDefs("Default")) {
|
||||
for (TechniqueDef techDef : def.getTechniqueDefs(TechniqueDef.DEFAULT_TECHNIQUE_NAME)) {
|
||||
DefineList defines = techDef.createDefineList();
|
||||
Shader shader = techDef.getShader(assetManager, rendererCaps, defines);
|
||||
for (Validator validator : validators) {
|
||||
|
@ -3,6 +3,7 @@ package jme3test.material;
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.Technique;
|
||||
import com.jme3.material.TechniqueDef;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Box;
|
||||
@ -27,7 +28,7 @@ public class TestShaderNodes extends SimpleApplication {
|
||||
Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
|
||||
|
||||
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();
|
||||
|
||||
// for (Shader.ShaderSource shaderSource : t.getShader().getSources()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user