OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CullSettings.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 
14 #ifndef OSG_CULLSETTINGS
15 #define OSG_CULLSETTINGS 1
16 
17 #include <iosfwd>
18 #include <osg/Matrix>
19 #include <osg/ClearNode>
20 
21 namespace osg {
22 
23 // forward declare
24 class ArgumentParser;
25 class ApplicationUsage;
26 
28 {
29  public:
30 
32  {
33  setDefaults();
34  readEnvironmentalVariables();
35  }
36 
38  {
39  setDefaults();
40  readEnvironmentalVariables();
41  readCommandLine(arguments);
42  }
43 
44  CullSettings(const CullSettings& cs);
45 
46  virtual ~CullSettings() {}
47 
48  CullSettings& operator = (const CullSettings& settings)
49  {
50  if (this==&settings) return *this;
51  setCullSettings(settings);
52  return *this;
53  }
54 
55 
56  virtual void setDefaults();
57 
58 
60  {
61  COMPUTE_NEAR_FAR_MODE = (0x1 << 0),
62  CULLING_MODE = (0x1 << 1),
63  LOD_SCALE = (0x1 << 2),
64  SMALL_FEATURE_CULLING_PIXEL_SIZE = (0x1 << 3),
65  CLAMP_PROJECTION_MATRIX_CALLBACK = (0x1 << 4),
66  NEAR_FAR_RATIO = (0x1 << 5),
67  IMPOSTOR_ACTIVE = (0x1 << 6),
68  DEPTH_SORT_IMPOSTOR_SPRITES = (0x1 << 7),
69  IMPOSTOR_PIXEL_ERROR_THRESHOLD = (0x1 << 8),
70  NUM_FRAMES_TO_KEEP_IMPOSTORS_SPRITES = (0x1 << 9),
71  CULL_MASK = (0x1 << 10),
72  CULL_MASK_LEFT = (0x1 << 11),
73  CULL_MASK_RIGHT = (0x1 << 12),
74  CLEAR_COLOR = (0x1 << 13),
75  CLEAR_MASK = (0x1 << 14),
76  LIGHTING_MODE = (0x1 << 15),
77  LIGHT = (0x1 << 16),
78  DRAW_BUFFER = (0x1 << 17),
79  READ_BUFFER = (0x1 << 18),
80 
81  NO_VARIABLES = 0x00000000,
82  ALL_VARIABLES = 0x7FFFFFFF
83  };
84 
85  typedef int InheritanceMask;
86 
88  void setInheritanceMask(InheritanceMask mask) { _inheritanceMask = mask; }
89 
91  InheritanceMask getInheritanceMask() const { return _inheritanceMask; }
92 
94  void setCullSettings(const CullSettings& settings);
95 
97  virtual void inheritCullSettings(const CullSettings& settings) { inheritCullSettings(settings, _inheritanceMask); }
98 
100  virtual void inheritCullSettings(const CullSettings& settings, unsigned int inheritanceMask);
101 
103  void readEnvironmentalVariables();
104 
106  void readCommandLine(ArgumentParser& arguments);
107 
108 
110  {
112  DO_NOT_MODIFY_INHERITANCE_MASK
113  };
114 
115  void setInheritanceMaskActionOnAttributeSetting(InheritanceMaskActionOnAttributeSetting action) { _inheritanceMaskActionOnAttributeSetting = action; }
116  InheritanceMaskActionOnAttributeSetting getInheritanceMaskActionOnAttributeSetting() const { return _inheritanceMaskActionOnAttributeSetting; }
117 
120  inline void applyMaskAction(unsigned int maskBit)
121  {
122  if (_inheritanceMaskActionOnAttributeSetting==DISABLE_ASSOCIATED_INHERITANCE_MASK_BIT)
123  {
124  _inheritanceMask = _inheritanceMask & (~maskBit);
125  }
126  }
127 
128 
134  void setImpostorsActive(bool active) { _impostorActive = active; applyMaskAction(IMPOSTOR_ACTIVE); }
135 
137  bool getImpostorsActive() const { return _impostorActive; }
138 
141  void setImpostorPixelErrorThreshold(float numPixels) { _impostorPixelErrorThreshold=numPixels; applyMaskAction(IMPOSTOR_PIXEL_ERROR_THRESHOLD); }
142 
144  float getImpostorPixelErrorThreshold() const { return _impostorPixelErrorThreshold; }
145 
147  void setDepthSortImpostorSprites(bool doDepthSort) { _depthSortImpostorSprites = doDepthSort; applyMaskAction(DEPTH_SORT_IMPOSTOR_SPRITES); }
148 
150  bool getDepthSortImpostorSprites() const { return _depthSortImpostorSprites; }
151 
154  void setNumberOfFrameToKeepImpostorSprites(int numFrames) { _numFramesToKeepImpostorSprites = numFrames; applyMaskAction(NUM_FRAMES_TO_KEEP_IMPOSTORS_SPRITES); }
155 
158  int getNumberOfFrameToKeepImpostorSprites() const { return _numFramesToKeepImpostorSprites; }
159 
161  {
162  DO_NOT_COMPUTE_NEAR_FAR = 0,
165  COMPUTE_NEAR_USING_PRIMITIVES
166  };
167 
168  void setComputeNearFarMode(ComputeNearFarMode cnfm) { _computeNearFar=cnfm; applyMaskAction(COMPUTE_NEAR_FAR_MODE); }
169  ComputeNearFarMode getComputeNearFarMode() const { return _computeNearFar;}
170 
171  void setNearFarRatio(double ratio) { _nearFarRatio = ratio; applyMaskAction(NEAR_FAR_RATIO); }
172  double getNearFarRatio() const { return _nearFarRatio; }
173 
175  {
176  NO_CULLING = 0x0,
177  VIEW_FRUSTUM_SIDES_CULLING = 0x1,
178  NEAR_PLANE_CULLING = 0x2,
179  FAR_PLANE_CULLING = 0x4,
180  VIEW_FRUSTUM_CULLING = VIEW_FRUSTUM_SIDES_CULLING|
181  NEAR_PLANE_CULLING|
182  FAR_PLANE_CULLING,
183  SMALL_FEATURE_CULLING = 0x8,
184  SHADOW_OCCLUSION_CULLING = 0x10,
185  CLUSTER_CULLING = 0x20,
186  DEFAULT_CULLING = VIEW_FRUSTUM_SIDES_CULLING|
187  SMALL_FEATURE_CULLING|
188  SHADOW_OCCLUSION_CULLING|
189  CLUSTER_CULLING,
190  ENABLE_ALL_CULLING = VIEW_FRUSTUM_CULLING|
191  SMALL_FEATURE_CULLING|
192  SHADOW_OCCLUSION_CULLING|
193  CLUSTER_CULLING
194  };
195 
196  typedef int CullingMode;
197 
199  void setCullingMode(CullingMode mode) { _cullingMode = mode; applyMaskAction(CULLING_MODE); }
200 
202  CullingMode getCullingMode() const { return _cullingMode; }
203 
204 
205  void setCullMask(osg::Node::NodeMask nm) { _cullMask = nm; applyMaskAction(CULL_MASK); }
206  osg::Node::NodeMask getCullMask() const { return _cullMask; }
207 
208  void setCullMaskLeft(osg::Node::NodeMask nm) { _cullMaskLeft = nm; applyMaskAction(CULL_MASK_LEFT); }
209  osg::Node::NodeMask getCullMaskLeft() const { return _cullMaskLeft; }
210 
211  void setCullMaskRight(osg::Node::NodeMask nm) { _cullMaskRight = nm; applyMaskAction(CULL_MASK_RIGHT); }
212  osg::Node::NodeMask getCullMaskRight() const { return _cullMaskRight; }
213 
215  void setLODScale(float scale) { _LODScale = scale; applyMaskAction(LOD_SCALE); }
216 
218  float getLODScale() const { return _LODScale; }
219 
222  void setSmallFeatureCullingPixelSize(float value) { _smallFeatureCullingPixelSize=value; applyMaskAction(SMALL_FEATURE_CULLING_PIXEL_SIZE); }
223 
225  float getSmallFeatureCullingPixelSize() const { return _smallFeatureCullingPixelSize; }
226 
227 
228 
233  {
234  virtual bool clampProjectionMatrixImplementation(osg::Matrixf& projection, double& znear, double& zfar) const = 0;
235  virtual bool clampProjectionMatrixImplementation(osg::Matrixd& projection, double& znear, double& zfar) const = 0;
236  };
237 
239  void setClampProjectionMatrixCallback(ClampProjectionMatrixCallback* cpmc) { _clampProjectionMatrixCallback = cpmc; applyMaskAction(CLAMP_PROJECTION_MATRIX_CALLBACK); }
241  ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() { return _clampProjectionMatrixCallback.get(); }
243  const ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() const { return _clampProjectionMatrixCallback.get(); }
244 
245 
247  void write(std::ostream& out);
248 
249  protected:
250 
251  InheritanceMask _inheritanceMask;
253 
255  CullingMode _cullingMode;
256  float _LODScale;
258 
265 
269 
270 
271 };
272 
273 
274 }
275 
276 #endif
void setNearFarRatio(double ratio)
Definition: CullSettings.h:171
#define OSG_EXPORT
Definition: Export.h:43
float getImpostorPixelErrorThreshold() const
Definition: CullSettings.h:144
InheritanceMaskActionOnAttributeSetting _inheritanceMaskActionOnAttributeSetting
Definition: CullSettings.h:252
ref_ptr< ClampProjectionMatrixCallback > _clampProjectionMatrixCallback
Definition: CullSettings.h:259
void setSmallFeatureCullingPixelSize(float value)
Definition: CullSettings.h:222
ComputeNearFarMode _computeNearFar
Definition: CullSettings.h:254
int _numFramesToKeepImpostorSprites
Definition: CullSettings.h:264
bool getDepthSortImpostorSprites() const
Definition: CullSettings.h:150
float getLODScale() const
Definition: CullSettings.h:218
void setCullingMode(CullingMode mode)
Definition: CullSettings.h:199
virtual ~CullSettings()
Definition: CullSettings.h:46
float _impostorPixelErrorThreshold
Definition: CullSettings.h:263
void setCullMask(osg::Node::NodeMask nm)
Definition: CullSettings.h:205
InheritanceMask _inheritanceMask
Definition: CullSettings.h:251
void readCommandLine(osg::ArgumentParser &parser)
Definition: Registry.h:645
float getSmallFeatureCullingPixelSize() const
Definition: CullSettings.h:225
void setDepthSortImpostorSprites(bool doDepthSort)
Definition: CullSettings.h:147
void setClampProjectionMatrixCallback(ClampProjectionMatrixCallback *cpmc)
Definition: CullSettings.h:239
InheritanceMaskActionOnAttributeSetting getInheritanceMaskActionOnAttributeSetting() const
Definition: CullSettings.h:116
virtual void inheritCullSettings(const CullSettings &settings)
Definition: CullSettings.h:97
ClampProjectionMatrixCallback * getClampProjectionMatrixCallback()
Definition: CullSettings.h:241
void setComputeNearFarMode(ComputeNearFarMode cnfm)
Definition: CullSettings.h:168
void setNumberOfFrameToKeepImpostorSprites(int numFrames)
Definition: CullSettings.h:154
void setImpostorPixelErrorThreshold(float numPixels)
Definition: CullSettings.h:141
int getNumberOfFrameToKeepImpostorSprites() const
Definition: CullSettings.h:158
Node::NodeMask _cullMaskRight
Definition: CullSettings.h:268
osg::Node::NodeMask getCullMask() const
Definition: CullSettings.h:206
Node::NodeMask _cullMask
Definition: CullSettings.h:266
const ClampProjectionMatrixCallback * getClampProjectionMatrixCallback() const
Definition: CullSettings.h:243
Node::NodeMask _cullMaskLeft
Definition: CullSettings.h:267
bool getImpostorsActive() const
Definition: CullSettings.h:137
CullingMode getCullingMode() const
Definition: CullSettings.h:202
void applyMaskAction(unsigned int maskBit)
Definition: CullSettings.h:120
InheritanceMask getInheritanceMask() const
Definition: CullSettings.h:91
CullingMode _cullingMode
Definition: CullSettings.h:255
void setInheritanceMaskActionOnAttributeSetting(InheritanceMaskActionOnAttributeSetting action)
Definition: CullSettings.h:115
void setCullMaskLeft(osg::Node::NodeMask nm)
Definition: CullSettings.h:208
void setInheritanceMask(InheritanceMask mask)
Definition: CullSettings.h:88
void setImpostorsActive(bool active)
Definition: CullSettings.h:134
bool _depthSortImpostorSprites
Definition: CullSettings.h:262
osg::Node::NodeMask getCullMaskLeft() const
Definition: CullSettings.h:209
void setLODScale(float scale)
Definition: CullSettings.h:215
ComputeNearFarMode getComputeNearFarMode() const
Definition: CullSettings.h:169
float _smallFeatureCullingPixelSize
Definition: CullSettings.h:257
InheritanceMaskActionOnAttributeSetting
Definition: CullSettings.h:109
Definition: AlphaFunc.h:19
CullSettings(ArgumentParser &arguments)
Definition: CullSettings.h:37
unsigned int NodeMask
Definition: Node.h:352
void setCullMaskRight(osg::Node::NodeMask nm)
Definition: CullSettings.h:211
double getNearFarRatio() const
Definition: CullSettings.h:172
osg::Node::NodeMask getCullMaskRight() const
Definition: CullSettings.h:212