Panda3D
stereoDisplayRegion.cxx
1 // Filename: stereoDisplayRegion.cxx
2 // Created by: drose (19Feb09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "stereoDisplayRegion.h"
16 #include "pandaNode.h"
17 
18 TypeHandle StereoDisplayRegion::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: StereoDisplayRegion::Constructor
22 // Access: Published
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 StereoDisplayRegion::
26 StereoDisplayRegion(GraphicsOutput *window,
27  const LVecBase4 &dimensions,
28  DisplayRegion *left, DisplayRegion *right) :
29  DisplayRegion(window, dimensions),
30  _left_eye(left),
31  _right_eye(right)
32 {
33  nassertv(window == left->get_window() &&
34  window == right->get_window());
35  set_stereo_channel(Lens::SC_stereo);
36  set_sort(0);
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: StereoDisplayRegion::Destructor
41 // Access: Published, Virtual
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 StereoDisplayRegion::
45 ~StereoDisplayRegion() {
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: StereoDisplayRegion::set_clear_active
50 // Access: Published, Virtual
51 // Description: Sets the clear-active flag for any bitplane.
52 ////////////////////////////////////////////////////////////////////
54 set_clear_active(int n, bool clear_active) {
55  // The clear_active flag gets set only on the parent, stereo display
56  // region.
57  DisplayRegion::set_clear_active(n, clear_active);
58 
59  // Except for non-color buffers. These also get set on the
60  // right display region by default, on the assumption that we want
61  // to clear these buffers between drawing the eyes, and that the
62  // right eye is the second of the pair.
63  if (n != RTP_color) {
64  _right_eye->set_clear_active(n, clear_active);
65  }
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: StereoDisplayRegion::set_clear_value
70 // Access: Published, Virtual
71 // Description: Sets the clear value for any bitplane.
72 ////////////////////////////////////////////////////////////////////
74 set_clear_value(int n, const LColor &clear_value) {
75  DisplayRegion::set_clear_value(n, clear_value);
76  _left_eye->set_clear_value(n, clear_value);
77  _right_eye->set_clear_value(n, clear_value);
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: StereoDisplayRegion::disable_clears
82 // Access: Published, Virtual
83 // Description: Disables both the color and depth clear. See
84 // set_clear_color_active and set_clear_depth_active.
85 ////////////////////////////////////////////////////////////////////
89  _left_eye->disable_clears();
90  _right_eye->disable_clears();
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: StereoDisplayRegion::set_pixel_zoom
95 // Access: Published, Virtual
96 // Description: Sets the pixel_zoom for left and right eyes.
97 ////////////////////////////////////////////////////////////////////
99 set_pixel_zoom(PN_stdfloat pixel_zoom) {
100  DisplayRegion::set_pixel_zoom(pixel_zoom);
101  _left_eye->set_pixel_zoom(pixel_zoom);
102  _right_eye->set_pixel_zoom(pixel_zoom);
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: StereoDisplayRegion::set_dimensions
107 // Access: Published, Virtual
108 // Description: Sets both the left and right DisplayRegions to the
109 // indicated dimensions.
110 ////////////////////////////////////////////////////////////////////
112 set_dimensions(int i, const LVecBase4 &dimensions) {
113  DisplayRegion::set_dimensions(i, dimensions);
114  _left_eye->set_dimensions(i, dimensions);
115  _right_eye->set_dimensions(i, dimensions);
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: StereoDisplayRegion::is_stereo
120 // Access: Published, Virtual
121 // Description: Returns true if this is a StereoDisplayRegion, false
122 // otherwise.
123 ////////////////////////////////////////////////////////////////////
125 is_stereo() const {
126  return true;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: StereoDisplayRegion::set_camera
131 // Access: Published, Virtual
132 // Description: Sets both the left and right DisplayRegions to the
133 // indicated camera.
134 ////////////////////////////////////////////////////////////////////
136 set_camera(const NodePath &camera) {
138  _left_eye->set_camera(camera);
139  _right_eye->set_camera(camera);
140 }
141 
142 ////////////////////////////////////////////////////////////////////
143 // Function: StereoDisplayRegion::set_active
144 // Access: Published, Virtual
145 // Description: Sets the active flag on both the left and right
146 // DisplayRegions to the indicated value.
147 ////////////////////////////////////////////////////////////////////
149 set_active(bool active) {
151  _left_eye->set_active(active);
152  _right_eye->set_active(active);
153  if (active) {
154  // Reenable the appropriate eyes according to our stereo_channel
155  // setting.
157  }
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: StereoDisplayRegion::set_sort
162 // Access: Published, Virtual
163 // Description: Sets the indicated sort value on the overall
164 // DisplayRegion, the indicated sort value + 1 on the
165 // left eye, and the indicated sort value + 2 on the
166 // right eye.
167 ////////////////////////////////////////////////////////////////////
169 set_sort(int sort) {
171  _left_eye->set_sort(sort + 1);
172  _right_eye->set_sort(sort + 2);
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function: StereoDisplayRegion::set_stereo_channel
177 // Access: Published, Virtual
178 // Description: Sets the stereo channels on the left and right eyes,
179 // and also sets the active flags independently on both
180 // eyes. For a StereoDisplayRegion, a different action
181 // is performed for each different value:
182 //
183 // SC_stereo - the left eye is set to SC_left, the right
184 // eye to SC_right, and both eyes are activated.
185 //
186 // SC_left - the left eye is set to SC_left and
187 // activated; the right eye is deactivated.
188 //
189 // SC_right - the right eye is set to SC_right and
190 // activated; the left eye is deactivated.
191 //
192 // SC_mono - the left eye is set to SC_mono and
193 // activated; the right eye is deactivated.
194 //
195 // This call also resets tex_view_offset to its default
196 // value, which is 0 for the left eye or 1 for the right
197 // eye of a stereo display region, or 0 for a mono
198 // display region.
199 ////////////////////////////////////////////////////////////////////
201 set_stereo_channel(Lens::StereoChannel stereo_channel) {
202  DisplayRegion::set_stereo_channel(stereo_channel);
203  if (!is_active()) {
204  return;
205  }
206 
207  switch (stereo_channel) {
208  case Lens::SC_stereo:
209  _left_eye->set_stereo_channel(Lens::SC_left);
210  _left_eye->set_active(true);
211  _right_eye->set_stereo_channel(Lens::SC_right);
212  _right_eye->set_active(true);
213  break;
214 
215  case Lens::SC_left:
216  _left_eye->set_stereo_channel(Lens::SC_left);
217  _left_eye->set_active(true);
218  _right_eye->set_active(false);
219  break;
220 
221  case Lens::SC_right:
222  _left_eye->set_active(false);
223  _right_eye->set_stereo_channel(Lens::SC_right);
224  _right_eye->set_active(true);
225  break;
226 
227  case Lens::SC_mono:
228  _left_eye->set_stereo_channel(Lens::SC_mono);
229  _left_eye->set_active(true);
230  _right_eye->set_active(false);
231  break;
232  }
233 }
234 
235 ////////////////////////////////////////////////////////////////////
236 // Function: StereoDisplayRegion::set_tex_view_offset
237 // Access: Published, Virtual
238 // Description: Sets the current texture view offset for this
239 // DisplayRegion. This is normally set to zero. If
240 // nonzero, it is used to select a particular view of
241 // any multiview textures that are rendered within this
242 // DisplayRegion.
243 //
244 // When you call this on a StereoDisplayRegion, it
245 // automatically sets the specified value on the left
246 // eye, and the specified value + 1 on the right eye.
247 ////////////////////////////////////////////////////////////////////
249 set_tex_view_offset(int tex_view_offset) {
250  DisplayRegion::set_tex_view_offset(tex_view_offset);
251  _left_eye->set_tex_view_offset(tex_view_offset);
252  _right_eye->set_tex_view_offset(tex_view_offset + 1);
253 }
254 
255 ////////////////////////////////////////////////////////////////////
256 // Function: StereoDisplayRegion::set_incomplete_render
257 // Access: Published, Virtual
258 // Description: Sets the incomplete_render flag on both the left and
259 // right DisplayRegions to the indicated value.
260 ////////////////////////////////////////////////////////////////////
262 set_incomplete_render(bool incomplete_render) {
263  DisplayRegion::set_incomplete_render(incomplete_render);
264  _left_eye->set_incomplete_render(incomplete_render);
265  _right_eye->set_incomplete_render(incomplete_render);
266 }
267 
268 ////////////////////////////////////////////////////////////////////
269 // Function: StereoDisplayRegion::set_texture_reload_priority
270 // Access: Published, Virtual
271 // Description: Sets the texture_reload_priority on both the left and
272 // right DisplayRegions to the indicated value.
273 ////////////////////////////////////////////////////////////////////
275 set_texture_reload_priority(int texture_reload_priority) {
276  DisplayRegion::set_texture_reload_priority(texture_reload_priority);
277  _left_eye->set_texture_reload_priority(texture_reload_priority);
278  _right_eye->set_texture_reload_priority(texture_reload_priority);
279 }
280 
281 ////////////////////////////////////////////////////////////////////
282 // Function: StereoDisplayRegion::set_cull_traverser
283 // Access: Published, Virtual
284 // Description: Sets the CullTraverser for both the left and right
285 // DisplayRegions.
286 ////////////////////////////////////////////////////////////////////
290  _left_eye->set_cull_traverser(trav);
291  _right_eye->set_cull_traverser(trav);
292 }
293 
294 ////////////////////////////////////////////////////////////////////
295 // Function: StereoDisplayRegion::set_target_tex_page
296 // Access: Published, Virtual
297 // Description: Sets the page and view on both the left and
298 // right DisplayRegions to the indicated value.
299 ////////////////////////////////////////////////////////////////////
303  _left_eye->set_target_tex_page(page);
304  _right_eye->set_target_tex_page(page);
305 }
306 
307 ////////////////////////////////////////////////////////////////////
308 // Function: StereoDisplayRegion::output
309 // Access: Published, Virtual
310 // Description:
311 ////////////////////////////////////////////////////////////////////
312 void StereoDisplayRegion::
313 output(ostream &out) const {
314  out << "StereoDisplayRegion(" << *_left_eye << ")";
315 }
316 
317 ////////////////////////////////////////////////////////////////////
318 // Function: StereoDisplayRegion::make_cull_result_graph
319 // Access: Published, Virtual
320 // Description: Returns a special scene graph constructed to
321 // represent the results of the last frame's cull
322 // operation.
323 ////////////////////////////////////////////////////////////////////
324 PT(PandaNode) StereoDisplayRegion::
325 make_cull_result_graph() {
326  PT(PandaNode) root = new PandaNode("stereo");
327 
328  PT(PandaNode) left = _left_eye->make_cull_result_graph();
329  left->set_name("left");
330  root->add_child(left, _left_eye->get_sort());
331 
332  PT(PandaNode) right = _right_eye->make_cull_result_graph();
333  right->set_name("right");
334  root->add_child(right, _right_eye->get_sort());
335 
336  return root;
337 }
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
virtual void disable_clears()
Disables both the color and depth clear.
virtual void set_sort(int sort)
Sets the sort value associated with the DisplayRegion.
virtual void set_clear_active(int n, bool clear_aux_active)
Sets the clear-active flag for any bitplane.
virtual void set_tex_view_offset(int tex_view_offset)
Sets the current texture view offset for this DisplayRegion.
Lens::StereoChannel get_stereo_channel() const
Returns whether the DisplayRegion is specified as the left or right channel of a stereo pair...
virtual void set_texture_reload_priority(int texture_reload_priority)
Sets the texture_reload_priority on both the left and right DisplayRegions to the indicated value...
void set_dimensions(PN_stdfloat l, PN_stdfloat r, PN_stdfloat b, PN_stdfloat t)
Changes the portion of the framebuffer this DisplayRegion corresponds to.
virtual void set_texture_reload_priority(int texture_reload_priority)
Specifies an integer priority which is assigned to any asynchronous texture reload requests spawned w...
virtual void set_target_tex_page(int page)
This is a special parameter that is only used when rendering the faces of a cube map or multipage and...
virtual void set_cull_traverser(CullTraverser *trav)
Specifies the CullTraverser that will be used to draw the contents of this DisplayRegion.
GraphicsOutput * get_window() const
Returns the GraphicsOutput that this DisplayRegion is ultimately associated with, or NULL if no windo...
virtual bool is_stereo() const
Returns true if this is a StereoDisplayRegion, false otherwise.
virtual void set_clear_value(int n, const LColor &clear_value)
Sets the clear value for any bitplane.
virtual void set_tex_view_offset(int tex_view_offset)
Sets the current texture view offset for this DisplayRegion.
virtual void set_incomplete_render(bool incomplete_render)
Sets the incomplete_render flag on both the left and right DisplayRegions to the indicated value...
virtual void set_active(bool active)
Sets the active flag associated with the DisplayRegion.
virtual void set_active(bool active)
Sets the active flag on both the left and right DisplayRegions to the indicated value.
virtual void set_camera(const NodePath &camera)
Sets both the left and right DisplayRegions to the indicated camera.
virtual void set_incomplete_render(bool incomplete_render)
Sets the incomplete_render flag.
virtual void set_stereo_channel(Lens::StereoChannel stereo_channel)
Sets the stereo channels on the left and right eyes, and also sets the active flags independently on ...
virtual void disable_clears()
Disables both the color and depth clear.
virtual void set_stereo_channel(Lens::StereoChannel stereo_channel)
Specifies whether the DisplayRegion represents the left or right channel of a stereo pair...
virtual void set_dimensions(int i, const LVecBase4 &dimensions)
Sets both the left and right DisplayRegions to the indicated dimensions.
This is a base class for the various different classes that represent the result of a frame of render...
int get_sort() const
Returns the sort value associated with the DisplayRegion.
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
virtual void set_camera(const NodePath &camera)
Sets the camera that is associated with this DisplayRegion.
virtual void set_pixel_zoom(PN_stdfloat pixel_zoom)
Sets the pixel_zoom for left and right eyes.
virtual void set_pixel_zoom(PN_stdfloat pixel_zoom)
Sets the amount by which the pixels of the region are scaled internally when filling the image intera...
virtual void set_target_tex_page(int page)
Sets the page and view on both the left and right DisplayRegions to the indicated value...
bool is_active() const
Returns the active flag associated with the DisplayRegion.
virtual void set_sort(int sort)
Sets the indicated sort value on the overall DisplayRegion, the indicated sort value + 1 on the left ...
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:61
virtual void set_cull_traverser(CullTraverser *trav)
Sets the CullTraverser for both the left and right DisplayRegions.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
virtual void set_clear_active(int n, bool clear_aux_active)
Sets the clear-active flag for any bitplane.
virtual void set_clear_value(int n, const LColor &clear_value)
Sets the clear value for any bitplane.