Code cleanup to use array.data() rather than &array[0]
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 17 Aug 2016 21:49:55 +0000 (23:49 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 18 Aug 2016 00:24:13 +0000 (02:24 +0200)
(Now without the build errors)

intern/cycles/render/mesh.cpp
intern/cycles/render/mesh_subdivision.cpp
intern/cycles/subd/subd_dice.cpp
intern/cycles/subd/subd_patch_table.cpp
intern/cycles/subd/subd_patch_table.h

index fcf4e69984df0476b5ee93377442789c196c9495..257e83171e955f252f4ce7391637836a91a04919 100644 (file)
@@ -298,17 +298,17 @@ int Mesh::split_vertex(int vertex)
 
        foreach(Attribute& attr, attributes.attributes) {
                if(attr.element == ATTR_ELEMENT_VERTEX) {
-                       vector<char> tmp(attr.data_sizeof());
-                       memcpy(&tmp[0], attr.data() + tmp.size()*vertex, tmp.size());
-                       attr.add(&tmp[0]);
+                       array<char> tmp(attr.data_sizeof());
+                       memcpy(tmp.data(), attr.data() + tmp.size()*vertex, tmp.size());
+                       attr.add(tmp.data());
                }
        }
 
        foreach(Attribute& attr, subd_attributes.attributes) {
                if(attr.element == ATTR_ELEMENT_VERTEX) {
-                       vector<char> tmp(attr.data_sizeof());
-                       memcpy(&tmp[0], attr.data() + tmp.size()*vertex, tmp.size());
-                       attr.add(&tmp[0]);
+                       array<char> tmp(attr.data_sizeof());
+                       memcpy(tmp.data(), attr.data() + tmp.size()*vertex, tmp.size());
+                       attr.add(tmp.data());
                }
        }
 
@@ -474,7 +474,7 @@ void Mesh::add_face_normals()
        bool flip = transform_negative_scaled;
 
        if(triangles_size) {
-               float3 *verts_ptr = &verts[0];
+               float3 *verts_ptr = verts.data();
 
                for(size_t i = 0; i < triangles_size; i++) {
                        fN[i] = compute_face_normal(get_triangle(i), verts_ptr);
@@ -568,7 +568,7 @@ void Mesh::pack_normals(Scene *scene, uint *tri_shader, float4 *vnormal)
        bool last_smooth = false;
 
        size_t triangles_size = num_triangles();
-       int *shader_ptr = (shader.size())? &shader[0]: NULL;
+       int *shader_ptr = shader.data();
 
        bool do_transform = transform_applied;
        Transform ntfm = transform_normal;
@@ -608,7 +608,7 @@ void Mesh::pack_verts(const vector<uint>& tri_prim_index,
        size_t verts_size = verts.size();
 
        if(verts_size && subd_faces.size()) {
-               float2 *vert_patch_uv_ptr = &vert_patch_uv[0];
+               float2 *vert_patch_uv_ptr = vert_patch_uv.data();
 
                for(size_t i = 0; i < verts_size; i++) {
                        tri_patch_uv[i] = vert_patch_uv_ptr[i];
@@ -636,8 +636,8 @@ void Mesh::pack_curves(Scene *scene, float4 *curve_key_co, float4 *curve_data, s
 
        /* pack curve keys */
        if(curve_keys_size) {
-               float3 *keys_ptr = &curve_keys[0];
-               float *radius_ptr = &curve_radius[0];
+               float3 *keys_ptr = curve_keys.data();
+               float *radius_ptr = curve_radius.data();
 
                for(size_t i = 0; i < curve_keys_size; i++)
                        curve_key_co[i] = make_float4(keys_ptr[i].x, keys_ptr[i].y, keys_ptr[i].z, radius_ptr[i]);
index efb40efbb79c12eaaefefb56dec8aabef9b9ddcc..f87425f00421af8efed14ca854ec74ecf5a59496 100644 (file)
@@ -45,7 +45,7 @@ namespace Far {
                setNumBaseVertices(refiner, mesh.verts.size());
                setNumBaseFaces(refiner, mesh.subd_faces.size());
 
-               ccl::Mesh::SubdFace* face = &mesh.subd_faces[0];
+               const ccl::Mesh::SubdFace* face = mesh.subd_faces.data();
 
                for(int i = 0; i < mesh.subd_faces.size(); i++, face++) {
                        setNumBaseFaceVertices(refiner, i, face->num_corners);
@@ -57,7 +57,7 @@ namespace Far {
        template<>
        bool TopologyRefinerFactory<ccl::Mesh>::assignComponentTopology(TopologyRefiner& refiner, ccl::Mesh const& mesh)
        {
-               ccl::Mesh::SubdFace* face = &mesh.subd_faces[0];
+               const ccl::Mesh::SubdFace* face = mesh.subd_faces.data();
 
                for(int i = 0; i < mesh.subd_faces.size(); i++, face++) {
                        IndexArray face_verts = getBaseFaceVertices(refiner, i);
@@ -195,7 +195,7 @@ public:
                        verts[i].value = mesh->verts[i];
                }
 
-               OsdValue<float3>* src = &verts[0];
+               OsdValue<float3>* src = verts.data();
                for(int i = 0; i < refiner->GetMaxLevel(); i++) {
                        OsdValue<float3>* dest = src + refiner->GetLevel(i).GetNumVertices();
                        Far::PrimvarRefiner(*refiner).Interpolate(i+1, src, dest);
@@ -219,7 +219,7 @@ public:
                        attr.resize(num_refiner_verts + num_local_points);
                        attr.flags |= ATTR_FINAL_SIZE;
 
-                       char* src = &attr.buffer[0];
+                       char* src = attr.buffer.data();
 
                        for(int i = 0; i < refiner->GetMaxLevel(); i++) {
                                char* dest = src + refiner->GetLevel(i).GetNumVertices() * attr.data_sizeof();
index 36981a20f3c868c12ef1f231c2a26ee649458f6a..a1bd349b16736e336cdc96dbeeff08fdfebfe347 100644 (file)
@@ -57,7 +57,7 @@ void EdgeDice::reserve(int num_verts)
 
        Attribute *attr_vN = mesh->attributes.add(ATTR_STD_VERTEX_NORMAL);
 
-       mesh_P = &mesh->verts[0];
+       mesh_P = mesh->verts.data();
        mesh_N = attr_vN->data_float3();
 }
 
index 68ec1b2c6a6f0d1a62c6333d578a80c04404f3d6..62572efa88ade12f06dcb02d9da7c1608dfdf4b0 100644 (file)
@@ -214,7 +214,7 @@ void PackedPatchTable::pack(Far::PatchTable* patch_table, int offset)
        }
 
        table.resize(total_size());
-       uint* data = &table[0];
+       uint* data = table.data();
 
        uint* array = data;
        uint* index = array + num_arrays * PATCH_ARRAY_SIZE;
@@ -259,7 +259,7 @@ void PackedPatchTable::pack(Far::PatchTable* patch_table, int offset)
 
 void PackedPatchTable::copy_adjusting_offsets(uint* dest, int doffset)
 {
-       uint* src = &table[0];
+       uint* src = table.data();
 
        /* arrays */
        for(int i = 0; i < num_arrays; i++) {
index c8c7ecf9e4796acaa3c620dcef83f2a6e091c0e9..3166a1691d829c6934266f25be0af0e557283554 100644 (file)
@@ -43,7 +43,7 @@ namespace Far { struct PatchTable; }
 #define PATCH_NODE_SIZE 1
 
 struct PackedPatchTable {
-       vector<uint> table;
+       array<uint> table;
 
        size_t num_arrays;
        size_t num_indices;