Beispiel #1
0
bool Framebuffer::assignDepthStencilBuffer(const TexturePointer& texture, const Format& format, uint32 subresource) {
    if (isSwapchain()) {
        return false;
    }

    Q_ASSERT(!texture || TextureUsageType::RENDERBUFFER == texture->getUsageType());

    // Check for the compatibility of size
    if (texture) {
        if (!validateTargetCompatibility(*texture)) {
            return false;
        }

        if (texture->source().empty()) {
            texture->setSource(_name + "::depthStencil");
        }
    }

    ++_depthStamp;
    updateSize(texture);

    // assign the new one
    _depthStencilBuffer = TextureView(texture, subresource, format);

    return true;
}
Beispiel #2
0
TexturePointer Texture::createExternal(const ExternalRecycler& recycler, const Sampler& sampler) {
    TexturePointer tex = std::make_shared<Texture>(TextureUsageType::EXTERNAL);
    tex->_type = TEX_2D;
    tex->_texelFormat = Element::COLOR_RGBA_32;
    tex->_maxMipLevel = 0;
    tex->_sampler = sampler;
    tex->setExternalRecycler(recycler);
    return tex;
}
Beispiel #3
0
TexturePointer Texture::create(TextureUsageType usageType, Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices, uint16 numMips, const Sampler& sampler)
{
    TexturePointer tex = std::make_shared<Texture>(usageType);
    tex->_storage.reset(new MemoryStorage());
    tex->_type = type;
    tex->_storage->assignTexture(tex.get());
    tex->resize(type, texelFormat, width, height, depth, numSamples, numSlices, numMips);

    tex->_sampler = sampler;

    return tex;
}
Beispiel #4
0
void Framebuffer::updateSize(const TexturePointer& texture) {
    if (!isEmpty()) {
        return;
    }

    if (texture) {
        _width = texture->getWidth();
        _height = texture->getHeight();
        _numSamples = texture->getNumSamples();
    } else {
        _width = _height = _numSamples = 0;
    }
}
Beispiel #5
0
// Render buffers
int Framebuffer::setRenderBuffer(uint32 slot, const TexturePointer& texture, uint32 subresource) {
    if (isSwapchain()) {
        return -1;
    }

    Q_ASSERT(!texture || TextureUsageType::RENDERBUFFER == texture->getUsageType());

    // Check for the slot
    if (slot >= getMaxNumRenderBuffers()) {
        return -1;
    }

    // Check for the compatibility of size
    if (texture) {
        if (!validateTargetCompatibility(*texture, subresource)) {
            return -1;
        }

        if (texture->source().empty()) {
            texture->setSource(_name + "::color::" + std::to_string(slot));
        }
    }

    ++_colorStamps[slot];

    updateSize(texture);

    // assign the new one
    _renderBuffers[slot] = TextureView(texture, subresource);

    // update the mask
    int mask = (1<<slot);
    _bufferMask = (_bufferMask & ~(mask));
    if (texture) {
        _bufferMask |= mask;
    }

    return slot;
}
    void update() override {
        gl::GLTexture* gltexture = nullptr;
        TexturePointer surface;
        if (_gpuObject.getColorStamps() != _colorStamps) {
            if (_gpuObject.hasColor()) {
                _colorBuffers.clear();
                static const GLenum colorAttachments[] = {
                    GL_COLOR_ATTACHMENT0,
                    GL_COLOR_ATTACHMENT1,
                    GL_COLOR_ATTACHMENT2,
                    GL_COLOR_ATTACHMENT3,
                    GL_COLOR_ATTACHMENT4,
                    GL_COLOR_ATTACHMENT5,
                    GL_COLOR_ATTACHMENT6,
                    GL_COLOR_ATTACHMENT7,
                    GL_COLOR_ATTACHMENT8,
                    GL_COLOR_ATTACHMENT9,
                    GL_COLOR_ATTACHMENT10,
                    GL_COLOR_ATTACHMENT11,
                    GL_COLOR_ATTACHMENT12,
                    GL_COLOR_ATTACHMENT13,
                    GL_COLOR_ATTACHMENT14,
                    GL_COLOR_ATTACHMENT15 };

                int unit = 0;
                auto backend = _backend.lock();
                for (auto& b : _gpuObject.getRenderBuffers()) {
                    surface = b._texture;
                    if (surface) {
                        Q_ASSERT(TextureUsageType::RENDERBUFFER == surface->getUsageType());
                        gltexture = backend->syncGPUObject(surface);
                    } else {
                        gltexture = nullptr;
                    }

                    if (gltexture) {
                        if (gltexture->_target == GL_TEXTURE_2D) {
                            glNamedFramebufferTexture(_id, colorAttachments[unit], gltexture->_texture, 0);
                        } else if (gltexture->_target == GL_TEXTURE_2D_MULTISAMPLE) {
                            glNamedFramebufferTexture(_id, colorAttachments[unit], gltexture->_texture, 0);
                        } else {
                            glNamedFramebufferTextureLayer(_id, colorAttachments[unit], gltexture->_texture, 0, b._subresource);
                        }
                        _colorBuffers.push_back(colorAttachments[unit]);
                    } else {
                        glNamedFramebufferTexture(_id, colorAttachments[unit], 0, 0);
                    }
                    unit++;
                }
            }
            _colorStamps = _gpuObject.getColorStamps();
        }

        GLenum attachement = GL_DEPTH_STENCIL_ATTACHMENT;
        if (!_gpuObject.hasStencil()) {
            attachement = GL_DEPTH_ATTACHMENT;
        } else if (!_gpuObject.hasDepth()) {
            attachement = GL_STENCIL_ATTACHMENT;
        }

        if (_gpuObject.getDepthStamp() != _depthStamp) {
            auto surface = _gpuObject.getDepthStencilBuffer();
            auto backend = _backend.lock();
            if (_gpuObject.hasDepthStencil() && surface) {
                Q_ASSERT(TextureUsageType::RENDERBUFFER == surface->getUsageType());
                gltexture = backend->syncGPUObject(surface);
            }

            if (gltexture) {
                if (gltexture->_target == GL_TEXTURE_2D) {
                    glNamedFramebufferTexture(_id, attachement, gltexture->_texture, 0);
                }
                else if (gltexture->_target == GL_TEXTURE_2D_MULTISAMPLE) {
                    glNamedFramebufferTexture(_id, attachement, gltexture->_texture, 0);
                } else {
                    glNamedFramebufferTextureLayer(_id, attachement, gltexture->_texture, 0,
                                                   _gpuObject.getDepthStencilBufferSubresource());
                }
            } else {
                glNamedFramebufferTexture(_id, attachement, 0, 0);
            }
            _depthStamp = _gpuObject.getDepthStamp();
        }

        // Last but not least, define where we draw
        if (!_colorBuffers.empty()) {
            glNamedFramebufferDrawBuffers(_id, (GLsizei)_colorBuffers.size(), _colorBuffers.data());
        } else {
            glNamedFramebufferDrawBuffer(_id, GL_NONE);
        }

        // Now check for completness
        _status = glCheckNamedFramebufferStatus(_id, GL_DRAW_FRAMEBUFFER);

        // restore the current framebuffer
        checkStatus();
    }