Commit: 3fea13ed6c0c1488b6f8a2853d76ca0872aabffd
Author: Tamito Kajiyama
Date:   Sun Oct 5 00:29:09 2014 +0900
Branches: master
https://developer.blender.org/rB3fea13ed6c0c1488b6f8a2853d76ca0872aabffd

Freestyle: Fix for view map caching not flashed properly in view port rendering.

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

M       source/blender/freestyle/intern/application/Controller.cpp
M       source/blender/freestyle/intern/scene_graph/NodeCamera.h
M       source/blender/freestyle/intern/scene_graph/SceneHash.cpp
M       source/blender/freestyle/intern/scene_graph/SceneHash.h

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

diff --git a/source/blender/freestyle/intern/application/Controller.cpp 
b/source/blender/freestyle/intern/application/Controller.cpp
index 86322bc..237176d 100644
--- a/source/blender/freestyle/intern/application/Controller.cpp
+++ b/source/blender/freestyle/intern/application/Controller.cpp
@@ -220,11 +220,10 @@ bool Controller::hitViewMapCache()
        if (!_EnableViewMapCache) {
                return false;
        }
-       real hashCode = sceneHashFunc.getValue();
-       if (prevSceneHash == hashCode) {
+       if (sceneHashFunc.match()) {
                return (NULL != _ViewMap);
        }
-       prevSceneHash = hashCode;
+       sceneHashFunc.store();
        return false;
 }
 
@@ -281,10 +280,26 @@ int Controller::LoadMesh(Render *re, SceneRenderLayer 
*srl)
                return 0;
 
        if (_EnableViewMapCache) {
+
+               NodeCamera *cam;
+               if (freestyle_proj[3][3] != 0.0)
+                       cam = new NodeOrthographicCamera;
+               else
+                       cam = new NodePerspectiveCamera;
+               double proj[16];
+               for (int i = 0; i < 4; i++) {
+                       for (int j = 0; j < 4; j++) {
+                               proj[i * 4 + j] = freestyle_proj[i][j];
+                       }
+               }
+               cam->setProjectionMatrix(proj);
+               _RootNode->AddChild(cam);
+
                sceneHashFunc.reset();
-               blenderScene->accept(sceneHashFunc);
+               //blenderScene->accept(sceneHashFunc);
+               _RootNode->accept(sceneHashFunc);
                if (G.debug & G_DEBUG_FREESTYLE) {
-                       printf("Scene hash       : %.16e\n", 
sceneHashFunc.getValue());
+                       cout << "Scene hash       : " << 
sceneHashFunc.toString() << endl;
                }
                if (hitViewMapCache()) {
                        ClearRootNode();
diff --git a/source/blender/freestyle/intern/scene_graph/NodeCamera.h 
b/source/blender/freestyle/intern/scene_graph/NodeCamera.h
index 5d84a62..78c34fd 100644
--- a/source/blender/freestyle/intern/scene_graph/NodeCamera.h
+++ b/source/blender/freestyle/intern/scene_graph/NodeCamera.h
@@ -53,7 +53,9 @@ public:
 
        /*! Default matrices: Identity for both projection and modelview. */
        NodeCamera(CameraType camera_type = GENERIC); 
+#if 0  /* UNUSED, gives warning in gcc */
        NodeCamera(const NodeCamera& iBrother);
+#endif
 
        virtual ~NodeCamera() {}
 
diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.cpp 
b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp
index 6e8856f..60b95aa 100644
--- a/source/blender/freestyle/intern/scene_graph/SceneHash.cpp
+++ b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp
@@ -24,16 +24,47 @@
 
 #include "SceneHash.h"
 
+#include <sstream>
+
 namespace Freestyle {
 
+string SceneHash::toString()
+{
+        stringstream ss;
+        ss << hex << _sum;
+        return ss.str();
+}
+
+void SceneHash::visitNodeCamera(NodeCamera& cam)
+{
+       double *proj = cam.projectionMatrix();
+       for (int i = 0; i < 16; i++) {
+               adler32((unsigned char *)&proj[i], sizeof(double));
+       }
+}
+
 void SceneHash::visitIndexedFaceSet(IndexedFaceSet& ifs)
 {
        const real *v = ifs.vertices();
        const unsigned n = ifs.vsize();
 
        for (unsigned i = 0; i < n; i++) {
-               _hashcode += v[i];
+               adler32((unsigned char *)&v[i], sizeof(v[i]));
+       }
+}
+
+static const int MOD_ADLER = 65521;
+
+void SceneHash::adler32(unsigned char *data, int size)
+{
+       uint32_t sum1 = _sum & 0xffff;
+       uint32_t sum2 = (_sum >> 16) & 0xffff;
+
+       for (int i = 0; i < size; i++) {
+               sum1 = (sum1 + data[i]) % MOD_ADLER;
+               sum2 = (sum1 + sum2) % MOD_ADLER;
        }
+       _sum = sum1 | (sum2 << 16);
 }
 
 } /* namespace Freestyle */
diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.h 
b/source/blender/freestyle/intern/scene_graph/SceneHash.h
index 8f5f847..5521b79 100644
--- a/source/blender/freestyle/intern/scene_graph/SceneHash.h
+++ b/source/blender/freestyle/intern/scene_graph/SceneHash.h
@@ -26,8 +26,11 @@
  */
 
 #include "IndexedFaceSet.h"
+#include "NodeCamera.h"
 #include "SceneVisitor.h"
 
+#include "BLI_sys_types.h"
+
 #ifdef WITH_CXX_GUARDEDALLOC
 #include "MEM_guardedalloc.h"
 #endif
@@ -39,23 +42,33 @@ class SceneHash : public SceneVisitor
 public:
        inline SceneHash() : SceneVisitor()
        {
-               _hashcode = 0.0;
+               _sum = 1;
        }
 
        virtual ~SceneHash() {}
 
+       VISIT_DECL(NodeCamera)
        VISIT_DECL(IndexedFaceSet)
 
-       inline real getValue() {
-               return _hashcode;
+       string toString();
+
+       inline bool match() {
+               return _sum == _prevSum;
+       }
+
+       inline void store() {
+               _prevSum = _sum;
        }
 
        inline void reset() {
-               _hashcode = 0.0;
+               _sum = 1;
        }
 
 private:
-       real _hashcode;
+       void adler32(unsigned char *data, int size);
+
+       uint32_t _sum;
+       uint32_t _prevSum;
 
 #ifdef WITH_CXX_GUARDEDALLOC
        MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SceneHash")

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

Reply via email to