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

This commit is contained in:
Tamito Kajiyama 2014-10-05 00:29:09 +09:00
parent 8fa55d95e4
commit 3fea13ed6c
4 changed files with 72 additions and 11 deletions

View File

@ -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();

View File

@ -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() {}

View File

@ -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 */

View File

@ -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")