OpenWalnut  1.5.0dev
WGEViewerEffectImageOverlay.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGEVIEWEREFFECTIMAGEOVERLAY_H
26 #define WGEVIEWEREFFECTIMAGEOVERLAY_H
27 
28 #include <memory>
29 
30 #include <osg/Texture2D>
31 
32 #include "WGEViewerEffect.h"
33 #include "callbacks/WGEShaderAnimationCallback.h"
34 #include "core/common/WLogger.h"
35 
36 class WGEViewer;
37 
38 /**
39  * Image Overlay Effect.
40  */
42 {
43 public:
44  /**
45  * Convenience typedef for a std::shared_ptr< WGEViewerEffectImageOverlay >.
46  */
47  typedef osg::ref_ptr< WGEViewerEffectImageOverlay > SPtr;
48 
49  /**
50  * Convenience typedef for a std::shared_ptr< const WGEViewerEffectImageOverlay >.
51  */
52  typedef osg::ref_ptr< const WGEViewerEffectImageOverlay > ConstSPtr;
53 
54  /**
55  * Default constructor.
56  */
58 
59  /**
60  * Destructor.
61  */
63 
64  /**
65  * 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
66  * effect is applied but does not have to. Important is a valid WGECamera, including a properly setup viewport.
67  *
68  * \param viewer the viewer in which the effect is used.
69  */
70  void setReferenceViewer( std::shared_ptr< WGEViewer > viewer );
71 
72  /**
73  * Query current reference viewer.
74  *
75  * \return the reference viewer or NULL if none has been set.
76  */
77  const std::shared_ptr< WGEViewer > getReferenceViewer() const;
78 
79 protected:
80  /**
81  * Width of the image in pixels.
82  */
83  osg::ref_ptr< osg::Uniform > m_overlayWidth;
84 
85  /**
86  * Height of the image in pixels.
87  */
88  osg::ref_ptr< osg::Uniform > m_overlayHeight;
89 
90  /**
91  * Width of the viewport in pixels.
92  */
93  osg::ref_ptr< osg::Uniform > m_viewportWidth;
94 
95  /**
96  * Height of the viewport in pixels.
97  */
98  osg::ref_ptr< osg::Uniform > m_viewportHeight;
99 
100  /**
101  * The viewer used to query the current reference cam.
102  */
103  std::shared_ptr< WGEViewer > m_viewer;
104 
105  /**
106  * The filename to load.
107  */
108  WPropFilename m_image;
109 
110  /**
111  * Enable to blend out the overlay.
112  */
113  WPropBool m_blendOutAuto;
114 
115  /**
116  * Time to blend out in seconds.
117  */
118  WPropDouble m_blendOutDuration;
119 
120  /**
121  * Animate blend out sequence
122  */
123  osg::ref_ptr< WGEShaderAnimationCallback > m_animationCallback;
124 
125  /**
126  * The texture.
127  */
128  osg::ref_ptr< osg::Texture2D > m_logoTexture;
129 
130  /**
131  * If true, the update callback is forced to reload the image.
132  */
134 
135 private:
136  /**
137  * Update the uniforms and textures if needed
138  */
139  class Updater: public osg::NodeCallback
140  {
141  public:
142  /**
143  * Called before draw on update
144  *
145  * \param node the node
146  * \param nv the visitor calling this.
147  */
148  virtual void operator() ( osg::Node* node, osg::NodeVisitor* nv );
149  };
150  /**
151  * Update callback for the viewport.
152  */
153  osg::ref_ptr< Updater > m_updater;
154 };
155 
156 #endif // WGEVIEWEREFFECTIMAGEOVERLAY_H
157 
Update the uniforms and textures if needed.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
Called before draw on update.
WPropBool m_blendOutAuto
Enable to blend out the overlay.
osg::ref_ptr< osg::Uniform > m_overlayWidth
Width of the image in pixels.
osg::ref_ptr< osg::Uniform > m_viewportHeight
Height of the viewport in pixels.
osg::ref_ptr< const WGEViewerEffectImageOverlay > ConstSPtr
Convenience typedef for a std::shared_ptr< const WGEViewerEffectImageOverlay >.
osg::ref_ptr< osg::Texture2D > m_logoTexture
The texture.
const std::shared_ptr< WGEViewer > getReferenceViewer() const
Query current reference viewer.
osg::ref_ptr< osg::Uniform > m_viewportWidth
Width of the viewport in pixels.
WPropFilename m_image
The filename to load.
osg::ref_ptr< WGEViewerEffectImageOverlay > SPtr
Convenience typedef for a std::shared_ptr< WGEViewerEffectImageOverlay >.
WPropDouble m_blendOutDuration
Time to blend out in seconds.
std::shared_ptr< WGEViewer > m_viewer
The viewer used to query the current reference cam.
WGEViewerEffectImageOverlay()
Default constructor.
osg::ref_ptr< osg::Uniform > m_overlayHeight
Height of the image in pixels.
osg::ref_ptr< Updater > m_updater
Update callback for the viewport.
osg::ref_ptr< WGEShaderAnimationCallback > m_animationCallback
Animate blend out sequence.
bool m_forceReload
If true, the update callback is forced to reload the image.
void setReferenceViewer(std::shared_ptr< WGEViewer > viewer)
Set the reference viewer.
Base class for implementing basic fullscreen effects for the WGEViewer.
Class for managing one view to the scene.
Definition: WGEViewer.h:71