mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 02:42:19 +02:00
Merge pull request #13078 from jherico/fix/14638
Make resource swapchains immutable
This commit is contained in:
commit
361fe75dc3
4 changed files with 23 additions and 28 deletions
|
@ -46,10 +46,10 @@ void GLBackend::do_setFramebuffer(const Batch& batch, size_t paramOffset) {
|
|||
}
|
||||
|
||||
void GLBackend::do_setFramebufferSwapChain(const Batch& batch, size_t paramOffset) {
|
||||
auto swapChain = batch._swapChains.get(batch._params[paramOffset]._uint);
|
||||
auto swapChain = std::static_pointer_cast<FramebufferSwapChain>(batch._swapChains.get(batch._params[paramOffset]._uint));
|
||||
if (swapChain) {
|
||||
auto index = batch._params[paramOffset + 1]._uint;
|
||||
FramebufferPointer framebuffer = static_cast<const FramebufferSwapChain*>(swapChain.get())->get(index);
|
||||
const auto& framebuffer = swapChain->get(index);
|
||||
setFramebuffer(framebuffer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ void GLBackend::do_setResourceFramebufferSwapChainTexture(const Batch& batch, si
|
|||
return;
|
||||
}
|
||||
|
||||
SwapChainPointer swapChain = batch._swapChains.get(batch._params[paramOffset + 0]._uint);
|
||||
auto swapChain = std::static_pointer_cast<FramebufferSwapChain>(batch._swapChains.get(batch._params[paramOffset + 0]._uint));
|
||||
|
||||
if (!swapChain) {
|
||||
releaseResourceTexture(slot);
|
||||
|
@ -276,9 +276,8 @@ void GLBackend::do_setResourceFramebufferSwapChainTexture(const Batch& batch, si
|
|||
}
|
||||
auto index = batch._params[paramOffset + 2]._uint;
|
||||
auto renderBufferSlot = batch._params[paramOffset + 3]._uint;
|
||||
FramebufferPointer resourceFramebuffer = static_cast<const FramebufferSwapChain*>(swapChain.get())->get(index);
|
||||
TexturePointer resourceTexture = resourceFramebuffer->getRenderBuffer(renderBufferSlot);
|
||||
|
||||
auto resourceFramebuffer = swapChain->get(index);
|
||||
auto resourceTexture = resourceFramebuffer->getRenderBuffer(renderBufferSlot);
|
||||
setResourceTexture(slot, resourceTexture);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,18 +15,18 @@ namespace gpu {
|
|||
class SwapChain {
|
||||
public:
|
||||
|
||||
SwapChain(unsigned int size = 2U) : _size{ size } {}
|
||||
SwapChain(uint8_t size = 2U) : _size{ size } {}
|
||||
virtual ~SwapChain() {}
|
||||
|
||||
void advance() {
|
||||
_frontIndex = (_frontIndex + 1) % _size;
|
||||
}
|
||||
|
||||
unsigned int getSize() const { return _size; }
|
||||
uint8_t getSize() const { return _size; }
|
||||
|
||||
protected:
|
||||
unsigned int _size;
|
||||
unsigned int _frontIndex{ 0U };
|
||||
const uint8_t _size;
|
||||
uint8_t _frontIndex{ 0U };
|
||||
|
||||
};
|
||||
typedef std::shared_ptr<SwapChain> SwapChainPointer;
|
||||
|
@ -41,16 +41,13 @@ namespace gpu {
|
|||
|
||||
using Type = R;
|
||||
using TypePointer = std::shared_ptr<R>;
|
||||
using TypeConstPointer = std::shared_ptr<const R>;
|
||||
|
||||
ResourceSwapChain(unsigned int size = 2U) : SwapChain{ size } {}
|
||||
|
||||
void reset() {
|
||||
for (auto& ptr : _resources) {
|
||||
ptr.reset();
|
||||
ResourceSwapChain(const std::vector<TypePointer>& v) : SwapChain{ std::min<uint8_t>((uint8_t)v.size(), MAX_SIZE) } {
|
||||
for (size_t i = 0; i < _size; ++i) {
|
||||
_resources[i] = v[i];
|
||||
}
|
||||
}
|
||||
|
||||
TypePointer& edit(unsigned int index) { return _resources[(index + _frontIndex) % _size]; }
|
||||
const TypePointer& get(unsigned int index) const { return _resources[(index + _frontIndex) % _size]; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -189,7 +189,6 @@ const int AntialiasingPass_NextMapSlot = 4;
|
|||
|
||||
Antialiasing::Antialiasing(bool isSharpenEnabled) :
|
||||
_isSharpenEnabled{ isSharpenEnabled } {
|
||||
_antialiasingBuffers = std::make_shared<gpu::FramebufferSwapChain>(2U);
|
||||
}
|
||||
|
||||
Antialiasing::~Antialiasing() {
|
||||
|
@ -325,25 +324,25 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const
|
|||
int width = sourceBuffer->getWidth();
|
||||
int height = sourceBuffer->getHeight();
|
||||
|
||||
if (_antialiasingBuffers->get(0)) {
|
||||
if (_antialiasingBuffers->get(0)->getSize() != uvec2(width, height)) {// || (sourceBuffer && (_antialiasingBuffer->getRenderBuffer(1) != sourceBuffer->getRenderBuffer(0)))) {
|
||||
_antialiasingBuffers->edit(0).reset();
|
||||
_antialiasingBuffers->edit(1).reset();
|
||||
_antialiasingTextures[0].reset();
|
||||
_antialiasingTextures[1].reset();
|
||||
}
|
||||
if (_antialiasingBuffers && _antialiasingBuffers->get(0) && _antialiasingBuffers->get(0)->getSize() != uvec2(width, height)) {
|
||||
_antialiasingBuffers.reset();
|
||||
_antialiasingTextures[0].reset();
|
||||
_antialiasingTextures[1].reset();
|
||||
}
|
||||
|
||||
if (!_antialiasingBuffers->get(0)) {
|
||||
|
||||
if (!_antialiasingBuffers) {
|
||||
std::vector<gpu::FramebufferPointer> antiAliasingBuffers;
|
||||
// Link the antialiasing FBO to texture
|
||||
auto format = sourceBuffer->getRenderBuffer(0)->getTexelFormat();
|
||||
auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR, gpu::Sampler::WRAP_CLAMP);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
auto& antiAliasingBuffer = _antialiasingBuffers->edit(i);
|
||||
antiAliasingBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("antialiasing"));
|
||||
antiAliasingBuffers.emplace_back(gpu::Framebuffer::create("antialiasing"));
|
||||
const auto& antiAliasingBuffer = antiAliasingBuffers.back();
|
||||
_antialiasingTextures[i] = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, defaultSampler);
|
||||
antiAliasingBuffer->setRenderBuffer(0, _antialiasingTextures[i]);
|
||||
}
|
||||
_antialiasingBuffers = std::make_shared<gpu::FramebufferSwapChain>(antiAliasingBuffers);
|
||||
}
|
||||
|
||||
gpu::doInBatch("Antialiasing::run", args->_context, [&](gpu::Batch& batch) {
|
||||
|
|
Loading…
Reference in a new issue