Exemplo n.º 1
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);
}
Exemplo n.º 2
0
bool WrappedOpenGL::Serialise_glNamedFramebufferTexture2DEXT(GLuint framebuffer, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
{
	SERIALISE_ELEMENT(GLenum, Attach, attachment);
	SERIALISE_ELEMENT(ResourceId, id, GetResourceManager()->GetID(TextureRes(GetCtx(), texture)));
	SERIALISE_ELEMENT(GLenum, TexTarget, textarget);
	SERIALISE_ELEMENT(int32_t, Level, level);
	SERIALISE_ELEMENT(ResourceId, fbid, (framebuffer == 0 ? ResourceId() : GetResourceManager()->GetID(FramebufferRes(GetCtx(), framebuffer))));
	
	if(m_State < WRITING)
	{
		GLResource res = GetResourceManager()->GetLiveResource(id);
		if(fbid == ResourceId())
		{
			glNamedFramebufferTexture2DEXT(0, Attach, TexTarget, res.name, Level);
		}
		else
		{
			GLResource fbres = GetResourceManager()->GetLiveResource(fbid);
			glNamedFramebufferTexture2DEXT(fbres.name, Attach, TexTarget, res.name, Level);
		}

		if(m_State == READING)
		{
			m_Textures[GetResourceManager()->GetLiveID(id)].creationFlags |= eTextureCreate_RTV;
		}
	}

	return true;
}
    void init(size_t width, size_t height, const GLenum internalFormats[NbColorBuffers], GLenum filter) {
        m_nWidth = width;
        m_nHeight = height;

        // Allocation of the textures for each attribute and attachment to the FBO
        for(uint32_t i = 0; i < COLORBUFFER_COUNT; ++i) {
            m_ColorBuffers[i] = GLTexture2D();
            m_ColorBuffers[i].setStorage(1, internalFormats[i], width, height);
            m_ColorBuffers[i].setMinFilter(filter);
            m_ColorBuffers[i].setMagFilter(filter);

            glNamedFramebufferTexture2DEXT(m_Fbo.glId(), GL_COLOR_ATTACHMENT0 + i,
                                         GL_TEXTURE_2D, m_ColorBuffers[i].glId(), 0);

            // Add corresponding draw buffer GL constant
            m_DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
        }
    }
    bool init(size_t width, size_t height, const GLenum internalFormats[NbColorBuffers],
              GLenum depthInternalFormat, GLenum filter = GL_NEAREST) {
        ParentClass::init(width, height, internalFormats, filter);

        // Allocation and attachment of depth texture
        m_DepthBuffer = GLTexture2D();
        m_DepthBuffer.setStorage(1, depthInternalFormat, width, height);
        m_DepthBuffer.setMinFilter(filter);
        m_DepthBuffer.setMagFilter(filter);

        glNamedFramebufferTexture2DEXT(ParentClass::m_Fbo.glId(), GL_DEPTH_ATTACHMENT,
                                     GL_TEXTURE_2D, m_DepthBuffer.glId(), 0);

        // check that the FBO is complete
        GLenum status = glCheckNamedFramebufferStatusEXT(ParentClass::m_Fbo.glId(), GL_DRAW_FRAMEBUFFER);
        if(GL_FRAMEBUFFER_COMPLETE != status) {
            std::cerr << GLFramebufferErrorString(status) << std::endl;
            return false;
        }

        return true;
    }