File: MultipassTechnique

package info (click to toggle)
openscenegraph 3.6.5%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 39,988 kB
  • sloc: cpp: 392,058; ansic: 21,495; java: 1,020; yacc: 548; makefile: 430; objc: 406; xml: 155; lex: 151; javascript: 34
file content (121 lines) | stat: -rw-r--r-- 4,142 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
*/

#ifndef OSGVOLUME_MULTIPASSTECHNIQUE
#define OSGVOLUME_MULTIPASSTECHNIQUE 1

#include <osgVolume/VolumeTechnique>
#include <osg/MatrixTransform>
#include <osg/Texture2D>

namespace osgVolume {



class OSGVOLUME_EXPORT MultipassTechnique : public VolumeTechnique
{
    public:

        MultipassTechnique();

        MultipassTechnique(const MultipassTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);

        META_Object(osgVolume, MultipassTechnique);

        virtual void init();

        virtual void update(osgUtil::UpdateVisitor* nv);

        virtual void backfaceSubgraphCullTraversal(osgUtil::CullVisitor* cv);

        virtual void cull(osgUtil::CullVisitor* cv);

        /** Clean scene graph from any terrain technique specific nodes.*/
        virtual void cleanSceneGraph();

        /** Traverse the terrain subgraph.*/
        virtual void traverse(osg::NodeVisitor& nv);

        enum RenderingMode
        {
            CUBE,
            HULL,
            CUBE_AND_HULL
        };

        RenderingMode computeRenderingMode();

        /** Container for render to texture objects used when doing multi-pass volume rendering techniques.*/
        struct OSGVOLUME_EXPORT MultipassTileData : public TileData
        {
            MultipassTileData(osgUtil::CullVisitor* cv, MultipassTechnique* mpt);

            virtual void update(osgUtil::CullVisitor* cv);

            void setUp(osg::ref_ptr<osg::Camera>& camera, osg::ref_ptr<osg::Texture2D>& texture2D, int width, int height);


            osg::observer_ptr<MultipassTechnique>       multipassTechnique;
            RenderingMode                               currentRenderingMode;

            osg::ref_ptr<osg::Texture2D>                frontFaceDepthTexture;
            osg::ref_ptr<osg::Camera>                   frontFaceRttCamera;

            osg::ref_ptr<osg::Texture2D>                backFaceDepthTexture;
            osg::ref_ptr<osg::Camera>                   backFaceRttCamera;

            osg::ref_ptr<osg::Uniform>                  eyeToTileUniform;
            osg::ref_ptr<osg::Uniform>                  tileToImageUniform;
        };

        /** Called from VolumeScene to create the TileData container when a multi-pass technique is being used.
         *  The TileData container caches any render to texture objects that are required. */
        virtual TileData* createTileData(osgUtil::CullVisitor* cv) { return new MultipassTileData(cv, this); }

    protected:

        virtual ~MultipassTechnique();

        osg::ref_ptr<osg::MatrixTransform> _transform;

        typedef std::map<osgUtil::CullVisitor::Identifier*, osg::Matrix> ModelViewMatrixMap;

        OpenThreads::Mutex _mutex;
        ModelViewMatrixMap _modelViewMatrixMap;

        osg::ref_ptr<osg::StateSet> _whenMovingStateSet;
        osg::ref_ptr<osg::StateSet> _volumeRenderStateSet;

        osg::StateSet* createStateSet(osg::StateSet* statesetPrototype, osg::Program* programPrototype, osg::Shader* shaderToAdd1=0, osg::Shader* shaderToAdd2=0);

        enum ShaderMask
        {
            CUBE_SHADERS = 1,
            HULL_SHADERS = 2,
            CUBE_AND_HULL_SHADERS = 4,
            STANDARD_SHADERS = 8,
            LIT_SHADERS = 16,
            ISO_SHADERS = 32,
            MIP_SHADERS = 64,
            TF_SHADERS = 128
        };

        typedef std::map<int, osg::ref_ptr<osg::StateSet> > StateSetMap;
        StateSetMap _stateSetMap;

        osg::ref_ptr<osg::StateSet> _frontFaceStateSet;
};

}

#endif