Commit: 0cd3e5e72cf1e007ffd5d7f9893b740d5b5f1622
Author: Kévin Dietrich
Date:   Sat May 16 18:11:31 2015 +0200
Branches: openvdb
https://developer.blender.org/rB0cd3e5e72cf1e007ffd5d7f9893b740d5b5f1622

Cycles: early exit add_volume if we already have a sampler allocated.

This is done by means of a vector of structs which stores the grids'
information, including the grid slot, which is returned if we have a
match.

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

M       intern/cycles/render/openvdb.cpp
M       intern/cycles/render/openvdb.h

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

diff --git a/intern/cycles/render/openvdb.cpp b/intern/cycles/render/openvdb.cpp
index 2ba468e..6a465b1 100644
--- a/intern/cycles/render/openvdb.cpp
+++ b/intern/cycles/render/openvdb.cpp
@@ -58,6 +58,44 @@ int OpenVDBManager::add_volume(const string &filename, const 
string &name, int s
        using namespace openvdb;
        size_t slot = -1;
 
+       /* Find existing grid */
+       for(size_t i = 0; i < current_grids.size(); ++i) {
+               GridDescription grid = current_grids[i];
+
+               if(grid.filename == filename && grid.name == name) {
+                       if(grid.sampling == sampling) {
+                               return grid.slot;
+                       }
+                       /* sampling was changed, remove the sampler */
+                       else {
+                               if(grid_type == NODE_VDB_FLOAT) {
+                                       if(grid.sampling == 
OPENVDB_SAMPLE_POINT) {
+                                               delete 
float_samplers_p[grid.slot];
+                                               float_samplers_p[grid.slot] = 
NULL;
+                                       }
+                                       else {
+                                               delete 
float_samplers_b[grid.slot];
+                                               float_samplers_b[grid.slot] = 
NULL;
+                                       }
+                               }
+                               else {
+                                       if(grid.sampling == 
OPENVDB_SAMPLE_POINT) {
+                                               delete 
vec3s_samplers_p[grid.slot];
+                                               vec3s_samplers_p[grid.slot] = 
NULL;
+                                       }
+                                       else {
+                                               delete 
vec3s_samplers_b[grid.slot];
+                                               vec3s_samplers_b[grid.slot] = 
NULL;
+                                       }
+                               }
+
+                               /* remove grid description too */
+                               std::swap(current_grids[i], 
current_grids.back());
+                               current_grids.pop_back();
+                       }
+               }
+       }
+
        try {
                io::File file(filename);
                file.open();
@@ -126,6 +164,14 @@ int OpenVDBManager::add_volume(const string &filename, 
const string &name, int s
                catch_exceptions();
        }
 
+       GridDescription descr;
+       descr.filename = filename;
+       descr.name = name;
+       descr.sampling = sampling;
+       descr.slot = slot;
+
+       current_grids.push_back(descr);
+
        return slot;
 }
 
diff --git a/intern/cycles/render/openvdb.h b/intern/cycles/render/openvdb.h
index 1419e70..8c25058 100644
--- a/intern/cycles/render/openvdb.h
+++ b/intern/cycles/render/openvdb.h
@@ -28,7 +28,14 @@ class DeviceScene;
 class Progress;
 class Scene;
 
-class OpenVDBManager {
+class OpenVDBManager { 
+       struct GridDescription {
+               string filename;
+               string name;
+               int sampling;
+               int slot;
+       };
+
 public:
        OpenVDBManager();
        ~OpenVDBManager();
@@ -40,6 +47,7 @@ public:
 
        bool need_update;
 
+       vector<GridDescription> current_grids;
        vector<openvdb::FloatGrid::Ptr> scalar_grids;
        vector<openvdb::Vec3SGrid::Ptr> vector_grids;

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

Reply via email to