LCOV - code coverage report
Current view: top level - eq/util - texture.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 1 1 100.0 %
Date: 2014-06-18 Functions: 2 2 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2014, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                    2010, Cedric Stalder <cedric.stalder@gmail.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_TEXTURE_H
      20             : #define EQUTIL_TEXTURE_H
      21             : 
      22             : #include <eq/client/frame.h>        // Frame::Buffer enum
      23             : 
      24             : #include <lunchbox/thread.h>         // thread debug macro
      25             : 
      26             : namespace eq
      27             : {
      28             : namespace util
      29             : {
      30             : namespace detail { class Texture; }
      31             : 
      32             : /**
      33             :  * A wrapper around OpenGL textures.
      34             :  *
      35             :  * So far used by the Image and Compositor. The target is assumed to be
      36             :  * GL_TEXTURE_RECTANGLE_ARB or GL_TEXTURE_2D.
      37             :  */
      38             : class Texture : public boost::noncopyable
      39             : {
      40             : public:
      41             :     /**
      42             :      * Construct a new Texture.
      43             :      *
      44             :      * A GLEWContext might be provided later using setGLEWContext(). It is
      45             :      * needed for operations using OpenGL extensions or version 1.2 or later
      46             :      * functions.
      47             :      * @version 1.0
      48             :      */
      49             :     EQ_API Texture( const unsigned target,
      50             :                     const GLEWContext* const glewContext = 0 );
      51             : 
      52             :     /** Destruct the texture. @version 1.0 */
      53             :     EQ_API virtual ~Texture();
      54             : 
      55             :     /** @name Data Access. */
      56             :     //@{
      57             :     /** @return the target of the texture. @version 1.0 */
      58             :     EQ_API unsigned getTarget() const;
      59             : 
      60             :     /**
      61             :      * @internal
      62             :      * @return the compressor target corresponding to the texture target.
      63             :      */
      64             :     uint32_t getCompressorTarget() const;
      65             : 
      66             :     /**
      67             :      * @return the internal (GPU) pixel format of the texture.
      68             :      * @sa init()
      69             :      * @version 1.0
      70             :      */
      71             :     EQ_API unsigned getInternalFormat() const;
      72             : 
      73             :     /**
      74             :      * Set the external data format and type.
      75             :      *
      76             :      * @param format the OpenGL format.
      77             :      * @param type the OpenGL Type.
      78             :      * @version 1.0
      79             :      */
      80             :     EQ_API void setExternalFormat( const uint32_t format,
      81             :                                    const uint32_t type );
      82             : 
      83             :     /**
      84             :      * @return the external data format of the texture, e.g., GL_RGBA.
      85             :      * @version 1.0
      86             :      */
      87             :     EQ_API unsigned getFormat() const;
      88             : 
      89             :     /**
      90             :      * @return the external data type of the texture, e.g., GL_HALF_FLOAT.
      91             :      * @version 1.0
      92             :      */
      93             :     EQ_API unsigned getType() const;
      94             : 
      95             :     /** @return the OpenGL texture name. @version 1.0 */
      96             :     EQ_API unsigned getName() const;
      97             : 
      98             :     /** @return the current width. @version 1.0 */
      99             :     EQ_API int32_t getWidth() const;
     100             : 
     101             :     /** @return the current height. @version 1.0 */
     102             :     EQ_API int32_t getHeight() const;
     103             : 
     104             :     /** @return true if the texture can be bound. @version 1.0 */
     105             :     EQ_API bool isValid() const;
     106             :     //@}
     107             : 
     108             :     /** @name Operations. */
     109             :     //@{
     110             :     /**
     111             :      * Initialize an OpenGL texture.
     112             :      *
     113             :      * @param internalFormat the OpenGL texture internal format.
     114             :      * @param width the width of the texture.
     115             :      * @param height the height of the texture.
     116             :      * @version 1.0
     117             :      */
     118             :     EQ_API void init( const unsigned internalFormat, const int32_t width,
     119             :                       const int32_t height );
     120             : 
     121             :     /**
     122             :      * Clear the texture, including deleting the GL texture name.
     123             :      * @version 1.0
     124             :      */
     125             :     EQ_API void flush();
     126             : 
     127             :     /** @internal Apply the given texture filtering parameter. */
     128             :     void applyZoomFilter( const ZoomFilter filter ) const;
     129             : 
     130             :     void applyWrap() const; //<! @internal
     131             : 
     132             :     /**
     133             :      * Copy the specified area from the current read buffer to the
     134             :      * texture at 0,0.
     135             :      * @version 1.0
     136             :      */
     137             :     EQ_API void copyFromFrameBuffer( const unsigned internalFormat,
     138             :                                      const fabric::PixelViewport& pvp );
     139             : 
     140             :     /** Copy the specified buffer to the texture at 0,0. @version 1.0 */
     141             :     EQ_API void upload( const int32_t width, const int32_t height,
     142             :                         const void* ptr );
     143             : 
     144             :     /**
     145             :      * Copy the texture data from the GPU to the given memory address.
     146             :      * @version 1.0
     147             :      */
     148             :     EQ_API void download( void* buffer ) const;
     149             : 
     150             :     /** Bind the texture. @version 1.0 */
     151             :     EQ_API void bind() const;
     152             : 
     153             :     /** Create and bind a texture to the current FBO. @version 1.0 */
     154             :     EQ_API void bindToFBO( const unsigned target, const int32_t width,
     155             :                            const int32_t height );
     156             : 
     157             :     /** Resize the texture. @version 1.0 */
     158             :     EQ_API void resize( const int32_t width, const int32_t height );
     159             : 
     160             :     /** Write the texture data as an rgb image file. @version 1.0 */
     161             :     EQ_API void writeRGB( const std::string& filename ) const;
     162             :     //@}
     163             : 
     164             :     EQ_API const GLEWContext* glewGetContext() const;
     165             :     EQ_API void setGLEWContext( const GLEWContext* context );
     166             : 
     167             :     /** @name Wrap existing GL textures */
     168             :     //@{
     169             :     /**
     170             :      * Flush the texture without deleting the GL texture name.
     171             :      * @version 1.0
     172             :      */
     173             :     EQ_API void flushNoDelete();
     174             : 
     175             :     /**
     176             :      * Use an OpenGL texture created externally.
     177             :      *
     178             :      * The previous GL texture, if any, is deallocated using flush(). The new
     179             :      * texture has to be of the correct target, size and internal format. The
     180             :      * texture is validated by this method.
     181             :      *
     182             :      * @param id The OpenGL texture name.
     183             :      * @param internalFormat the OpenGL texture internal format.
     184             :      * @param width the width of the texture.
     185             :      * @param height the height of the texture.
     186             :      * @version 1.0
     187             :      */
     188             :     EQ_API void setGLData( const unsigned id, const unsigned internalFormat,
     189             :                            const int32_t width, const int32_t height );
     190             :     //@}
     191             : 
     192             : private:
     193             :     detail::Texture* const _impl;
     194             : 
     195             :     /**
     196             :      * Set the internal pixel format of the texture, e.g., GL_RGBA16F.
     197             :      *
     198             :      * Automatically sets the external format and type to one matching the
     199             :      * internal format.
     200             :      *
     201             :      * @param internalFormat the OpenGL internal texture format.
     202             :      */
     203             :     void _setInternalFormat( const unsigned internalFormat );
     204             : 
     205             :     /** Generate, if needed, a GL texture name. */
     206             :     void _generate();
     207             : 
     208             :     /** Set the size of the texture, updating the _defined flag. */
     209             :     void _grow( const int32_t width, const int32_t height );
     210             : 
     211        1780 :     LB_TS_VAR( _thread );
     212             : };
     213             : /** Print the texture state to the given output stream. @version 1.7.1 */
     214             : EQ_API std::ostream& operator << ( std::ostream&, const Texture& );
     215             : 
     216             : }
     217             : }
     218             : 
     219             : #endif // EQUTIL_TEXTURE_H

Generated by: LCOV version 1.10