Files
oak-editor/app/render/backend/rendercache.h
T
itsmattkc 5227e10f39 render one frame per thread for increased parallelism
If the nodes are now stateless, there's nothing stopping the renderer from
rendering multiple frames at once. Earlier since the nodes held some of their
input/output data (and that data could change per frame), it was not possible
to render multiple frames at once without conflicts. Now that the node state is
held in render threads, they can do whatever they want at any time.
2019-12-06 15:37:31 +11:00

65 lines
979 B
C++

#ifndef RENDERCACHE_H
#define RENDERCACHE_H
#include <QMap>
#include <QMutex>
template<class K, class V>
class RenderCache
{
public:
RenderCache() = default;
void Clear(){values_.clear();}
void Add(K key, V val){values_.insert(key, val);}
V Get(K key) const {return values_.value(key);}
bool Has(K key) const {return values_.contains(key);}
private:
QMap<K, V> values_;
};
template<class K, class V>
class ThreadSafeRenderCache
{
public:
ThreadSafeRenderCache() = default;
void Clear() {
lock_.lock();
values_.clear();
lock_.unlock();
}
void Add(K key, V val) {
lock_.lock();
values_.insert(key, val);
lock_.unlock();
}
V Get(K key) {
lock_.lock();
V val = values_.value(key);
lock_.unlock();
return val;
}
bool Has(K key) {
lock_.lock();
bool has = values_.contains(key);
lock_.unlock();
return has;
}
private:
QMap<K, V> values_;
QMutex lock_;
};
#endif // RENDERCACHE_H