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