Basic Image AlgorithmS Library 2.8.0

OffscreenRendering.cpp

00001 #include <GLviewer/OffscreenRendering.hh>
00002 #include <OpenGLFramework/Base/glfScreen.hh>
00003 
00004 #ifdef BIAS_HAVE_CLASS_OFFSCREENRENDERING
00005 
00006 using namespace BIAS;
00007 using namespace std;
00008 
00009 OffscreenRendering::OffscreenRendering()
00010 {
00011   initialized_ = false;
00012 }
00013 
00014 OffscreenRendering::~OffscreenRendering()
00015 {
00016 }
00017 
00018 int OffscreenRendering::Init(int imgWidth, int imgHeight)
00019 {    
00020     try {
00021     
00022     depthBuffer_.Create(GL_DEPTH_COMPONENT24, imgWidth, imgHeight);
00023     colorBuffer_.Create(GL_RGBA8, imgWidth, imgHeight);
00024 
00025     fbo_.Create();
00026     fbo_.AttachRenderbuffer(depthBuffer_, GL_DEPTH_ATTACHMENT_EXT);
00027     fbo_.AttachRenderbuffer(colorBuffer_, GL_COLOR_ATTACHMENT0_EXT);
00028     fbo_.CheckComplete();
00029     fbo_.ClearDepthBuffer();
00030     fbo_.ClearColorBuffer();
00031     
00032     // bind default render target
00033     glfScreen::GetInstance().Bind();
00034   
00035   } catch (glfException& e) {
00036     BIASERR("Failed to create offscreen fbo: " << e.GetMessageString());
00037     return -1;
00038   }
00039   
00040   initialized_ = true;
00041   return 0;
00042 }
00043 
00044 bool OffscreenRendering::IsInitialized() const
00045 {
00046   return initialized_;
00047 }
00048 
00049 glfFramebufferObject* OffscreenRendering::GetFBO()
00050 {
00051   if(!initialized_){
00052     BIASWARN("OffscreenRendering has no valid framebuffer object, not initialised, returning NULL"); 
00053     return NULL;
00054   }
00055   return &fbo_;
00056 }
00057 
00058 #endif
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends