1 #ifndef COIN_SORENDERMANAGER_H
2 #define COIN_SORENDERMANAGER_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/SbColor4f.h>
37 #include <Inventor/SbVec2s.h>
38 #include <Inventor/actions/SoGLRenderAction.h>
39 
40 class SbViewportRegion;
41 class SoEvent;
42 class SoGLRenderAction;
43 class SoAudioRenderAction;
44 class SoNode;
45 class SoCamera;
46 class SoNodeSensor;
47 class SoOneShotSensor;
48 class SoSensor;
49 class SoRenderManagerP;
50 
51 typedef void SoRenderManagerRenderCB(void * userdata, class SoRenderManager * mgr);
52 
53 class COIN_DLL_API SoRenderManager {
54 public:
55 
56   class COIN_DLL_API Superimposition {
57   public:
58     enum StateFlags {
59       ZBUFFERON    = 0x0001,
60       CLEARZBUFFER = 0x0002,
61       AUTOREDRAW   = 0x0004,
62       BACKGROUND   = 0x0008
63     };
64 
65     Superimposition(SoNode * scene,
66                     SbBool enabled,
67                     SoRenderManager * manager,
68                     uint32_t flags);
69     ~Superimposition();
70 
71     void render(SoGLRenderAction * action, SbBool clearcolorbuffer = FALSE);
72     void setEnabled(SbBool yes);
73     int getStateFlags(void) const;
74     void setTransparencyType(SoGLRenderAction::TransparencyType transparencytype);
75 
76   private:
77     static void changeCB(void * data, SoSensor * sensor);
78     class SuperimpositionP * pimpl;
79   };
80 
81   enum RenderMode {
82     AS_IS,
83     WIREFRAME,
84     POINTS,
85     WIREFRAME_OVERLAY,
86     HIDDEN_LINE,
87     BOUNDING_BOX
88   };
89 
90   enum StereoMode {
91     MONO,
92     ANAGLYPH,
93     SEPARATE_OUTPUT,
94     QUAD_BUFFER = SEPARATE_OUTPUT,
95     INTERLEAVED_ROWS,
96     INTERLEAVED_COLUMNS
97   };
98 
99   enum BufferType {
100     BUFFER_SINGLE,
101     BUFFER_DOUBLE
102   };
103 
104   enum AutoClippingStrategy {
105     NO_AUTO_CLIPPING,
106     FIXED_NEAR_PLANE,
107     VARIABLE_NEAR_PLANE
108   };
109 
110   SoRenderManager(void);
111   virtual ~SoRenderManager();
112 
113   virtual void render(const SbBool clearwindow = TRUE,
114                       const SbBool clearzbuffer = TRUE);
115 
116   virtual void render(SoGLRenderAction * action,
117                       const SbBool initmatrices = TRUE,
118                       const SbBool clearwindow = TRUE,
119                       const SbBool clearzbuffer = TRUE);
120 
121   Superimposition * addSuperimposition(SoNode * scene,
122                                        uint32_t flags =
123                                        Superimposition::AUTOREDRAW |
124                                        Superimposition::ZBUFFERON  |
125                                        Superimposition::CLEARZBUFFER);
126   void removeSuperimposition(Superimposition * s);
127 
128   virtual void setSceneGraph(SoNode * const sceneroot);
129   virtual SoNode * getSceneGraph(void) const;
130 
131   void setCamera(SoCamera * camera);
132   SoCamera * getCamera(void) const;
133 
134   void setAutoClipping(AutoClippingStrategy autoclipping);
135   AutoClippingStrategy getAutoClipping(void) const;
136   void setNearPlaneValue(float value);
137   float getNearPlaneValue(void) const;
138   void setTexturesEnabled(const SbBool onoff);
139   SbBool isTexturesEnabled(void) const;
140   void setDoubleBuffer(const SbBool enable);
141   SbBool isDoubleBuffer(void) const;
142   void setRenderMode(const RenderMode mode);
143   RenderMode getRenderMode(void) const;
144   void setStereoMode(const StereoMode mode);
145   StereoMode getStereoMode(void) const;
146   void setStereoOffset(const float offset);
147   float getStereoOffset(void) const;
148 
149   void setRenderCallback(SoRenderManagerRenderCB * f,
150                          void * const userData = NULL);
151 
152   SbBool isAutoRedraw(void) const;
153   void setRedrawPriority(const uint32_t priority);
154   uint32_t getRedrawPriority(void) const;
155 
156   void scheduleRedraw(void);
157   void setWindowSize(const SbVec2s & newsize);
158   const SbVec2s & getWindowSize(void) const;
159   void setSize(const SbVec2s & newsize);
160   const SbVec2s & getSize(void) const;
161   void setOrigin(const SbVec2s & newOrigin);
162   const SbVec2s & getOrigin(void) const;
163   void setViewportRegion(const SbViewportRegion & newRegion);
164   const SbViewportRegion & getViewportRegion(void) const;
165   void setBackgroundColor(const SbColor4f & color);
166   const SbColor4f & getBackgroundColor(void) const;
167   void setOverlayColor(const SbColor4f & color);
168   SbColor4f getOverlayColor(void) const;
169   void setBackgroundIndex(const int index);
170   int getBackgroundIndex(void) const;
171   void setRGBMode(const SbBool onOrOff);
172   SbBool isRGBMode(void) const;
173   virtual void activate(void);
174   virtual void deactivate(void);
175 
176   void setAntialiasing(const SbBool smoothing, const int numPasses);
177   void getAntialiasing(SbBool & smoothing, int & numPasses) const;
178   void setGLRenderAction(SoGLRenderAction * const action);
179   SoGLRenderAction * getGLRenderAction(void) const;
180   void setAudioRenderAction(SoAudioRenderAction * const action);
181   SoAudioRenderAction * getAudioRenderAction(void) const;
182 
183   static void enableRealTimeUpdate(const SbBool flag);
184   static SbBool isRealTimeUpdateEnabled(void);
185   static uint32_t getDefaultRedrawPriority(void);
186 
187   void addPreRenderCallback(SoRenderManagerRenderCB * cb, void * data);
188   void removePreRenderCallback(SoRenderManagerRenderCB * cb, void * data);
189 
190   void addPostRenderCallback(SoRenderManagerRenderCB * cb, void * data);
191   void removePostRenderCallback(SoRenderManagerRenderCB * cb, void * data);
192 
193   void reinitialize(void);
194 
195 protected:
196   int isActive(void) const;
197   void redraw(void);
198 
199   void renderScene(SoGLRenderAction * action,
200                    SoNode * scene,
201                    uint32_t clearmask);
202 
203   void actuallyRender(SoGLRenderAction * action,
204                       const SbBool initmatrices = TRUE,
205                       const SbBool clearwindow = TRUE,
206                       const SbBool clearzbuffer = TRUE);
207 
208   void renderSingle(SoGLRenderAction * action,
209                     SbBool initmatrices,
210                     SbBool clearwindow,
211                     SbBool clearzbuffer);
212 
213   void renderStereo(SoGLRenderAction * action,
214                     SbBool initmatrices,
215                     SbBool clearwindow,
216                     SbBool clearzbuffer);
217 
218   void initStencilBufferForInterleavedStereo(void);
219   void clearBuffers(SbBool color, SbBool depth);
220 
221 private:
222   void attachRootSensor(SoNode * const sceneroot);
223   void attachClipSensor(SoNode * const sceneroot);
224   void detachRootSensor(void);
225   void detachClipSensor(void);
226   static void nodesensorCB(void * data, SoSensor *);
227   static void prerendercb(void * userdata, SoGLRenderAction * action);
228 
229   SoRenderManagerP * pimpl;
230   friend class SoRenderManagerP;
231   friend class SoSceneManager;
232   friend class Superimposition;
233 
234 }; // SoRenderManager
235 
236 #endif // !COIN_SORENDERMANAGER_H
237