root/OpenSceneGraph/trunk/examples/osgoit/DepthPeeling.h @ 13556

Revision 13556, 3.0 kB (checked in by robert, 4 days ago)

Moved widgets from VolumeEditorWidget? to TransferFunctionWidget?, and widget utilities into WidgetUtils?.

Line 
1
2#include <osg/Referenced>
3#include <osg/Node>
4#include <osg/Camera>
5#include <osg/TextureRectangle>
6#include <osg/Texture2D>
7#include <osgGA/GUIEventHandler>
8
9#include <limits>
10
11#ifndef DEPTHPEELING_H
12#define DEPTHPEELING_H
13
14// Some choices for the kind of textures we can use ...
15#define USE_TEXTURE_RECTANGLE
16//#define USE_NON_POWER_OF_TWO_TEXTURE
17#define USE_PACKED_DEPTH_STENCIL
18
19template<typename T>
20inline T
21nextPowerOfTwo(T k)
22{
23    if (k == T(0))
24        return 1;
25    k--;
26    for (int i = 1; i < std::numeric_limits<T>::digits; i <<= 1)
27        k = k | k >> i;
28    return k + 1;
29}
30
31class DepthPeeling : public osg::Referenced {
32public:
33
34    DepthPeeling(unsigned int width, unsigned int height);
35    void setSolidScene(osg::Node* scene);
36    void setTransparentScene(osg::Node* scene);
37    osg::Node* getRoot();
38    void resize(int width, int height);
39    void setNumPasses(unsigned int numPasses);
40    unsigned int getNumPasses() const;
41    void setTexUnit(unsigned int texUnit);
42    void setShowAllLayers(bool showAllLayers);
43    bool getShowAllLayers() const;
44    void setOffsetValue(unsigned int offsetValue);
45    unsigned int getOffsetValue() const;
46
47    static const char *PeelingShader; /* use this to support depth peeling in GLSL shaders in transparent objects */
48
49    class EventHandler : public osgGA::GUIEventHandler {
50    public:
51        EventHandler(DepthPeeling* depthPeeling);
52
53        /** Handle events, return true if handled, false otherwise. */
54        virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&, osg::Object*, osg::NodeVisitor*);
55
56    protected:
57        osg::ref_ptr<DepthPeeling> _depthPeeling;
58    };
59
60protected:
61    osg::Node *createQuad(unsigned int layerNumber, unsigned int numTiles);
62    void createPeeling();
63
64    class CullCallback : public osg::NodeCallback {
65    public:
66        CullCallback(unsigned int texUnit, unsigned int texWidth, unsigned int texHeight, unsigned int offsetValue);
67        virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
68
69    private:
70        unsigned int _texUnit;
71        unsigned int _texWidth;
72        unsigned int _texHeight;
73        unsigned int _offsetValue;
74    };
75
76    unsigned int _numPasses;
77    unsigned int _texUnit;
78    unsigned int _texWidth;
79    unsigned int _texHeight;
80    bool _showAllLayers;
81    unsigned int _offsetValue;
82
83    // The root node that is handed over to the viewer
84    osg::ref_ptr<osg::Group> _root;
85
86    // The scene that is displayed
87    osg::ref_ptr<osg::Group> _solidscene;
88    osg::ref_ptr<osg::Group> _transparentscene;
89
90    // The final camera that composites the pre rendered textures to the final picture
91    osg::ref_ptr<osg::Camera> _compositeCamera;
92
93#ifdef USE_TEXTURE_RECTANGLE
94    std::vector<osg::ref_ptr<osg::TextureRectangle> > _depthTextures;
95    std::vector<osg::ref_ptr<osg::TextureRectangle> > _colorTextures;
96#else
97    std::vector<osg::ref_ptr<osg::Texture2D> > _depthTextures;
98    std::vector<osg::ref_ptr<osg::Texture2D> > _colorTextures;
99#endif
100};
101
102#endif // #ifndef DEPTHPEELING_H
Note: See TracBrowser for help on using the browser.