00001 /*************************************************************************** 00002 * Copyright (c) 2008 Art Tevs * 00003 * * 00004 * This library is free software; you can redistribute it and/or modify * 00005 * it under the terms of the GNU Lesser General Public License as * 00006 * published by the Free Software Foundation; either version 3 of * 00007 * the License, or (at your option) any later version. * 00008 * * 00009 * This library is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00012 * GNU Lesse General Public License for more details. * 00013 * * 00014 * The full license is in LICENSE file included with this distribution. * 00015 ***************************************************************************/ 00016 00017 #ifndef _C_UNIT_INMIPMAPOUT_H_ 00018 #define _C_UNIT_INMIPMAPOUT_H_ 00019 00020 00021 //------------------------------------------------------------------------- 00022 // Includes 00023 //------------------------------------------------------------------------- 00024 #include <osgPPU/Export.h> 00025 #include <osgPPU/UnitInOut.h> 00026 00027 namespace osgPPU 00028 { 00029 //! Compute mipmapped output texture based on the input data 00030 /** 00031 * UnitInMipmapOut do generate mipmap levels of an output texture 00032 * by applying the shader to the input data. To generate the mipmapped 00033 * output the input texture has to be reused. Therefore the output texture 00034 * will be applied as an input texture. If input textures are already exists 00035 * the output texture will be applied to the next free slot. 00036 * Use this Unit to generate mipmaps of an input texture. 00037 * The shader has to be able to generate correct mipmap levels out of 00038 * the input data and/or previous levels. 00039 * 00040 * You can also setup this unit in that way, that it do generate 00041 * the mipmaps for the input texture and hence do not use any other output texture, 00042 * which of course save some memory. 00043 **/ 00044 class OSGPPU_EXPORT UnitInMipmapOut : public UnitInOut { 00045 public: 00046 META_Node(osgPPU,UnitInMipmapOut); 00047 00048 //! Create default ppfx 00049 UnitInMipmapOut(); 00050 UnitInMipmapOut(const UnitInMipmapOut&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); 00051 00052 //! Release it and used memory 00053 virtual ~UnitInMipmapOut(); 00054 00055 /** 00056 * Initialize the UnitInMipmapOut. 00057 * This will check if the unit is marked as dirty 00058 * and will therefor setup the input and output texture properly. 00059 **/ 00060 virtual void init(); 00061 00062 /** 00063 * Specify the index of the input texture for which the mipmaps should 00064 * be generated. Set to -1 if you would like to create an independent 00065 * output texture in which the input texture incl. mipmaps will be stored. 00066 **/ 00067 inline void generateMipmapForInputTexture(int index) 00068 { 00069 mGenerateMipmapInputIndex = index; 00070 dirty(); 00071 } 00072 00073 /** 00074 * Get index of an input texture for which the mipmaps are generated. If returns 00075 * -1 then the output texture is unequal input texture. 00076 **/ 00077 int getGenerateMipmapForInputTextureIndex() const { return mGenerateMipmapInputIndex; } 00078 00079 /** 00080 * Enable or disable the shader for the mipmap generation. 00081 * If the shader is disabled then the glGenerateMipmapEXT function 00082 * will be used to generate the mipmaps. Otehrwise the shader is used. 00083 **/ 00084 void setUseShader(bool use) { if (mUseShader != use) dirty(); mUseShader = use; } 00085 00086 /** 00087 * Get a flag if a shader is used to generate mipmaps. If returns false, 00088 * then the hardware mipmap generation is enabled. 00089 **/ 00090 bool getUseShader() const { return mUseShader; } 00091 00092 protected: 00093 00094 void enableMipmapGeneration(); 00095 bool noticeBeginRendering (osg::RenderInfo&, const osg::Drawable* ); 00096 void noticeFinishRendering(osg::RenderInfo &renderInfo, const osg::Drawable* drawable); 00097 void createAndAttachFBOs(osg::Texture* output, int mrt); 00098 00099 std::vector<osg::ref_ptr<osg::FrameBufferObject> > mMipmapFBO; 00100 std::vector<osg::ref_ptr<osg::Viewport> > mMipmapViewport; 00101 std::vector<osg::ref_ptr<osg::Drawable> > mMipmapDrawable; 00102 00103 osg::ref_ptr<osg::RefMatrix> mProjectionMatrix; 00104 osg::ref_ptr<osg::RefMatrix> mModelviewMatrix; 00105 00106 int mNumLevels; 00107 int mGenerateMipmapInputIndex; 00108 bool mUseShader; 00109 00110 int mOutputWidth; 00111 int mOutputHeight; 00112 }; 00113 00114 }; 00115 00116 #endif
Copyright (C) 2008 by Art Tevs (LGPL)