LCOV - code coverage report
Current view: top level - eq/fabric - channel.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 39 55 70.9 %
Date: 2014-06-18 Functions: 41 88 46.6 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2010-2013, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                    2010, Cedric Stalder <cedric.stalder@gmail.com>
       4             :  *                    2013, Julio Delgado Mangas <julio.delgadomangas@epfl.ch>
       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 EQFABRIC_CHANNEL_H
      21             : #define EQFABRIC_CHANNEL_H
      22             : 
      23             : #include <eq/fabric/object.h>        // base class
      24             : #include <eq/fabric/paths.h>
      25             : #include <eq/fabric/renderContext.h> // member
      26             : #include <eq/fabric/types.h>
      27             : 
      28             : namespace eq
      29             : {
      30             : namespace fabric
      31             : {
      32             : /** Base data transport class for channels. @sa eq::Channel */
      33             : template< class W, class C > class Channel : public Object
      34             : {
      35             : public:
      36             :     typedef LeafVisitor< C > Visitor; //!< The channel visitor type
      37             :     typedef W Parent; //!< The parent window type
      38             : 
      39             :     /**
      40             :      * The drawable format defines the components used as an alternate drawable
      41             :      * for this channel. If an alternate drawable is configured, the channel
      42             :      * uses the appropriate targets in place of the window's frame buffer.
      43             :      * @version 1.0
      44             :      */
      45             :     enum Drawable
      46             :     {
      47             :         FB_WINDOW   = LB_BIT_NONE, //!< Use the window's frame buffer
      48             :         FBO_COLOR   = LB_BIT1,     //!< Use an FBO for color values
      49             :         FBO_DEPTH   = LB_BIT2,     //!< Use an FBO for depth values
      50             :         FBO_STENCIL = LB_BIT3      //!< Use an FBO for stencil values
      51             :     };
      52             : 
      53             :     /** @name Data Access */
      54             :     //@{
      55             :     /** @internal Initialize this channel (calls virtual methods) */
      56             :     void init();
      57             : 
      58             :     /** @return the parent window. @version 1.0 */
      59        6183 :     W* getWindow() { return _window; }
      60             : 
      61             :     /** @return the parent window. @version 1.0 */
      62          54 :     const W* getWindow() const { return _window; }
      63             : 
      64             :     /** @internal @return the native view identifier and version. */
      65           0 :     bool isDestination() const
      66           0 :         { return _data.nativeContext.view.identifier != 0;}
      67             : 
      68             :     /** @internal Update the native view identifier and version. */
      69             :     void setViewVersion( const co::ObjectVersion& view );
      70             : 
      71             :     /** @internal @return the native view identifier and version. */
      72          13 :     const co::ObjectVersion& getViewVersion() const
      73          13 :         { return _data.nativeContext.view; }
      74             : 
      75             :     /** @internal Set the channel's pixel viewport wrt its parent window. */
      76             :     void setPixelViewport( const PixelViewport& pvp );
      77             : 
      78             :     /** @internal Set the channel's viewport wrt its parent window. */
      79             :     EQFABRIC_INL void setViewport( const Viewport& vp );
      80             : 
      81             :     /** @internal Notification that the vp/pvp has changed. */
      82             :     virtual void notifyViewportChanged();
      83             : 
      84             :     /** @return the native pixel viewport. @version 1.0 */
      85           0 :     const PixelViewport& getNativePixelViewport() const
      86           0 :         { return _data.nativeContext.pvp; }
      87             : 
      88             :     /** @return true if a viewport was specified last. @version 1.0 */
      89        1086 :     bool hasFixedViewport() const { return _data.fixedVP; }
      90             : 
      91             :     /**
      92             :      * Set the near and far planes for this channel.
      93             :      *
      94             :      * The given near and far planes update the current perspective and
      95             :      * orthographics frustum accordingly. Furthermore, they will be used in the
      96             :      * future by the server to compute the frusta.
      97             :      *
      98             :      * @param nearPlane the near plane.
      99             :      * @param farPlane the far plane.
     100             :      * @version 1.0
     101             :      */
     102             :     EQFABRIC_INL void setNearFar( const float nearPlane, const float farPlane );
     103             : 
     104             :     /**
     105             :      * @return the channel's framebuffer attachment configuration.
     106             :      * @version 1.0
     107             :      */
     108         509 :     uint32_t getDrawable() const { return _drawable; }
     109             : 
     110             :     /**
     111             :      * Perform a depth-first traversal of this channel.
     112             :      *
     113             :      * @param visitor the visitor.
     114             :      * @return the result of the visitor traversal.
     115             :      * @version 1.0
     116             :      */
     117             :     EQFABRIC_INL VisitorResult accept( Visitor& visitor );
     118             : 
     119             :     /** Const-version of accept(). @version 1.0 */
     120             :     EQFABRIC_INL VisitorResult accept( Visitor& visitor ) const;
     121             : 
     122             :     /**
     123             :      * Set the capabilities supported by the channel
     124             :      *
     125             :      * Channel which do not support all capabilities required by the current
     126             :      * destination view do not execute any tasks. The capabilities are an
     127             :      * application-defined bit mask. By default all bits are set.
     128             :      * @version 1.0
     129             :      */
     130             :     EQFABRIC_INL void setCapabilities( const uint64_t bitmask );
     131             : 
     132             :     /** @return the supported capabilities. @version 1.0 */
     133             :     EQFABRIC_INL uint64_t getCapabilities() const;
     134             : 
     135             :     /** @warning Undocumented - may not be supported in the future */
     136             :     EQFABRIC_INL void setMaxSize( const Vector2i& size );
     137             : 
     138             :     void setOverdraw( const Vector4i& overdraw ); //!< @internal
     139         368 :     const Vector2i& getMaxSize()  const { return _maxSize; } //!< @internal
     140             : 
     141             :     /** @internal @return the index path to this channel. */
     142             :     EQFABRIC_INL ChannelPath getPath() const;
     143             : 
     144             :     EQFABRIC_INL virtual void backup(); //!< @internal
     145             :     EQFABRIC_INL virtual void restore(); //!< @internal
     146             :     //@}
     147             : 
     148             :     /**
     149             :      * @name Context-specific data access.
     150             :      *
     151             :      * The data returned by these methods depends on the context (callback) they
     152             :      * are called from, typically the data for the current rendering task. If
     153             :      * they are called outside of a frame task method, they return the channel's
     154             :      * native parameter, e.g., a placeholder value for the task decomposition
     155             :      * parameters.
     156             :      */
     157             :     //@{
     158             :     /** @return the current draw buffer for glDrawBuffer. @version 1.0 */
     159          12 :     uint32_t getDrawBuffer() const { return _context->buffer; }
     160             : 
     161             :     /** @return the current read buffer for glReadBuffer. @version 1.0 */
     162          12 :     uint32_t getReadBuffer() const { return _context->buffer; }
     163             : 
     164             :     /** @return the current color mask for glColorMask. @version 1.0 */
     165          17 :     const ColorMask& getDrawBufferMask() const
     166          17 :         { return _context->bufferMask; }
     167             : 
     168             :     /**
     169             :      * @return the current pixel viewport for glViewport and glScissor.
     170             :      * @version 1.0
     171             :      */
     172         818 :     const PixelViewport& getPixelViewport() const { return _context->pvp; }
     173             : 
     174             :     /**
     175             :      * Select perspective or orthographic rendering.
     176             :      *
     177             :      * Influences the behaviour of getFrustum, getHeadTransform and the
     178             :      * corresponding apply methods in eq::Channel. Intended to be overwritten by
     179             :      * the implementation to select orthographic rendering.
     180             :      * @version 1.0
     181             :      */
     182          34 :     virtual bool useOrtho() const { return false; }
     183             : 
     184             :     /**
     185             :      * @return the current frustum for glFrustum or glOrtho.
     186             :      * @version 1.0
     187             :      */
     188          26 :     const Frustumf& getFrustum() const
     189          26 :         { return useOrtho() ? getOrtho() : getPerspective(); }
     190             : 
     191             :     /**
     192             :      * @return the current perspective frustum for glFrustum.
     193             :      * @version 1.0
     194             :      */
     195          30 :     const Frustumf& getPerspective() const { return _context->frustum; }
     196             : 
     197             :     /**
     198             :      * @return the current orthographic frustum for glOrtho.
     199             :      * @version 1.0
     200             :      */
     201           0 :     const Frustumf& getOrtho() const { return _context->ortho; }
     202             : 
     203             :     /**
     204             :      * Return the view matrix.
     205             :      *
     206             :      * The view matrix is part of the GL_MODEL*VIEW* matrix, and is typically
     207             :      * applied first to the GL_MODELVIEW matrix.
     208             :      *
     209             :      * @return the head transformation matrix
     210             :      * @version 1.0
     211             :      */
     212           0 :     const Matrix4f& getHeadTransform() const
     213           0 :         { return useOrtho() ? getOrthoTransform() : getPerspectiveTransform(); }
     214             : 
     215             :     /**
     216             :      * Return the perspective view matrix.
     217             :      *
     218             :      * The view matrix is part of the GL_MODEL*VIEW* matrix, and is typically
     219             :      * applied first to the GL_MODELVIEW matrix.
     220             :      *
     221             :      * @return the head transformation matrix
     222             :      * @version 1.0
     223             :      */
     224           4 :     const Matrix4f& getPerspectiveTransform() const
     225           4 :         { return _context->headTransform; }
     226             : 
     227             :     /**
     228             :      * Return the orthographic view matrix.
     229             :      *
     230             :      * The view matrix is part of the GL_MODEL*VIEW* matrix, and is typically
     231             :      * applied first to the GL_MODELVIEW matrix.
     232             :      *
     233             :      * @return the head transformation matrix
     234             :      * @version 1.0
     235             :      */
     236           0 :     const Matrix4f& getOrthoTransform() const
     237           0 :         { return _context->orthoTransform; }
     238             : 
     239             :     /**
     240             :      * @return the fractional viewport wrt the destination view.
     241             :      * @version 1.0
     242             :      */
     243        1095 :     const Viewport& getViewport() const { return _context->vp; }
     244             : 
     245             :     /**
     246             :      * @return the database range for the current rendering task.
     247             :      * @version 1.0
     248             :      */
     249           0 :     const Range& getRange() const { return _context->range; }
     250             : 
     251             :     /**
     252             :      * @return the pixel decomposition for the current rendering task.
     253             :      * @version 1.0
     254             :      */
     255           0 :     const Pixel& getPixel() const { return _context->pixel; }
     256             : 
     257             :     /**
     258             :      * @return the subpixel decomposition for the current rendering task.
     259             :      * @version 1.0
     260             :      */
     261           4 :     const SubPixel& getSubPixel() const { return _context->subpixel; }
     262             : 
     263             :     /**
     264             :      * @return the up/downscale zoom factor for the current rendering task.
     265             :      * @version 1.0
     266             :      */
     267           1 :     const Zoom& getZoom() const { return _context->zoom; }
     268             : 
     269             :     /**
     270             :      * @return the DPlex period for the current rendering task.
     271             :      * @version 1.0
     272             :      */
     273           0 :     uint32_t getPeriod() const { return _context->period; }
     274             : 
     275             :     /**
     276             :      * @return the DPlex phase for the current rendering task.
     277             :      * @version 1.0
     278             :      */
     279           0 :     uint32_t getPhase() const { return _context->phase; }
     280             : 
     281             :     /**
     282             :      * Get the channel's current position wrt the destination channel.
     283             :      *
     284             :      * Note that computing this value from the current viewport and pixel
     285             :      * viewport is inaccurate because it neglects rounding errors of the pixel
     286             :      * viewport done by the server.
     287             :      *
     288             :      * @return the channel's current position wrt the destination channel.
     289             :      * @version 1.0
     290             :      */
     291           0 :     const Vector2i& getPixelOffset() const { return _context->offset; }
     292             : 
     293             :     /** @return the currently rendered eye pass. @version 1.0 */
     294           8 :     Eye getEye() const { return _context->eye; }
     295             : 
     296             :     /** @warning Undocumented - may not be supported in the future */
     297         282 :     const Vector4i& getOverdraw() const { return _context->overdraw; }
     298             : 
     299             :     /** @warning Undocumented - may not be supported in the future */
     300          34 :     uint32_t getTaskID() const { return _context->taskID; }
     301             :     //@}
     302             : 
     303             :     /** @name Attributes */
     304             :     //@{
     305             :     // Note: also update string array initialization in channel.cpp
     306             :     /** Integer attributes for a channel. @version 1.0 */
     307             :     enum IAttribute
     308             :     {
     309             :         /** Statistics gathering mode (OFF, FASTEST [ON], NICEST) */
     310             :         IATTR_HINT_STATISTICS,
     311             :         /** Use a send token for output frames (OFF, ON) */
     312             :         IATTR_HINT_SENDTOKEN,
     313             :         IATTR_LAST,
     314             :         IATTR_ALL = IATTR_LAST + 5
     315             :     };
     316             : 
     317             :     /** String attributes. */
     318             :     enum SAttribute
     319             :     {
     320             :         SATTR_DUMP_IMAGE,
     321             :         SATTR_LAST,
     322             :         SATTR_ALL = SATTR_LAST + 5
     323             :     };
     324             : 
     325             :     /** @return the value of an integer attribute. @version 1.0 */
     326             :     EQFABRIC_INL int32_t getIAttribute( const IAttribute attr ) const;
     327             : 
     328             :     /** @return the value of a string attribute. @version 1.7.2 */
     329             :     EQFABRIC_INL std::string getSAttribute( const SAttribute attr ) const;
     330             : 
     331             :     /** @return the name of an integer attribute. @version 1.7.2 */
     332             :     EQFABRIC_INL static const std::string& getIAttributeString(
     333             :         const IAttribute attr );
     334             : 
     335             :     /** @return the name of an string attribute. @version 1.7.2 */
     336             :     EQFABRIC_INL static const std::string& getSAttributeString(
     337             :         const SAttribute attr );
     338             :     //@}
     339             : 
     340           0 :     virtual bool omitOutput() const { return false; } //!< @internal
     341           0 :     virtual void output( std::ostream& ) const {} //!< @internal
     342             : 
     343             : protected:
     344             :     /** Construct a new channel. @internal */
     345             :     EQFABRIC_INL Channel( W* parent );
     346             : 
     347             :     /** Construct a copy of a channel (view/segment dest). @internal */
     348             :     Channel( const Channel& from );
     349             : 
     350             :     /** Destruct the channel. @internal */
     351             :     EQFABRIC_INL virtual ~Channel();
     352             : 
     353             :     /** @internal */
     354             :     EQFABRIC_INL virtual void serialize( co::DataOStream& os,
     355             :                                          const uint64_t dirtyBits );
     356             :     /** @internal */
     357             :     EQFABRIC_INL virtual void deserialize( co::DataIStream& is,
     358             :                                            const uint64_t dirtyBits );
     359             : 
     360             :     /** @internal @sa Serializable::setDirty() */
     361             :     EQFABRIC_INL virtual void setDirty( const uint64_t bits );
     362             : 
     363             :     void setDrawable( const uint32_t drawable ); //!< @internal
     364             : 
     365             :     /** @name Render context access */
     366             :     //@{
     367             :     /** @internal Override the channel's native render context. */
     368          42 :     void overrideContext( RenderContext& context ) { _context = &context; }
     369             : 
     370             :     /** @internal Re-set the channel's native render context. */
     371          42 :     void resetContext() { _context = &_data.nativeContext; }
     372             : 
     373             :     /** @internal @return the current render context. */
     374           1 :     const RenderContext& getContext() const { return *_context; }
     375             : 
     376             :     /** @internal @return the native render context. */
     377          30 :     const RenderContext& getNativeContext() const
     378          30 :         { return _data.nativeContext; }
     379             :     //@}
     380             : 
     381             :     /** @internal */
     382        5852 :     void setIAttribute( const IAttribute attr, const int32_t value )
     383        5852 :         { _iAttributes[attr] = value; setDirty( DIRTY_ATTRIBUTES ); }
     384             : 
     385             :     /** @internal */
     386        5017 :     void setSAttribute( const SAttribute attr, const std::string& value )
     387        5017 :         { _sAttributes[attr] = value; setDirty( DIRTY_ATTRIBUTES ); }
     388             : 
     389             :     /** @internal */
     390         101 :     virtual ChangeType getChangeType() const { return UNBUFFERED; }
     391             : 
     392             :     enum DirtyBits
     393             :     {
     394             :         DIRTY_ATTRIBUTES    = Object::DIRTY_CUSTOM << 0, //   64
     395             :         DIRTY_VIEWPORT      = Object::DIRTY_CUSTOM << 1, //  128
     396             :         DIRTY_MEMBER        = Object::DIRTY_CUSTOM << 2, //  256
     397             :         DIRTY_FRUSTUM       = Object::DIRTY_CUSTOM << 3, //  512
     398             :         DIRTY_CAPABILITIES  = Object::DIRTY_CUSTOM << 4, // 1024
     399             :         DIRTY_CHANNEL_BITS =
     400             :         DIRTY_ATTRIBUTES | DIRTY_VIEWPORT | DIRTY_MEMBER |
     401             :         DIRTY_FRUSTUM | DIRTY_OBJECT_BITS
     402             :     };
     403             : 
     404             :     /** @internal @return the bits to be re-committed by the master. */
     405           8 :     virtual uint64_t getRedistributableBits() const
     406           8 :         { return DIRTY_CHANNEL_BITS; }
     407             : 
     408          15 :     virtual void updateCapabilities() {} //!< @internal
     409             : 
     410             : private:
     411             :     /** The parent window. */
     412             :     W* const _window;
     413             : 
     414        3060 :     struct BackupData
     415             :     {
     416        3958 :         BackupData() : capabilities( LB_BIT_ALL_64 ), fixedVP( true ) {}
     417             : 
     418             :         /** The native render context parameters of this channel. */
     419             :         RenderContext nativeContext;
     420             : 
     421             :         /** Bitmask of supported capabilities */
     422             :         uint64_t capabilities;
     423             : 
     424             :         /** true if the vp is immutable, false if the pvp is immutable */
     425             :         bool fixedVP;
     426             :     }
     427             :         _data, _backup;
     428             : 
     429             :     /** The current rendering context. */
     430             :     RenderContext* _context;
     431             : 
     432             :     /** Integer attributes. */
     433             :     int32_t _iAttributes[IATTR_ALL];
     434             : 
     435             :     /** String attributes. */
     436             :     std::string _sAttributes[SATTR_ALL];
     437             : 
     438             :     /** An alternate drawable config. */
     439             :     uint32_t _drawable;
     440             : 
     441             :     /** Overdraw limiter */
     442             :     Vector2i    _maxSize;
     443             : 
     444             :     struct Private;
     445             :     Private* _private; // placeholder for binary-compatible changes
     446             : };
     447             : 
     448             : template< class W, class C > EQFABRIC_INL
     449             : std::ostream& operator << ( std::ostream&, const Channel< W, C >& );
     450             : }
     451             : }
     452             : 
     453             : #endif // EQFABRIC_CHANNEL_H

Generated by: LCOV version 1.10