OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
shadervisitor.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_COMPONENTS_SHADERVISITOR_H
2 #define OPENMW_COMPONENTS_SHADERVISITOR_H
3 
4 #include <osg/NodeVisitor>
5 
6 namespace Resource
7 {
8  class ImageManager;
9 }
10 
11 namespace Shader
12 {
13 
14  class ShaderManager;
15 
17  class ShaderVisitor : public osg::NodeVisitor
18  {
19  public:
20  ShaderVisitor(ShaderManager& shaderManager, Resource::ImageManager& imageManager, const std::string& defaultVsTemplate, const std::string& defaultFsTemplate);
21 
24  void setForceShaders(bool force);
25 
27  void setClampLighting(bool clamp);
28 
31  void setForcePerPixelLighting(bool force);
32 
36  void setAllowedToModifyStateSets(bool allowed);
37 
39  void setAutoUseNormalMaps(bool use);
40 
41  void setNormalMapPattern(const std::string& pattern);
42  void setNormalHeightMapPattern(const std::string& pattern);
43 
44  void setAutoUseSpecularMaps(bool use);
45 
46  void setSpecularMapPattern(const std::string& pattern);
47 
48  virtual void apply(osg::Node& node);
49 
50  virtual void apply(osg::Drawable& drawable);
51  virtual void apply(osg::Geometry& geometry);
52 
53  void applyStateSet(osg::ref_ptr<osg::StateSet> stateset, osg::Node& node);
54 
55  void pushRequirements();
56  void popRequirements();
57 
58  private:
63 
65  std::string mNormalMapPattern;
67 
69  std::string mSpecularMapPattern;
70 
73 
75  {
78 
79  // <texture stage, texture name>
80  std::map<int, std::string> mTextures;
81 
83 
85  // osg::Material::ColorMode
88  bool mNormalHeight; // true if normal map has height info in alpha channel
89 
90  // -1 == no tangents required
92  };
93  std::vector<ShaderRequirements> mRequirements;
94 
95  std::string mDefaultVsTemplate;
96  std::string mDefaultFsTemplate;
97 
98  void createProgram(const ShaderRequirements& reqs, osg::Node& node);
99  };
100 
101 }
102 
103 #endif
int mVertexColorMode
Definition: shadervisitor.hpp:86
void setNormalHeightMapPattern(const std::string &pattern)
Definition: shadervisitor.cpp:390
std::string mDefaultFsTemplate
Definition: shadervisitor.hpp:96
void setNormalMapPattern(const std::string &pattern)
Definition: shadervisitor.cpp:385
void setForceShaders(bool force)
Definition: shadervisitor.cpp:55
void pushRequirements()
Definition: shadervisitor.cpp:239
void createProgram(const ShaderRequirements &reqs, osg::Node &node)
Definition: shadervisitor.cpp:249
bool mAutoUseNormalMaps
Definition: shadervisitor.hpp:64
bool mForcePerPixelLighting
Definition: shadervisitor.hpp:61
void applyStateSet(osg::ref_ptr< osg::StateSet > stateset, osg::Node &node)
Definition: shadervisitor.cpp:102
std::string mNormalMapPattern
Definition: shadervisitor.hpp:65
std::vector< ShaderRequirements > mRequirements
Definition: shadervisitor.hpp:93
bool mForceShaders
Definition: shadervisitor.hpp:59
std::map< int, std::string > mTextures
Definition: shadervisitor.hpp:80
void setForcePerPixelLighting(bool force)
Definition: shadervisitor.cpp:65
bool mColorMaterial
Definition: shadervisitor.hpp:84
void setAllowedToModifyStateSets(bool allowed)
Definition: shadervisitor.cpp:375
virtual void apply(osg::Node &node)
Definition: shadervisitor.cpp:70
Adjusts the given subgraph to render using shaders.
Definition: shadervisitor.hpp:17
ShaderVisitor(ShaderManager &shaderManager, Resource::ImageManager &imageManager, const std::string &defaultVsTemplate, const std::string &defaultFsTemplate)
Definition: shadervisitor.cpp:39
bool mShaderRequired
Definition: shadervisitor.hpp:82
void setClampLighting(bool clamp)
Set whether lighting is clamped for visual compatibility with the fixed function pipeline.
Definition: shadervisitor.cpp:60
ShaderRequirements()
Definition: shadervisitor.cpp:24
Handles loading/caching of Images.
Definition: imagemanager.hpp:23
~ShaderRequirements()
Definition: shadervisitor.cpp:34
bool mNormalHeight
Definition: shadervisitor.hpp:88
Resource::ImageManager & mImageManager
Definition: shadervisitor.hpp:72
Definition: shadervisitor.hpp:74
void setAutoUseSpecularMaps(bool use)
Definition: shadervisitor.cpp:395
void popRequirements()
Definition: shadervisitor.cpp:244
std::string mSpecularMapPattern
Definition: shadervisitor.hpp:69
std::string mNormalHeightMapPattern
Definition: shadervisitor.hpp:66
void setSpecularMapPattern(const std::string &pattern)
Definition: shadervisitor.cpp:400
int mTexStageRequiringTangents
Definition: shadervisitor.hpp:91
Reads shader template files and turns them into a concrete shader, based on a list of define's...
Definition: shadermanager.hpp:18
std::string mDefaultVsTemplate
Definition: shadervisitor.hpp:95
bool mClampLighting
Definition: shadervisitor.hpp:60
bool mMaterialOverridden
Definition: shadervisitor.hpp:87
ShaderManager & mShaderManager
Definition: shadervisitor.hpp:71
void setAutoUseNormalMaps(bool use)
Automatically use normal maps if a file with suitable name exists (see normal map pattern)...
Definition: shadervisitor.cpp:380
bool mAllowedToModifyStateSets
Definition: shadervisitor.hpp:62
bool mAutoUseSpecularMaps
Definition: shadervisitor.hpp:68