-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatchCache.h
85 lines (74 loc) · 2.28 KB
/
PatchCache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* CUDARadiosity 0.87a
* Copyright 2012 by David Sargeant, Patrick Gradie, Michael Rogers
*
* Based on code from rrv (Radiosity Renderer and Visualizer) by TODO
* Distributed under GPL (see <http://www.gnu.org/licenses/>)
*
*/
#ifndef PATCHCACHE_H
#define PATCHCACHE_H
/**
* @file PatchCache.h
* @brief Class PatchCache - cache for radiosity renderer.
* @author xdudka00
* @date 2007-11-18
*/
#include "PatchCacheLine.h"
#include <vector>
#include <queue>
class FormFactorEngine;
class PatchRandomAccessEnumerator;
/**
* Now using priority queue to optimal usage of given memory.
* @brief Cache for radiosity renderer.
*/
class PatchCache {
public:
/**
* @param patchEnumerator @b Shared instance of PatchRandomAccessEnumerator.
* @param ffTreshold Pair of patches with smaller form factor than formFactorTreshold will be ignored.
* @param maxCacheSize Maximum size of patch cache (in bytes).
* @note Maximum cache size is raw size (estimated). The real cache size can be greater.
*/
PatchCache(PatchRandomAccessEnumerator *patchEnumerator, float ffTreshold, long maxCacheSize);
~PatchCache();
/**
* This computation respectes form factor for each patch.
* @brief @return Return radiosity summarized from all patches.
* @param destPatch Destination patch to compute radiosity for.
*/
Color totalRadiosity(int destPatch);
/**
* @brief Return current patch cache size.
* @note This is raw size (estimated). The real cache size can be greater.
*/
long int cacheRawSize() const;
private:
PatchRandomAccessEnumerator *patchEnumerator_;
float ffTreshold_;
long maxCacheSize_;
size_t patchCount_;
FormFactorEngine *ffe_;
// Cache container (containing cache-lines)
typedef std::vector<PatchCacheLine*> TCache;
TCache *cache_;
long int cachedItems_;
// Priority queue used to optimize memory usage
class TQueueItem {
PatchCacheLine **cl_;
public:
TQueueItem(PatchCacheLine **cl): cl_(cl) { }
// Key of priority queue ordering
operator int() const {
return (*cl_)->itemCount();
}
// Return reference to pointer to cache-line
PatchCacheLine*& pCacheLine() const {
return (*cl_);
}
};
typedef std::priority_queue<TQueueItem> TQueue;
TQueue *cacheQueue_;
};
#endif // PATCHCACHE_H