From 3fea13ed6c0c1488b6f8a2853d76ca0872aabffd Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Sun, 5 Oct 2014 00:29:09 +0900 Subject: Freestyle: Fix for view map caching not flashed properly in view port rendering. --- .../freestyle/intern/application/Controller.cpp | 25 ++++++++++++---- .../freestyle/intern/scene_graph/NodeCamera.h | 2 ++ .../freestyle/intern/scene_graph/SceneHash.cpp | 33 +++++++++++++++++++++- .../freestyle/intern/scene_graph/SceneHash.h | 23 +++++++++++---- 4 files changed, 72 insertions(+), 11 deletions(-) (limited to 'source/blender/freestyle/intern') diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp index 86322bcd350..237176df5e3 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 5d84a624830..78c34fdef6d 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 6e8856f1b93..60b95aaf6c5 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 + 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 8f5f847eaab..5521b792e89 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") -- cgit v1.2.3