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;
	}
Exemple #2
0
GLFramebuffer::GLFramebuffer(const GLFramebufferDesc& desc)
   : _width(0)
   , _height(0)
{
   glGenFramebuffers(1, &_framebuffer_id);
   glNamedFramebufferParameteri(_framebuffer_id, GL_FRAMEBUFFER_DEFAULT_WIDTH, desc.default_width);
   glNamedFramebufferParameteri(_framebuffer_id, GL_FRAMEBUFFER_DEFAULT_HEIGHT, desc.default_height);

   for (const auto& attachment : desc.attachments)
   {
      auto cubemap = dynamic_cast<GLTextureCubemap*>(attachment.texture.get());
      if (cubemap)
      {
         for (int i = 0; i < 6; ++i)
            glNamedFramebufferTexture2DEXT(_framebuffer_id, attachment.attachment_type + i, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, attachment.texture->id(), attachment.texture_level);         
      }
      else
      {
         glNamedFramebufferTexture2DEXT(_framebuffer_id, attachment.attachment_type, GL_TEXTURE_2D, attachment.texture->id(), attachment.texture_level);
      }
      _width = attachment.texture->width();
      _height = attachment.texture->height();
      _attachments[attachment.attachment_type] = attachment.texture;
   }

   auto check = glCheckNamedFramebufferStatus(_framebuffer_id, GL_FRAMEBUFFER);
}
	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;
	}
    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;
    }
bool GLFramebufferObject::checkStatus( GLenum* pStatus )
{
    bool isComplete = false;

    GLenum status = glCheckNamedFramebufferStatus( m_id, GL_FRAMEBUFFER );
    switch( status )
    {
    case GL_FRAMEBUFFER_COMPLETE:
        isComplete = true;
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
        fprintf( stderr, "Framebuffer incomplete: incomplete attachment.\n" );
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
        fprintf( stderr, "Framebuffer incomplete: no attachments.\n" );
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
        fprintf( stderr,
            "Framebuffer incomplete: drawbuffer set to GL_NONE.\n" );
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
        fprintf( stderr,
            "framebuffer incpmplete: readbuffer set to GL_NONE.\n" );
        break;
    case GL_FRAMEBUFFER_UNSUPPORTED:
        fprintf( stderr, "Framebuffer incomplete: format unsupported.\n" );
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
        fprintf( stderr, "Framebuffer incomplete: inconsistent number of"
            " multisamples.\n" );
        break;
    case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
        fprintf( stderr, "Framebuffer incomplete: inconsistent layering.\n" );
    default:
        fprintf( stderr, "Can't get here!\n" );
        assert( false );
    }

    if( pStatus != nullptr )
    {
        *pStatus = status;
    }
    return isComplete;
}
GLenum AbstractFramebuffer::checkStatusImplementationDSA(const FramebufferTarget target) {
    return glCheckNamedFramebufferStatus(_id, GLenum(target));
}
Exemple #7
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);
    }
		u32 Framebuffer::checkStatus() const
		{
			return glCheckNamedFramebufferStatus(m_id, GL_FRAMEBUFFER);
		}
    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();
    }