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