OpenWalnut  1.4.0
WGEViewerEffectImageOverlay.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WGEVIEWEREFFECTIMAGEOVERLAY_H
00026 #define WGEVIEWEREFFECTIMAGEOVERLAY_H
00027 
00028 #include "core/common/WLogger.h"
00029 
00030 #include "WGEViewerEffect.h"
00031 
00032 class WGEViewer;
00033 
00034 /**
00035  * Image Overlay Effect.
00036  */
00037 class WGEViewerEffectImageOverlay: public WGEViewerEffect
00038 {
00039 public:
00040     /**
00041      * Convenience typedef for a boost::shared_ptr< WGEViewerEffectImageOverlay >.
00042      */
00043     typedef osg::ref_ptr< WGEViewerEffectImageOverlay > SPtr;
00044 
00045     /**
00046      * Convenience typedef for a boost::shared_ptr< const WGEViewerEffectImageOverlay >.
00047      */
00048     typedef osg::ref_ptr< const WGEViewerEffectImageOverlay > ConstSPtr;
00049 
00050     /**
00051      * Default constructor.
00052      */
00053     WGEViewerEffectImageOverlay();
00054 
00055     /**
00056      * Destructor.
00057      */
00058     virtual ~WGEViewerEffectImageOverlay();
00059 
00060     /**
00061      * Set the reference viewer. Needed as the effect itself is not able to query important camera states. This can be the viewer on which the
00062      * effect is applied but does not have to. Important is a valid WGECamera, including a properly setup viewport.
00063      *
00064      * \param viewer the viewer in which the effect is used.
00065      */
00066     void setReferenceViewer( boost::shared_ptr< WGEViewer > viewer );
00067 
00068     /**
00069      * Query current reference viewer.
00070      *
00071      * \return the reference viewer or NULL if none has been set.
00072      */
00073     const boost::shared_ptr< WGEViewer > getReferenceViewer() const;
00074 
00075 protected:
00076     /**
00077      * Width of the image in pixels.
00078      */
00079     osg::ref_ptr< osg::Uniform > m_overlayWidth;
00080 
00081     /**
00082      * Height of the image in pixels.
00083      */
00084     osg::ref_ptr< osg::Uniform > m_overlayHeight;
00085 
00086     /**
00087      * Width of the viewport in pixels.
00088      */
00089     osg::ref_ptr< osg::Uniform > m_viewportWidth;
00090 
00091     /**
00092      * Height of the viewport in pixels.
00093      */
00094     osg::ref_ptr< osg::Uniform > m_viewportHeight;
00095 
00096     /**
00097      * The viewer used to query the current reference cam.
00098      */
00099     boost::shared_ptr< WGEViewer > m_viewer;
00100 
00101     /**
00102      * The filename to load.
00103      */
00104     WPropFilename m_image;
00105 
00106     /**
00107      * The texture.
00108      */
00109     osg::ref_ptr< osg::Texture2D > m_logoTexture;
00110 
00111     /**
00112      * If true, the update callback is forced to reload the image.
00113      */
00114     bool m_forceReload;
00115 
00116 private:
00117     /**
00118      * Update the uniforms and textures if needed
00119      */
00120     class Updater: public osg::NodeCallback
00121     {
00122     public:
00123         /**
00124          * Called before draw on update
00125          *
00126          * \param node the node
00127          * \param nv the visitor calling this.
00128          */
00129         virtual void operator() ( osg::Node* node, osg::NodeVisitor* nv );
00130     };
00131     /**
00132      * Update callback for the viewport.
00133      */
00134     osg::ref_ptr< Updater > m_updater;
00135 };
00136 
00137 #endif  // WGEVIEWEREFFECTIMAGEOVERLAY_H
00138