diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-05-08 01:09:08 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2016-06-08 22:45:40 +0300 |
commit | 2419d4c4ebf63c04c9c33efc8acc379d06661d9a (patch) | |
tree | 53901e787d0eff2d51b0a7b2a7b8e3dd7dec6bb7 /intern/cycles/render | |
parent | 13a7893495d7dacd5b12c9ac6a6fb5035ba1016d (diff) |
Code refactor: modify mesh storage to use arrays rather than vectors, separate some arrays.
Differential Revision: https://developer.blender.org/D2016
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/attribute.cpp | 20 | ||||
-rw-r--r-- | intern/cycles/render/attribute.h | 6 | ||||
-rw-r--r-- | intern/cycles/render/curves.h | 34 | ||||
-rw-r--r-- | intern/cycles/render/light.cpp | 8 | ||||
-rw-r--r-- | intern/cycles/render/mesh.cpp | 190 | ||||
-rw-r--r-- | intern/cycles/render/mesh.h | 51 | ||||
-rw-r--r-- | intern/cycles/render/mesh_displace.cpp | 9 | ||||
-rw-r--r-- | intern/cycles/render/object.cpp | 18 | ||||
-rw-r--r-- | intern/cycles/render/particles.cpp | 11 | ||||
-rw-r--r-- | intern/cycles/render/particles.h | 2 | ||||
-rw-r--r-- | intern/cycles/render/session.cpp | 2 |
11 files changed, 200 insertions, 151 deletions
diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp index b7de83d89c1..71a3cba6811 100644 --- a/intern/cycles/render/attribute.cpp +++ b/intern/cycles/render/attribute.cpp @@ -51,13 +51,13 @@ void Attribute::set(ustring name_, TypeDesc type_, AttributeElement element_) type == TypeDesc::TypeNormal || type == TypeDesc::TypeMatrix); } -void Attribute::reserve(int numverts, int numtris, int numsteps, int numcurves, int numkeys, bool resize) +void Attribute::resize(int numverts, int numtris, int numsteps, int numcurves, int numkeys, bool reserve_only) { - if(resize) { - buffer.resize(buffer_size(numverts, numtris, numsteps, numcurves, numkeys), 0); + if(reserve_only) { + buffer.reserve(buffer_size(numverts, numtris, numsteps, numcurves, numkeys)); } else { - buffer.reserve(buffer_size(numverts, numtris, numsteps, numcurves, numkeys)); + buffer.resize(buffer_size(numverts, numtris, numsteps, numcurves, numkeys), 0); } } @@ -263,7 +263,7 @@ AttributeSet::~AttributeSet() { } -Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement element, bool resize) +Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement element) { Attribute *attr = find(name); @@ -291,9 +291,9 @@ Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement eleme /* this is weak .. */ if(triangle_mesh) - attr->reserve(triangle_mesh->verts.size(), triangle_mesh->triangles.size(), triangle_mesh->motion_steps, 0, 0, resize); + attr->resize(triangle_mesh->verts.size(), triangle_mesh->num_triangles(), triangle_mesh->motion_steps, 0, 0, false); if(curve_mesh) - attr->reserve(0, 0, curve_mesh->motion_steps, curve_mesh->curves.size(), curve_mesh->curve_keys.size(), resize); + attr->resize(0, 0, curve_mesh->motion_steps, curve_mesh->num_curves(), curve_mesh->curve_keys.size(), false); return attr; } @@ -448,13 +448,13 @@ Attribute *AttributeSet::find(AttributeRequest& req) return find(req.std); } -void AttributeSet::reserve() +void AttributeSet::resize(bool reserve_only) { foreach(Attribute& attr, attributes) { if(triangle_mesh) - attr.reserve(triangle_mesh->verts.size(), triangle_mesh->triangles.size(), triangle_mesh->motion_steps, 0, 0, true); + attr.resize(triangle_mesh->verts.size(), triangle_mesh->num_triangles(), triangle_mesh->motion_steps, 0, 0, reserve_only); if(curve_mesh) - attr.reserve(0, 0, 0, curve_mesh->curves.size(), curve_mesh->curve_keys.size(), true); + attr.resize(0, 0, 0, curve_mesh->num_curves(), curve_mesh->curve_keys.size(), reserve_only); } } diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h index 01102d22aaa..41b3626afd3 100644 --- a/intern/cycles/render/attribute.h +++ b/intern/cycles/render/attribute.h @@ -58,7 +58,7 @@ public: Attribute() {} ~Attribute(); void set(ustring name, TypeDesc type, AttributeElement element); - void reserve(int numverts, int numfaces, int numsteps, int numcurves, int numkeys, bool resize); + void resize(int numverts, int numfaces, int numsteps, int numcurves, int numkeys, bool reserve_only); size_t data_sizeof() const; size_t element_size(int numverts, int numfaces, int numsteps, int numcurves, int numkeys) const; @@ -104,7 +104,7 @@ public: AttributeSet(); ~AttributeSet(); - Attribute *add(ustring name, TypeDesc type, AttributeElement element, bool resize = true); + Attribute *add(ustring name, TypeDesc type, AttributeElement element); Attribute *find(ustring name) const; void remove(ustring name); @@ -114,7 +114,7 @@ public: Attribute *find(AttributeRequest& req); - void reserve(); + void resize(bool reserve_only = false); void clear(); }; diff --git a/intern/cycles/render/curves.h b/intern/cycles/render/curves.h index 3d9b4e1f347..e41967eebf5 100644 --- a/intern/cycles/render/curves.h +++ b/intern/cycles/render/curves.h @@ -63,23 +63,23 @@ public: ParticleCurveData(); ~ParticleCurveData(); - vector<int> psys_firstcurve; - vector<int> psys_curvenum; - vector<int> psys_shader; - - vector<float> psys_rootradius; - vector<float> psys_tipradius; - vector<float> psys_shape; - vector<bool> psys_closetip; - - vector<int> curve_firstkey; - vector<int> curve_keynum; - vector<float> curve_length; - vector<float3> curve_uv; - vector<float3> curve_vcol; - - vector<float3> curvekey_co; - vector<float> curvekey_time; + array<int> psys_firstcurve; + array<int> psys_curvenum; + array<int> psys_shader; + + array<float> psys_rootradius; + array<float> psys_tipradius; + array<float> psys_shape; + array<bool> psys_closetip; + + array<int> curve_firstkey; + array<int> curve_keynum; + array<float> curve_length; + array<float3> curve_uv; + array<float3> curve_vcol; + + array<float3> curvekey_co; + array<float> curvekey_time; }; /* HairSystem Manager */ diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index c20bf6b5e9e..9ef35820254 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -247,7 +247,8 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen /* count triangles */ if(have_emission) { - for(size_t i = 0; i < mesh->triangles.size(); i++) { + size_t mesh_num_triangles = mesh->num_triangles(); + for(size_t i = 0; i < mesh_num_triangles; i++) { int shader_index = mesh->shader[i]; Shader *shader = (shader_index < mesh->used_shaders.size()) ? mesh->used_shaders[shader_index] : scene->default_surface; @@ -319,7 +320,8 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen use_light_visibility = true; } - for(size_t i = 0; i < mesh->triangles.size(); i++) { + size_t mesh_num_triangles = mesh->num_triangles(); + for(size_t i = 0; i < mesh_num_triangles; i++) { int shader_index = mesh->shader[i]; Shader *shader = (shader_index < mesh->used_shaders.size()) ? mesh->used_shaders[shader_index] : scene->default_surface; @@ -331,7 +333,7 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen distribution[offset].w = __int_as_float(object_id); offset++; - Mesh::Triangle t = mesh->triangles[i]; + Mesh::Triangle t = mesh->get_triangle(i); float3 p1 = mesh->verts[t.v[0]]; float3 p2 = mesh->verts[t.v[1]]; float3 p3 = mesh->verts[t.v[2]]; diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp index d26404035eb..722632b9934 100644 --- a/intern/cycles/render/mesh.cpp +++ b/intern/cycles/render/mesh.cpp @@ -51,14 +51,14 @@ void Mesh::Triangle::bounds_grow(const float3 *verts, BoundBox& bounds) const /* Curve */ -void Mesh::Curve::bounds_grow(const int k, const float4 *curve_keys, BoundBox& bounds) const +void Mesh::Curve::bounds_grow(const int k, const float3 *curve_keys, const float *curve_radius, BoundBox& bounds) const { float3 P[4]; - P[0] = float4_to_float3(curve_keys[max(first_key + k - 1,first_key)]); - P[1] = float4_to_float3(curve_keys[first_key + k]); - P[2] = float4_to_float3(curve_keys[first_key + k + 1]); - P[3] = float4_to_float3(curve_keys[min(first_key + k + 2, first_key + num_keys - 1)]); + P[0] = curve_keys[max(first_key + k - 1,first_key)]; + P[1] = curve_keys[first_key + k]; + P[2] = curve_keys[first_key + k + 1]; + P[3] = curve_keys[min(first_key + k + 2, first_key + num_keys - 1)]; float3 lower; float3 upper; @@ -67,7 +67,7 @@ void Mesh::Curve::bounds_grow(const int k, const float4 *curve_keys, BoundBox& b curvebounds(&lower.y, &upper.y, P, 1); curvebounds(&lower.z, &upper.z, P, 2); - float mr = max(curve_keys[first_key + k].w, curve_keys[first_key + k + 1].w); + float mr = max(curve_radius[first_key + k], curve_radius[first_key + k + 1]); bounds.grow(lower, mr); bounds.grow(upper, mr); @@ -99,6 +99,8 @@ Mesh::Mesh() attributes.triangle_mesh = this; curve_attributes.curve_mesh = this; + geometry_flags = GEOMETRY_NONE; + has_volume = false; has_surface_bssrdf = false; } @@ -108,21 +110,49 @@ Mesh::~Mesh() delete bvh; } -void Mesh::reserve(int numverts, int numtris, int numcurves, int numcurvekeys) +void Mesh::resize_mesh(int numverts, int numtris) { - /* reserve space to add verts and triangles later */ verts.resize(numverts); - triangles.resize(numtris); + triangles.resize(numtris * 3); shader.resize(numtris); smooth.resize(numtris); forms_quad.resize(numtris); - curve_keys.resize(numcurvekeys); - curves.resize(numcurves); + attributes.resize(); +} - attributes.reserve(); - curve_attributes.reserve(); +void Mesh::reserve_mesh(int numverts, int numtris) +{ + /* reserve space to add verts and triangles later */ + verts.reserve(numverts); + triangles.reserve(numtris * 3); + shader.reserve(numtris); + smooth.reserve(numtris); + + forms_quad.reserve(numtris); + + attributes.resize(true); +} + +void Mesh::resize_curves(int numcurves, int numkeys) +{ + curve_keys.resize(numkeys); + curve_radius.resize(numkeys); + curve_first_key.resize(numcurves); + curve_shader.resize(numcurves); + + curve_attributes.resize(); +} + +void Mesh::reserve_curves(int numcurves, int numkeys) +{ + curve_keys.reserve(numkeys); + curve_radius.reserve(numkeys); + curve_first_key.reserve(numcurves); + curve_shader.reserve(numcurves); + + curve_attributes.resize(true); } void Mesh::clear() @@ -136,7 +166,9 @@ void Mesh::clear() forms_quad.clear(); curve_keys.clear(); - curves.clear(); + curve_radius.clear(); + curve_first_key.clear(); + curve_shader.clear(); attributes.clear(); curve_attributes.clear(); @@ -151,7 +183,7 @@ void Mesh::clear() int Mesh::split_vertex(int vertex) { /* copy vertex location and vertex attributes */ - verts.push_back(verts[vertex]); + add_vertex(verts[vertex]); foreach(Attribute& attr, attributes.attributes) { if(attr.element == ATTR_ELEMENT_VERTEX) { @@ -164,48 +196,31 @@ int Mesh::split_vertex(int vertex) return verts.size() - 1; } -void Mesh::set_triangle(int i, int v0, int v1, int v2, int shader_, bool smooth_, bool forms_quad_) +void Mesh::add_vertex(float3 P) { - Triangle tri; - tri.v[0] = v0; - tri.v[1] = v1; - tri.v[2] = v2; - - triangles[i] = tri; - shader[i] = shader_; - smooth[i] = smooth_; - forms_quad[i] = forms_quad_; + verts.push_back_reserved(P); } void Mesh::add_triangle(int v0, int v1, int v2, int shader_, bool smooth_, bool forms_quad_) { - Triangle tri; - tri.v[0] = v0; - tri.v[1] = v1; - tri.v[2] = v2; - - triangles.push_back(tri); - shader.push_back(shader_); - smooth.push_back(smooth_); - forms_quad.push_back(forms_quad_); + triangles.push_back_reserved(v0); + triangles.push_back_reserved(v1); + triangles.push_back_reserved(v2); + shader.push_back_reserved(shader_); + smooth.push_back_reserved(smooth_); + forms_quad.push_back_reserved(forms_quad_); } void Mesh::add_curve_key(float3 co, float radius) { - float4 key = float3_to_float4(co); - key.w = radius; - - curve_keys.push_back(key); + curve_keys.push_back_reserved(co); + curve_radius.push_back_reserved(radius); } void Mesh::add_curve(int first_key, int num_keys, int shader) { - Curve curve; - curve.first_key = first_key; - curve.num_keys = num_keys; - curve.shader = shader; - - curves.push_back(curve); + curve_first_key.push_back_reserved(first_key); + curve_shader.push_back_reserved(shader); } void Mesh::compute_bounds() @@ -219,7 +234,7 @@ void Mesh::compute_bounds() bnds.grow(verts[i]); for(size_t i = 0; i < curve_keys_size; i++) - bnds.grow(float4_to_float3(curve_keys[i]), curve_keys[i].w); + bnds.grow(curve_keys[i], curve_radius[i]); Attribute *attr = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); if(use_motion_blur && attr) { @@ -247,7 +262,7 @@ void Mesh::compute_bounds() bnds.grow_safe(verts[i]); for(size_t i = 0; i < curve_keys_size; i++) - bnds.grow_safe(float4_to_float3(curve_keys[i]), curve_keys[i].w); + bnds.grow_safe(curve_keys[i], curve_radius[i]); if(use_motion_blur && attr) { size_t steps_size = verts.size() * (motion_steps - 1); @@ -301,15 +316,14 @@ void Mesh::add_face_normals() float3 *fN = attr_fN->data_float3(); /* compute face normals */ - size_t triangles_size = triangles.size(); + size_t triangles_size = num_triangles(); bool flip = transform_negative_scaled; if(triangles_size) { float3 *verts_ptr = &verts[0]; - Triangle *triangles_ptr = &triangles[0]; for(size_t i = 0; i < triangles_size; i++) { - fN[i] = compute_face_normal(triangles_ptr[i], verts_ptr); + fN[i] = compute_face_normal(get_triangle(i), verts_ptr); if(flip) fN[i] = -fN[i]; @@ -329,7 +343,7 @@ void Mesh::add_vertex_normals() { bool flip = transform_negative_scaled; size_t verts_size = verts.size(); - size_t triangles_size = triangles.size(); + size_t triangles_size = num_triangles(); /* static vertex normals */ if(!attributes.find(ATTR_STD_VERTEX_NORMAL)) { @@ -344,11 +358,10 @@ void Mesh::add_vertex_normals() memset(vN, 0, verts.size()*sizeof(float3)); if(triangles_size) { - Triangle *triangles_ptr = &triangles[0]; for(size_t i = 0; i < triangles_size; i++) for(size_t j = 0; j < 3; j++) - vN[triangles_ptr[i].v[j]] += fN[i]; + vN[get_triangle(i).v[j]] += fN[i]; } for(size_t i = 0; i < verts_size; i++) { @@ -374,12 +387,10 @@ void Mesh::add_vertex_normals() memset(mN, 0, verts.size()*sizeof(float3)); if(triangles_size) { - Triangle *triangles_ptr = &triangles[0]; - for(size_t i = 0; i < triangles_size; i++) { for(size_t j = 0; j < 3; j++) { - float3 fN = compute_face_normal(triangles_ptr[i], mP); - mN[triangles_ptr[i].v[j]] += fN; + float3 fN = compute_face_normal(get_triangle(i), mP); + mN[get_triangle(i).v[j]] += fN; } } } @@ -402,8 +413,8 @@ void Mesh::pack_normals(Scene *scene, uint *tri_shader, float4 *vnormal) uint last_shader = -1; bool last_smooth = false; - size_t triangles_size = triangles.size(); - uint *shader_ptr = (shader.size())? &shader[0]: NULL; + size_t triangles_size = num_triangles(); + int *shader_ptr = (shader.size())? &shader[0]: NULL; bool do_transform = transform_applied; Transform ntfm = transform_normal; @@ -446,13 +457,11 @@ void Mesh::pack_verts(float4 *tri_verts, float4 *tri_vindex, size_t vert_offset) } } - size_t triangles_size = triangles.size(); + size_t triangles_size = num_triangles(); if(triangles_size) { - Triangle *triangles_ptr = &triangles[0]; - for(size_t i = 0; i < triangles_size; i++) { - Triangle t = triangles_ptr[i]; + Triangle t = get_triangle(i); tri_vindex[i] = make_float4( __int_as_float(t.v[0] + vert_offset), @@ -466,27 +475,25 @@ void Mesh::pack_verts(float4 *tri_verts, float4 *tri_vindex, size_t vert_offset) void Mesh::pack_curves(Scene *scene, float4 *curve_key_co, float4 *curve_data, size_t curvekey_offset) { size_t curve_keys_size = curve_keys.size(); - float4 *keys_ptr = NULL; /* pack curve keys */ if(curve_keys_size) { - keys_ptr = &curve_keys[0]; + float3 *keys_ptr = &curve_keys[0]; + float *radius_ptr = &curve_radius[0]; for(size_t i = 0; i < curve_keys_size; i++) - curve_key_co[i] = keys_ptr[i]; + curve_key_co[i] = make_float4(keys_ptr[i].x, keys_ptr[i].y, keys_ptr[i].z, radius_ptr[i]); } /* pack curve segments */ - size_t curve_num = curves.size(); + size_t curve_num = num_curves(); if(curve_num) { - Curve *curve_ptr = &curves[0]; - int shader_id = 0; - for(size_t i = 0; i < curve_num; i++) { - Curve curve = curve_ptr[i]; - Shader *shader = (curve.shader < used_shaders.size()) ? - used_shaders[curve.shader] : scene->default_surface; + 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( @@ -732,7 +739,7 @@ void MeshManager::update_svm_attributes(Device *device, DeviceScene *dscene, Sce else id = scene->shader_manager->get_attribute_id(req.std); - if(mesh->triangles.size()) { + if(mesh->num_triangles()) { attr_map[index].x = id; attr_map[index].y = req.triangle_element; attr_map[index].z = as_uint(req.triangle_offset); @@ -747,7 +754,7 @@ void MeshManager::update_svm_attributes(Device *device, DeviceScene *dscene, Sce index++; - if(mesh->curves.size()) { + if(mesh->num_curves()) { attr_map[index].x = id; attr_map[index].y = req.curve_element; attr_map[index].z = as_uint(req.curve_offset); @@ -793,9 +800,9 @@ static void update_attribute_element_size(Mesh *mesh, if(mattr) { size_t size = mattr->element_size( mesh->verts.size(), - mesh->triangles.size(), + mesh->num_triangles(), mesh->motion_steps, - mesh->curves.size(), + mesh->num_curves(), mesh->curve_keys.size()); if(mattr->element == ATTR_ELEMENT_VOXEL) { @@ -836,9 +843,9 @@ static void update_attribute_element_offset(Mesh *mesh, /* store attribute data in arrays */ size_t size = mattr->element_size( mesh->verts.size(), - mesh->triangles.size(), + mesh->num_triangles(), mesh->motion_steps, - mesh->curves.size(), + mesh->num_curves(), mesh->curve_keys.size()); if(mattr->element == ATTR_ELEMENT_VOXEL) { @@ -1052,10 +1059,10 @@ void MeshManager::device_update_mesh(Device *device, DeviceScene *dscene, Scene mesh->curve_offset = curve_size; vert_size += mesh->verts.size(); - tri_size += mesh->triangles.size(); + tri_size += mesh->num_triangles(); curve_key_size += mesh->curve_keys.size(); - curve_size += mesh->curves.size(); + curve_size += mesh->num_curves(); } if(tri_size != 0) { @@ -1465,16 +1472,17 @@ void Mesh::tessellate(DiagSplit *split) if(!forms_quad[f]) { /* triangle */ LinearTrianglePatch patch; + Triangle triangle = get_triangle(f); float3 *hull = patch.hull; float3 *normals = patch.normals; for(int i = 0; i < 3; i++) { - hull[i] = verts[triangles[f].v[i]]; + hull[i] = verts[triangle.v[i]]; } if(smooth[f]) { for(int i = 0; i < 3; i++) { - normals[i] = vN[triangles[f].v[i]]; + normals[i] = vN[triangle.v[i]]; } } else { @@ -1488,19 +1496,21 @@ void Mesh::tessellate(DiagSplit *split) else { /* quad */ LinearQuadPatch patch; + Triangle triangle0 = get_triangle(f); + Triangle triangle1 = get_triangle(f+1); float3 *hull = patch.hull; float3 *normals = patch.normals; - hull[0] = verts[triangles[f ].v[0]]; - hull[1] = verts[triangles[f ].v[1]]; - hull[3] = verts[triangles[f ].v[2]]; - hull[2] = verts[triangles[f+1].v[2]]; + hull[0] = verts[triangle0.v[0]]; + hull[1] = verts[triangle0.v[1]]; + hull[3] = verts[triangle0.v[2]]; + hull[2] = verts[triangle1.v[2]]; if(smooth[f]) { - normals[0] = vN[triangles[f ].v[0]]; - normals[1] = vN[triangles[f ].v[1]]; - normals[3] = vN[triangles[f ].v[2]]; - normals[2] = vN[triangles[f+1].v[2]]; + normals[0] = vN[triangle0.v[0]]; + normals[1] = vN[triangle0.v[1]]; + normals[3] = vN[triangle0.v[2]]; + normals[2] = vN[triangle1.v[2]]; } else { for(int i = 0; i < 4; i++) { diff --git a/intern/cycles/render/mesh.h b/intern/cycles/render/mesh.h index 557b664bff3..2d1f3e3a83e 100644 --- a/intern/cycles/render/mesh.h +++ b/intern/cycles/render/mesh.h @@ -51,17 +51,41 @@ public: void bounds_grow(const float3 *verts, BoundBox& bounds) const; }; + Triangle get_triangle(size_t i) const + { + Triangle tri = {{triangles[i*3 + 0], triangles[i*3 + 1], triangles[i*3 + 2]}}; + return tri; + } + + size_t num_triangles() const + { + return triangles.size() / 3; + } + /* Mesh Curve */ struct Curve { int first_key; int num_keys; - uint shader; int num_segments() { return num_keys - 1; } - void bounds_grow(const int k, const float4 *curve_keys, BoundBox& bounds) const; + void bounds_grow(const int k, const float3 *curve_keys, const float *curve_radius, BoundBox& bounds) const; }; + Curve get_curve(size_t i) const + { + int first = curve_first_key[i]; + int next_first = (i+1 < curve_first_key.size()) ? curve_first_key[i+1] : curve_keys.size(); + + Curve curve = {first, next_first - first}; + return curve; + } + + size_t num_curves() const + { + return curve_first_key.size(); + } + /* Displacement */ enum DisplacementMethod { DISPLACE_BUMP = 0, @@ -82,17 +106,19 @@ public: int geometry_flags; /* used to distinguish meshes with no verts and meshed for which geometry is not created */ - vector<float3> verts; - vector<Triangle> triangles; - vector<uint> shader; - vector<bool> smooth; - vector<bool> forms_quad; /* used to tell if triangle is part of a quad patch */ + array<int> triangles; + array<float3> verts; + array<int> shader; + array<bool> smooth; + array<bool> forms_quad; /* used to tell if triangle is part of a quad patch */ bool has_volume; /* Set in the device_update_flags(). */ bool has_surface_bssrdf; /* Set in the device_update_flags(). */ - vector<float4> curve_keys; /* co + radius */ - vector<Curve> curves; + array<float3> curve_keys; + array<float> curve_radius; + array<int> curve_first_key; + array<int> curve_shader; vector<Shader*> used_shaders; AttributeSet attributes; @@ -123,9 +149,12 @@ public: Mesh(); ~Mesh(); - void reserve(int numverts, int numfaces, int numcurves, int numcurvekeys); + void resize_mesh(int numverts, int numfaces); + void reserve_mesh(int numverts, int numfaces); + void resize_curves(int numcurves, int numkeys); + void reserve_curves(int numcurves, int numkeys); void clear(); - void set_triangle(int i, int v0, int v1, int v2, int shader, bool smooth, bool forms_quad = false); + void add_vertex(float3 P); void add_triangle(int v0, int v1, int v2, int shader, bool smooth, bool forms_quad = false); void add_curve_key(float3 loc, float radius); void add_curve(int first_key, int num_keys, int shader); diff --git a/intern/cycles/render/mesh_displace.cpp b/intern/cycles/render/mesh_displace.cpp index d19bf2084d7..95f46ff02a2 100644 --- a/intern/cycles/render/mesh_displace.cpp +++ b/intern/cycles/render/mesh_displace.cpp @@ -60,8 +60,9 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me uint4 *d_input_data = d_input.resize(num_verts); size_t d_input_size = 0; - for(size_t i = 0; i < mesh->triangles.size(); i++) { - Mesh::Triangle t = mesh->triangles[i]; + size_t num_triangles = mesh->num_triangles(); + for(size_t i = 0; i < num_triangles; i++) { + Mesh::Triangle t = mesh->get_triangle(i); int shader_index = mesh->shader[i]; Shader *shader = (shader_index < mesh->used_shaders.size()) ? mesh->used_shaders[shader_index] : scene->default_surface; @@ -146,8 +147,8 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me float4 *offset = (float4*)d_output.data_pointer; Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); - for(size_t i = 0; i < mesh->triangles.size(); i++) { - Mesh::Triangle t = mesh->triangles[i]; + for(size_t i = 0; i < num_triangles; i++) { + Mesh::Triangle t = mesh->get_triangle(i); int shader_index = mesh->shader[i]; Shader *shader = (shader_index < mesh->used_shaders.size()) ? mesh->used_shaders[shader_index] : scene->default_surface; diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index e2fe0bd72a1..4e74940aff1 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -137,12 +137,12 @@ void Object::apply_transform(bool apply_to_motion) /* apply transform to curve keys */ for(size_t i = 0; i < mesh->curve_keys.size(); i++) { - float3 co = transform_point(&tfm, float4_to_float3(mesh->curve_keys[i])); - float radius = mesh->curve_keys[i].w * scalar; + float3 co = transform_point(&tfm, mesh->curve_keys[i]); + float radius = mesh->curve_radius[i] * scalar; /* scale for curve radius is only correct for uniform scale */ - mesh->curve_keys[i] = float3_to_float4(co); - mesh->curve_keys[i].w = radius; + mesh->curve_keys[i] = co; + mesh->curve_radius[i] = radius; } if(apply_to_motion) { @@ -269,7 +269,9 @@ void ObjectManager::device_update_object_transform(UpdateObejctTransformState *s state->surface_area_lock.unlock(); if(it == state->surface_area_map.end()) { - foreach(Mesh::Triangle& t, mesh->triangles) { + size_t num_triangles = mesh->num_triangles(); + for(size_t j = 0; j < num_triangles; j++) { + Mesh::Triangle t = mesh->get_triangle(j); float3 p1 = mesh->verts[t.v[0]]; float3 p2 = mesh->verts[t.v[1]]; float3 p3 = mesh->verts[t.v[2]]; @@ -288,7 +290,9 @@ void ObjectManager::device_update_object_transform(UpdateObejctTransformState *s surface_area *= uniform_scale; } else { - foreach(Mesh::Triangle& t, mesh->triangles) { + size_t num_triangles = mesh->num_triangles(); + for(size_t j = 0; j < num_triangles; j++) { + Mesh::Triangle t = mesh->get_triangle(j); float3 p1 = transform_point(&tfm, mesh->verts[t.v[0]]); float3 p2 = transform_point(&tfm, mesh->verts[t.v[1]]); float3 p3 = transform_point(&tfm, mesh->verts[t.v[2]]); @@ -360,7 +364,7 @@ void ObjectManager::device_update_object_transform(UpdateObejctTransformState *s state->object_flag[object_index] = flag; /* Have curves. */ - if(mesh->curves.size()) { + if(mesh->num_curves()) { state->have_curves = true; } } diff --git a/intern/cycles/render/particles.cpp b/intern/cycles/render/particles.cpp index 50726bb4574..1a35d60fb4b 100644 --- a/intern/cycles/render/particles.cpp +++ b/intern/cycles/render/particles.cpp @@ -58,8 +58,8 @@ void ParticleSystemManager::device_update_particles(Device *device, DeviceScene * adds one dummy particle at the beginning to avoid invalid lookups, * in case a shader uses particle info without actual particle data. */ int num_particles = 1; - foreach(ParticleSystem *psys, scene->particle_systems) - num_particles += psys->particles.size(); + for(size_t j = 0; j < scene->particle_systems.size(); j++) + num_particles += scene->particle_systems[j]->particles.size(); float4 *particles = dscene->particles.resize(PARTICLE_SIZE*num_particles); @@ -71,9 +71,12 @@ void ParticleSystemManager::device_update_particles(Device *device, DeviceScene particles[4] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); int i = 1; - foreach(ParticleSystem *psys, scene->particle_systems) { - foreach(Particle &pa, psys->particles) { + for(size_t j = 0; j < scene->particle_systems.size(); j++) { + ParticleSystem *psys = scene->particle_systems[j]; + + for(size_t k = 0; k < psys->particles.size(); k++) { /* pack in texture */ + Particle& pa = psys->particles[k]; int offset = i*PARTICLE_SIZE; particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, pa.size); diff --git a/intern/cycles/render/particles.h b/intern/cycles/render/particles.h index bf2b6b77015..2509e27b44b 100644 --- a/intern/cycles/render/particles.h +++ b/intern/cycles/render/particles.h @@ -47,7 +47,7 @@ public: void tag_update(Scene *scene); - vector<Particle> particles; + array<Particle> particles; }; /* ParticleSystem Manager */ diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp index 76979e9ba3e..1cd76ff2b39 100644 --- a/intern/cycles/render/session.cpp +++ b/intern/cycles/render/session.cpp @@ -630,7 +630,7 @@ DeviceRequestedFeatures Session::get_requested_device_features() requested_features.use_camera_motion = scene->camera->use_motion; foreach(Object *object, scene->objects) { Mesh *mesh = object->mesh; - if(mesh->curves.size() > 0) { + if(mesh->num_curves()) { requested_features.use_hair = true; } requested_features.use_object_motion |= object->use_motion | mesh->use_motion_blur; |