OpenWalnut 1.3.1
|
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 WGETEXTUREHUD_H 00026 #define WGETEXTUREHUD_H 00027 00028 #include <list> 00029 #include <string> 00030 00031 #include <boost/thread.hpp> 00032 00033 #include <osg/Projection> 00034 #include <osg/Geode> 00035 #include <osg/Texture2D> 00036 #include <osg/TexMat> 00037 00038 #include "WGEGroupNode.h" 00039 00040 /** 00041 * This class implements a HUD showing several textures on screen. This is especially useful as debugging tool during offscreen rendering. It is 00042 * possible to add and remove textures to it. The size of the texture on screen depends on the screen size, as well as the layout of each texture 00043 * depends on the screen size. 00044 */ 00045 class WGETextureHud: public osg::Projection 00046 { 00047 public: 00048 /** 00049 * Default constructor. 00050 */ 00051 WGETextureHud(); 00052 00053 /** 00054 * Destructor. 00055 */ 00056 virtual ~WGETextureHud(); 00057 00058 /** 00059 * Class implementing one texture HUD entry representing a texture in the HUD. 00060 */ 00061 class WGETextureHudEntry: public osg::MatrixTransform 00062 { 00063 public: // NOLINT 00064 /** 00065 * Constructor. 00066 * 00067 * \param texture the texture to show in the HUD 00068 * \param name a telling name to support the illustrative function of the HUD 00069 * \param transparency true if transparency should be shown 00070 */ 00071 WGETextureHudEntry( osg::ref_ptr< osg::Texture2D > texture, std::string name, bool transparency = false ); 00072 00073 /** 00074 * Destructor. 00075 */ 00076 ~WGETextureHudEntry(); 00077 00078 /** 00079 * Returns the real width of the contained texture. 00080 * 00081 * \return the real width. 00082 */ 00083 unsigned int getRealWidth() const; 00084 00085 /** 00086 * Returns the real height of the contained texture. 00087 * 00088 * \return the real height. 00089 */ 00090 unsigned int getRealHeight() const; 00091 00092 /** 00093 * Get the texture matrix state for this entry. 00094 * 00095 * \return the texture matrix state 00096 */ 00097 osg::ref_ptr< osg::TexMat > getTextureMatrix() const; 00098 00099 /** 00100 * Returns the name of the entry. 00101 * 00102 * \return name of the entry. 00103 */ 00104 std::string getName() const; 00105 00106 /** 00107 * Gets the texture associated with the entry. 00108 * 00109 * \return the texture 00110 */ 00111 osg::ref_ptr< osg::Texture2D > getTexture() const; 00112 00113 protected: 00114 /** 00115 * The texture. 00116 */ 00117 osg::ref_ptr< osg::Texture2D > m_texture; 00118 00119 /** 00120 * The texture matrix for this entry. 00121 */ 00122 osg::ref_ptr< osg::TexMat > m_texMat; 00123 00124 /** 00125 * The name for this HUD entry. 00126 */ 00127 std::string m_name; 00128 00129 private: 00130 }; 00131 00132 /** 00133 * Adds the specified HUD element to the HUD. 00134 * 00135 * \param texture the texture to show. 00136 */ 00137 void addTexture( osg::ref_ptr< WGETextureHudEntry > texture ); 00138 00139 /** 00140 * Remove the texture from the HUD. 00141 * 00142 * \param texture the texture to remove. 00143 */ 00144 void removeTexture( osg::ref_ptr< WGETextureHudEntry > texture ); 00145 00146 /** 00147 * Remove the texture from the HUD. 00148 * 00149 * \param texture the texture to remove. 00150 */ 00151 void removeTexture( osg::ref_ptr< osg::Texture > texture ); 00152 00153 /** 00154 * Gets the maximum width of a tex element. 00155 * 00156 * \return the maximum width. 00157 */ 00158 unsigned int getMaxElementWidth() const; 00159 00160 /** 00161 * Sets the new maximum width of a texture column. 00162 * 00163 * \param width the new width 00164 */ 00165 void setMaxElementWidth( unsigned int width ); 00166 00167 /** 00168 * Sets the viewport of the camera housing this HUD. It is needed to have proper scaling of each texture tile. You can use 00169 * \ref WGEViewportCallback to handle this automatically. 00170 * 00171 * \param viewport the viewport 00172 */ 00173 void setViewport( osg::Viewport* viewport ); 00174 00175 /** 00176 * Set the viewport to be used for textures too. This is useful if an offscreen rendering renders only into a part of the texture. If 00177 * coupling is disabled, the whole texture gets rendered. 00178 * 00179 * \param couple if true, the viewport set by \ref setViewport gets also used for texture space. 00180 */ 00181 void coupleViewportWithTextureViewport( bool couple = true ); 00182 00183 /** 00184 * Returns the render bin used by the HUD. 00185 * 00186 * \return the bin number 00187 */ 00188 size_t getRenderBin() const; 00189 00190 protected: 00191 /** 00192 * The group Node where all those texture reside in. Theoretically, it is nonsense to use a separate group inside a osg::Projection since it 00193 * also is a group node. But WGEGroupNode offers all those nice and thread-safe insert/remove methods. 00194 */ 00195 osg::ref_ptr< WGEGroupNode > m_group; 00196 00197 /** 00198 * The maximum element width. 00199 */ 00200 unsigned int m_maxElementWidth; 00201 00202 /** 00203 * The render bin to use 00204 */ 00205 size_t m_renderBin; 00206 00207 /** 00208 * The current viewport of 00209 */ 00210 osg::Viewport* m_viewport; 00211 00212 /** 00213 * The viewport in texture space to allow viewing parts of the texture. 00214 */ 00215 bool m_coupleTexViewport; 00216 00217 private: 00218 /** 00219 * Callback which aligns and renders the textures. 00220 */ 00221 class SafeUpdateCallback : public osg::NodeCallback 00222 { 00223 public: // NOLINT 00224 /** 00225 * Constructor. 00226 * 00227 * \param hud just set the creating HUD as pointer for later reference. 00228 */ 00229 explicit SafeUpdateCallback( WGETextureHud* hud ): m_hud( hud ) 00230 { 00231 }; 00232 00233 /** 00234 * operator () - called during the update traversal. 00235 * 00236 * \param node the osg node 00237 * \param nv the node visitor 00238 */ 00239 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv ); 00240 00241 /** 00242 * Pointer used to access members of the hud. This is faster than casting the first parameter of operator() to WGETextureHud. 00243 */ 00244 WGETextureHud* m_hud; 00245 }; 00246 }; 00247 00248 #endif // WGETEXTUREHUD_H 00249