LCOV - code coverage report
Current view: top level - eq/util - texture.h (source / functions) Hit Total Coverage
Test: Equalizer Lines: 1 1 100.0 %
Date: 2016-07-30 05:04:55 Functions: 2 2 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2015, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                          Cedric Stalder <cedric.stalder@gmail.com>
       4             :  *                          Daniel Nachbaur <danielnachbaur@gmail.com>
       5             :  *
       6             :  * This library is free software; you can redistribute it and/or modify it under
       7             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       8             :  * by the Free Software Foundation.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      11             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      12             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      13             :  * details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      17             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             :  */
      19             : 
      20             : #ifndef EQUTIL_TEXTURE_H
      21             : #define EQUTIL_TEXTURE_H
      22             : 
      23             : #include <eq/frame.h> // Frame::Buffer enum
      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
      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             :     EQ_API void applyZoomFilter( const ZoomFilter filter ) const;
     129             : 
     130             :     EQ_API 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, const int32_t samples = 1 );
     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             :     Texture( const Texture& ) = delete;
     194             :     Texture& operator=( const Texture& ) = delete;
     195             :     detail::Texture* const _impl;
     196             : 
     197             :     /**
     198             :      * Set the internal pixel format of the texture, e.g., GL_RGBA16F.
     199             :      *
     200             :      * Automatically sets the external format and type to one matching the
     201             :      * internal format.
     202             :      *
     203             :      * @param internalFormat the OpenGL internal texture format.
     204             :      */
     205             :     void _setInternalFormat( const unsigned internalFormat );
     206             : 
     207             :     /** Generate, if needed, a GL texture name. */
     208             :     void _generate();
     209             : 
     210             :     /** Set the size of the texture, updating the _defined flag. */
     211             :     void _grow( const int32_t width, const int32_t height );
     212             : 
     213        1648 :     LB_TS_VAR( _thread );
     214             : };
     215             : /** Print the texture state to the given output stream. @version 1.7.1 */
     216             : EQ_API std::ostream& operator << ( std::ostream&, const Texture& );
     217             : 
     218             : }
     219             : }
     220             : 
     221             : #endif // EQUTIL_TEXTURE_H

Generated by: LCOV version 1.11