Commits

Michael Ludwig  committed 4678e7c

Improve optimal performance for texture coordinate assignment by adding texture tracking to AppliedEffects.

  • Participants
  • Parent commits 1701146

Comments (0)

Files changed (3)

File ferox-scene/src/main/java/com/ferox/scene/task/ffp/AppliedEffects.java

     private final BlendFactor destBlend;
     private final BlendFactor sourceBlend;
 
+    private final boolean diffuseTexture;
+    private final boolean decalTexture;
+    private final boolean emissiveTexture;
+
     private final Matrix4 viewMatrix;
 
     public AppliedEffects() {
         shadowLight = null;
         destBlend = BlendFactor.ZERO;
         sourceBlend = BlendFactor.ONE;
+        diffuseTexture = false;
+        decalTexture = false;
+        emissiveTexture = false;
         viewMatrix = new Matrix4();
     }
 
     private AppliedEffects(@Const Matrix4 view, BlendFactor sourceBlend, BlendFactor destBlend,
-                           Light shadowLight) {
+                           Light shadowLight, boolean diffuseTexture, boolean decalTexture,
+                           boolean emissiveTexture) {
         this.sourceBlend = sourceBlend;
         this.destBlend = destBlend;
         this.shadowLight = shadowLight;
+        this.diffuseTexture = diffuseTexture;
+        this.decalTexture = decalTexture;
+        this.emissiveTexture = emissiveTexture;
         viewMatrix = view;
     }
 
     }
 
     public AppliedEffects applyBlending(BlendFactor source, BlendFactor dest) {
-        return new AppliedEffects(viewMatrix, source, dest, shadowLight);
+        return new AppliedEffects(viewMatrix, source, dest, shadowLight, diffuseTexture, decalTexture,
+                                  emissiveTexture);
     }
 
     public AppliedEffects applyShadowMapping(Light light) {
-        return new AppliedEffects(viewMatrix, sourceBlend, destBlend, light);
+        return new AppliedEffects(viewMatrix, sourceBlend, destBlend, light, diffuseTexture, decalTexture,
+                                  emissiveTexture);
     }
 
     public AppliedEffects applyViewMatrix(@Const Matrix4 view) {
-        return new AppliedEffects(view.clone(), sourceBlend, destBlend, shadowLight);
+        return new AppliedEffects(view.clone(), sourceBlend, destBlend, shadowLight, diffuseTexture,
+                                  decalTexture, emissiveTexture);
+    }
+
+    public AppliedEffects applyTexturing(boolean useDiffuse, boolean useDecal, boolean useEmissive) {
+        return new AppliedEffects(viewMatrix, sourceBlend, destBlend, shadowLight, useDiffuse, useDecal,
+                                  useEmissive);
+    }
+
+    public boolean isDiffuseTextureEnabled() {
+        return diffuseTexture;
+    }
+
+    public boolean isDecalTextureEnabled() {
+        return decalTexture;
+    }
+
+    public boolean isEmissiveTextureEnabled() {
+        return emissiveTexture;
     }
 
     @Const

File ferox-scene/src/main/java/com/ferox/scene/task/ffp/GeometryState.java

         r.setNormals(normals);
         r.setIndices(indices);
 
-        if (texCoords == null) {
-            r.setTextureObjectPlanes(FixedFunctionRenderTask.DIFFUSE_TEXTURE_UNIT, OBJ_PLANES);
-            r.setTextureCoordinateSource(FixedFunctionRenderTask.DIFFUSE_TEXTURE_UNIT,
-                                         FixedFunctionRenderer.TexCoordSource.OBJECT);
-
-            r.setTextureObjectPlanes(FixedFunctionRenderTask.DECAL_TEXTURE_UNIT, OBJ_PLANES);
-            r.setTextureCoordinateSource(FixedFunctionRenderTask.DECAL_TEXTURE_UNIT,
-                                         FixedFunctionRenderer.TexCoordSource.OBJECT);
-
-            r.setTextureObjectPlanes(FixedFunctionRenderTask.EMISSIVE_TEXTURE_UNIT, OBJ_PLANES);
-            r.setTextureCoordinateSource(FixedFunctionRenderTask.EMISSIVE_TEXTURE_UNIT,
-                                         FixedFunctionRenderer.TexCoordSource.OBJECT);
-        } else {
-            r.setTextureCoordinateSource(FixedFunctionRenderTask.DIFFUSE_TEXTURE_UNIT,
-                                         FixedFunctionRenderer.TexCoordSource.ATTRIBUTE);
-            r.setTextureCoordinates(FixedFunctionRenderTask.DIFFUSE_TEXTURE_UNIT, texCoords);
-
-            r.setTextureCoordinateSource(FixedFunctionRenderTask.DECAL_TEXTURE_UNIT,
-                                         FixedFunctionRenderer.TexCoordSource.ATTRIBUTE);
-            r.setTextureCoordinates(FixedFunctionRenderTask.DECAL_TEXTURE_UNIT, texCoords);
-
-            r.setTextureCoordinateSource(FixedFunctionRenderTask.EMISSIVE_TEXTURE_UNIT,
-                                         FixedFunctionRenderer.TexCoordSource.ATTRIBUTE);
-            r.setTextureCoordinates(FixedFunctionRenderTask.EMISSIVE_TEXTURE_UNIT, texCoords);
+        if (effects.isDiffuseTextureEnabled()) {
+            setTextureCoordinates(r, FixedFunctionRenderTask.DIFFUSE_TEXTURE_UNIT);
+        }
+        if (effects.isDecalTextureEnabled()) {
+            setTextureCoordinates(r, FixedFunctionRenderTask.DECAL_TEXTURE_UNIT);
+        }
+        if (effects.isEmissiveTextureEnabled()) {
+            setTextureCoordinates(r, FixedFunctionRenderTask.EMISSIVE_TEXTURE_UNIT);
         }
 
         currentNode.visitChildren(effects, access);
     }
 
+    private void setTextureCoordinates(FixedFunctionRenderer r, int unit) {
+        if (texCoords == null) {
+            r.setTextureObjectPlanes(unit, OBJ_PLANES);
+            r.setTextureCoordinateSource(unit, FixedFunctionRenderer.TexCoordSource.OBJECT);
+        } else {
+            r.setTextureCoordinateSource(unit, FixedFunctionRenderer.TexCoordSource.ATTRIBUTE);
+            r.setTextureCoordinates(unit, texCoords);
+        }
+    }
+
     @Override
     public int hashCode() {
         int hash = 17;

File ferox-scene/src/main/java/com/ferox/scene/task/ffp/TextureState.java

     public void visitNode(StateNode currentNode, AppliedEffects effects, HardwareAccessLayer access) {
         FixedFunctionRenderer r = access.getCurrentContext().getFixedFunctionRenderer();
 
-        // FIXME if texCoords are null, turn on OBJ coord generation
         if (diffuseTexture != null) {
             r.setTexture(FixedFunctionRenderTask.DIFFUSE_TEXTURE_UNIT, diffuseTexture);
             // multiplicative blending with vertex color
             r.setTextureCombineRGB(FixedFunctionRenderTask.EMISSIVE_TEXTURE_UNIT, CombineFunction.ADD,
                                    CombineSource.CURR_TEX, CombineOperand.COLOR, CombineSource.PREV_TEX,
                                    CombineOperand.COLOR, CombineSource.CONST_COLOR, CombineOperand.COLOR);
-            // REPLACE with alpha(PREV_TEX) as arg0 preserves the original
-            // alpha
+            // REPLACE with alpha(PREV_TEX) as arg0 preserves the original alpha
             r.setTextureCombineAlpha(FixedFunctionRenderTask.EMISSIVE_TEXTURE_UNIT, CombineFunction.REPLACE,
                                      CombineSource.PREV_TEX, CombineOperand.ALPHA, CombineSource.CURR_TEX,
                                      CombineOperand.ALPHA, CombineSource.CONST_COLOR, CombineOperand.ALPHA);
             r.setTexture(FixedFunctionRenderTask.EMISSIVE_TEXTURE_UNIT, null);
         }
 
-        currentNode.visitChildren(effects, access);
+        currentNode.visitChildren(
+                effects.applyTexturing(diffuseTexture != null, decalTexture != null, emittedTexture != null),
+                access);
     }
 
     @Override