void blitColor(const GLFramebuffer& source, int src_attachment, const GLFramebuffer* destination, int dst_attachment) { int destination_id = destination ? destination->id() : 0; glNamedFramebufferReadBuffer(source.id(), GL_COLOR_ATTACHMENT0 + src_attachment); if (destination) glNamedFramebufferDrawBuffer(destination_id, GL_COLOR_ATTACHMENT0 + dst_attachment); glBlitNamedFramebuffer(source.id(), destination_id, 0, 0, source.width(), source.height(), 0, 0, source.width(), source.height(), GL_COLOR_BUFFER_BIT, GL_NEAREST); }
kit::PixelBuffer::Ptr kit::PixelBuffer::create(glm::uvec2 resolution, kit::PixelBuffer::AttachmentList colorattachments) { kit::PixelBuffer::Ptr returner = std::make_shared<kit::PixelBuffer>(); returner->m_resolution = resolution; if(colorattachments.size() == 0) { KIT_GL(glNamedFramebufferDrawBuffer(returner->m_glHandle, GL_NONE)); } else { // Keep track of attachments and create a drawbuffers std::vector<GLenum> drawBuffers(colorattachments.size()); uint32_t currAttachment = 0; // Add/create color attachments for(auto & info : colorattachments) { // Fill the drawbuffer GLenum currEnum = GL_COLOR_ATTACHMENT0+ currAttachment; drawBuffers[currAttachment] = currEnum; currAttachment++; // Add texture if exists, otherwise create it if(info.texture != nullptr) { // Assert resolution if(info.texture->getResolution().x != resolution.x || info.texture->getResolution().y != resolution.y) { KIT_THROW("Pixelbuffer attachments must be of the same size"); } returner->m_colorAttachments.push_back(info.texture); KIT_GL(glNamedFramebufferTexture(returner->m_glHandle, currEnum, info.texture->getHandle(), 0)); } else { kit::Texture::Ptr adder = kit::Texture::create2D(resolution, info.format, info.edgeSamplingMode, info.minFilteringMode, info.magFilteringMode); returner->m_colorAttachments.push_back(adder); KIT_GL(glNamedFramebufferTexture(returner->m_glHandle, currEnum, adder->getHandle(), 0)); } } // Set drawbuffers KIT_GL(glNamedFramebufferDrawBuffers(returner->m_glHandle, (GLsizei)drawBuffers.size(), &drawBuffers[0])); } return returner; }
void AbstractFramebuffer::drawBufferImplementationDSA(const GLenum buffer) { glNamedFramebufferDrawBuffer(_id, buffer); }
void GLFramebuffer::setDrawColorBuffer(int color_attachment) { glNamedFramebufferDrawBuffer(id(), GL_COLOR_ATTACHMENT0 + color_attachment); }
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; for (auto& b : _gpuObject.getRenderBuffers()) { surface = b._texture; if (surface) { gltexture = gl::GLTexture::sync<GL45Backend::GL45Texture>(*_backend.lock().get(), surface, false); // Grab the gltexture and don't transfer } else { gltexture = nullptr; } if (gltexture) { glNamedFramebufferTexture(_id, colorAttachments[unit], gltexture->_texture, 0); _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(); if (_gpuObject.hasDepthStencil() && surface) { gltexture = gl::GLTexture::sync<GL45Backend::GL45Texture>(*_backend.lock().get(), surface, false); // Grab the gltexture and don't transfer } if (gltexture) { glNamedFramebufferTexture(_id, attachement, gltexture->_texture, 0); } 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(GL_DRAW_FRAMEBUFFER); }
void GLFramebufferObject::setDrawBuffer( GLenum attachment ) { glNamedFramebufferDrawBuffer( m_id, attachment ); }
void Framebuffer::drawBuffer(const Attachment attachment) const { glNamedFramebufferDrawBuffer(m_id, (u32)attachment); }
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(); }