/**************************************************************************** * Render Radiance Scaling * * Meshlab's plugin * * * * Copyright(C) 2010 * * Vergne Romain, Dumas Olivier * * INRIA - Institut Nationnal de Recherche en Informatique et Automatique * * * * All rights reserved. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * for more details. * * * ****************************************************************************/ #include "framebufferObject.h" #include #include using namespace std; std::vector _buffers; FramebufferObject::FramebufferObject() : fbo_id(0) { glGenFramebuffersEXT(1,&fbo_id); } FramebufferObject::~FramebufferObject() { glDeleteFramebuffersEXT(1,&fbo_id); } void FramebufferObject::attachTexture(GLenum tex_target,GLuint tex_id, GLenum attachment,int mip_level,int z_slice) { unbindCurrentBindThis(); glBindTexture(tex_target,tex_id); if(tex_target==GL_TEXTURE_1D) glFramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT,attachment, GL_TEXTURE_1D,tex_id,mip_level); else if(tex_target == GL_TEXTURE_3D) glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT,attachment, GL_TEXTURE_3D,tex_id,mip_level,z_slice); else glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,attachment, tex_target,tex_id,mip_level); unbindThisBindCurrent(); } void FramebufferObject::attachRenderBuffer(GLuint buff_id,GLenum attachment) { unbindCurrentBindThis(); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,attachment, GL_RENDERBUFFER_EXT,buff_id); unbindThisBindCurrent(); } void FramebufferObject::unattach(GLenum attachment) { unbindCurrentBindThis(); GLenum type = getAttachedType(attachment); switch(type){ case GL_RENDERBUFFER_EXT: attachRenderBuffer(0, attachment); break; case GL_TEXTURE: attachTexture(GL_TEXTURE_2D, 0, attachment); break; default: break; } unbindThisBindCurrent(); } void FramebufferObject::unattachAll() { int nb_attachments = getMaxColorAttachments(); for(int i=0;i