Rename clip proxy rebuild function so it's no longer called in the same way
[blender.git] / intern / cycles / render / mesh.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #include "bvh.h"
20 #include "bvh_build.h"
21
22 #include "device.h"
23 #include "shader.h"
24 #include "light.h"
25 #include "mesh.h"
26 #include "object.h"
27 #include "scene.h"
28
29 #include "osl_globals.h"
30
31 #include "util_cache.h"
32 #include "util_foreach.h"
33 #include "util_progress.h"
34 #include "util_set.h"
35
36 CCL_NAMESPACE_BEGIN
37
38 /* Mesh */
39
40 Mesh::Mesh()
41 : attributes(this)
42 {
43         need_update = true;
44         transform_applied = false;
45         transform_negative_scaled = false;
46         displacement_method = DISPLACE_BUMP;
47
48         bvh = NULL;
49
50         tri_offset = 0;
51         vert_offset = 0;
52 }
53
54 Mesh::~Mesh()
55 {
56         delete bvh;
57 }
58
59 void Mesh::reserve(int numverts, int numtris)
60 {
61         /* reserve space to add verts and triangles later */
62         verts.resize(numverts);
63         triangles.resize(numtris);
64         shader.resize(numtris);
65         smooth.resize(numtris);
66         attributes.reserve(numverts, numtris);
67 }
68
69 void Mesh::clear()
70 {
71         /* clear all verts and triangles */
72         verts.clear();
73         triangles.clear();
74         shader.clear();
75         smooth.clear();
76
77         attributes.clear();
78         used_shaders.clear();
79
80         transform_applied = false;
81         transform_negative_scaled = false;
82 }
83
84 void Mesh::add_triangle(int v0, int v1, int v2, int shader_, bool smooth_)
85 {
86         Triangle t;
87         t.v[0] = v0;
88         t.v[1] = v1;
89         t.v[2] = v2;
90
91         triangles.push_back(t);
92         shader.push_back(shader_);
93         smooth.push_back(smooth_);
94 }
95
96 void Mesh::compute_bounds()
97 {
98         BoundBox bnds;
99         size_t verts_size = verts.size();
100
101         for(size_t i = 0; i < verts_size; i++)
102                 bnds.grow(verts[i]);
103
104         /* happens mostly on empty meshes */
105         if(!bnds.valid())
106                 bnds.grow(make_float3(0.0f, 0.0f, 0.0f));
107
108         bounds = bnds;
109 }
110
111 void Mesh::add_face_normals()
112 {
113         /* don't compute if already there */
114         if(attributes.find(Attribute::STD_FACE_NORMAL))
115                 return;
116
117         /* get attributes */
118         Attribute *attr_fN = attributes.add(Attribute::STD_FACE_NORMAL);
119         float3 *fN = attr_fN->data_float3();
120
121         /* compute face normals */
122         size_t triangles_size = triangles.size();
123         bool flip = transform_negative_scaled;
124
125         if(triangles_size) {
126                 float3 *verts_ptr = &verts[0];
127                 Triangle *triangles_ptr = &triangles[0];
128
129                 for(size_t i = 0; i < triangles_size; i++) {
130                         Triangle t = triangles_ptr[i];
131                         float3 v0 = verts_ptr[t.v[0]];
132                         float3 v1 = verts_ptr[t.v[1]];
133                         float3 v2 = verts_ptr[t.v[2]];
134
135                         fN[i] = normalize(cross(v1 - v0, v2 - v0));
136
137                         if(flip)
138                                 fN[i] = -fN[i];
139                 }
140         }
141 }
142
143 void Mesh::add_vertex_normals()
144 {
145         /* don't compute if already there */
146         if(attributes.find(Attribute::STD_VERTEX_NORMAL))
147                 return;
148
149         /* get attributes */
150         Attribute *attr_fN = attributes.find(Attribute::STD_FACE_NORMAL);
151         Attribute *attr_vN = attributes.add(Attribute::STD_VERTEX_NORMAL);
152
153         float3 *fN = attr_fN->data_float3();
154         float3 *vN = attr_vN->data_float3();
155
156         /* compute vertex normals */
157         memset(vN, 0, verts.size()*sizeof(float3));
158
159         size_t verts_size = verts.size();
160         size_t triangles_size = triangles.size();
161         bool flip = transform_negative_scaled;
162
163         if(triangles_size) {
164                 Triangle *triangles_ptr = &triangles[0];
165
166                 for(size_t i = 0; i < triangles_size; i++)
167                         for(size_t j = 0; j < 3; j++)
168                                 vN[triangles_ptr[i].v[j]] += fN[i];
169         }
170
171         for(size_t i = 0; i < verts_size; i++) {
172                 vN[i] = normalize(vN[i]);
173                 if(flip)
174                         vN[i] = -vN[i];
175         }
176 }
177
178 void Mesh::pack_normals(Scene *scene, float4 *normal, float4 *vnormal)
179 {
180         Attribute *attr_fN = attributes.find(Attribute::STD_FACE_NORMAL);
181         Attribute *attr_vN = attributes.find(Attribute::STD_VERTEX_NORMAL);
182
183         float3 *fN = attr_fN->data_float3();
184         float3 *vN = attr_vN->data_float3();
185         int shader_id = 0;
186         uint last_shader = -1;
187         bool last_smooth = false;
188
189         size_t triangles_size = triangles.size();
190         uint *shader_ptr = (shader.size())? &shader[0]: NULL;
191
192         for(size_t i = 0; i < triangles_size; i++) {
193                 normal[i].x = fN[i].x;
194                 normal[i].y = fN[i].y;
195                 normal[i].z = fN[i].z;
196
197                 /* stuff shader id in here too */
198                 if(shader_ptr[i] != last_shader || last_smooth != smooth[i]) {
199                         last_shader = shader_ptr[i];
200                         last_smooth = smooth[i];
201                         shader_id = scene->shader_manager->get_shader_id(last_shader, this, last_smooth);
202                 }
203
204                 normal[i].w = __int_as_float(shader_id);
205         }
206
207         size_t verts_size = verts.size();
208
209         for(size_t i = 0; i < verts_size; i++)
210                 vnormal[i] = make_float4(vN[i].x, vN[i].y, vN[i].z, 0.0f);
211 }
212
213 void Mesh::pack_verts(float4 *tri_verts, float4 *tri_vindex, size_t vert_offset)
214 {
215         size_t verts_size = verts.size();
216
217         if(verts_size) {
218                 float3 *verts_ptr = &verts[0];
219
220                 for(size_t i = 0; i < verts_size; i++) {
221                         float3 p = verts_ptr[i];
222                         tri_verts[i] = make_float4(p.x, p.y, p.z, 0.0f);
223                 }
224         }
225
226         size_t triangles_size = triangles.size();
227
228         if(triangles_size) {
229                 Triangle *triangles_ptr = &triangles[0];
230
231                 for(size_t i = 0; i < triangles_size; i++) {
232                         Triangle t = triangles_ptr[i];
233
234                         tri_vindex[i] = make_float4(
235                                 __int_as_float(t.v[0] + vert_offset),
236                                 __int_as_float(t.v[1] + vert_offset),
237                                 __int_as_float(t.v[2] + vert_offset),
238                                 0);
239                 }
240         }
241 }
242
243 void Mesh::compute_bvh(SceneParams *params, Progress& progress)
244 {
245         Object object;
246         object.mesh = this;
247
248         vector<Object*> objects;
249         objects.push_back(&object);
250
251         if(bvh && !need_update_rebuild) {
252                 progress.set_substatus("Refitting BVH");
253                 bvh->objects = objects;
254                 bvh->refit(progress);
255         }
256         else {
257                 progress.set_substatus("Building BVH");
258
259                 BVHParams bparams;
260                 bparams.use_cache = params->use_bvh_cache;
261                 bparams.use_spatial_split = params->use_bvh_spatial_split;
262                 bparams.use_qbvh = params->use_qbvh;
263
264                 delete bvh;
265                 bvh = BVH::create(bparams, objects);
266                 bvh->build(progress);
267         }
268 }
269
270 void Mesh::tag_update(Scene *scene, bool rebuild)
271 {
272         need_update = true;
273         if(rebuild)
274                 need_update_rebuild = true;
275
276         scene->mesh_manager->need_update = true;
277         scene->object_manager->need_update = true;
278
279         foreach(uint sindex, used_shaders)
280                 if(scene->shaders[sindex]->has_surface_emission)
281                         scene->light_manager->need_update = true;
282 }
283
284 /* Mesh Manager */
285
286 MeshManager::MeshManager()
287 {
288         bvh = NULL;
289         need_update = true;
290 }
291
292 MeshManager::~MeshManager()
293 {
294         delete bvh;
295 }
296
297 void MeshManager::update_osl_attributes(Device *device, Scene *scene, vector<AttributeRequestSet>& mesh_attributes)
298 {
299 #ifdef WITH_OSL
300         /* for OSL, a hash map is used to lookup the attribute by name. */
301         OSLGlobals *og = (OSLGlobals*)device->osl_memory();
302
303         og->object_name_map.clear();
304         og->attribute_map.clear();
305
306         og->attribute_map.resize(scene->objects.size());
307
308         for(size_t i = 0; i < scene->objects.size(); i++) {
309                 /* set object name to object index map */
310                 Object *object = scene->objects[i];
311                 og->object_name_map[object->name] = i;
312
313                 /* set object attributes */
314                 foreach(ParamValue& attr, object->attributes) {
315                         OSLGlobals::Attribute osl_attr;
316
317                         osl_attr.type = attr.type();
318                         osl_attr.elem = ATTR_ELEMENT_VALUE;
319                         osl_attr.value = attr;
320
321                         og->attribute_map[i][attr.name()] = osl_attr;
322                 }
323
324                 /* find mesh attributes */
325                 size_t j;
326
327                 for(j = 0; j < scene->meshes.size(); j++)
328                         if(scene->meshes[j] == object->mesh)
329                                 break;
330
331                 AttributeRequestSet& attributes = mesh_attributes[j];
332
333                 /* set object attributes */
334                 foreach(AttributeRequest& req, attributes.requests) {
335                         OSLGlobals::Attribute osl_attr;
336
337                         osl_attr.elem = req.element;
338                         osl_attr.offset = req.offset;
339
340                         if(req.type == TypeDesc::TypeFloat)
341                                 osl_attr.type = TypeDesc::TypeFloat;
342                         else
343                                 osl_attr.type = TypeDesc::TypeColor;
344
345                         if(req.std != Attribute::STD_NONE) {
346                                 /* if standard attribute, add lookup by std:: name convention */
347                                 ustring stdname = ustring(string("std::") + Attribute::standard_name(req.std).c_str());
348                                 og->attribute_map[i][stdname] = osl_attr;
349                         }
350                         else if(req.name != ustring()) {
351                                 /* add lookup by mesh attribute name */
352                                 og->attribute_map[i][req.name] = osl_attr;
353                         }
354                 }
355         }
356 #endif
357 }
358
359 void MeshManager::update_svm_attributes(Device *device, DeviceScene *dscene, Scene *scene, vector<AttributeRequestSet>& mesh_attributes)
360 {
361         /* for SVM, the attributes_map table is used to lookup the offset of an
362          * attribute, based on a unique shader attribute id. */
363
364         /* compute array stride */
365         int attr_map_stride = 0;
366
367         for(size_t i = 0; i < scene->meshes.size(); i++)
368                 attr_map_stride = max(attr_map_stride, mesh_attributes[i].size());
369
370         if(attr_map_stride == 0)
371                 return;
372         
373         /* create attribute map */
374         uint4 *attr_map = dscene->attributes_map.resize(attr_map_stride*scene->objects.size());
375         memset(attr_map, 0, dscene->attributes_map.size()*sizeof(uint));
376
377         for(size_t i = 0; i < scene->objects.size(); i++) {
378                 Object *object = scene->objects[i];
379
380                 /* find mesh attributes */
381                 size_t j;
382
383                 for(j = 0; j < scene->meshes.size(); j++)
384                         if(scene->meshes[j] == object->mesh)
385                                 break;
386
387                 AttributeRequestSet& attributes = mesh_attributes[j];
388
389                 /* set object attributes */
390                 j = 0;
391
392                 foreach(AttributeRequest& req, attributes.requests) {
393                         int index = i*attr_map_stride + j;
394                         uint id;
395
396                         if(req.std == Attribute::STD_NONE)
397                                 id = scene->shader_manager->get_attribute_id(req.name);
398                         else
399                                 id = scene->shader_manager->get_attribute_id(req.std);
400
401                         attr_map[index].x = id;
402                         attr_map[index].y = req.element;
403                         attr_map[index].z = req.offset;
404
405                         if(req.type == TypeDesc::TypeFloat)
406                                 attr_map[index].w = NODE_ATTR_FLOAT;
407                         else
408                                 attr_map[index].w = NODE_ATTR_FLOAT3;
409
410                         j++;
411                 }
412         }
413
414         /* copy to device */
415         dscene->data.bvh.attributes_map_stride = attr_map_stride;
416         device->tex_alloc("__attributes_map", dscene->attributes_map);
417 }
418
419 void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
420 {
421         progress.set_status("Updating Mesh", "Computing attributes");
422
423         /* gather per mesh requested attributes. as meshes may have multiple
424          * shaders assigned, this merges the requested attributes that have
425          * been set per shader by the shader manager */
426         vector<AttributeRequestSet> mesh_attributes(scene->meshes.size());
427
428         for(size_t i = 0; i < scene->meshes.size(); i++) {
429                 Mesh *mesh = scene->meshes[i];
430
431                 foreach(uint sindex, mesh->used_shaders) {
432                         Shader *shader = scene->shaders[sindex];
433                         mesh_attributes[i].add(shader->attributes);
434                 }
435         }
436
437         /* mesh attribute are stored in a single array per data type. here we fill
438          * those arrays, and set the offset and element type to create attribute
439          * maps next */
440         vector<float> attr_float;
441         vector<float4> attr_float3;
442
443         for(size_t i = 0; i < scene->meshes.size(); i++) {
444                 Mesh *mesh = scene->meshes[i];
445                 AttributeRequestSet& attributes = mesh_attributes[i];
446
447                 /* todo: we now store std and name attributes from requests even if
448                    they actually refer to the same mesh attributes, optimize */
449                 foreach(AttributeRequest& req, attributes.requests) {
450                         Attribute *mattr = mesh->attributes.find(req);
451
452                         /* todo: get rid of this exception */
453                         if(!mattr && req.std == Attribute::STD_GENERATED) {
454                                 mattr = mesh->attributes.add(Attribute::STD_GENERATED);
455                                 if(mesh->verts.size())
456                                         memcpy(mattr->data_float3(), &mesh->verts[0], sizeof(float3)*mesh->verts.size());
457                         }
458
459                         /* attribute not found */
460                         if(!mattr) {
461                                 req.element = ATTR_ELEMENT_NONE;
462                                 req.offset = 0;
463                                 continue;
464                         }
465
466                         /* we abuse AttributeRequest to pass on info like element and
467                            offset, it doesn't really make sense but is convenient */
468
469                         /* store element and type */
470                         if(mattr->element == Attribute::VERTEX)
471                                 req.element = ATTR_ELEMENT_VERTEX;
472                         else if(mattr->element == Attribute::FACE)
473                                 req.element = ATTR_ELEMENT_FACE;
474                         else if(mattr->element == Attribute::CORNER)
475                                 req.element = ATTR_ELEMENT_CORNER;
476
477                         req.type = mattr->type;
478
479                         /* store attribute data in arrays */
480                         size_t size = mattr->element_size(mesh->verts.size(), mesh->triangles.size());
481
482                         if(mattr->type == TypeDesc::TypeFloat) {
483                                 float *data = mattr->data_float();
484                                 req.offset = attr_float.size();
485
486                                 for(size_t k = 0; k < size; k++)
487                                         attr_float.push_back(data[k]);
488                         }
489                         else {
490                                 float3 *data = mattr->data_float3();
491                                 req.offset = attr_float3.size();
492
493                                 for(size_t k = 0; k < size; k++) {
494                                         float3 f3 = data[k];
495                                         float4 f4 = make_float4(f3.x, f3.y, f3.z, 0.0f);
496
497                                         attr_float3.push_back(f4);
498                                 }
499                         }
500
501                         /* mesh vertex/triangle index is global, not per object, so we sneak
502                            a correction for that in here */
503                         if(req.element == ATTR_ELEMENT_VERTEX)
504                                 req.offset -= mesh->vert_offset;
505                         else if(mattr->element == Attribute::FACE)
506                                 req.offset -= mesh->tri_offset;
507                         else if(mattr->element == Attribute::CORNER)
508                                 req.offset -= 3*mesh->tri_offset;
509
510                         if(progress.get_cancel()) return;
511                 }
512         }
513
514         /* create attribute lookup maps */
515         if(scene->params.shadingsystem == SceneParams::OSL)
516                 update_osl_attributes(device, scene, mesh_attributes);
517         else
518                 update_svm_attributes(device, dscene, scene, mesh_attributes);
519
520         if(progress.get_cancel()) return;
521
522         /* copy to device */
523         progress.set_status("Updating Mesh", "Copying Attributes to device");
524
525         if(attr_float.size()) {
526                 dscene->attributes_float.copy(&attr_float[0], attr_float.size());
527                 device->tex_alloc("__attributes_float", dscene->attributes_float);
528         }
529         if(attr_float3.size()) {
530                 dscene->attributes_float3.copy(&attr_float3[0], attr_float3.size());
531                 device->tex_alloc("__attributes_float3", dscene->attributes_float3);
532         }
533 }
534
535 void MeshManager::device_update_mesh(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
536 {
537         /* count and update offsets */
538         size_t vert_size = 0;
539         size_t tri_size = 0;
540
541         foreach(Mesh *mesh, scene->meshes) {
542                 mesh->vert_offset = vert_size;
543                 mesh->tri_offset = tri_size;
544
545                 vert_size += mesh->verts.size();
546                 tri_size += mesh->triangles.size();
547         }
548
549         if(tri_size == 0)
550                 return;
551
552         /* normals */
553         progress.set_status("Updating Mesh", "Computing normals");
554
555         float4 *normal = dscene->tri_normal.resize(tri_size);
556         float4 *vnormal = dscene->tri_vnormal.resize(vert_size);
557         float4 *tri_verts = dscene->tri_verts.resize(vert_size);
558         float4 *tri_vindex = dscene->tri_vindex.resize(tri_size);
559
560         foreach(Mesh *mesh, scene->meshes) {
561                 mesh->pack_normals(scene, &normal[mesh->tri_offset], &vnormal[mesh->vert_offset]);
562                 mesh->pack_verts(&tri_verts[mesh->vert_offset], &tri_vindex[mesh->tri_offset], mesh->vert_offset);
563
564                 if(progress.get_cancel()) return;
565         }
566
567         /* vertex coordinates */
568         progress.set_status("Updating Mesh", "Copying Mesh to device");
569
570         device->tex_alloc("__tri_normal", dscene->tri_normal);
571         device->tex_alloc("__tri_vnormal", dscene->tri_vnormal);
572         device->tex_alloc("__tri_verts", dscene->tri_verts);
573         device->tex_alloc("__tri_vindex", dscene->tri_vindex);
574 }
575
576 void MeshManager::device_update_bvh(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
577 {
578         /* bvh build */
579         progress.set_status("Updating Scene BVH", "Building");
580
581         BVHParams bparams;
582         bparams.top_level = true;
583         bparams.use_qbvh = scene->params.use_qbvh;
584         bparams.use_spatial_split = scene->params.use_bvh_spatial_split;
585
586         delete bvh;
587         bvh = BVH::create(bparams, scene->objects);
588         bvh->build(progress);
589
590         if(progress.get_cancel()) return;
591
592         /* copy to device */
593         progress.set_status("Updating Scene BVH", "Copying BVH to device");
594
595         PackedBVH& pack = bvh->pack;
596
597         if(pack.nodes.size()) {
598                 dscene->bvh_nodes.reference((float4*)&pack.nodes[0], pack.nodes.size());
599                 device->tex_alloc("__bvh_nodes", dscene->bvh_nodes);
600         }
601         if(pack.object_node.size()) {
602                 dscene->object_node.reference((uint*)&pack.object_node[0], pack.object_node.size());
603                 device->tex_alloc("__object_node", dscene->object_node);
604         }
605         if(pack.tri_woop.size()) {
606                 dscene->tri_woop.reference(&pack.tri_woop[0], pack.tri_woop.size());
607                 device->tex_alloc("__tri_woop", dscene->tri_woop);
608         }
609         if(pack.prim_visibility.size()) {
610                 dscene->prim_visibility.reference((uint*)&pack.prim_visibility[0], pack.prim_visibility.size());
611                 device->tex_alloc("__prim_visibility", dscene->prim_visibility);
612         }
613         if(pack.prim_index.size()) {
614                 dscene->prim_index.reference((uint*)&pack.prim_index[0], pack.prim_index.size());
615                 device->tex_alloc("__prim_index", dscene->prim_index);
616         }
617         if(pack.prim_object.size()) {
618                 dscene->prim_object.reference((uint*)&pack.prim_object[0], pack.prim_object.size());
619                 device->tex_alloc("__prim_object", dscene->prim_object);
620         }
621
622         dscene->data.bvh.root = pack.root_index;
623 }
624
625 void MeshManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
626 {
627         if(!need_update)
628                 return;
629
630         /* update normals */
631         foreach(Mesh *mesh, scene->meshes) {
632                 foreach(uint shader, mesh->used_shaders)
633                         if(scene->shaders[shader]->need_update_attributes)
634                                 mesh->need_update = true;
635
636                 if(mesh->need_update) {
637                         mesh->add_face_normals();
638                         mesh->add_vertex_normals();
639
640                         if(progress.get_cancel()) return;
641                 }
642         }
643
644         /* device update */
645         device_free(device, dscene);
646
647         device_update_mesh(device, dscene, scene, progress);
648         if(progress.get_cancel()) return;
649
650         device_update_attributes(device, dscene, scene, progress);
651         if(progress.get_cancel()) return;
652
653         /* update displacement */
654         bool displacement_done = false;
655
656         foreach(Mesh *mesh, scene->meshes)
657                 if(mesh->need_update && displace(device, scene, mesh, progress))
658                         displacement_done = true;
659
660         /* todo: properly handle cancel halfway displacement */
661         if(progress.get_cancel()) return;
662
663         /* device re-update after displacement */
664         if(displacement_done) {
665                 device_free(device, dscene);
666
667                 device_update_mesh(device, dscene, scene, progress);
668                 if(progress.get_cancel()) return;
669
670                 device_update_attributes(device, dscene, scene, progress);
671                 if(progress.get_cancel()) return;
672         }
673
674         /* update bvh */
675         size_t i = 0, num_instance_bvh = 0;
676
677         foreach(Mesh *mesh, scene->meshes)
678                 if(mesh->need_update && !mesh->transform_applied)
679                         num_instance_bvh++;
680
681         foreach(Mesh *mesh, scene->meshes) {
682                 if(mesh->need_update) {
683                         mesh->compute_bounds();
684
685                         if(!mesh->transform_applied) {
686                                 string msg = "Updating Mesh BVH ";
687                                 if(mesh->name == "")
688                                         msg += string_printf("%ld/%ld", i+1, num_instance_bvh);
689                                 else
690                                         msg += string_printf("%s %ld/%ld", mesh->name.c_str(), i+1, num_instance_bvh);
691                                 progress.set_status(msg, "Building BVH");
692
693                                 mesh->compute_bvh(&scene->params, progress);
694                         }
695
696                         if(progress.get_cancel()) return;
697
698                         mesh->need_update = false;
699                         mesh->need_update_rebuild = false;
700                 }
701
702                 i++;
703         }
704         
705         foreach(Shader *shader, scene->shaders)
706                 shader->need_update_attributes = false;
707
708         foreach(Object *object, scene->objects)
709                 object->compute_bounds();
710
711         if(progress.get_cancel()) return;
712
713         device_update_bvh(device, dscene, scene, progress);
714
715         need_update = false;
716 }
717
718 void MeshManager::device_free(Device *device, DeviceScene *dscene)
719 {
720         device->tex_free(dscene->bvh_nodes);
721         device->tex_free(dscene->object_node);
722         device->tex_free(dscene->tri_woop);
723         device->tex_free(dscene->prim_visibility);
724         device->tex_free(dscene->prim_index);
725         device->tex_free(dscene->prim_object);
726         device->tex_free(dscene->tri_normal);
727         device->tex_free(dscene->tri_vnormal);
728         device->tex_free(dscene->tri_vindex);
729         device->tex_free(dscene->tri_verts);
730         device->tex_free(dscene->attributes_map);
731         device->tex_free(dscene->attributes_float);
732         device->tex_free(dscene->attributes_float3);
733
734         dscene->bvh_nodes.clear();
735         dscene->object_node.clear();
736         dscene->tri_woop.clear();
737         dscene->prim_visibility.clear();
738         dscene->prim_index.clear();
739         dscene->prim_object.clear();
740         dscene->tri_normal.clear();
741         dscene->tri_vnormal.clear();
742         dscene->tri_vindex.clear();
743         dscene->tri_verts.clear();
744         dscene->attributes_map.clear();
745         dscene->attributes_float.clear();
746         dscene->attributes_float3.clear();
747 }
748
749 void MeshManager::tag_update(Scene *scene)
750 {
751         need_update = true;
752         scene->object_manager->need_update = true;
753 }
754
755 CCL_NAMESPACE_END
756