osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarth/ShaderUtils

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003  * Copyright 2008-2010 Pelican Mapping
00004  * http://osgearth.org
00005  *
00006  * osgEarth is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 #ifndef OSGEARTH_SHADER_UTILS_H
00020 #define OSGEARTH_SHADER_UTILS_H 1
00021 
00022 #include <osgEarth/Common>
00023 #include <osg/NodeCallback>
00024 #include <osg/StateSet>
00025 #include <osg/Uniform>
00026 #include <osg/observer_ptr>
00027 
00028 namespace osgEarth
00029 {
00034     class OSGEARTH_EXPORT UpdateLightingUniformsHelper
00035     {
00036     public:
00037         UpdateLightingUniformsHelper( bool useUpdateTraversal =false );
00038         ~UpdateLightingUniformsHelper();
00039 
00040         void cullTraverse( osg::Node* node, osg::NodeVisitor* nv );
00041         void updateTraverse( osg::Node* node );
00042 
00043     protected:
00044         int   _maxLights;
00045         bool* _lightEnabled;
00046         bool  _lightingEnabled;
00047         bool  _dirty;
00048         bool  _applied;
00049         bool  _useUpdateTrav;
00050         OpenThreads::Mutex _stateSetMutex;
00051 
00052         osg::ref_ptr<osg::Uniform> _lightingEnabledUniform;
00053         osg::ref_ptr<osg::Uniform> _lightEnabledUniform;
00054     };
00055 
00061     class OSGEARTH_EXPORT ArrayUniform //  : public osg::Referenced
00062     {
00063     public:
00065         ArrayUniform() { }
00066 
00070         ArrayUniform(
00071             const std::string& name,
00072             osg::Uniform::Type type,
00073             osg::StateSet*     stateSet,
00074             unsigned           size =1 );
00075 
00076         void attach(
00077             const std::string& name,
00078             osg::Uniform::Type type,
00079             osg::StateSet*     stateSet,
00080             unsigned           size =1 );
00081 
00082         void detach();
00083 
00084         // ArrayUniform( osg::Uniform::Type type, const std::string& name, int size );
00085 
00087         //ArrayUniform( osg::StateSet* from, const std::string& name );
00088 
00089         void setElement( unsigned index, int value );
00090         void setElement( unsigned index, unsigned value );
00091         void setElement( unsigned index, bool value );
00092         void setElement( unsigned index, float value );
00093         void setElement( unsigned index, const osg::Matrix& value );
00094         void setElement( unsigned index, const osg::Vec3& value );
00095 
00096         bool getElement( unsigned index, int& out_value ) const;
00097         bool getElement( unsigned index, unsigned& out_value ) const;
00098         bool getElement( unsigned index, bool& out_value ) const;
00099         bool getElement( unsigned index, float& out_value ) const;
00100         bool getElement( unsigned index, osg::Matrix& out_value ) const;
00101         bool getElement( unsigned index, osg::Vec3& out_value ) const;
00102 
00103         bool isValid() const { return _uniform.valid() && _uniformAlt.valid(); }
00104         int getNumElements() const { return isValid() ? _uniform->getNumElements() : -1; }
00105 
00106     private:
00107         osg::ref_ptr<osg::Uniform>       _uniform;
00108         osg::ref_ptr<osg::Uniform>       _uniformAlt;
00109         osg::observer_ptr<osg::StateSet> _stateSet;
00110 
00111         void ensureCapacity( unsigned newSize );
00112     };
00113 }
00114 
00115 #endif // OSGEARTH_SHADER_UTILS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines