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