LCOV - code coverage report
Current view: top level - eq/util - frameBufferObject.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 2 9 22.2 %
Date: 2014-06-18 Functions: 3 8 37.5 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2008-2009, Cedric Stalder <cedric.stalder@gmail.com>
       3             :  *               2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #ifndef EQUTIL_FRAMEBUFFEROBJECT_H
      20             : #define EQUTIL_FRAMEBUFFEROBJECT_H
      21             : 
      22             : #include <eq/util/texture.h> // member
      23             : #include <eq/util/types.h>
      24             : 
      25             : #include <vector>
      26             : 
      27             : namespace eq
      28             : {
      29             : namespace util
      30             : {
      31             : /** A C++ class to abstract OpenGL frame buffer objects */
      32             : class FrameBufferObject
      33             : {
      34             : public:
      35             :     /** Construct a new Frame Buffer Object. @version 1.0 */
      36             :     EQ_API FrameBufferObject( const GLEWContext* const glewContext,
      37             :                               const unsigned textureTarget = 0x84F5
      38             :                               /*GL_TEXTURE_RECTANGLE_ARB*/ );
      39             : 
      40             :     /** Destruct the Frame Buffer Object. @version 1.0 */
      41             :     EQ_API ~FrameBufferObject();
      42             : 
      43             :     /**
      44             :      * Add one color texture to the FBO.
      45             :      *
      46             :      * The first color texture is automatically created in the constructor. The
      47             :      * maximum number of textures per FBO is 16. Added color textures will have
      48             :      * the same format as the existing texture(s). This method has to be called
      49             :      * on an uninitialized FBO.
      50             :      *
      51             :      * @return false if color texture can't be added, otherwise true.
      52             :      * @version 1.0
      53             :      */
      54             :     EQ_API bool addColorTexture();
      55             : 
      56             :     /**
      57             :      * Initialize the Frame Buffer Object.
      58             :      *
      59             :      * On successful initialization, the FBO is bound.
      60             :      *
      61             :      * @param width the initial width of the rendering buffer.
      62             :      * @param height the initial height of the rendering buffer.
      63             :      * @param colorFormat The internal color texture format, e.g., GL_RGBA.
      64             :      * @param depthSize The bit depth of the depth attachment.
      65             :      * @param stencilSize The bit depth of the stencil attachment.
      66             :      * @return ERROR_NONE on success, Error code on failure.
      67             :      * @sa resize()
      68             :      * @version 1.0
      69             :      */
      70             :     EQ_API Error init( const int32_t width, const int32_t height,
      71             :                        const unsigned colorFormat, const int32_t depthSize,
      72             :                        const int32_t stencilSize );
      73             : 
      74             :     /** De-initialize the Frame Buffer Object. @version 1.0 */
      75             :     EQ_API void exit();
      76             : 
      77             :     /**
      78             :      * Bind to the Frame Buffer Object.
      79             :      *
      80             :      * The FBO becomes the read and draw buffer of the current context.
      81             :      * @version 1.0
      82             :      */
      83             :     EQ_API void bind();
      84             : 
      85             :     /**
      86             :      * Unbind any Frame Buffer Object and use the default drawable for the
      87             :      * current context.
      88             :      * @version 1.0
      89             :      */
      90             :     EQ_API void unbind();
      91             : 
      92             :     /**
      93             :      * Resize the FBO.
      94             :      *
      95             :      * The FBO has to be initialized and bound. It is not changed if the size
      96             :      * does not change.
      97             :      *
      98             :      * @return true on success, false on error.
      99             :      * @return ERROR_NONE on success, Error code on failure.
     100             :      * @version 1.0
     101             :      */
     102             :     EQ_API Error resize( const int32_t width, const int32_t height );
     103             : 
     104             :     /** @return the current width. @version 1.0 */
     105           0 :     int32_t getWidth() const
     106           0 :         { LBASSERT( !_colors.empty( )); return _colors.front()->getWidth();}
     107             : 
     108             :     /** @return the current height. @version 1.0 */
     109           0 :     int32_t getHeight() const
     110           0 :         { LBASSERT( !_colors.empty()); return _colors.front()->getHeight();}
     111             : 
     112             :     /** @return the vector of color textures. @version 1.0 */
     113           0 :     const Textures& getColorTextures() const { return _colors; }
     114             : 
     115             :     /** @return the depth texture. @version 1.0 */
     116           0 :     const Texture& getDepthTexture() const { return _depth; }
     117             : 
     118             :     /** @return the GLEW context. @version 1.0 */
     119          26 :     const GLEWContext* glewGetContext() const { return _glewContext; }
     120             : 
     121             :     /** @return true if the fbo is valid. @version 1.0 */
     122           0 :     bool isValid() const { return _valid; }
     123             : 
     124             : private:
     125             :     unsigned _fboID; //!< the FBO GL name
     126             : 
     127             :     Textures _colors; //!< Multiple color textures
     128             :     Texture _depth;
     129             : 
     130             :     const GLEWContext* const _glewContext;
     131             : 
     132             :     bool _valid;
     133             : 
     134          26 :     LB_TS_VAR( _thread );
     135             : 
     136             :     /** Check the result after changes to an FBO and set the _valid flag. */
     137             :     Error _checkStatus();
     138             : };
     139             : }
     140             : }
     141             : 
     142             : #endif // EQUTIL_FRAMEBUFFEROBJECT_H

Generated by: LCOV version 1.10