ecere/gfx/3D/Object: computeLightVector flag to avoid always recomputing uselessly
authorJerome St-Louis <jerome@ecere.com>
Wed, 3 Aug 2016 00:20:30 +0000 (20:20 -0400)
committerJerome St-Louis <jerome@ecere.com>
Wed, 3 Aug 2016 00:27:05 +0000 (20:27 -0400)
ecere/src/gfx/3D/Object.ec
ecere/src/gfx/3D/models/Object3DSFormat.ec
ecere/src/gfx/Display.ec

index 80c7446..186881f 100644 (file)
@@ -21,6 +21,7 @@ public class ObjectFlags
 {
 public:
    bool root:1, viewSpace:1, ownMesh:1, translucent:1, flipWindings:1, keysLoaded:1, transform:1, mesh:1, light:1, camera:1, localMatrixSet:1;
+   bool computeLightVectors:1;
    int hierarchy:16:16;
 };
 
@@ -797,6 +798,7 @@ public:
             {
                nVertices += child.mesh.nVertices;
                flags |= child.mesh.flags;
+               this.flags.computeLightVectors |= child.flags.computeLightVectors;
             }
          }
 
index e7a2ff4..c85b210 100644 (file)
@@ -380,6 +380,7 @@ static void ComputeNormals(Mesh mesh, FileInfo * info, Object object)
    int nNewVertices;
    Vector3Df * mVertices;
    double cutOff = cos(Degrees { SMOOTH_CUTOFF });
+   bool hasBumpMap = false;
 
    Map<SharedSourceVertexInfo, SharedDestVertexInfo> sharedVertices { };
    Map<SourceVertexInfo, DestVertexInfo> vertexMap { };
@@ -407,6 +408,8 @@ static void ComputeNormals(Mesh mesh, FileInfo * info, Object object)
    {
       Face * face = &faces[c];
       int i;
+      if(face->material && face->material.bumpMap)
+         hasBumpMap = true;
 
       // Zero space points
       if(!mVertices[face->indices[0]].OnCompare(mVertices[face->indices[1]]) &&
@@ -698,6 +701,7 @@ static void ComputeNormals(Mesh mesh, FileInfo * info, Object object)
    }
 
    mesh.Unlock({ normals = true, tangents = true });
+   object.flags.computeLightVectors = hasBumpMap;
 
    // Free all the temporary stuff
 
index f6a4a5f..217a181 100644 (file)
@@ -947,7 +947,7 @@ public:
                   displaySystem.driver.PushMatrix(this);
 
 #if ENABLE_GL_FFP
-               if(object.mesh.tangents && object.mesh.normals)
+               if(object.mesh.tangents && object.mesh.normals && object.flags.computeLightVectors)
                {
                   Mesh mesh = object.mesh;
                   if(!glCaps_shaders)