OpenWalnut
1.4.0
|
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 WGEOFFSCREENTEXTUREPASS_H 00026 #define WGEOFFSCREENTEXTUREPASS_H 00027 00028 #include <string> 00029 00030 #include <osg/Geode> 00031 #include <osg/TexMat> 00032 00033 #include "WGEOffscreenRenderPass.h" 00034 00035 class WGETextureHud; 00036 00037 /** 00038 * This class encapsulates an OSG Camera and a corresponding framebuffer object. It is a specialized variant of \ref WGEOffscreenRenderPass, 00039 * optimized for processing textures. Therefore, it creates an correctly sized quad and can process each pixel in the fragment shader. 00040 */ 00041 class WGEOffscreenTexturePass: public WGEOffscreenRenderPass 00042 { 00043 public: 00044 /** 00045 * Creates a new offscreen rendering instance. 00046 * 00047 * \param textureWidth the width of all the textures created and used by this render pass. This should be large enough for every reasonable 00048 * viewport size. 00049 * \param textureHeight the height of all the textures created and used by this render pass. This should be large enough for every reasonable 00050 * viewport size.* 00051 * \param num the order number. This camera gets rendered at the num'th place in the pre render queue of the subgraph it is attached to. 00052 */ 00053 WGEOffscreenTexturePass( size_t textureWidth, size_t textureHeight, int num = 0 ); 00054 00055 /** 00056 * Creates a new offscreen rendering instance. 00057 * 00058 * \param textureWidth the width of all the textures created and used by this render pass. This should be large enough for every reasonable 00059 * viewport size. 00060 * \param textureHeight the height of all the textures created and used by this render pass. This should be large enough for every reasonable 00061 * viewport size.* 00062 * \param num the order number. This camera gets rendered at the num'th place in the pre render queue of the subgraph it is attached to. 00063 * \param hud the hud that gets notified about attached and detached textures. Useful for debugging. 00064 * \param name the name of this render pass. This is a nice debugging feature in conjunction with WGETextureHud as it gets displayed there. 00065 */ 00066 WGEOffscreenTexturePass( size_t textureWidth, size_t textureHeight, osg::ref_ptr< WGETextureHud > hud, std::string name, int num = 0 ); 00067 00068 /** 00069 * Destructor. 00070 */ 00071 virtual ~WGEOffscreenTexturePass(); 00072 00073 protected: 00074 private: 00075 /** 00076 * Sets the whole node up. Used to get some code duplication out of the constructors. 00077 */ 00078 void setup(); 00079 00080 /** 00081 * The texture matrix for this pass. Used to scale the texture coordinates according to viewport/texture size relation. 00082 */ 00083 osg::ref_ptr< osg::TexMat > m_texMat; 00084 00085 /** 00086 * Callback which aligns and renders the textures. 00087 */ 00088 class TextureMatrixUpdateCallback : public osg::NodeCallback 00089 { 00090 public: // NOLINT 00091 /** 00092 * Constructor. 00093 * 00094 * \param pass the pass to which this callback is applied. Needed for accessing some mebers. 00095 */ 00096 explicit TextureMatrixUpdateCallback( WGEOffscreenTexturePass* pass ): m_pass( pass ) 00097 { 00098 }; 00099 00100 /** 00101 * operator () - called during the update traversal. 00102 * 00103 * \param node the osg node 00104 * \param nv the node visitor 00105 */ 00106 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv ); 00107 00108 /** 00109 * The pass used in conjunction with this callback. 00110 */ 00111 WGEOffscreenTexturePass* m_pass; 00112 }; 00113 }; 00114 00115 #endif // WGEOFFSCREENTEXTUREPASS_H 00116