Beispiel #1
0
bool BlurInOutResource::updateResources(const gpu::FramebufferPointer& sourceFramebuffer, Resources& blurringResources) {
    if (!sourceFramebuffer) {
        return false;
    }
    if (_blurredFramebuffer && _blurredFramebuffer->getSize() != sourceFramebuffer->getSize()) {
        _blurredFramebuffer.reset();
    }

    if (!_blurredFramebuffer) {
        _blurredFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("blur"));

        // attach depthStencil if present in source
        //if (sourceFramebuffer->hasDepthStencil()) {
        //    _blurredFramebuffer->setDepthStencilBuffer(sourceFramebuffer->getDepthStencilBuffer(), sourceFramebuffer->getDepthStencilBufferFormat());
        //}
        auto blurringSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT);
        auto blurringTarget = gpu::TexturePointer(gpu::Texture::create2D(sourceFramebuffer->getRenderBuffer(0)->getTexelFormat(), sourceFramebuffer->getWidth(), sourceFramebuffer->getHeight(), blurringSampler));
        _blurredFramebuffer->setRenderBuffer(0, blurringTarget);
    } 

    blurringResources.sourceTexture = sourceFramebuffer->getRenderBuffer(0);
    blurringResources.blurringFramebuffer = _blurredFramebuffer;
    blurringResources.blurringTexture = _blurredFramebuffer->getRenderBuffer(0);

    if (_generateOutputFramebuffer) {
        if (_outputFramebuffer && _outputFramebuffer->getSize() != sourceFramebuffer->getSize()) {
            _outputFramebuffer.reset();
        }

        // The job output the blur result in a new Framebuffer spawning here.
        // Let s make sure it s ready for this
        if (!_outputFramebuffer) {
            _outputFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("blurOutput"));

            // attach depthStencil if present in source
         /*   if (sourceFramebuffer->hasDepthStencil()) {
                _outputFramebuffer->setDepthStencilBuffer(sourceFramebuffer->getDepthStencilBuffer(), sourceFramebuffer->getDepthStencilBufferFormat());
            }*/
            auto blurringSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT);
            auto blurringTarget = gpu::TexturePointer(gpu::Texture::create2D(sourceFramebuffer->getRenderBuffer(0)->getTexelFormat(), sourceFramebuffer->getWidth(), sourceFramebuffer->getHeight(), blurringSampler));
            _outputFramebuffer->setRenderBuffer(0, blurringTarget);
        }

        // Should be good to use the output Framebuffer as final
        blurringResources.finalFramebuffer = _outputFramebuffer;
    } else {
        // Just the reuse the input as output to blur itself.
        blurringResources.finalFramebuffer = sourceFramebuffer;
    }

    return true;
}
Beispiel #2
0
void FramebufferCache::releaseFramebuffer(const gpu::FramebufferPointer& framebuffer) {
    if (QSize(framebuffer->getSize().x, framebuffer->getSize().y) == _frameBufferSize) {
        _cachedFramebuffers.push_back(framebuffer);
    }
}
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);
    }
}