Panda3D
 All Classes Functions Variables Enumerations
stereoDisplayRegion.cxx
00001 // Filename: stereoDisplayRegion.cxx
00002 // Created by:  drose (19Feb09)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "stereoDisplayRegion.h"
00016 #include "pandaNode.h"
00017 
00018 TypeHandle StereoDisplayRegion::_type_handle;
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: StereoDisplayRegion::Constructor
00022 //       Access: Published
00023 //  Description:
00024 ////////////////////////////////////////////////////////////////////
00025 StereoDisplayRegion::
00026 StereoDisplayRegion(GraphicsOutput *window,
00027                     const LVecBase4 &dimensions,
00028                     DisplayRegion *left, DisplayRegion *right) :
00029   DisplayRegion(window, dimensions),
00030   _left_eye(left),
00031   _right_eye(right)
00032 {
00033   nassertv(window == left->get_window() &&
00034            window == right->get_window());
00035   set_stereo_channel(Lens::SC_stereo);
00036   set_sort(0);
00037 }
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //     Function: StereoDisplayRegion::Destructor
00041 //       Access: Published, Virtual
00042 //  Description:
00043 ////////////////////////////////////////////////////////////////////
00044 StereoDisplayRegion::
00045 ~StereoDisplayRegion() {
00046 }
00047 
00048 ////////////////////////////////////////////////////////////////////
00049 //     Function: StereoDisplayRegion::set_clear_active
00050 //       Access: Published, Virtual
00051 //  Description: Sets the clear-active flag for any bitplane.
00052 ////////////////////////////////////////////////////////////////////
00053 void StereoDisplayRegion::
00054 set_clear_active(int n, bool clear_active) {
00055   // The clear_active flag gets set only on the parent, stereo display
00056   // region.
00057   DisplayRegion::set_clear_active(n, clear_active);
00058 
00059   // Except for depth and stencil buffers.  These also get set on the
00060   // right display region by default, on the assumption that we want
00061   // to clear these buffers between drawing the eyes, and that the
00062   // right eye is the second of the pair.
00063   switch (n) {
00064   case RTP_stencil:
00065   case RTP_depth_stencil:
00066   case RTP_depth:
00067     _right_eye->set_clear_active(n, clear_active);
00068     break;
00069 
00070   default:
00071     break;
00072   }
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: StereoDisplayRegion::set_clear_value
00077 //       Access: Published, Virtual
00078 //  Description: Sets the clear value for any bitplane.
00079 ////////////////////////////////////////////////////////////////////
00080 void StereoDisplayRegion::
00081 set_clear_value(int n, const LColor &clear_value) {
00082   DisplayRegion::set_clear_value(n, clear_value);
00083   _left_eye->set_clear_value(n, clear_value);
00084   _right_eye->set_clear_value(n, clear_value);
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: StereoDisplayRegion::disable_clears
00089 //       Access: Published, Virtual
00090 //  Description: Disables both the color and depth clear.  See
00091 //               set_clear_color_active and set_clear_depth_active.
00092 ////////////////////////////////////////////////////////////////////
00093 void StereoDisplayRegion::
00094 disable_clears() {
00095   DisplayRegion::disable_clears();
00096   _left_eye->disable_clears();
00097   _right_eye->disable_clears();
00098 }
00099 
00100 ////////////////////////////////////////////////////////////////////
00101 //     Function: StereoDisplayRegion::set_pixel_zoom
00102 //       Access: Published, Virtual
00103 //  Description: Sets the pixel_zoom for left and right eyes.
00104 ////////////////////////////////////////////////////////////////////
00105 void StereoDisplayRegion::
00106 set_pixel_zoom(PN_stdfloat pixel_zoom) {
00107   DisplayRegion::set_pixel_zoom(pixel_zoom);
00108   _left_eye->set_pixel_zoom(pixel_zoom);
00109   _right_eye->set_pixel_zoom(pixel_zoom);
00110 }
00111 
00112 ////////////////////////////////////////////////////////////////////
00113 //     Function: StereoDisplayRegion::set_dimensions
00114 //       Access: Published, Virtual
00115 //  Description: Sets both the left and right DisplayRegions to the
00116 //               indicated dimensions.
00117 ////////////////////////////////////////////////////////////////////
00118 void StereoDisplayRegion::
00119 set_dimensions(const LVecBase4 &dimensions) {
00120   DisplayRegion::set_dimensions(dimensions);
00121   _left_eye->set_dimensions(dimensions);
00122   _right_eye->set_dimensions(dimensions);
00123 }
00124 
00125 ////////////////////////////////////////////////////////////////////
00126 //     Function: StereoDisplayRegion::is_stereo
00127 //       Access: Published, Virtual
00128 //  Description: Returns true if this is a StereoDisplayRegion, false
00129 //               otherwise.
00130 ////////////////////////////////////////////////////////////////////
00131 bool StereoDisplayRegion::
00132 is_stereo() const {
00133   return true;
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: StereoDisplayRegion::set_camera
00138 //       Access: Published, Virtual
00139 //  Description: Sets both the left and right DisplayRegions to the
00140 //               indicated camera.
00141 ////////////////////////////////////////////////////////////////////
00142 void StereoDisplayRegion::
00143 set_camera(const NodePath &camera) {
00144   DisplayRegion::set_camera(camera);
00145   _left_eye->set_camera(camera);
00146   _right_eye->set_camera(camera);
00147 }
00148 
00149 ////////////////////////////////////////////////////////////////////
00150 //     Function: StereoDisplayRegion::set_active
00151 //       Access: Published, Virtual
00152 //  Description: Sets the active flag on both the left and right
00153 //               DisplayRegions to the indicated value.
00154 ////////////////////////////////////////////////////////////////////
00155 void StereoDisplayRegion::
00156 set_active(bool active) {
00157   DisplayRegion::set_active(active);
00158   _left_eye->set_active(active);
00159   _right_eye->set_active(active);
00160   if (active) {
00161     // Reenable the appropriate eyes according to our stereo_channel
00162     // setting.
00163     set_stereo_channel(get_stereo_channel());
00164   }
00165 }
00166 
00167 ////////////////////////////////////////////////////////////////////
00168 //     Function: StereoDisplayRegion::set_sort
00169 //       Access: Published, Virtual
00170 //  Description: Sets the indicated sort value on the overall
00171 //               DisplayRegion, the indicated sort value + 1 on the
00172 //               left eye, and the indicated sort value + 2 on the
00173 //               right eye.
00174 ////////////////////////////////////////////////////////////////////
00175 void StereoDisplayRegion::
00176 set_sort(int sort) {
00177   DisplayRegion::set_sort(sort);
00178   _left_eye->set_sort(sort + 1);
00179   _right_eye->set_sort(sort + 2);
00180 }
00181 
00182 ////////////////////////////////////////////////////////////////////
00183 //     Function: StereoDisplayRegion::set_stereo_channel
00184 //       Access: Published, Virtual
00185 //  Description: Sets the stereo channels on the left and right eyes,
00186 //               and also sets the active flags independently on both
00187 //               eyes.  For a StereoDisplayRegion, a different action
00188 //               is performed for each different value:
00189 //
00190 //               SC_stereo - the left eye is set to SC_left, the right
00191 //               eye to SC_right, and both eyes are activated.
00192 //
00193 //               SC_left - the left eye is set to SC_left and
00194 //               activated; the right eye is deactivated.
00195 //
00196 //               SC_right - the right eye is set to SC_right and
00197 //               activated; the left eye is deactivated.
00198 //
00199 //               SC_mono - the left eye is set to SC_mono and
00200 //               activated; the right eye is deactivated.
00201 //
00202 //               This call also resets tex_view_offset to its default
00203 //               value, which is 0 for the left eye or 1 for the right
00204 //               eye of a stereo display region, or 0 for a mono
00205 //               display region.
00206 ////////////////////////////////////////////////////////////////////
00207 void StereoDisplayRegion::
00208 set_stereo_channel(Lens::StereoChannel stereo_channel) {
00209   DisplayRegion::set_stereo_channel(stereo_channel);
00210   if (!is_active()) {
00211     return;
00212   }
00213 
00214   switch (stereo_channel) {
00215   case Lens::SC_stereo:
00216     _left_eye->set_stereo_channel(Lens::SC_left);
00217     _left_eye->set_active(true);
00218     _right_eye->set_stereo_channel(Lens::SC_right);
00219     _right_eye->set_active(true);
00220     break;
00221 
00222   case Lens::SC_left:
00223     _left_eye->set_stereo_channel(Lens::SC_left);
00224     _left_eye->set_active(true);
00225     _right_eye->set_active(false);
00226     break;
00227 
00228   case Lens::SC_right:
00229     _left_eye->set_active(false);
00230     _right_eye->set_stereo_channel(Lens::SC_right);
00231     _right_eye->set_active(true);
00232     break;
00233 
00234   case Lens::SC_mono:
00235     _left_eye->set_stereo_channel(Lens::SC_mono);
00236     _left_eye->set_active(true);
00237     _right_eye->set_active(false);
00238     break;
00239   }
00240 }
00241 
00242 ////////////////////////////////////////////////////////////////////
00243 //     Function: StereoDisplayRegion::set_tex_view_offset
00244 //       Access: Published, Virtual
00245 //  Description: Sets the current texture view offset for this
00246 //               DisplayRegion.  This is normally set to zero.  If
00247 //               nonzero, it is used to select a particular view of
00248 //               any multiview textures that are rendered within this
00249 //               DisplayRegion.
00250 //
00251 //               When you call this on a StereoDisplayRegion, it
00252 //               automatically sets the specified value on the left
00253 //               eye, and the specified value + 1 on the right eye.
00254 ////////////////////////////////////////////////////////////////////
00255 void StereoDisplayRegion::
00256 set_tex_view_offset(int tex_view_offset) {
00257   DisplayRegion::set_tex_view_offset(tex_view_offset);
00258   _left_eye->set_tex_view_offset(tex_view_offset);
00259   _right_eye->set_tex_view_offset(tex_view_offset + 1);
00260 }
00261 
00262 ////////////////////////////////////////////////////////////////////
00263 //     Function: StereoDisplayRegion::set_incomplete_render
00264 //       Access: Published, Virtual
00265 //  Description: Sets the incomplete_render flag on both the left and
00266 //               right DisplayRegions to the indicated value.
00267 ////////////////////////////////////////////////////////////////////
00268 void StereoDisplayRegion::
00269 set_incomplete_render(bool incomplete_render) {
00270   DisplayRegion::set_incomplete_render(incomplete_render);
00271   _left_eye->set_incomplete_render(incomplete_render);
00272   _right_eye->set_incomplete_render(incomplete_render);
00273 }
00274 
00275 ////////////////////////////////////////////////////////////////////
00276 //     Function: StereoDisplayRegion::set_texture_reload_priority
00277 //       Access: Published, Virtual
00278 //  Description: Sets the texture_reload_priority on both the left and
00279 //               right DisplayRegions to the indicated value.
00280 ////////////////////////////////////////////////////////////////////
00281 void StereoDisplayRegion::
00282 set_texture_reload_priority(int texture_reload_priority) {
00283   DisplayRegion::set_texture_reload_priority(texture_reload_priority);
00284   _left_eye->set_texture_reload_priority(texture_reload_priority);
00285   _right_eye->set_texture_reload_priority(texture_reload_priority);
00286 }
00287 
00288 ////////////////////////////////////////////////////////////////////
00289 //     Function: StereoDisplayRegion::set_cull_traverser
00290 //       Access: Published, Virtual
00291 //  Description: Sets the CullTraverser for both the left and right
00292 //               DisplayRegions.
00293 ////////////////////////////////////////////////////////////////////
00294 void StereoDisplayRegion::
00295 set_cull_traverser(CullTraverser *trav) {
00296   DisplayRegion::set_cull_traverser(trav);
00297   _left_eye->set_cull_traverser(trav);
00298   _right_eye->set_cull_traverser(trav);
00299 }
00300 
00301 ////////////////////////////////////////////////////////////////////
00302 //     Function: StereoDisplayRegion::set_cube_map_index
00303 //       Access: Published, Virtual
00304 //  Description: Sets the cube_map_index on both the left and
00305 //               right DisplayRegions to the indicated value.
00306 ////////////////////////////////////////////////////////////////////
00307 void StereoDisplayRegion::
00308 set_cube_map_index(int cube_map_index) {
00309   DisplayRegion::set_cube_map_index(cube_map_index);
00310   _left_eye->set_cube_map_index(cube_map_index);
00311   _right_eye->set_cube_map_index(cube_map_index);
00312 }
00313 
00314 ////////////////////////////////////////////////////////////////////
00315 //     Function: StereoDisplayRegion::output
00316 //       Access: Published, Virtual
00317 //  Description:
00318 ////////////////////////////////////////////////////////////////////
00319 void StereoDisplayRegion::
00320 output(ostream &out) const {
00321   out << "StereoDisplayRegion(" << *_left_eye << ")";
00322 }
00323 
00324 ////////////////////////////////////////////////////////////////////
00325 //     Function: StereoDisplayRegion::make_cull_result_graph
00326 //       Access: Published, Virtual
00327 //  Description: Returns a special scene graph constructed to
00328 //               represent the results of the last frame's cull
00329 //               operation.
00330 ////////////////////////////////////////////////////////////////////
00331 PT(PandaNode) StereoDisplayRegion::
00332 make_cull_result_graph() {
00333   PT(PandaNode) root = new PandaNode("stereo");
00334 
00335   PT(PandaNode) left = _left_eye->make_cull_result_graph();
00336   left->set_name("left");
00337   root->add_child(left, _left_eye->get_sort());
00338 
00339   PT(PandaNode) right = _right_eye->make_cull_result_graph();
00340   right->set_name("right");
00341   root->add_child(right, _right_eye->get_sort());
00342 
00343   return root;
00344 }
 All Classes Functions Variables Enumerations