From b6729c46d402499a3dfa0cfc904ccb44518a9521 Mon Sep 17 00:00:00 2001 From: Kirill Vainer Date: Sun, 10 Apr 2016 12:15:01 -0400 Subject: [PATCH] code / comment cleanup --- .../main/java/com/jme3/material/Material.java | 20 ++----- .../java/com/jme3/material/Technique.java | 4 +- .../main/java/com/jme3/renderer/Camera.java | 12 ++-- .../java/com/jme3/renderer/RenderManager.java | 58 ++++++++++--------- .../java/com/jme3/scene/VertexBuffer.java | 3 +- .../com/jme3/material/plugins/J3MLoader.java | 31 +++++----- 6 files changed, 58 insertions(+), 70 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/material/Material.java b/jme3-core/src/main/java/com/jme3/material/Material.java index 75564d444..d66f88a0b 100644 --- a/jme3-core/src/main/java/com/jme3/material/Material.java +++ b/jme3-core/src/main/java/com/jme3/material/Material.java @@ -75,18 +75,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { // 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(); - private static final RenderState depthOnly = new RenderState(); - static { - depthOnly.setDepthTest(true); - depthOnly.setDepthWrite(true); - depthOnly.setFaceCullMode(RenderState.FaceCullMode.Back); - depthOnly.setColorWrite(false); - - additiveLight.setBlendMode(RenderState.BlendMode.AlphaAdditive); - additiveLight.setDepthWrite(false); - } private AssetKey key; private String name; private MaterialDef def; @@ -98,7 +87,6 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { private boolean transparent = false; private boolean receivesShadows = false; private int sortingId = -1; - private transient ColorRGBA ambientLightColor = new ColorRGBA(0, 0, 0, 1); public Material(MaterialDef def) { if (def == null) { @@ -742,9 +730,11 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { lastTech = techDef; } if (tech == null) { - throw new UnsupportedOperationException("No default technique on material '" + def.getName() + "'\n" - + " is supported by the video hardware. The caps " - + lastTech.getRequiredCaps() + " are required."); + throw new UnsupportedOperationException( + String.format("No technique '%s' on material " + + "'%s' is supported by the video hardware. " + + "The capabilities %s are required.", + name, def.getName(), lastTech.getRequiredCaps())); } } else if (technique == tech) { // attempting to switch to an already diff --git a/jme3-core/src/main/java/com/jme3/material/Technique.java b/jme3-core/src/main/java/com/jme3/material/Technique.java index 3a4fa71da..8ca95b178 100644 --- a/jme3-core/src/main/java/com/jme3/material/Technique.java +++ b/jme3-core/src/main/java/com/jme3/material/Technique.java @@ -183,8 +183,8 @@ public final class Technique { * @return nothing. * * @deprecated Preset defines are precompiled into - * {@link TechniqueDef#getShaderPrologue()}, whereas - * dynamic defines are available via {@link #getParamDefines()}. + * {@link TechniqueDef#getShaderPrologue()}, whereas dynamic defines are + * available via {@link #getParamDefines()}. */ @Deprecated public DefineList getAllDefines() { diff --git a/jme3-core/src/main/java/com/jme3/renderer/Camera.java b/jme3-core/src/main/java/com/jme3/renderer/Camera.java index 0ce5bafd7..2d4a61a45 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/Camera.java +++ b/jme3-core/src/main/java/com/jme3/renderer/Camera.java @@ -1005,12 +1005,12 @@ public class Camera implements Savable, Cloneable { * * NOTE: This method is used internally for culling, for public usage, * the plane state of the bounding volume must be saved and restored, e.g: - * BoundingVolume bv;
- * Camera c;
- * int planeState = bv.getPlaneState();
- * bv.setPlaneState(0);
- * c.contains(bv);
- * bv.setPlaneState(plateState);
+ * BoundingVolume bv;
+ * Camera c;
+ * int planeState = bv.getPlaneState();
+ * bv.setPlaneState(0);
+ * c.contains(bv);
+ * bv.setPlaneState(plateState);
*
* * @param bound the bound to check for culling diff --git a/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java b/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java index f250b2f65..50cc207f7 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java +++ b/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java @@ -74,20 +74,19 @@ 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(); + private final Renderer renderer; + private final UniformBindingManager uniformBindingManager = new UniformBindingManager(); + private final ArrayList preViewPorts = new ArrayList<>(); + private final ArrayList viewPorts = new ArrayList<>(); + private final ArrayList postViewPorts = new ArrayList<>(); private Camera prevCam = null; private Material forcedMaterial = null; private String forcedTechnique = null; private RenderState forcedRenderState = null; private final List forcedOverrides = new ArrayList<>(); private int viewX, viewY, viewWidth, viewHeight; - private Matrix4f orthoMatrix = new Matrix4f(); - private LightList filteredLightList = new LightList(null); - private String tmpTech; + private final Matrix4f orthoMatrix = new Matrix4f(); + private final LightList filteredLightList = new LightList(null); private boolean handleTranlucentBucket = true; private AppProfiler prof; private LightFilter lightFilter = new DefaultLightFilter(); @@ -552,49 +551,54 @@ public class RenderManager { * for rendering the material, and the material's own render state is ignored. * Otherwise, the material's render state is used as intended. * - * @param g The geometry to render - * + * @param geom The geometry to render + * * @see Technique * @see RenderState * @see Material#selectTechnique(java.lang.String, com.jme3.renderer.RenderManager) * @see Material#render(com.jme3.scene.Geometry, com.jme3.renderer.RenderManager) */ - public void renderGeometry(Geometry g) { - if (g.isIgnoreTransform()) { + public void renderGeometry(Geometry geom) { + if (geom.isIgnoreTransform()) { setWorldMatrix(Matrix4f.IDENTITY); } else { - setWorldMatrix(g.getWorldMatrix()); + setWorldMatrix(geom.getWorldMatrix()); } // Perform light filtering if we have a light filter. - LightList lightList = g.getWorldLightList(); + LightList lightList = geom.getWorldLightList(); if (lightFilter != null) { filteredLightList.clear(); - lightFilter.filterLights(g, filteredLightList); + lightFilter.filterLights(geom, filteredLightList); lightList = filteredLightList; } - + + Material material = geom.getMaterial(); //if forcedTechnique we try to force it for render, //if it does not exists in the mat def, we check for forcedMaterial and render the geom if not null //else the geom is not rendered if (forcedTechnique != null) { - MaterialDef matDef = g.getMaterial().getMaterialDef(); + MaterialDef matDef = material.getMaterialDef(); if (matDef.getTechniqueDefs(forcedTechnique) != null) { - tmpTech = g.getMaterial().getActiveTechnique() != null - ? g.getMaterial().getActiveTechnique().getDef().getName() + + Technique activeTechnique = material.getActiveTechnique(); + + String previousTechniqueName = activeTechnique != null + ? activeTechnique.getDef().getName() : TechniqueDef.DEFAULT_TECHNIQUE_NAME; - g.getMaterial().selectTechnique(forcedTechnique, this); + + geom.getMaterial().selectTechnique(forcedTechnique, this); //saving forcedRenderState for future calls RenderState tmpRs = forcedRenderState; - if (g.getMaterial().getActiveTechnique().getDef().getForcedRenderState() != null) { + if (geom.getMaterial().getActiveTechnique().getDef().getForcedRenderState() != null) { //forcing forced technique renderState - forcedRenderState = g.getMaterial().getActiveTechnique().getDef().getForcedRenderState(); + forcedRenderState = geom.getMaterial().getActiveTechnique().getDef().getForcedRenderState(); } // use geometry's material - g.getMaterial().render(g, lightList, this); - g.getMaterial().selectTechnique(tmpTech, this); + material.render(geom, lightList, this); + material.selectTechnique(previousTechniqueName, this); //restoring forcedRenderState forcedRenderState = tmpRs; @@ -603,13 +607,13 @@ public class RenderManager { //If forcedTechnique does not exists, and forcedMaterial is not set, the geom MUST NOT be rendered } else if (forcedMaterial != null) { // use forced material - forcedMaterial.render(g, lightList, this); + forcedMaterial.render(geom, lightList, this); } } else if (forcedMaterial != null) { // use forced material - forcedMaterial.render(g, lightList, this); + forcedMaterial.render(geom, lightList, this); } else { - g.getMaterial().render(g, lightList, this); + material.render(geom, lightList, this); } } diff --git a/jme3-core/src/main/java/com/jme3/scene/VertexBuffer.java b/jme3-core/src/main/java/com/jme3/scene/VertexBuffer.java index 5652b9295..70d40a64c 100644 --- a/jme3-core/src/main/java/com/jme3/scene/VertexBuffer.java +++ b/jme3-core/src/main/java/com/jme3/scene/VertexBuffer.java @@ -108,8 +108,7 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable { * Do not use. */ @Deprecated - MiscAttrib, - + Reserved0, /** * Specifies the index buffer, must contain integer data * (ubyte, ushort, or uint). diff --git a/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java b/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java index 8b0f831c5..a7a4cc39f 100644 --- a/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java +++ b/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java @@ -79,14 +79,14 @@ public class J3MLoader implements AssetLoader { private RenderState renderState; private ArrayList presetDefines = new ArrayList(); - private EnumMap shaderLanguage; - private EnumMap shaderName; + private EnumMap shaderLanguages; + private EnumMap shaderNames; private static final String whitespacePattern = "\\p{javaWhitespace}+"; public J3MLoader() { - shaderLanguage = new EnumMap(Shader.ShaderType.class); - shaderName = new EnumMap(Shader.ShaderType.class); + shaderLanguages = new EnumMap<>(Shader.ShaderType.class); + shaderNames = new EnumMap<>(Shader.ShaderType.class); } @@ -109,8 +109,8 @@ public class J3MLoader implements AssetLoader { } private void readShaderDefinition(Shader.ShaderType shaderType, String name, String language) { - shaderName.put(shaderType, name); - shaderLanguage.put(shaderType, language); + shaderNames.put(shaderType, name); + shaderLanguages.put(shaderType, language); } // LightMode @@ -120,10 +120,6 @@ public class J3MLoader implements AssetLoader { throw new IOException("LightMode statement syntax incorrect"); } LightMode lm = LightMode.valueOf(split[1]); - if (lm == LightMode.FixedPipeline) { - throw new UnsupportedOperationException("OpenGL1 is not supported"); - } - technique.setLightMode(lm); } @@ -453,8 +449,7 @@ public class J3MLoader implements AssetLoader { }else if (split[0].equals("Blend")){ renderState.setBlendMode(BlendMode.valueOf(split[1])); }else if (split[0].equals("AlphaTestFalloff")){ - renderState.setAlphaTest(true); - renderState.setAlphaFallOff(Float.parseFloat(split[1])); + // Ignore for backwards compatbility }else if (split[0].equals("PolyOffset")){ float factor = Float.parseFloat(split[1]); float units = Float.parseFloat(split[2]); @@ -462,7 +457,7 @@ public class J3MLoader implements AssetLoader { }else if (split[0].equals("ColorWrite")){ renderState.setColorWrite(parseBoolean(split[1])); }else if (split[0].equals("PointSprite")){ - renderState.setPointSprite(parseBoolean(split[1])); + // Ignore for backwards compatbility }else if (split[0].equals("DepthFunc")){ renderState.setDepthFunc(RenderState.TestFunction.valueOf(split[1])); }else if (split[0].equals("AlphaFunc")){ @@ -622,8 +617,8 @@ public class J3MLoader implements AssetLoader { technique.setShaderFile(technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100"); } - if (shaderName.containsKey(Shader.ShaderType.Vertex) && shaderName.containsKey(Shader.ShaderType.Fragment)) { - technique.setShaderFile(shaderName, shaderLanguage); + if (shaderNames.containsKey(Shader.ShaderType.Vertex) && shaderNames.containsKey(Shader.ShaderType.Fragment)) { + technique.setShaderFile(shaderNames, shaderLanguages); } technique.setShaderPrologue(createShaderPrologue(presetDefines)); @@ -644,8 +639,8 @@ public class J3MLoader implements AssetLoader { materialDef.addTechniqueDef(technique); technique = null; - shaderLanguage.clear(); - shaderName.clear(); + shaderLanguages.clear(); + shaderNames.clear(); presetDefines.clear(); } @@ -767,7 +762,7 @@ public class J3MLoader implements AssetLoader { protected void initNodesLoader() { if (!isUseNodes) { - isUseNodes = shaderName.get(Shader.ShaderType.Vertex) == null && shaderName.get(Shader.ShaderType.Fragment) == null; + isUseNodes = shaderNames.get(Shader.ShaderType.Vertex) == null && shaderNames.get(Shader.ShaderType.Fragment) == null; if (isUseNodes) { if (nodesLoaderDelegate == null) { nodesLoaderDelegate = new ShaderNodeLoaderDelegate();