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 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 /** 00046 * Creates a new offscreen rendering instance. 00047 * 00048 * \param textureWidth the width of all the textures created and used by this render pass. This should be large enough for every reasonable 00049 * viewport size. 00050 * \param textureHeight the height of all the textures created and used by this render pass. This should be large enough for every reasonable 00051 * viewport size.* 00052 * \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. 00053 */ 00054 WGEOffscreenTexturePass( size_t textureWidth, size_t textureHeight, int num = 0 ); 00055 00056 /** 00057 * Creates a new offscreen rendering instance. 00058 * 00059 * \param textureWidth the width of all the textures created and used by this render pass. This should be large enough for every reasonable 00060 * viewport size. 00061 * \param textureHeight the height of all the textures created and used by this render pass. This should be large enough for every reasonable 00062 * viewport size.* 00063 * \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. 00064 * \param hud the hud that gets notified about attached and detached textures. Useful for debugging. 00065 * \param name the name of this render pass. This is a nice debugging feature in conjunction with WGETextureHud as it gets displayed there. 00066 */ 00067 WGEOffscreenTexturePass( size_t textureWidth, size_t textureHeight, osg::ref_ptr< WGETextureHud > hud, std::string name, int num = 0 ); 00068 00069 /** 00070 * Destructor. 00071 */ 00072 virtual ~WGEOffscreenTexturePass(); 00073 00074 protected: 00075 private: 00076 00077 /** 00078 * Sets the whole node up. Used to get some code duplication out of the constructors. 00079 */ 00080 void setup(); 00081 00082 /** 00083 * The texture matrix for this pass. Used to scale the texture coordinates according to viewport/texture size relation. 00084 */ 00085 osg::ref_ptr< osg::TexMat > m_texMat; 00086 00087 /** 00088 * Callback which aligns and renders the textures. 00089 */ 00090 class TextureMatrixUpdateCallback : public osg::NodeCallback 00091 { 00092 public: // NOLINT 00093 00094 /** 00095 * Constructor. 00096 * 00097 * \param pass the pass to which this callback is applied. Needed for accessing some mebers. 00098 */ 00099 explicit TextureMatrixUpdateCallback( WGEOffscreenTexturePass* pass ): m_pass( pass ) 00100 { 00101 }; 00102 00103 /** 00104 * operator () - called during the update traversal. 00105 * 00106 * \param node the osg node 00107 * \param nv the node visitor 00108 */ 00109 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv ); 00110 00111 /** 00112 * The pass used in conjunction with this callback. 00113 */ 00114 WGEOffscreenTexturePass* m_pass; 00115 }; 00116 }; 00117 00118 #endif // WGEOFFSCREENTEXTUREPASS_H 00119