mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 18:55:01 +02:00
FramebufferCache, cleanup & thread safety
This commit is contained in:
parent
a455f3a435
commit
bb6abf11d3
2 changed files with 14 additions and 26 deletions
|
@ -11,34 +11,25 @@
|
|||
|
||||
#include "FramebufferCache.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <gpu/Format.h>
|
||||
#include <gpu/Framebuffer.h>
|
||||
|
||||
#include <QMap>
|
||||
#include <QQueue>
|
||||
#include <gpu/Batch.h>
|
||||
#include "RenderUtilsLogging.h"
|
||||
|
||||
static QQueue<gpu::FramebufferPointer> _cachedFramebuffers;
|
||||
|
||||
FramebufferCache::FramebufferCache() {
|
||||
}
|
||||
|
||||
FramebufferCache::~FramebufferCache() {
|
||||
_cachedFramebuffers.clear();
|
||||
}
|
||||
|
||||
void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) {
|
||||
//If the size changed, we need to delete our FBOs
|
||||
if (_frameBufferSize != frameBufferSize) {
|
||||
_frameBufferSize = frameBufferSize;
|
||||
_selfieFramebuffer.reset();
|
||||
_cachedFramebuffers.clear();
|
||||
_occlusionFramebuffer.reset();
|
||||
_occlusionTexture.reset();
|
||||
_occlusionBlurredFramebuffer.reset();
|
||||
_occlusionBlurredTexture.reset();
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
_cachedFramebuffers.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,8 +46,6 @@ void FramebufferCache::createPrimaryFramebuffer() {
|
|||
|
||||
auto smoothSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR);
|
||||
|
||||
|
||||
|
||||
resizeAmbientOcclusionBuffers();
|
||||
}
|
||||
|
||||
|
@ -87,7 +76,8 @@ void FramebufferCache::resizeAmbientOcclusionBuffers() {
|
|||
|
||||
|
||||
gpu::FramebufferPointer FramebufferCache::getFramebuffer() {
|
||||
if (_cachedFramebuffers.isEmpty()) {
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
if (_cachedFramebuffers.empty()) {
|
||||
_cachedFramebuffers.push_back(gpu::FramebufferPointer(gpu::Framebuffer::create(gpu::Element::COLOR_SRGBA_32, _frameBufferSize.width(), _frameBufferSize.height())));
|
||||
}
|
||||
gpu::FramebufferPointer result = _cachedFramebuffers.front();
|
||||
|
@ -96,6 +86,7 @@ gpu::FramebufferPointer FramebufferCache::getFramebuffer() {
|
|||
}
|
||||
|
||||
void FramebufferCache::releaseFramebuffer(const gpu::FramebufferPointer& framebuffer) {
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
if (QSize(framebuffer->getSize().x, framebuffer->getSize().y) == _frameBufferSize) {
|
||||
_cachedFramebuffers.push_back(framebuffer);
|
||||
}
|
||||
|
|
|
@ -11,13 +11,10 @@
|
|||
|
||||
#include <QSize>
|
||||
|
||||
#include <gpu/Framebuffer.h>
|
||||
#include <mutex>
|
||||
#include <gpu/Forward.h>
|
||||
#include <DependencyManager.h>
|
||||
|
||||
namespace gpu {
|
||||
class Batch;
|
||||
}
|
||||
|
||||
/// Stores cached textures, including render-to-texture targets.
|
||||
class FramebufferCache : public Dependency {
|
||||
SINGLETON_DEPENDENCY
|
||||
|
@ -47,9 +44,6 @@ public:
|
|||
void releaseFramebuffer(const gpu::FramebufferPointer& framebuffer);
|
||||
|
||||
private:
|
||||
FramebufferCache();
|
||||
virtual ~FramebufferCache();
|
||||
|
||||
void createPrimaryFramebuffer();
|
||||
|
||||
gpu::FramebufferPointer _shadowFramebuffer;
|
||||
|
@ -65,6 +59,9 @@ private:
|
|||
QSize _frameBufferSize{ 100, 100 };
|
||||
int _AOResolutionLevel = 1; // AO perform at half res
|
||||
|
||||
std::mutex _mutex;
|
||||
std::list<gpu::FramebufferPointer> _cachedFramebuffers;
|
||||
|
||||
// Resize/reallocate the buffers used for AO
|
||||
// the size of the AO buffers is scaled by the AOResolutionScale;
|
||||
void resizeAmbientOcclusionBuffers();
|
||||
|
|
Loading…
Reference in a new issue