~ubuntu-branches/debian/sid/osgearth/sid

« back to all changes in this revision

Viewing changes to src/osgEarthFeatures/StencilVolumeNode

  • Committer: Bazaar Package Importer
  • Author(s): Pirmin Kalberer
  • Date: 2011-07-14 22:13:36 UTC
  • Revision ID: james.westby@ubuntu.com-20110714221336-94igk9rskxveh794
Tags: upstream-2.0+dfsg
ImportĀ upstreamĀ versionĀ 2.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*-c++-*- */
 
2
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 
3
 * Copyright 2008-2009 Pelican Ventures, Inc.
 
4
 * http://osgearth.org
 
5
 *
 
6
 * osgEarth is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU Lesser General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 
18
 */
 
19
#ifndef OSGEARTHFEATURES_STENCIL_VOLUME_NODE_H
 
20
#define OSGEARTHFEATURES_STENCIL_VOLUME_NODE_H 1
 
21
 
 
22
#include <osgEarthFeatures/Common>
 
23
#include <osgEarthFeatures/Filter>
 
24
#include <osgEarthFeatures/Geometry>
 
25
#include <osgEarth/MaskNode>
 
26
#include <osg/Group>
 
27
#include <osg/Vec4>
 
28
 
 
29
namespace osgEarth { namespace Features 
 
30
{
 
31
    class OSGEARTHFEATURES_EXPORT StencilVolumeNode : public osgEarth::MaskNode
 
32
    {
 
33
    public:
 
34
        /**
 
35
         * Constructs a stencil masking node.
 
36
         *
 
37
         * @param preRenderChildrenToDepthBuffer
 
38
         *     Normally, this node will render the stencil volumes first and then
 
39
         *     render the children (which will be masked by the stencil). If you need
 
40
         *     to pre-render the children to the depth buffer, set this to TRUE. You
 
41
         *     need to do this is you are creating a straight render mask.
 
42
         *
 
43
         * @param inverted
 
44
         *     Inverts the stencil buffer, masking the opposite pixels that would
 
45
         *     normally be masked.
 
46
         */
 
47
        StencilVolumeNode(
 
48
            bool preRenderChildrenToDepthBuffer =false,
 
49
            bool inverted =false );
 
50
 
 
51
        StencilVolumeNode( const StencilVolumeNode& rhs, const osg::CopyOp& op =osg::CopyOp::DEEP_COPY_ALL );
 
52
 
 
53
        META_Node(osgEarth::Features,StencilVolumeNode);
 
54
        
 
55
        virtual void traverse( osg::NodeVisitor& nv );
 
56
 
 
57
    public: // props
 
58
 
 
59
        // sets the render bins and returns the next available bin.
 
60
        int setBaseRenderBin( int bin );
 
61
 
 
62
        // adds stenciling volume geometry
 
63
        void addVolumes( osg::Node* node );
 
64
 
 
65
        // adds the node to draw once the stencil is in place.
 
66
        //void setChild( osg::Node* node );
 
67
 
 
68
    public: //osg::Group overrides
 
69
 
 
70
        virtual bool addChild( Node *child );
 
71
        virtual bool insertChild( unsigned int index, Node *child );
 
72
        virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
 
73
        virtual bool replaceChild( Node *origChild, Node* newChild );
 
74
        virtual bool setChild( unsigned  int i, Node* node );
 
75
        virtual osg::BoundingSphere computeBound() const;
 
76
 
 
77
    protected:
 
78
        void init();
 
79
 
 
80
        osg::ref_ptr<osg::Group> _root;
 
81
        osg::Group* _stencilGroup1;
 
82
        osg::Group* _stencilGroup2;
 
83
        osg::Group* _depthPass;
 
84
        osg::Group* _renderPass;
 
85
        bool _inverted;
 
86
        bool _preRenderChildrenToDepthBuffer;
 
87
    };
 
88
 
 
89
 
 
90
    class OSGEARTHFEATURES_EXPORT StencilVolumeFactory
 
91
    {
 
92
    public:
 
93
        static osg::Geode* createVolume(
 
94
            Geometry*            geom,
 
95
            double               offset,
 
96
            double               height,
 
97
            const FilterContext& context );
 
98
    };
 
99
 
 
100
} } // namespace osgEarth::Features
 
101
 
 
102
#endif // OSGEARTHFEATURES_STENCIL_VOLUME_NODE_H
 
103