OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShaderGen.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
19 #ifndef OSGUTIL_SHADER_STATE_
20 #define OSGUTIL_SHADER_STATE_ 1
21 
22 #include <osgUtil/Export>
23 #include <osg/NodeVisitor>
24 #include <osg/State>
25 
26 namespace osgUtil
27 {
28 
30 {
31 public:
32  enum StateMask
33  {
34  BLEND = 1,
35  LIGHTING = 2,
36  FOG = 4,
37  DIFFUSE_MAP = 8, //< Texture in unit 0
38  NORMAL_MAP = 16 //< Texture in unit 1 and vertex attribute array 6
39  };
40 
41  typedef std::map<int, osg::ref_ptr<osg::StateSet> > StateSetMap;
42 
44 
45  void setStateSet(int stateMask, osg::StateSet *program);
46  osg::StateSet *getStateSet(int stateMask) const;
47  osg::StateSet *getOrCreateStateSet(int stateMask);
48 
49 protected:
50  osg::StateSet *createStateSet(int stateMask) const;
52  StateSetMap _stateSetMap;
53 
54 };
55 
57 {
58 public:
60  ShaderGenVisitor(ShaderGenCache *stateCache);
61 
62  void setStateCache(ShaderGenCache *stateCache) { _stateCache = stateCache; }
63  ShaderGenCache *getStateCache() const { return _stateCache.get(); }
64 
66  void setRootStateSet(osg::StateSet *stateSet);
67  osg::StateSet *getRootStateSet() const { return _rootStateSet.get(); }
68 
69  void apply(osg::Node &node);
70  void apply(osg::Geode &geode);
71 
72  void reset();
73 
74 protected:
75  void update(osg::Drawable *drawable);
76 
80 };
81 
82 }
83 
84 #endif
This class provides an object-oriented thread mutex interface.
Definition: Mutex.h:31
StateSetMap _stateSetMap
Definition: ShaderGen.h:52
std::map< int, osg::ref_ptr< osg::StateSet > > StateSetMap
Definition: ShaderGen.h:41
osg::ref_ptr< ShaderGenCache > _stateCache
Definition: ShaderGen.h:77
ShaderGenCache * getStateCache() const
Definition: ShaderGen.h:63
OpenThreads::Mutex _mutex
Definition: ShaderGen.h:51
osg::ref_ptr< osg::State > _state
Definition: ShaderGen.h:78
osg::ref_ptr< osg::StateSet > _rootStateSet
Definition: ShaderGen.h:79
osg::StateSet * getRootStateSet() const
Definition: ShaderGen.h:67
Definition: Node.h:71
#define OSGUTIL_EXPORT
Definition: Export.h:40
void setStateCache(ShaderGenCache *stateCache)
Definition: ShaderGen.h:62
Shader generator framework.
Definition: RenderInfo.h:20