root/OpenSceneGraph/trunk/include/osg/CullSettings @ 10838

Revision 10838, 12.7 kB (checked in by robert, 5 years ago)

From Paul Martz, "This change address the following issue: an app opens a Viewer on a multidisplay system, configured to setUpViewAcrossAllDisplays, with a non-default clear mask. In this case, OSG failed to propagate the clear mask to the slave Cameras, resulting in the clear mask being ignored. To fix this issue, this revision adds a new CullSettings::VariablesMask? bit, CLEAR_MASK, to explicitly control inheritance of the clear mask. This bit is set by default, which means that the clear mask now inherits by default, whereas previously it did not."

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
21namespace osg {
22
23// forward declare
24class ArgumentParser;
25class ApplicationUsage;
26
27class OSG_EXPORT CullSettings
28{
29    public:
30
31        CullSettings()
32        {
33            setDefaults();
34            readEnvironmentalVariables();
35        }
36
37        CullSettings(ArgumentParser& arguments)
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       
59        enum VariablesMask
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                           = 0xFFFFFFFF
83        };
84
85        /** Set the inheritance mask used in inheritCullSettings to control which variables get overwritten by the passed in CullSettings object.*/
86        void setInheritanceMask(unsigned int mask) { _inheritanceMask = mask; }
87
88        /** Get the inheritance mask used in inheritCullSettings to control which variables get overwritten by the passed in CullSettings object.*/
89        unsigned int getInheritanceMask() const { return _inheritanceMask; }
90       
91        /** Set the local cull settings values from specified CullSettings object.*/
92        void setCullSettings(const CullSettings& settings);
93
94        /** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/
95        virtual void inheritCullSettings(const CullSettings& settings) { inheritCullSettings(settings, _inheritanceMask); }
96
97        /** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/
98        virtual void inheritCullSettings(const CullSettings& settings, unsigned int inheritanceMask);
99
100        /** read the environmental variables.*/
101        void readEnvironmentalVariables();
102
103        /** read the commandline arguments.*/
104        void readCommandLine(ArgumentParser& arguments);
105
106
107        enum InheritanceMaskActionOnAttributeSetting
108        {
109            DISABLE_ASSOCIATED_INHERITANCE_MASK_BIT,
110            DO_NOT_MODIFY_INHERITANCE_MASK
111        };
112       
113        void setInheritanceMaskActionOnAttributeSetting(InheritanceMaskActionOnAttributeSetting action) { _inheritanceMaskActionOnAttributeSetting = action; }
114        InheritanceMaskActionOnAttributeSetting getInheritanceMaskActionOnAttributeSetting() const { return _inheritanceMaskActionOnAttributeSetting; }
115
116        /** Apply the action, specified by the InheritanceMaskActionOnAttributeSetting, to apply to the inheritance bit mask.
117          * This method is called by CullSettings::set*() parameter methods to ensure that CullSettings inheritance mechanisms doesn't overwrite the local parameter settings.*/
118        inline void applyMaskAction(unsigned int maskBit)
119        {
120            if (_inheritanceMaskActionOnAttributeSetting==DISABLE_ASSOCIATED_INHERITANCE_MASK_BIT)
121            {
122                _inheritanceMask = _inheritanceMask & (~maskBit);
123            }
124        }
125
126
127        /** Switch the creation of Impostors on or off.
128          * Setting active to false forces the CullVisitor to use the Impostor
129          * LOD children for rendering. Setting active to true forces the
130          * CullVisitor to create the appropriate pre-rendering stages which
131          * render to the ImpostorSprite's texture.*/
132        void setImpostorsActive(bool active) { _impostorActive = active; applyMaskAction(IMPOSTOR_ACTIVE); }
133
134        /** Get whether impostors are active or not. */
135        bool getImpostorsActive() const { return _impostorActive; }
136
137        /** Set the impostor error threshold.
138          * Used in calculation of whether impostors remain valid.*/
139        void setImpostorPixelErrorThreshold(float numPixels) { _impostorPixelErrorThreshold=numPixels;  applyMaskAction(IMPOSTOR_PIXEL_ERROR_THRESHOLD); }
140
141        /** Get the impostor error threshold.*/
142        float getImpostorPixelErrorThreshold() const { return _impostorPixelErrorThreshold; }
143
144        /** Set whether ImpostorSprite's should be placed in a depth sorted bin for rendering.*/
145        void setDepthSortImpostorSprites(bool doDepthSort) { _depthSortImpostorSprites = doDepthSort; applyMaskAction(DEPTH_SORT_IMPOSTOR_SPRITES); }
146
147        /** Get whether ImpostorSprite's are depth sorted bin for rendering.*/
148        bool getDepthSortImpostorSprites() const { return _depthSortImpostorSprites; }
149
150        /** Set the number of frames that an ImpostorSprite is kept whilst not being beyond,
151          * before being recycled.*/
152        void setNumberOfFrameToKeepImpostorSprites(int numFrames) { _numFramesToKeepImpostorSprites = numFrames; applyMaskAction(NUM_FRAMES_TO_KEEP_IMPOSTORS_SPRITES); }
153
154        /** Get the number of frames that an ImpostorSprite is kept whilst not being beyond,
155          * before being recycled.*/
156        int getNumberOfFrameToKeepImpostorSprites() const { return _numFramesToKeepImpostorSprites; }
157
158        enum ComputeNearFarMode
159        {
160            DO_NOT_COMPUTE_NEAR_FAR = 0,
161            COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES,
162            COMPUTE_NEAR_FAR_USING_PRIMITIVES
163        };
164
165        void setComputeNearFarMode(ComputeNearFarMode cnfm) { _computeNearFar=cnfm; applyMaskAction(COMPUTE_NEAR_FAR_MODE); }
166        ComputeNearFarMode getComputeNearFarMode() const { return _computeNearFar;}
167
168        void setNearFarRatio(double ratio) { _nearFarRatio = ratio; applyMaskAction(NEAR_FAR_RATIO); }
169        double getNearFarRatio() const { return _nearFarRatio; }
170
171        enum CullingModeValues
172        {
173            NO_CULLING                  = 0x0,
174            VIEW_FRUSTUM_SIDES_CULLING  = 0x1,
175            NEAR_PLANE_CULLING          = 0x2,
176            FAR_PLANE_CULLING           = 0x4,
177            VIEW_FRUSTUM_CULLING        = VIEW_FRUSTUM_SIDES_CULLING|
178                                          NEAR_PLANE_CULLING|
179                                          FAR_PLANE_CULLING,
180            SMALL_FEATURE_CULLING       = 0x8,
181            SHADOW_OCCLUSION_CULLING    = 0x10,
182            CLUSTER_CULLING             = 0x20,
183            DEFAULT_CULLING             = VIEW_FRUSTUM_SIDES_CULLING|
184                                          SMALL_FEATURE_CULLING|
185                                          SHADOW_OCCLUSION_CULLING|
186                                          CLUSTER_CULLING,
187            ENABLE_ALL_CULLING          = VIEW_FRUSTUM_CULLING|
188                                          SMALL_FEATURE_CULLING|
189                                          SHADOW_OCCLUSION_CULLING|
190                                          CLUSTER_CULLING
191        };
192       
193        typedef unsigned int CullingMode;
194
195        /** Set the culling mode for the CullVisitor to use.*/
196        void setCullingMode(CullingMode mode) { _cullingMode = mode; applyMaskAction(CULLING_MODE); }
197       
198        /** Returns the current CullingMode.*/
199        CullingMode getCullingMode() const { return _cullingMode; }
200
201
202        void setCullMask(osg::Node::NodeMask nm) { _cullMask = nm; applyMaskAction(CULL_MASK); }
203        osg::Node::NodeMask getCullMask() const { return _cullMask; }
204
205        void setCullMaskLeft(osg::Node::NodeMask nm) { _cullMaskLeft = nm; applyMaskAction(CULL_MASK_LEFT); }
206        osg::Node::NodeMask getCullMaskLeft() const { return _cullMaskLeft; }
207
208        void setCullMaskRight(osg::Node::NodeMask nm) { _cullMaskRight = nm; applyMaskAction(CULL_MASK_RIGHT); }
209        osg::Node::NodeMask getCullMaskRight() const { return _cullMaskRight; }
210
211        /** Set the LOD bias for the CullVisitor to use.*/
212        void setLODScale(float scale) { _LODScale = scale; applyMaskAction(LOD_SCALE); }
213       
214        /** Get the LOD bias.*/
215        float getLODScale() const { return _LODScale; }
216
217        /** Set the Small Feature Culling Pixel Size.*/
218        void setSmallFeatureCullingPixelSize(float value) { _smallFeatureCullingPixelSize=value; applyMaskAction(SMALL_FEATURE_CULLING_PIXEL_SIZE); }
219
220        /** Get the Small Feature Culling Pixel Size.*/
221        float getSmallFeatureCullingPixelSize() const { return _smallFeatureCullingPixelSize; }
222
223
224
225        /** Callback for overriding the CullVisitor's default clamping of the projection matrix to computed near and far values.
226          * Note, both Matrixf and Matrixd versions of clampProjectionMatrixImplementation must be implemented as the CullVisitor
227          * can target either Matrix data type, configured at compile time.*/
228        struct ClampProjectionMatrixCallback : public osg::Referenced
229        {
230            virtual bool clampProjectionMatrixImplementation(osg::Matrixf& projection, double& znear, double& zfar) const = 0;
231            virtual bool clampProjectionMatrixImplementation(osg::Matrixd& projection, double& znear, double& zfar) const = 0;
232        };
233       
234        /** set the ClampProjectionMatrixCallback.*/
235        void setClampProjectionMatrixCallback(ClampProjectionMatrixCallback* cpmc) { _clampProjectionMatrixCallback = cpmc; applyMaskAction(CLAMP_PROJECTION_MATRIX_CALLBACK); }
236        /** get the non const ClampProjectionMatrixCallback.*/
237        ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() { return _clampProjectionMatrixCallback.get(); }
238        /** get the const ClampProjectionMatrixCallback.*/
239        const ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() const { return _clampProjectionMatrixCallback.get(); }
240
241
242        /** Write out internal settings of CullSettings. */
243        void write(std::ostream& out);
244
245    protected:
246
247        unsigned int                                _inheritanceMask;
248        InheritanceMaskActionOnAttributeSetting     _inheritanceMaskActionOnAttributeSetting;
249
250        ComputeNearFarMode                          _computeNearFar;
251        CullingMode                                 _cullingMode;
252        float                                       _LODScale;
253        float                                       _smallFeatureCullingPixelSize;
254
255        ref_ptr<ClampProjectionMatrixCallback>      _clampProjectionMatrixCallback;
256        double                                      _nearFarRatio;
257        bool                                        _impostorActive;
258        bool                                        _depthSortImpostorSprites;
259        float                                       _impostorPixelErrorThreshold;
260        int                                         _numFramesToKeepImpostorSprites;   
261
262        Node::NodeMask                              _cullMask;
263        Node::NodeMask                              _cullMaskLeft;
264        Node::NodeMask                              _cullMaskRight;
265 
266
267};
268
269
270}
271
272#endif
Note: See TracBrowser for help on using the browser.