osWindow.cpp

00001 
00002 /* Copyright (c) 2005-2009, Stefan Eilemann <eile@equalizergraphics.com>
00003                           , Makhinya Maxim
00004  *
00005  * This library is free software; you can redistribute it and/or modify it under
00006  * the terms of the GNU Lesser General Public License version 2.1 as published
00007  * by the Free Software Foundation.
00008  *  
00009  * This library is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00012  * details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this library; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #include "osWindow.h"
00020 
00021 #include "frameBufferObject.h"
00022 #include "global.h"
00023 #include "pipe.h"
00024 
00025 using namespace std;
00026 
00027 namespace eq
00028 {
00029 
00030 OSWindow::OSWindow( Window* parent )
00031     : _window( parent )
00032     , _glewContext( new GLEWContext )
00033     , _glewInitialized( false )
00034     , _fbo( 0 )
00035 {
00036     EQASSERT( _window ); 
00037 }
00038 
00039 OSWindow::~OSWindow()
00040 {
00041     delete _glewContext;
00042     _glewContext = 0;
00043     _glewInitialized = false;
00044 }
00045 
00046 const Pipe* OSWindow::getPipe() const
00047 {
00048     EQASSERT( _window );
00049     return _window->getPipe();
00050 }
00051 Pipe* OSWindow::getPipe()
00052 {
00053     EQASSERT( _window );
00054     return _window->getPipe();
00055 }
00056 
00057 const Node* OSWindow::getNode() const
00058 {
00059     EQASSERT( _window );
00060     return _window->getNode();
00061 }
00062 Node* OSWindow::getNode()
00063 {
00064     EQASSERT( _window );
00065     return _window->getNode();
00066 }
00067 
00068 const Config* OSWindow::getConfig() const
00069 {
00070     EQASSERT( _window );
00071     return _window->getConfig();
00072 }
00073 Config* OSWindow::getConfig()
00074 {
00075     EQASSERT( _window );
00076     return _window->getConfig();
00077 }
00078 
00079 int32_t OSWindow::getIAttribute( const Window::IAttribute attr ) const
00080 {
00081     EQASSERT( _window );
00082     return _window->getIAttribute( attr );
00083 }
00084 
00085 WGLEWContext* OSWindow::wglewGetContext()
00086 {
00087     EQASSERT( _window );
00088     return _window->wglewGetContext();
00089 }
00090 
00091 void OSWindow::initGLEW()
00092 {
00093     if( _glewInitialized )
00094         return;
00095 
00096     const GLenum result = glewInit();
00097     if( result != GLEW_OK )
00098         _window->setErrorMessage( "GLEW initialization failed: " + result );
00099     else
00100         _glewInitialized = true;
00101 }
00102     
00103 bool OSWindow::configInitFBO()
00104 {
00105     if( !_glewInitialized ||
00106         !GLEW_ARB_texture_non_power_of_two ||
00107         !GLEW_EXT_framebuffer_object )
00108     {
00109         _window->setErrorMessage( "Framebuffer objects unsupported" );
00110          return false;
00111     }
00112     
00113     // needs glew initialized (see above)
00114     _fbo = new FrameBufferObject( _glewContext );
00115     _fbo->setColorFormat( _window->getColorType());
00116     
00117     const PixelViewport& pvp = _window->getPixelViewport();
00118     
00119     int depthSize = getIAttribute( Window::IATTR_PLANES_DEPTH );
00120     if( depthSize == AUTO )
00121          depthSize = 24;
00122 
00123     int stencilSize = getIAttribute( Window::IATTR_PLANES_STENCIL );
00124     if( stencilSize == AUTO )
00125         stencilSize = 1;
00126 
00127     if( _fbo->init( pvp.w, pvp.h, depthSize, stencilSize ) )
00128         return true;
00129     
00130     _window->setErrorMessage( "FBO initialization failed: " + 
00131                               _fbo->getErrorMessage( ));
00132     delete _fbo;
00133     _fbo = 0;
00134     return false;
00135 }
00136 
00137 void OSWindow::configExitFBO()
00138 {   
00139     if( _fbo )
00140         _fbo->exit();
00141 
00142     delete _fbo;
00143     _fbo = 0;
00144 }
00145 
00146 void OSWindow::makeCurrent() const 
00147 {
00148     bindFrameBuffer();
00149     getPipe()->setCurrent( _window );
00150 }
00151 
00152 void OSWindow::bindFrameBuffer() const 
00153 {
00154    if( !_glewInitialized )
00155        return;
00156     
00157    if( _fbo )
00158        _fbo->bind();
00159    else if( GLEW_EXT_framebuffer_object )
00160        glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
00161 }
00162 
00163 }
Generated on Mon Aug 10 18:58:40 2009 for Equalizer 0.9 by  doxygen 1.5.8