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