Commit: 328e65afb1bcc15109172cf72ca31ca9df23e06a
Author: Mai Lavelle
Date:   Thu Jun 16 08:08:08 2016 -0400
Branches: temp-cycles-microdisplacement
https://developer.blender.org/rB328e65afb1bcc15109172cf72ca31ca9df23e06a

Simplify how primitive counts are passed to Attribute

Refactor Attribute so that primitives counts don't need to be passed around
everywhere and can be calculated from one place.

===================================================================

M       intern/cycles/render/attribute.cpp
M       intern/cycles/render/attribute.h
M       intern/cycles/render/mesh.cpp

===================================================================

diff --git a/intern/cycles/render/attribute.cpp 
b/intern/cycles/render/attribute.cpp
index 99298d6..c8e60cb 100644
--- a/intern/cycles/render/attribute.cpp
+++ b/intern/cycles/render/attribute.cpp
@@ -51,14 +51,13 @@ void Attribute::set(ustring name_, TypeDesc type_, 
AttributeElement element_)
                type == TypeDesc::TypeNormal || type == TypeDesc::TypeMatrix);
 }
 
-void Attribute::resize(int numverts, int numtris, int numsteps, int numcurves, 
int numkeys,
-                       int numpatches, AttributePrimitive prim, bool 
reserve_only)
+void Attribute::resize(Mesh *mesh, AttributePrimitive prim, bool reserve_only)
 {
        if(reserve_only) {
-               buffer.reserve(buffer_size(numverts, numtris, numsteps, 
numcurves, numkeys, numpatches, prim));
+               buffer.reserve(buffer_size(mesh, prim));
        }
        else {
-               buffer.resize(buffer_size(numverts, numtris, numsteps, 
numcurves, numkeys, numpatches, prim), 0);
+               buffer.resize(buffer_size(mesh, prim), 0);
        }
 }
 
@@ -127,11 +126,10 @@ size_t Attribute::data_sizeof() const
                return sizeof(float3);
 }
 
-size_t Attribute::element_size(int numverts, int numtris, int numsteps, int 
numcurves, int numkeys,
-                               int numpatches, AttributePrimitive prim) const
+size_t Attribute::element_size(Mesh *mesh, AttributePrimitive prim) const
 {
        size_t size;
-       
+
        switch(element) {
                case ATTR_ELEMENT_OBJECT:
                case ATTR_ELEMENT_MESH:
@@ -139,32 +137,32 @@ size_t Attribute::element_size(int numverts, int numtris, 
int numsteps, int numc
                        size = 1;
                        break;
                case ATTR_ELEMENT_VERTEX:
-                       size = numverts;
+                       size = mesh->verts.size();
                        break;
                case ATTR_ELEMENT_VERTEX_MOTION:
-                       size = numverts * (numsteps - 1);
+                       size = mesh->verts.size() * (mesh->motion_steps - 1);
                        break;
                case ATTR_ELEMENT_FACE:
                        if(prim == ATTR_PRIM_TRIANGLE)
-                               size = numtris;
+                               size = mesh->num_triangles();
                        else
-                               size = numpatches;
+                               size = mesh->patches.size();
                        break;
                case ATTR_ELEMENT_CORNER:
                case ATTR_ELEMENT_CORNER_BYTE:
                        if(prim == ATTR_PRIM_TRIANGLE)
-                               size = numtris*3;
+                               size = mesh->num_triangles()*3;
                        else
-                               size = numpatches*4;
+                               size = mesh->patches.size()*4;
                        break;
                case ATTR_ELEMENT_CURVE:
-                       size = numcurves;
+                       size = mesh->num_curves();
                        break;
                case ATTR_ELEMENT_CURVE_KEY:
-                       size = numkeys;
+                       size = mesh->curve_keys.size();
                        break;
                case ATTR_ELEMENT_CURVE_KEY_MOTION:
-                       size = numkeys * (numsteps - 1);
+                       size = mesh->curve_keys.size() * (mesh->motion_steps - 
1);
                        break;
                default:
                        size = 0;
@@ -174,10 +172,9 @@ size_t Attribute::element_size(int numverts, int numtris, 
int numsteps, int numc
        return size;
 }
 
-size_t Attribute::buffer_size(int numverts, int numtris, int numsteps, int 
numcurves, int numkeys,
-                              int numpatches, AttributePrimitive prim) const
+size_t Attribute::buffer_size(Mesh *mesh, AttributePrimitive prim) const
 {
-       return element_size(numverts, numtris, numsteps, numcurves, numkeys, 
numpatches, prim)*data_sizeof();
+       return element_size(mesh, prim)*data_sizeof();
 }
 
 bool Attribute::same_storage(TypeDesc a, TypeDesc b)
@@ -301,14 +298,12 @@ Attribute *AttributeSet::add(ustring name, TypeDesc type, 
AttributeElement eleme
 
        /* this is weak .. */
        if(triangle_mesh)
-               attr->resize(triangle_mesh->verts.size(), 
triangle_mesh->num_triangles(), triangle_mesh->motion_steps, 0, 0,
-                            0, ATTR_PRIM_TRIANGLE, false);
+               attr->resize(triangle_mesh, ATTR_PRIM_TRIANGLE, false);
        if(curve_mesh)
-               attr->resize(0, 0, curve_mesh->motion_steps, 
curve_mesh->num_curves(), curve_mesh->curve_keys.size(),
-                            0, ATTR_PRIM_CURVE, false);
+               attr->resize(curve_mesh, ATTR_PRIM_CURVE, false);
        if(subd_mesh)
-               attr->resize(subd_mesh->verts.size(), 0, 0, 0, 0, 
subd_mesh->patches.size(), ATTR_PRIM_SUBD, false);
-       
+               attr->resize(subd_mesh, ATTR_PRIM_SUBD, false);
+
        return attr;
 }
 
@@ -466,12 +461,11 @@ void AttributeSet::resize(bool reserve_only)
 {
        foreach(Attribute& attr, attributes) {
                if(triangle_mesh)
-                       attr.resize(triangle_mesh->verts.size(), 
triangle_mesh->num_triangles(), triangle_mesh->motion_steps, 0, 0,
-                                   0, ATTR_PRIM_TRIANGLE, reserve_only);
+                       attr.resize(triangle_mesh, ATTR_PRIM_TRIANGLE, 
reserve_only);
                if(curve_mesh)
-                       attr.resize(0, 0, 0, curve_mesh->num_curves(), 
curve_mesh->curve_keys.size(), 0, ATTR_PRIM_CURVE, reserve_only);
+                       attr.resize(curve_mesh, ATTR_PRIM_CURVE, reserve_only);
                if(subd_mesh)
-                       attr.resize(subd_mesh->verts.size(), 0, 0, 0, 0, 
subd_mesh->patches.size(), ATTR_PRIM_SUBD, reserve_only);
+                       attr.resize(subd_mesh, ATTR_PRIM_SUBD, reserve_only);
        }
 }
 
diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h
index cb0426b..6f31470 100644
--- a/intern/cycles/render/attribute.h
+++ b/intern/cycles/render/attribute.h
@@ -58,14 +58,11 @@ public:
        Attribute() {}
        ~Attribute();
        void set(ustring name, TypeDesc type, AttributeElement element);
-       void resize(int numverts, int numfaces, int numsteps, int numcurves, 
int numkeys,
-                   int numpatches, AttributePrimitive prim, bool reserve_only);
+       void resize(Mesh *mesh, AttributePrimitive prim, bool reserve_only);
 
        size_t data_sizeof() const;
-       size_t element_size(int numverts, int numfaces, int numsteps, int 
numcurves, int numkeys,
-                           int numpatches, AttributePrimitive prim) const;
-       size_t buffer_size(int numverts, int numfaces, int numsteps, int 
numcurves, int numkeys,
-                          int numpatches, AttributePrimitive prim) const;
+       size_t element_size(Mesh *mesh, AttributePrimitive prim) const;
+       size_t buffer_size(Mesh *mesh, AttributePrimitive prim) const;
 
        char *data() { return (buffer.size())? &buffer[0]: NULL; };
        float3 *data_float3() { return (float3*)data(); }
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 6ccff95..520eac0 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -932,14 +932,7 @@ static void update_attribute_element_size(Mesh *mesh,
                                           size_t *attr_uchar4_size)
 {
        if(mattr) {
-               size_t size = mattr->element_size(
-                       mesh->verts.size(),
-                       mesh->num_triangles(),
-                       mesh->motion_steps,
-                       mesh->num_curves(),
-                       mesh->curve_keys.size(),
-                       mesh->patches.size(),
-                       prim);
+               size_t size = mattr->element_size(mesh, prim);
 
                if(mattr->element == ATTR_ELEMENT_VOXEL) {
                        /* pass */
@@ -978,14 +971,7 @@ static void update_attribute_element_offset(Mesh *mesh,
                type = mattr->type;
 
                /* store attribute data in arrays */
-               size_t size = mattr->element_size(
-                       mesh->verts.size(),
-                       mesh->num_triangles(),
-                       mesh->motion_steps,
-                       mesh->num_curves(),
-                       mesh->curve_keys.size(),
-                       mesh->patches.size(),
-                       prim);
+               size_t size = mattr->element_size(mesh, prim);
 
                if(mattr->element == ATTR_ELEMENT_VOXEL) {
                        /* store slot in offset value */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to