AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
DepthPeeling.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16/* This code comes from an example in OpenSceneGraph: example/osgoit.cpp */
17
18#ifndef AGXOSG_DEPTHPEELING_H
19#define AGXOSG_DEPTHPEELING_H
20
21#include <osg/Version>
22#ifdef OSG_VERSION_GREATER_OR_EQUAL
23#if OSG_VERSION_GREATER_OR_EQUAL(3,0,0)
24# define AGX_HAVE_DEPTHPEELING 1
25#endif
26#endif
27
28#ifdef AGX_HAVE_DEPTHPEELING
29
30#include <agxOSG/export.h>
31
32#include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
33#include <osg/Referenced>
34#include <osg/Group>
35#include <osg/TextureRectangle>
36#include <osgViewer/ViewerEventHandlers>
37#include <agx/PopDisableWarnings.h> // End of disabled warnings.
38
39// Some choices for the kind of textures we can use ...
40#define USE_TEXTURE_RECTANGLE
41// #define USE_NON_POWER_OF_TWO_TEXTURE
42#define USE_PACKED_DEPTH_STENCIL
43
44
45#ifdef _MSC_VER
46# pragma warning(push)
47// warning C4251: 'X' : class 'Y' needs to have dll-interface to be used by clients of class 'Z'
48# pragma warning( disable : 4251 )
49#endif
50
51namespace osg
52{
53 class Node;
54}
55
56namespace agxOSG
57{
58
60 class AGXOSG_EXPORT DepthPeeling : public osg::Referenced {
61
62 public:
63
64 DepthPeeling(unsigned width, unsigned height);
65
66 void setScene(osg::Node* scene);
67
68 osg::Node* getRoot();
69
70 void resize(int width, int height);
71
72 void setNumPasses(unsigned numPasses);
73 unsigned getNumPasses() const { return m_numPasses; }
74
75 void setTexUnit(unsigned texUnit);
76
77 void setShowAllLayers(bool showAllLayers);
78 bool getShowAllLayers() const;
79
80 void setEnable(bool depthPeelingEnabled);
81 bool getEnable() const { return m_depthPeelingEnabled; }
82 bool isEnabled() const { return m_depthPeelingEnabled; }
83
84 void setOffsetValue(unsigned offsetValue);
85
86 unsigned getOffsetValue() const { return m_offsetValue; }
87
88 class EventHandler : public osgGA::GUIEventHandler {
89 public:
90 EventHandler(DepthPeeling* depthPeeling);
91 protected:
92 bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&, osg::Object*, osg::NodeVisitor*);
93 using osgGA::GUIEventHandler::handle;
94 osg::ref_ptr<DepthPeeling> m_depthPeeling;
95 };
96
97
98 protected:
99
100 osg::Node*createQuad(unsigned layerNumber, unsigned numTiles);
101
102 class CullCallback : public osg::NodeCallback {
103 public:
104 CullCallback(unsigned texUnit, unsigned texWidth, unsigned texHeight, unsigned offsetValue);
105
106 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
107
108 private:
109 unsigned m_texUnit;
110 unsigned m_texWidth;
111 unsigned m_texHeight;
112 unsigned m_offsetValue;
113 };
114
115 void createPeeling();
116
117
118
119 unsigned m_numPasses;
120 unsigned m_texUnit;
121 unsigned m_texWidth;
122 unsigned m_texHeight;
123 bool m_showAllLayers;
124 bool m_depthPeelingEnabled;
125 unsigned m_offsetValue;
126
127 // The root node that is handed over to the viewer
128 osg::ref_ptr<osg::Group> m_root;
129
130 // The scene that is displayed
131 osg::ref_ptr<osg::Group> m_scene;
132
133 // The final camera that composites the pre rendered textures to the final picture
134 osg::ref_ptr<osg::Camera> m_compositeCamera;
135
136#ifdef USE_TEXTURE_RECTANGLE
137 osg::ref_ptr<osg::TextureRectangle> m_depthTextures[2];
138 std::vector<osg::ref_ptr<osg::TextureRectangle> > m_colorTextures;
139#else
140 osg::ref_ptr<osg::Texture2D> m_depthTextures[2];
141 std::vector<osg::ref_ptr<osg::Texture2D> > m_colorTextures;
142#endif
143 };
144
145
146} // namespace agxOSG
147
148#ifdef _MSC_VER
149# pragma warning(pop)
150#endif
151
152
153#endif
154
155#endif
#define AGXOSG_EXPORT
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.