Panda3D
|
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 float l, float r, float b, float t, 00028 DisplayRegion *left, DisplayRegion *right) : 00029 DisplayRegion(window, l, r, b, t), 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 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: StereoDisplayRegion::Destructor 00040 // Access: Published, Virtual 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 StereoDisplayRegion:: 00044 ~StereoDisplayRegion() { 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: StereoDisplayRegion::set_clear_active 00049 // Access: Published, Virtual 00050 // Description: Sets the clear-active flag for any bitplane. 00051 //////////////////////////////////////////////////////////////////// 00052 void StereoDisplayRegion:: 00053 set_clear_active(int n, bool clear_active) { 00054 // The clear_active flag gets set only on the parent, stereo display 00055 // region. 00056 DisplayRegion::set_clear_active(n, clear_active); 00057 00058 // Except for depth and stencil buffers. These also get set on the 00059 // right display region by default, on the assumption that we want 00060 // to clear these buffers between drawing the eyes, and that the 00061 // right eye is the second of the pair. 00062 switch (n) { 00063 case RTP_stencil: 00064 case RTP_depth_stencil: 00065 case RTP_depth: 00066 _right_eye->set_clear_active(n, clear_active); 00067 break; 00068 00069 default: 00070 break; 00071 } 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: StereoDisplayRegion::set_clear_value 00076 // Access: Published, Virtual 00077 // Description: Sets the clear value for any bitplane. 00078 //////////////////////////////////////////////////////////////////// 00079 void StereoDisplayRegion:: 00080 set_clear_value(int n, const Colorf &clear_value) { 00081 DisplayRegion::set_clear_value(n, clear_value); 00082 _left_eye->set_clear_value(n, clear_value); 00083 _right_eye->set_clear_value(n, clear_value); 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: StereoDisplayRegion::disable_clears 00088 // Access: Published, Virtual 00089 // Description: Disables both the color and depth clear. See 00090 // set_clear_color_active and set_clear_depth_active. 00091 //////////////////////////////////////////////////////////////////// 00092 void StereoDisplayRegion:: 00093 disable_clears() { 00094 DisplayRegion::disable_clears(); 00095 _left_eye->disable_clears(); 00096 _right_eye->disable_clears(); 00097 } 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: StereoDisplayRegion::set_pixel_zoom 00101 // Access: Published, Virtual 00102 // Description: Sets the pixel_zoom for left and right eyes. 00103 //////////////////////////////////////////////////////////////////// 00104 void StereoDisplayRegion:: 00105 set_pixel_zoom(float pixel_zoom) { 00106 DisplayRegion::set_pixel_zoom(pixel_zoom); 00107 _left_eye->set_pixel_zoom(pixel_zoom); 00108 _right_eye->set_pixel_zoom(pixel_zoom); 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: StereoDisplayRegion::set_dimensions 00113 // Access: Published, Virtual 00114 // Description: Sets both the left and right DisplayRegions to the 00115 // indicated dimensions. 00116 //////////////////////////////////////////////////////////////////// 00117 void StereoDisplayRegion:: 00118 set_dimensions(float l, float r, float b, float t) { 00119 DisplayRegion::set_dimensions(l, r, b, t); 00120 _left_eye->set_dimensions(l, r, b, t); 00121 _right_eye->set_dimensions(l, r, b, t); 00122 } 00123 00124 //////////////////////////////////////////////////////////////////// 00125 // Function: StereoDisplayRegion::is_stereo 00126 // Access: Published, Virtual 00127 // Description: Returns true if this is a StereoDisplayRegion, false 00128 // otherwise. 00129 //////////////////////////////////////////////////////////////////// 00130 bool StereoDisplayRegion:: 00131 is_stereo() const { 00132 return true; 00133 } 00134 00135 //////////////////////////////////////////////////////////////////// 00136 // Function: StereoDisplayRegion::set_camera 00137 // Access: Published, Virtual 00138 // Description: Sets both the left and right DisplayRegions to the 00139 // indicated camera. 00140 //////////////////////////////////////////////////////////////////// 00141 void StereoDisplayRegion:: 00142 set_camera(const NodePath &camera) { 00143 DisplayRegion::set_camera(camera); 00144 _left_eye->set_camera(camera); 00145 _right_eye->set_camera(camera); 00146 } 00147 00148 //////////////////////////////////////////////////////////////////// 00149 // Function: StereoDisplayRegion::set_active 00150 // Access: Published, Virtual 00151 // Description: Sets the active flag on both the left and right 00152 // DisplayRegions to the indicated value. 00153 //////////////////////////////////////////////////////////////////// 00154 void StereoDisplayRegion:: 00155 set_active(bool active) { 00156 DisplayRegion::set_active(active); 00157 _left_eye->set_active(active); 00158 _right_eye->set_active(active); 00159 if (active) { 00160 // Reenable the appropriate eyes according to our stereo_channel 00161 // setting. 00162 set_stereo_channel(get_stereo_channel()); 00163 } 00164 } 00165 00166 //////////////////////////////////////////////////////////////////// 00167 // Function: StereoDisplayRegion::set_sort 00168 // Access: Published, Virtual 00169 // Description: Sets the indicated sort value on the overall 00170 // DisplayRegion, the indicated sort value + 1 on the 00171 // left eye, and the indicated sort value + 2 on the 00172 // right eye. 00173 //////////////////////////////////////////////////////////////////// 00174 void StereoDisplayRegion:: 00175 set_sort(int sort) { 00176 DisplayRegion::set_sort(sort); 00177 _left_eye->set_sort(sort + 1); 00178 _right_eye->set_sort(sort + 2); 00179 } 00180 00181 //////////////////////////////////////////////////////////////////// 00182 // Function: StereoDisplayRegion::set_stereo_channel 00183 // Access: Published, Virtual 00184 // Description: Sets the stereo channels on the left and right eyes, 00185 // and also sets the active flags independently on both 00186 // eyes. For a StereoDisplayRegion, a different action 00187 // is performed for each different value: 00188 // 00189 // SC_stereo - the left eye is set to SC_left, the right 00190 // eye to SC_right, and both eyes are activated. 00191 // 00192 // SC_left - the left eye is set to SC_left and 00193 // activated; the right eye is deactivated. 00194 // 00195 // SC_right - the right eye is set to SC_right and 00196 // activated; the left eye is deactivated. 00197 // 00198 // SC_mono - the left eye is set to SC_mono and 00199 // activated; the right eye is deactivated. 00200 //////////////////////////////////////////////////////////////////// 00201 void StereoDisplayRegion:: 00202 set_stereo_channel(Lens::StereoChannel stereo_channel) { 00203 DisplayRegion::set_stereo_channel(stereo_channel); 00204 if (!is_active()) { 00205 return; 00206 } 00207 00208 switch (stereo_channel) { 00209 case Lens::SC_stereo: 00210 _left_eye->set_stereo_channel(Lens::SC_left); 00211 _left_eye->set_active(true); 00212 _right_eye->set_stereo_channel(Lens::SC_right); 00213 _right_eye->set_active(true); 00214 break; 00215 00216 case Lens::SC_left: 00217 _left_eye->set_stereo_channel(Lens::SC_left); 00218 _left_eye->set_active(true); 00219 _right_eye->set_active(false); 00220 break; 00221 00222 case Lens::SC_right: 00223 _left_eye->set_active(false); 00224 _right_eye->set_stereo_channel(Lens::SC_right); 00225 _right_eye->set_active(true); 00226 break; 00227 00228 case Lens::SC_mono: 00229 _left_eye->set_stereo_channel(Lens::SC_mono); 00230 _left_eye->set_active(true); 00231 _right_eye->set_active(false); 00232 break; 00233 } 00234 } 00235 00236 //////////////////////////////////////////////////////////////////// 00237 // Function: StereoDisplayRegion::set_incomplete_render 00238 // Access: Published, Virtual 00239 // Description: Sets the incomplete_render flag on both the left and 00240 // right DisplayRegions to the indicated value. 00241 //////////////////////////////////////////////////////////////////// 00242 void StereoDisplayRegion:: 00243 set_incomplete_render(bool incomplete_render) { 00244 DisplayRegion::set_incomplete_render(incomplete_render); 00245 _left_eye->set_incomplete_render(incomplete_render); 00246 _right_eye->set_incomplete_render(incomplete_render); 00247 } 00248 00249 //////////////////////////////////////////////////////////////////// 00250 // Function: StereoDisplayRegion::set_texture_reload_priority 00251 // Access: Published, Virtual 00252 // Description: Sets the texture_reload_priority on both the left and 00253 // right DisplayRegions to the indicated value. 00254 //////////////////////////////////////////////////////////////////// 00255 void StereoDisplayRegion:: 00256 set_texture_reload_priority(int texture_reload_priority) { 00257 DisplayRegion::set_texture_reload_priority(texture_reload_priority); 00258 _left_eye->set_texture_reload_priority(texture_reload_priority); 00259 _right_eye->set_texture_reload_priority(texture_reload_priority); 00260 } 00261 00262 //////////////////////////////////////////////////////////////////// 00263 // Function: StereoDisplayRegion::set_cull_traverser 00264 // Access: Published, Virtual 00265 // Description: Sets the CullTraverser for both the left and right 00266 // DisplayRegions. 00267 //////////////////////////////////////////////////////////////////// 00268 void StereoDisplayRegion:: 00269 set_cull_traverser(CullTraverser *trav) { 00270 DisplayRegion::set_cull_traverser(trav); 00271 _left_eye->set_cull_traverser(trav); 00272 _right_eye->set_cull_traverser(trav); 00273 } 00274 00275 //////////////////////////////////////////////////////////////////// 00276 // Function: StereoDisplayRegion::set_cube_map_index 00277 // Access: Published, Virtual 00278 // Description: Sets the cube_map_index on both the left and 00279 // right DisplayRegions to the indicated value. 00280 //////////////////////////////////////////////////////////////////// 00281 void StereoDisplayRegion:: 00282 set_cube_map_index(int cube_map_index) { 00283 DisplayRegion::set_cube_map_index(cube_map_index); 00284 _left_eye->set_cube_map_index(cube_map_index); 00285 _right_eye->set_cube_map_index(cube_map_index); 00286 } 00287 00288 //////////////////////////////////////////////////////////////////// 00289 // Function: StereoDisplayRegion::output 00290 // Access: Published, Virtual 00291 // Description: 00292 //////////////////////////////////////////////////////////////////// 00293 void StereoDisplayRegion:: 00294 output(ostream &out) const { 00295 out << "StereoDisplayRegion(" << *_left_eye << ")"; 00296 } 00297 00298 //////////////////////////////////////////////////////////////////// 00299 // Function: StereoDisplayRegion::make_cull_result_graph 00300 // Access: Published, Virtual 00301 // Description: Returns a special scene graph constructed to 00302 // represent the results of the last frame's cull 00303 // operation. 00304 //////////////////////////////////////////////////////////////////// 00305 PT(PandaNode) StereoDisplayRegion:: 00306 make_cull_result_graph() { 00307 PT(PandaNode) root = new PandaNode("stereo"); 00308 00309 PT(PandaNode) left = _left_eye->make_cull_result_graph(); 00310 left->set_name("left"); 00311 root->add_child(left, _left_eye->get_sort()); 00312 00313 PT(PandaNode) right = _right_eye->make_cull_result_graph(); 00314 right->set_name("right"); 00315 root->add_child(right, _right_eye->get_sort()); 00316 00317 return root; 00318 }