diff options
author | phil <[email protected]> | 2016-12-11 17:06:24 +1300 |
---|---|---|
committer | phil <[email protected]> | 2016-12-11 17:06:24 +1300 |
commit | 57180b6da144f70a85e376faedf581ee2352a304 (patch) | |
tree | 8497662d39102df75f6baf218a7acbb1a274b1e7 | |
parent | 3b5bbbc4d0aca4bd59492d64e813e18d6b766b8c (diff) |
SimpleShaderappearance more program and attributeset pointer re-use
As this make a large difference to the render pipeline call stack
performance
-rw-r--r-- | src/main/java/org/jogamp/java3d/utils/shader/Cube.java | 1 | ||||
-rw-r--r-- | src/main/java/org/jogamp/java3d/utils/shader/SimpleShaderAppearance.java | 30 |
2 files changed, 24 insertions, 7 deletions
diff --git a/src/main/java/org/jogamp/java3d/utils/shader/Cube.java b/src/main/java/org/jogamp/java3d/utils/shader/Cube.java index 8ef1098..e2a5981 100644 --- a/src/main/java/org/jogamp/java3d/utils/shader/Cube.java +++ b/src/main/java/org/jogamp/java3d/utils/shader/Cube.java @@ -37,7 +37,6 @@ import org.jogamp.java3d.GeometryArray; import org.jogamp.java3d.J3DBuffer; import org.jogamp.java3d.Shape3D; import org.jogamp.java3d.TriangleArray; -import org.jogamp.java3d.utils.shader.SimpleShaderAppearance; /** * Note Cube does not have normals and so cannot be used for lit geometries diff --git a/src/main/java/org/jogamp/java3d/utils/shader/SimpleShaderAppearance.java b/src/main/java/org/jogamp/java3d/utils/shader/SimpleShaderAppearance.java index e5da160..2b7f2ce 100644 --- a/src/main/java/org/jogamp/java3d/utils/shader/SimpleShaderAppearance.java +++ b/src/main/java/org/jogamp/java3d/utils/shader/SimpleShaderAppearance.java @@ -174,6 +174,9 @@ public class SimpleShaderAppearance extends ShaderAppearance private static HashMap<GLSLShaderProgram, String> vertexShaderSources = new HashMap<GLSLShaderProgram, String>(); private static HashMap<GLSLShaderProgram, String> fragmentShaderSources = new HashMap<GLSLShaderProgram, String>(); + private static ShaderAttributeSet baseMapShaderAttributeSet = null; + private static HashMap<String, ShaderAttributeSet> shaderAttributeSetCache = new HashMap<String, ShaderAttributeSet>(); + private boolean buildBasedOnAttributes = false; // we can't set it in the super class as tex coord gen is not supported in the pipeline @@ -384,8 +387,7 @@ public class SimpleShaderAppearance extends ShaderAppearance || this.getPolygonAttributes().getCapability(PolygonAttributes.ALLOW_MODE_READ))//poly attributes are live but can be read // finally we must be allowed to set the shader program while live - && ((!this.isLive() && !this.isCompiled()) || (this.getCapability(ALLOW_SHADER_PROGRAM_WRITE))) - ) + && ((!this.isLive() && !this.isCompiled()) || (this.getCapability(ALLOW_SHADER_PROGRAM_WRITE)))) { boolean hasTexture = this.getTexture() != null || this.getTextureUnitCount() > 0; if (this.getTextureUnitCount() > 0) @@ -690,22 +692,38 @@ public class SimpleShaderAppearance extends ShaderAppearance vertexShaderSource = vertexShaderSources.get(shaderProgram); fragmentShaderSource = fragmentShaderSources.get(shaderProgram); + //It is REALLY important for render performance to try to have the same shader program object + // and the exact same shader attribute set object if (hasTexture) { - ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet(); - shaderAttributeSet.put(new ShaderAttributeValue("BaseMap", new Integer(0))); if (texCoordGenModeObjLinear) { Vector4f planeS = new Vector4f(); texCoordGeneration.getPlaneS(planeS); Vector4f planeT = new Vector4f(); texCoordGeneration.getPlaneT(planeT); - + String key = "planeS " + planeS + " planeT " + planeT; + ShaderAttributeSet shaderAttributeSet = shaderAttributeSetCache.get(key); + if (shaderAttributeSet == null) + { + shaderAttributeSet = new ShaderAttributeSet(); + shaderAttributeSet.put(new ShaderAttributeValue("BaseMap", new Integer(0))); shaderAttributeSet.put(new ShaderAttributeValue("texCoordGenPlaneS", planeS)); shaderAttributeSet.put(new ShaderAttributeValue("texCoordGenPlaneT", planeT)); + shaderAttributeSetCache.put(key, shaderAttributeSet); + } + setShaderAttributeSet(shaderAttributeSet); + } + else + { + if (baseMapShaderAttributeSet == null) + { + baseMapShaderAttributeSet = new ShaderAttributeSet(); + baseMapShaderAttributeSet.put(new ShaderAttributeValue("BaseMap", new Integer(0))); + } + setShaderAttributeSet(baseMapShaderAttributeSet); } - setShaderAttributeSet(shaderAttributeSet); } } |