Cycles: Remove some redundant checks
authorMai Lavelle <mai.lavelle@gmail.com>
Thu, 25 Aug 2016 14:45:48 +0000 (10:45 -0400)
committerMai Lavelle <mai.lavelle@gmail.com>
Thu, 25 Aug 2016 14:52:00 +0000 (10:52 -0400)
intern/cycles/render/mesh.cpp

index 5bd22bf1de8da53a46bc7a9fbe827355dafaf53c..35d1a441975640273010a9f3e6c9b66e35659150 100644 (file)
@@ -511,17 +511,17 @@ void Mesh::add_vertex_normals()
                /* compute vertex normals */
                memset(vN, 0, verts.size()*sizeof(float3));
 
-               if(triangles_size) {
-
-                       for(size_t i = 0; i < triangles_size; i++)
-                               for(size_t j = 0; j < 3; j++)
-                                       vN[get_triangle(i).v[j]] += fN[i];
+               for(size_t i = 0; i < triangles_size; i++) {
+                       for(size_t j = 0; j < 3; j++) {
+                               vN[get_triangle(i).v[j]] += fN[i];
+                       }
                }
 
                for(size_t i = 0; i < verts_size; i++) {
                        vN[i] = normalize(vN[i]);
-                       if(flip)
+                       if(flip) {
                                vN[i] = -vN[i];
+                       }
                }
        }
 
@@ -540,19 +540,18 @@ void Mesh::add_vertex_normals()
                        /* compute */
                        memset(mN, 0, verts.size()*sizeof(float3));
 
-                       if(triangles_size) {
-                               for(size_t i = 0; i < triangles_size; i++) {
-                                       for(size_t j = 0; j < 3; j++) {
-                                               float3 fN = compute_face_normal(get_triangle(i), mP);
-                                               mN[get_triangle(i).v[j]] += fN;
-                                       }
+                       for(size_t i = 0; i < triangles_size; i++) {
+                               for(size_t j = 0; j < 3; j++) {
+                                       float3 fN = compute_face_normal(get_triangle(i), mP);
+                                       mN[get_triangle(i).v[j]] += fN;
                                }
                        }
 
                        for(size_t i = 0; i < verts_size; i++) {
                                mN[i] = normalize(mN[i]);
-                               if(flip)
+                               if(flip) {
                                        mN[i] = -mN[i];
+                               }
                        }
                }
        }
@@ -647,16 +646,14 @@ void Mesh::pack_verts(const vector<uint>& tri_prim_index,
 
        size_t triangles_size = num_triangles();
 
-       if(triangles_size) {
-               for(size_t i = 0; i < triangles_size; i++) {
-                       Triangle t = get_triangle(i);
-                       tri_vindex[i] = make_uint4(t.v[0] + vert_offset,
-                                                  t.v[1] + vert_offset,
-                                                  t.v[2] + vert_offset,
-                                                  tri_prim_index[i + tri_offset]);
+       for(size_t i = 0; i < triangles_size; i++) {
+               Triangle t = get_triangle(i);
+               tri_vindex[i] = make_uint4(t.v[0] + vert_offset,
+                                          t.v[1] + vert_offset,
+                                          t.v[2] + vert_offset,
+                                          tri_prim_index[i + tri_offset]);
 
-                       tri_patch[i] = (!subd_faces.size()) ? -1 : (triangle_patch[i]*8 + patch_offset);
-               }
+               tri_patch[i] = (!subd_faces.size()) ? -1 : (triangle_patch[i]*8 + patch_offset);
        }
 }
 
@@ -676,20 +673,18 @@ void Mesh::pack_curves(Scene *scene, float4 *curve_key_co, float4 *curve_data, s
        /* pack curve segments */
        size_t curve_num = num_curves();
 
-       if(curve_num) {
-               for(size_t i = 0; i < curve_num; i++) {
-                       Curve curve = get_curve(i);
-                       int shader_id = curve_shader[i];
-                       Shader *shader = (shader_id < used_shaders.size()) ?
-                               used_shaders[shader_id] : scene->default_surface;
-                       shader_id = scene->shader_manager->get_shader_id(shader, this, false);
-
-                       curve_data[i] = make_float4(
-                               __int_as_float(curve.first_key + curvekey_offset),
-                               __int_as_float(curve.num_keys),
-                               __int_as_float(shader_id),
-                               0.0f);
-               }
+       for(size_t i = 0; i < curve_num; i++) {
+               Curve curve = get_curve(i);
+               int shader_id = curve_shader[i];
+               Shader *shader = (shader_id < used_shaders.size()) ?
+                       used_shaders[shader_id] : scene->default_surface;
+               shader_id = scene->shader_manager->get_shader_id(shader, this, false);
+
+               curve_data[i] = make_float4(
+                       __int_as_float(curve.first_key + curvekey_offset),
+                       __int_as_float(curve.num_keys),
+                       __int_as_float(shader_id),
+                       0.0f);
        }
 }
 
@@ -698,13 +693,30 @@ void Mesh::pack_patches(uint *patch_data, uint vert_offset, uint face_offset, ui
        size_t num_faces = subd_faces.size();
        int ngons = 0;
 
-       if(num_faces) {
-               for(size_t f = 0; f < num_faces; f++) {
-                       SubdFace face = subd_faces[f];
+       for(size_t f = 0; f < num_faces; f++) {
+               SubdFace face = subd_faces[f];
+
+               if(face.is_quad()) {
+                       int c[4];
+                       memcpy(c, &subd_face_corners[face.start_corner], sizeof(int)*4);
 
-                       if(face.is_quad()) {
+                       *(patch_data++) = c[0] + vert_offset;
+                       *(patch_data++) = c[1] + vert_offset;
+                       *(patch_data++) = c[2] + vert_offset;
+                       *(patch_data++) = c[3] + vert_offset;
+
+                       *(patch_data++) = f+face_offset;
+                       *(patch_data++) = face.num_corners;
+                       *(patch_data++) = face.start_corner + corner_offset;
+                       *(patch_data++) = 0;
+               }
+               else {
+                       for(int i = 0; i < face.num_corners; i++) {
                                int c[4];
-                               memcpy(c, &subd_face_corners[face.start_corner], sizeof(int)*4);
+                               c[0] = subd_face_corners[face.start_corner + mod(i + 0, face.num_corners)];
+                               c[1] = subd_face_corners[face.start_corner + mod(i + 1, face.num_corners)];
+                               c[2] = verts.size() - num_subd_verts + ngons;
+                               c[3] = subd_face_corners[face.start_corner + mod(i - 1, face.num_corners)];
 
                                *(patch_data++) = c[0] + vert_offset;
                                *(patch_data++) = c[1] + vert_offset;
@@ -712,31 +724,12 @@ void Mesh::pack_patches(uint *patch_data, uint vert_offset, uint face_offset, ui
                                *(patch_data++) = c[3] + vert_offset;
 
                                *(patch_data++) = f+face_offset;
-                               *(patch_data++) = face.num_corners;
+                               *(patch_data++) = face.num_corners | (i << 16);
                                *(patch_data++) = face.start_corner + corner_offset;
-                               *(patch_data++) = 0;
+                               *(patch_data++) = subd_face_corners.size() + ngons + corner_offset;
                        }
-                       else {
-                               for(int i = 0; i < face.num_corners; i++) {
-                                       int c[4];
-                                       c[0] = subd_face_corners[face.start_corner + mod(i + 0, face.num_corners)];
-                                       c[1] = subd_face_corners[face.start_corner + mod(i + 1, face.num_corners)];
-                                       c[2] = verts.size() - num_subd_verts + ngons;
-                                       c[3] = subd_face_corners[face.start_corner + mod(i - 1, face.num_corners)];
-
-                                       *(patch_data++) = c[0] + vert_offset;
-                                       *(patch_data++) = c[1] + vert_offset;
-                                       *(patch_data++) = c[2] + vert_offset;
-                                       *(patch_data++) = c[3] + vert_offset;
-
-                                       *(patch_data++) = f+face_offset;
-                                       *(patch_data++) = face.num_corners | (i << 16);
-                                       *(patch_data++) = face.start_corner + corner_offset;
-                                       *(patch_data++) = subd_face_corners.size() + ngons + corner_offset;
-                               }
 
-                               ngons++;
-                       }
+                       ngons++;
                }
        }
 }