root/OpenSceneGraph/trunk/src/osgUtil/DisplayRequirementsVisitor.cpp @ 13041

Revision 13041, 2.4 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • 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#if defined(_MSC_VER)
14    #pragma warning( disable : 4786 )
15#endif
16
17#include <stdio.h>
18#include <string.h>
19#include <list>
20#include <set>
21
22#include <osgUtil/DisplayRequirementsVisitor>
23
24using namespace osg;
25using namespace osgUtil;
26
27DisplayRequirementsVisitor::DisplayRequirementsVisitor()
28{
29    setTraversalMode(NodeVisitor::TRAVERSE_ALL_CHILDREN);
30}
31
32void DisplayRequirementsVisitor::applyStateSet(StateSet& stateset)
33{
34    if (!_ds) _ds = new osg::DisplaySettings;
35
36   unsigned int min = 0; // assume stencil not needed by this stateset.
37
38   if (stateset.getMode(GL_STENCIL_TEST) & StateAttribute::ON)
39   {
40        min = 1; // number stencil bits we need at least.
41   }
42
43   if (stateset.getAttribute(StateAttribute::STENCIL))
44   {
45        min = 1; // number stencil bits we need at least.
46   }
47
48   if (min>_ds->getMinimumNumStencilBits())
49   {
50        // only update if new minimum exceeds previous minimum.
51        _ds->setMinimumNumStencilBits(min);
52   }
53}
54
55void DisplayRequirementsVisitor::apply(Node& node)
56{
57    osg::StateSet* stateset = node.getStateSet();
58    if (stateset) applyStateSet(*stateset);
59
60    if (strcmp(node.className(),"Impostor")==0)
61    {
62        if (!_ds) _ds = new osg::DisplaySettings;
63
64        unsigned int min = 1; // number alpha bits we need at least.
65        if (min>_ds->getMinimumNumAlphaBits())
66        {
67            // only update if new minimum exceeds previous minimum.
68            _ds->setMinimumNumAlphaBits(min);
69        }
70    }
71
72    traverse(node);
73}
74
75void DisplayRequirementsVisitor::apply(Geode& geode)
76{
77    osg::StateSet* geode_stateset = geode.getStateSet();
78    if (geode_stateset) applyStateSet(*geode_stateset);
79
80    for(unsigned int i = 0; i < geode.getNumDrawables(); i++ )
81    {
82        osg::StateSet* stateset = geode.getDrawable(i)->getStateSet();
83        if (stateset) applyStateSet(*stateset);
84    }
85}
Note: See TracBrowser for help on using the browser.