LCOV - code coverage report
Current view: top level - eq/fabric - channel.h (source / functions) Hit Total Coverage
Test: Equalizer Lines: 41 61 67.2 %
Date: 2017-12-16 05:07:20 Functions: 33 126 26.2 %

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

Generated by: LCOV version 1.11