예제 #1
0
	bool initFramebuffer()
	{
		glCreateFramebuffers(1, &FramebufferName);
		glNamedFramebufferTexture(FramebufferName, GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0);
		glNamedFramebufferTexture(FramebufferName, GL_DEPTH_ATTACHMENT, TextureName[texture::RENDERBUFFER], 0);

		return glCheckNamedFramebufferStatus(FramebufferName, GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
	}
예제 #2
0
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;
}
	bool initFramebuffer()
	{
		glCreateFramebuffers(framebuffer::MAX, &FramebufferName[0]);
		glNamedFramebufferTexture(FramebufferName[framebuffer::RENDER], GL_COLOR_ATTACHMENT0, TextureName[texture::MULTISAMPLE], 0);
		glNamedFramebufferTexture(FramebufferName[framebuffer::RESOLVE], GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0);

		if(glCheckNamedFramebufferStatus(FramebufferName[framebuffer::RENDER], GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
			return false;
		if(glCheckNamedFramebufferStatus(FramebufferName[framebuffer::RESOLVE], GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
			return false;

		return true;
	}
예제 #4
0
    void __init_frame_buffer()try {

        isOK=true;
        if (width_<=0) { throw QString("width is null"); }
        if (height_<=0) {throw QString("height is null");}

        glCreateFramebuffers(1,&fbo_);

        glCreateTextures(GL_TEXTURE_2D,1,&depth_texture_);
        glCreateTextures(GL_TEXTURE_2D,1,&color1_texture_);
        glCreateTextures(GL_TEXTURE_2D,1,&color0_texture_);

        glTextureStorage2D(depth_texture_,1,GL_DEPTH_COMPONENT32,width_,height_);
        glTextureStorage2D(color1_texture_,1,GL_RGB16F,width_,height_);
        glTextureStorage2D(color0_texture_,1,GL_RGB16F,width_,height_);

        glNamedFramebufferTexture(fbo_,GL_DEPTH_ATTACHMENT,depth_texture_,0);
        glNamedFramebufferTexture(fbo_,GL_COLOR_ATTACHMENT0,color0_texture_, 0 );
        glNamedFramebufferTexture(fbo_,GL_COLOR_ATTACHMENT1,color1_texture_, 0 );

#if defined(_DEBUG)
        /*check*/
        GLenum fboStatus = glCheckNamedFramebufferStatus(
            fbo_,GL_DRAW_FRAMEBUFFER);
        if (fboStatus!=GL_FRAMEBUFFER_COMPLETE){
            isOK=false;
            switch ( fboStatus )
            {
                case GL_FRAMEBUFFER_UNDEFINED: qDebug() << "GL_FRAMEBUFFER_UNDEFINED"; break;
                case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT"; break;
                case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT"; break;
                case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER"; break;
                case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER"; break;
                case GL_FRAMEBUFFER_UNSUPPORTED:qDebug() << "GL_FRAMEBUFFER_UNSUPPORTED"; break;
                case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE"; break;
                case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:qDebug() << "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS"; break;
                default:
                    break;
            }
            return ;
        }

#endif

    }/*__init_frame_buffer*/
    catch (const QString & error) {
        isOK=false;
        qDebug().noquote()<<error;
    }
예제 #5
0
void GLFramebufferObject::detach( GLenum attachment )
{
    GLenum type = getAttachedType( attachment );
    switch( type )
    {
    case GL_NONE:
        break;

    case GL_FRAMEBUFFER_DEFAULT:
        break;

    case GL_RENDERBUFFER:
        // 0 ==> detach
        glNamedFramebufferRenderbuffer( m_id, attachment, GL_RENDERBUFFER, 0 );
        break;

    case GL_TEXTURE:
        glNamedFramebufferTexture( m_id, attachment,
            0, // texture id, 0 ==> detach
            0 ); // mipmap level
        break;

    default:
        fprintf( stderr, "GLFramebufferObject::detach() ERROR: Unknown attached resource type\n" );
        assert( false );
        break;
    }
}
	bool initFramebuffer()
	{
		glCreateFramebuffers(1, &FramebufferName);
		glNamedFramebufferTexture(FramebufferName, GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0);

		return this->checkFramebuffer(FramebufferName);
	}
예제 #7
0
			Framebuffer& attachColorBuffer(Texture2D& texture,GLint level=0) noexcept
				{
			//	API defect?: Limited compile-time range, but the spec sais unlimited...
				static_assert(N>=0,"");
				static_assert((N<32 && GL_COLOR_ATTACHMENT0 + 32==GL_DEPTH_ATTACHMENT)
					|| (GL_COLOR_ATTACHMENT0 + 32!=GL_DEPTH_ATTACHMENT),"");

				glNamedFramebufferTexture(m_handle,N+GL_COLOR_ATTACHMENT0,texture.handle(),level);
				return *this;
				}
예제 #8
0
bool
OGLCoreFramebuffer::bindRenderTexture(GraphicsTexturePtr renderTexture, GLenum attachment, GLint level, GLint layer) noexcept
{
	assert(renderTexture);

	auto texture = renderTexture->downcast<OGLCoreTexture>();
	auto textureID = texture->getInstanceID();
	auto& textureDesc = renderTexture->getGraphicsTextureDesc();

	if (textureDesc.getTexDim() == GraphicsTextureDim::GraphicsTextureDim2DArray ||
		textureDesc.getTexDim() == GraphicsTextureDim::GraphicsTextureDimCube ||
		textureDesc.getTexDim() == GraphicsTextureDim::GraphicsTextureDimCubeArray)
	{
		glNamedFramebufferTextureLayer(_fbo, attachment, textureID, level, layer);
	}
	else
	{
		glNamedFramebufferTexture(_fbo, attachment, textureID, level);
	}

	return OGLCheck::checkError();
}
void FramebufferAttachment(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level)
{
	glNamedFramebufferTexture(framebuffer, attachment, texture, level);
}
예제 #10
0
    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);
    }
예제 #11
0
void GLFramebufferObject::attachTexture( GLenum attachment, GLTextureRectangle* pTexture, int mipmapLevel )
{
    glNamedFramebufferTexture( m_id, attachment, pTexture->id(), mipmapLevel );
}
예제 #12
0
		void Framebuffer::attachTexture(Attachment attachment, u32 textureId, u32 level) const
		{
			glNamedFramebufferTexture(m_id, (u32)attachment, textureId, level);
		}
예제 #13
0
    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();
    }
예제 #14
0
			Framebuffer& attachStencilBuffer(Texture2D& texture,GLint level) noexcept
				{
				glNamedFramebufferTexture(m_handle,GL_STENCIL_ATTACHMENT,texture.handle(),level);
				return *this;
				}
예제 #15
0
			Framebuffer& attachDepthBuffer(Texture2D& texture,GLint level) noexcept
				{
				glNamedFramebufferTexture(m_handle,GL_DEPTH_ATTACHMENT,texture.handle(),level);
				return *this;
				}