00001 // Filename: graphicsOutput.I 00002 // Created by: drose (06Feb04) 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 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: GraphicsOutput::get_gsg 00018 // Access: Published 00019 // Description: Returns the GSG that is associated with this window. 00020 // There is a one-to-one association between windows and 00021 // GSG's. 00022 // 00023 // This may return NULL if the graphics context has not 00024 // yet been created for the window, e.g. before the 00025 // first frame has rendered; or after the window has 00026 // been closed. 00027 //////////////////////////////////////////////////////////////////// 00028 INLINE GraphicsStateGuardian *GraphicsOutput:: 00029 get_gsg() const { 00030 return _gsg; 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: GraphicsOutput::get_pipe 00035 // Access: Published 00036 // Description: Returns the GraphicsPipe that this window is 00037 // associated with. It is possible that the 00038 // GraphicsPipe might have been deleted while an 00039 // outstanding PT(GraphicsOutput) prevented all of its 00040 // children windows from also being deleted; in this 00041 // unlikely case, get_pipe() may return NULL. 00042 //////////////////////////////////////////////////////////////////// 00043 INLINE GraphicsPipe *GraphicsOutput:: 00044 get_pipe() const { 00045 return _pipe; 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: GraphicsOutput::get_engine 00050 // Access: Published 00051 // Description: Returns the graphics engine that created this output. 00052 // Since there is normally only one GraphicsEngine 00053 // object in an application, this is usually the same as 00054 // the global GraphicsEngine. 00055 //////////////////////////////////////////////////////////////////// 00056 INLINE GraphicsEngine *GraphicsOutput:: 00057 get_engine() const { 00058 return _engine; 00059 } 00060 00061 //////////////////////////////////////////////////////////////////// 00062 // Function: GraphicsOutput::get_name 00063 // Access: Published 00064 // Description: Returns the name that was passed to the 00065 // GraphicsOutput constructor. 00066 //////////////////////////////////////////////////////////////////// 00067 INLINE const string &GraphicsOutput:: 00068 get_name() const { 00069 return _name; 00070 } 00071 00072 //////////////////////////////////////////////////////////////////// 00073 // Function: GraphicsOutput::count_textures 00074 // Access: Published 00075 // Description: If the GraphicsOutput is set to render into a 00076 // texture, returns the number of textures that are 00077 // being rendered into. Normally, the textures would 00078 // be associated with different buffers - a color 00079 // texture, a depth texture, and a stencil texture. 00080 //////////////////////////////////////////////////////////////////// 00081 INLINE int GraphicsOutput:: 00082 count_textures() const { 00083 CDReader cdata(_cycler); 00084 return cdata->_textures.size(); 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: GraphicsOutput::has_texture 00089 // Access: Published 00090 // Description: Returns true if the GraphicsOutput is rendering 00091 // into any textures at all. 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE bool GraphicsOutput:: 00094 has_texture() const { 00095 CDReader cdata(_cycler); 00096 return (cdata->_textures.size() > 0); 00097 } 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: GraphicsOutput::get_texture 00101 // Access: Published 00102 // Description: Returns the nth texture into which the GraphicsOutput 00103 // renders. Returns NULL if there is no such texture. 00104 // 00105 // If the texture is non-NULL, it may be applied to 00106 // geometry to be rendered for any other windows or 00107 // outputs that share the same GSG as this 00108 // GraphicsOutput. The effect is undefined for windows 00109 // that share a different GSG; usually in these cases 00110 // the texture will be invalid. 00111 //////////////////////////////////////////////////////////////////// 00112 INLINE Texture *GraphicsOutput:: 00113 get_texture(int i) const { 00114 CDReader cdata(_cycler); 00115 if ((i < 0) || (i >= ((int)cdata->_textures.size()))) { 00116 return (Texture *)NULL; 00117 } 00118 return cdata->_textures[i]._texture; 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: GraphicsOutput::get_texture_plane 00123 // Access: Published 00124 // Description: Returns the RenderTexturePlane associated with the 00125 // nth render-texture. Returns 0 if there is no such 00126 // texture. 00127 //////////////////////////////////////////////////////////////////// 00128 INLINE GraphicsOutput::RenderTexturePlane GraphicsOutput:: 00129 get_texture_plane(int i) const { 00130 CDReader cdata(_cycler); 00131 if ((i < 0) || (i >= ((int)cdata->_textures.size()))) { 00132 return (RenderTexturePlane)0; 00133 } 00134 return cdata->_textures[i]._plane; 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: GraphicsOutput::get_rtm_mode 00139 // Access: Published 00140 // Description: Returns the RenderTextureMode associated with the 00141 // nth render-texture. Returns RTM_none if there is 00142 // no such texture. 00143 //////////////////////////////////////////////////////////////////// 00144 INLINE GraphicsOutput::RenderTextureMode GraphicsOutput:: 00145 get_rtm_mode(int i) const { 00146 CDReader cdata(_cycler); 00147 if ((i < 0) || (i >= ((int)cdata->_textures.size()))) { 00148 return RTM_none; 00149 } 00150 return cdata->_textures[i]._rtm_mode; 00151 } 00152 00153 //////////////////////////////////////////////////////////////////// 00154 // Function: GraphicsOutput::get_x_size 00155 // Access: Published 00156 // Description: Returns the visible width of the window or buffer, if 00157 // it is known. In certain cases (e.g. fullscreen 00158 // windows), the size may not be known until after the 00159 // object has been fully created. Check has_size() 00160 // first. 00161 // 00162 // Certain objects (like windows) may change size 00163 // spontaneously; this method is not thread-safe. To 00164 // get the size of a window in a thread-safe manner, 00165 // query get_properties(). 00166 //////////////////////////////////////////////////////////////////// 00167 INLINE int GraphicsOutput:: 00168 get_x_size() const { 00169 return _x_size; 00170 } 00171 00172 //////////////////////////////////////////////////////////////////// 00173 // Function: GraphicsOutput::get_y_size 00174 // Access: Published 00175 // Description: Returns the visible height of the window or buffer, 00176 // if it is known. In certain cases (e.g. fullscreen 00177 // windows), the size may not be known until after the 00178 // object has been fully created. Check has_size() 00179 // first. 00180 // 00181 // Certain objects (like windows) may change size 00182 // spontaneously; this method is not thread-safe. To 00183 // get the size of a window in a thread-safe manner, 00184 // query get_properties(). 00185 //////////////////////////////////////////////////////////////////// 00186 INLINE int GraphicsOutput:: 00187 get_y_size() const { 00188 return _y_size; 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: GraphicsOutput::get_fb_x_size 00193 // Access: Published 00194 // Description: Returns the internal width of the window or buffer. 00195 // This is almost always the same as get_x_size(), 00196 // except when a pixel_zoom is in effect--see 00197 // set_pixel_zoom(). 00198 //////////////////////////////////////////////////////////////////// 00199 INLINE int GraphicsOutput:: 00200 get_fb_x_size() const { 00201 return max(int(_x_size * get_pixel_factor()), 1); 00202 } 00203 00204 //////////////////////////////////////////////////////////////////// 00205 // Function: GraphicsOutput::get_fb_y_size 00206 // Access: Published 00207 // Description: Returns the internal height of the window or buffer. 00208 // This is almost always the same as get_y_size(), 00209 // except when a pixel_zoom is in effect--see 00210 // set_pixel_zoom(). 00211 //////////////////////////////////////////////////////////////////// 00212 INLINE int GraphicsOutput:: 00213 get_fb_y_size() const { 00214 return max(int(_y_size * get_pixel_factor()), 1); 00215 } 00216 00217 //////////////////////////////////////////////////////////////////// 00218 // Function: GraphicsOutput::get_sbs_left_x_size 00219 // Access: Published 00220 // Description: If side-by-side stereo is enabled, this returns the 00221 // pixel width of the left eye, based on scaling 00222 // get_x_size() by get_sbs_left_dimensions(). If 00223 // side-by-side stereo is not enabled, this returns the 00224 // same as get_x_size(). 00225 //////////////////////////////////////////////////////////////////// 00226 INLINE int GraphicsOutput:: 00227 get_sbs_left_x_size() const { 00228 PN_stdfloat left_w = _sbs_left_dimensions[1] - _sbs_left_dimensions[0]; 00229 return max(int(_x_size * left_w), 1); 00230 } 00231 00232 //////////////////////////////////////////////////////////////////// 00233 // Function: GraphicsOutput::get_sbs_left_y_size 00234 // Access: Published 00235 // Description: If side-by-side stereo is enabled, this returns the 00236 // pixel height of the left eye, based on scaling 00237 // get_y_size() by get_sbs_left_dimensions(). If 00238 // side-by-side stereo is not enabled, this returns the 00239 // same as get_y_size(). 00240 //////////////////////////////////////////////////////////////////// 00241 INLINE int GraphicsOutput:: 00242 get_sbs_left_y_size() const { 00243 PN_stdfloat left_h = _sbs_left_dimensions[3] - _sbs_left_dimensions[2]; 00244 return max(int(_y_size * left_h), 1); 00245 } 00246 00247 //////////////////////////////////////////////////////////////////// 00248 // Function: GraphicsOutput::get_sbs_right_x_size 00249 // Access: Published 00250 // Description: If side-by-side stereo is enabled, this returns the 00251 // pixel width of the right eye, based on scaling 00252 // get_x_size() by get_sbs_right_dimensions(). If 00253 // side-by-side stereo is not enabled, this returns the 00254 // same as get_x_size(). 00255 //////////////////////////////////////////////////////////////////// 00256 INLINE int GraphicsOutput:: 00257 get_sbs_right_x_size() const { 00258 PN_stdfloat right_w = _sbs_right_dimensions[1] - _sbs_right_dimensions[0]; 00259 return max(int(_x_size * right_w), 1); 00260 } 00261 00262 //////////////////////////////////////////////////////////////////// 00263 // Function: GraphicsOutput::get_sbs_right_y_size 00264 // Access: Published 00265 // Description: If side-by-side stereo is enabled, this returns the 00266 // pixel height of the right eye, based on scaling 00267 // get_y_size() by get_sbs_right_dimensions(). If 00268 // side-by-side stereo is not enabled, this returns the 00269 // same as get_y_size(). 00270 //////////////////////////////////////////////////////////////////// 00271 INLINE int GraphicsOutput:: 00272 get_sbs_right_y_size() const { 00273 PN_stdfloat right_h = _sbs_right_dimensions[3] - _sbs_right_dimensions[2]; 00274 return max(int(_y_size * right_h), 1); 00275 } 00276 00277 //////////////////////////////////////////////////////////////////// 00278 // Function: GraphicsOutput::has_size 00279 // Access: Published 00280 // Description: Returns true if the size of the window/frame buffer 00281 // is known, false otherwise. In certain cases the size 00282 // may not be known until after the object has been 00283 // fully created. Also, certain objects (like windows) 00284 // may change size spontaneously. 00285 //////////////////////////////////////////////////////////////////// 00286 INLINE bool GraphicsOutput:: 00287 has_size() const { 00288 return _has_size; 00289 } 00290 00291 //////////////////////////////////////////////////////////////////// 00292 // Function: GraphicsOutput::is_valid 00293 // Access: Published 00294 // Description: Returns true if the output is fully created and ready 00295 // for rendering, false otherwise. 00296 //////////////////////////////////////////////////////////////////// 00297 INLINE bool GraphicsOutput:: 00298 is_valid() const { 00299 return _is_valid && _is_nonzero_size; 00300 } 00301 00302 //////////////////////////////////////////////////////////////////// 00303 // Function: GraphicsOutput::is_nonzero_size 00304 // Access: Published 00305 // Description: Returns true if the output has a nonzero size in both 00306 // X and Y, or false if it is zero (and therefore 00307 // invalid). 00308 //////////////////////////////////////////////////////////////////// 00309 INLINE bool GraphicsOutput:: 00310 is_nonzero_size() const { 00311 return _is_nonzero_size; 00312 } 00313 00314 //////////////////////////////////////////////////////////////////// 00315 // Function: GraphicsOutput::get_inverted 00316 // Access: Published 00317 // Description: Returns the current setting of the inverted flag. 00318 // When this is true, the scene is rendered into the 00319 // window upside-down, flipped like a mirror along the X 00320 // axis. See set_inverted(). 00321 //////////////////////////////////////////////////////////////////// 00322 INLINE bool GraphicsOutput:: 00323 get_inverted() const { 00324 return _inverted; 00325 } 00326 00327 //////////////////////////////////////////////////////////////////// 00328 // Function: GraphicsOutput::set_swap_eyes 00329 // Access: Public 00330 // Description: Changes the "swap eyes" flag. This flag is normally 00331 // false. When it is true, the left and right channels 00332 // of a stereo DisplayRegion are sent to the opposite 00333 // channels in the rendering backend. This is meant to 00334 // work around hardware that inadvertently swaps the 00335 // output channels, or hardware for which it cannot be 00336 // determined which channel is which until runtime. 00337 //////////////////////////////////////////////////////////////////// 00338 INLINE void GraphicsOutput:: 00339 set_swap_eyes(bool swap_eyes) { 00340 _swap_eyes = swap_eyes; 00341 } 00342 00343 //////////////////////////////////////////////////////////////////// 00344 // Function: GraphicsOutput::get_swap_eyes 00345 // Access: Public 00346 // Description: Returns the current setting of the "swap eyes" flag. 00347 // See set_swap_eyes(). 00348 //////////////////////////////////////////////////////////////////// 00349 INLINE bool GraphicsOutput:: 00350 get_swap_eyes() const { 00351 return _swap_eyes; 00352 } 00353 00354 //////////////////////////////////////////////////////////////////// 00355 // Function: GraphicsOutput::set_red_blue_stereo 00356 // Access: Published 00357 // Description: Enables red-blue stereo mode on this particular 00358 // window. When red-blue stereo mode is in effect, 00359 // DisplayRegions that have the "left" channel set will 00360 // render in the red (or specified) channel only, while 00361 // DisplayRegions that have the "right" channel set will 00362 // render in the blue (or specified) channel only. 00363 // 00364 // The remaining two parameters specify the particular 00365 // color channel(s) to associate with each eye. Use the 00366 // bits defined in ColorWriteAttrib::Channels. 00367 // 00368 // This can be used to achieve a cheesy stereo mode in 00369 // the absence of hardware-supported stereo. 00370 //////////////////////////////////////////////////////////////////// 00371 INLINE void GraphicsOutput:: 00372 set_red_blue_stereo(bool red_blue_stereo, 00373 unsigned int left_eye_color_mask, 00374 unsigned int right_eye_color_mask) { 00375 _red_blue_stereo = red_blue_stereo; 00376 if (_red_blue_stereo) { 00377 _left_eye_color_mask = left_eye_color_mask; 00378 _right_eye_color_mask = right_eye_color_mask; 00379 } else { 00380 _left_eye_color_mask = 0x0f; 00381 _right_eye_color_mask = 0x0f; 00382 } 00383 } 00384 00385 //////////////////////////////////////////////////////////////////// 00386 // Function: GraphicsOutput::get_red_blue_stereo 00387 // Access: Published 00388 // Description: Returns whether red-blue stereo mode is in effect for 00389 // this particular window. See set_red_blue_stereo(). 00390 //////////////////////////////////////////////////////////////////// 00391 INLINE bool GraphicsOutput:: 00392 get_red_blue_stereo() const { 00393 return _red_blue_stereo; 00394 } 00395 00396 //////////////////////////////////////////////////////////////////// 00397 // Function: GraphicsOutput::get_left_eye_color_mask 00398 // Access: Published 00399 // Description: Returns the color mask in effect when rendering a 00400 // left-eye view in red_blue stereo mode. This is one 00401 // or more bits defined in ColorWriteAttrib::Channels. 00402 // See set_red_blue_stereo(). 00403 //////////////////////////////////////////////////////////////////// 00404 INLINE unsigned int GraphicsOutput:: 00405 get_left_eye_color_mask() const { 00406 return _left_eye_color_mask; 00407 } 00408 00409 //////////////////////////////////////////////////////////////////// 00410 // Function: GraphicsOutput::get_right_eye_color_mask 00411 // Access: Published 00412 // Description: Returns the color mask in effect when rendering a 00413 // right-eye view in red_blue stereo mode. This is one 00414 // or more bits defined in ColorWriteAttrib::Channels. 00415 // See set_red_blue_stereo(). 00416 //////////////////////////////////////////////////////////////////// 00417 INLINE unsigned int GraphicsOutput:: 00418 get_right_eye_color_mask() const { 00419 return _right_eye_color_mask; 00420 } 00421 00422 //////////////////////////////////////////////////////////////////// 00423 // Function: GraphicsOutput::get_side_by_side_stereo 00424 // Access: Published 00425 // Description: Returns whether side-by-side stereo mode is in effect for 00426 // this particular window. See set_side_by_side_stereo(). 00427 //////////////////////////////////////////////////////////////////// 00428 INLINE bool GraphicsOutput:: 00429 get_side_by_side_stereo() const { 00430 return _side_by_side_stereo; 00431 } 00432 00433 //////////////////////////////////////////////////////////////////// 00434 // Function: GraphicsOutput::get_sbs_left_dimensions 00435 // Access: Published 00436 // Description: Returns the effective sub-region of the window for 00437 // displaying the left channel, if side-by-side stereo 00438 // mode is in effect for the window. See 00439 // set_side_by_side_stereo(). 00440 //////////////////////////////////////////////////////////////////// 00441 INLINE const LVecBase4 &GraphicsOutput:: 00442 get_sbs_left_dimensions() const { 00443 return _sbs_left_dimensions; 00444 } 00445 00446 //////////////////////////////////////////////////////////////////// 00447 // Function: GraphicsOutput::get_sbs_right_dimensions 00448 // Access: Published 00449 // Description: Returns the effective sub-region of the window for 00450 // displaying the right channel, if side-by-side stereo 00451 // mode is in effect for the window. See 00452 // set_side_by_side_stereo(). 00453 //////////////////////////////////////////////////////////////////// 00454 INLINE const LVecBase4 &GraphicsOutput:: 00455 get_sbs_right_dimensions() const { 00456 return _sbs_right_dimensions; 00457 } 00458 00459 //////////////////////////////////////////////////////////////////// 00460 // Function: GraphicsOutput::get_fb_properties 00461 // Access: Published 00462 // Description: Returns the framebuffer properties of the window. 00463 //////////////////////////////////////////////////////////////////// 00464 INLINE const FrameBufferProperties &GraphicsOutput:: 00465 get_fb_properties() const { 00466 return _fb_properties; 00467 } 00468 00469 //////////////////////////////////////////////////////////////////// 00470 // Function: GraphicsOutput::is_stereo 00471 // Access: Published 00472 // Description: Returns Returns true if this window can render stereo 00473 // DisplayRegions, either through red-blue stereo (see 00474 // set_red_blue_stereo()) or through true hardware 00475 // stereo rendering. 00476 //////////////////////////////////////////////////////////////////// 00477 INLINE bool GraphicsOutput:: 00478 is_stereo() const { 00479 return _red_blue_stereo || _side_by_side_stereo || _fb_properties.is_stereo(); 00480 } 00481 00482 //////////////////////////////////////////////////////////////////// 00483 // Function: GraphicsOutput::clear_delete_flag 00484 // Access: Published 00485 // Description: Resets the delete flag, so the GraphicsOutput will 00486 // not be automatically deleted before the beginning of 00487 // the next frame. 00488 //////////////////////////////////////////////////////////////////// 00489 INLINE void GraphicsOutput:: 00490 clear_delete_flag() { 00491 _delete_flag = false; 00492 } 00493 00494 //////////////////////////////////////////////////////////////////// 00495 // Function: GraphicsOutput::get_sort 00496 // Access: Published 00497 // Description: Returns the sorting order of this particular 00498 // GraphicsOutput. The various GraphicsOutputs within a 00499 // particular thread will be rendered in the indicated 00500 // order. 00501 //////////////////////////////////////////////////////////////////// 00502 INLINE int GraphicsOutput:: 00503 get_sort() const { 00504 return _sort; 00505 } 00506 00507 //////////////////////////////////////////////////////////////////// 00508 // Function: GraphicsOutput::set_child_sort 00509 // Access: Published 00510 // Description: Specifies the sort value of future offscreen buffers 00511 // created by make_texture_sort(). 00512 // 00513 // The purpose of this method is to allow the user to 00514 // limit the sort value chosen for a buffer created via 00515 // make_texture_buffer(). Normally, this buffer will be 00516 // assigned a value of get_sort() - 1, so that it 00517 // will be rendered before this window is rendered; but 00518 // sometimes this isn't sufficiently early, especially 00519 // if other buffers also have a view into the same 00520 // scene. 00521 // 00522 // If you specify a value here, then new buffers created 00523 // via make_texture_buffer() will be given that sort 00524 // value instead of get_sort() - 1. 00525 //////////////////////////////////////////////////////////////////// 00526 INLINE void GraphicsOutput:: 00527 set_child_sort(int child_sort) { 00528 _child_sort = child_sort; 00529 _got_child_sort = true; 00530 } 00531 00532 //////////////////////////////////////////////////////////////////// 00533 // Function: GraphicsOutput::clear_child_sort 00534 // Access: Published 00535 // Description: Resets the sort value of future offscreen buffers 00536 // created by make_texture_sort() to the default value. 00537 // See set_child_sort(). 00538 //////////////////////////////////////////////////////////////////// 00539 INLINE void GraphicsOutput:: 00540 clear_child_sort() { 00541 _got_child_sort = false; 00542 } 00543 00544 //////////////////////////////////////////////////////////////////// 00545 // Function: GraphicsOutput::get_child_sort 00546 // Access: Published 00547 // Description: Returns the sort value of future offscreen buffers 00548 // created by make_texture_sort(). See set_child_sort(). 00549 //////////////////////////////////////////////////////////////////// 00550 INLINE int GraphicsOutput:: 00551 get_child_sort() const { 00552 if (_got_child_sort) { 00553 return _child_sort; 00554 } else { 00555 return get_sort() - 1; 00556 } 00557 } 00558 00559 //////////////////////////////////////////////////////////////////// 00560 // Function: GraphicsOutput::trigger_copy 00561 // Access: Published 00562 // Description: When the GraphicsOutput is in triggered copy mode, 00563 // this function triggers the copy (at the end of the 00564 // next frame). 00565 //////////////////////////////////////////////////////////////////// 00566 INLINE void GraphicsOutput:: 00567 trigger_copy() { 00568 _trigger_copy = true; 00569 } 00570 00571 //////////////////////////////////////////////////////////////////// 00572 // Function: GraphicsOutput::make_display_region 00573 // Access: Published 00574 // Description: Creates a new DisplayRegion that covers the entire 00575 // window. 00576 // 00577 // If is_stereo() is true for this window, and 00578 // default-stereo-camera is configured true, this 00579 // actually makes a StereoDisplayRegion. Call 00580 // make_mono_display_region() or 00581 // make_stereo_display_region() if you want to insist on 00582 // one or the other. 00583 //////////////////////////////////////////////////////////////////// 00584 INLINE DisplayRegion *GraphicsOutput:: 00585 make_display_region() { 00586 return make_display_region(0.0f, 1.0f, 0.0f, 1.0f); 00587 } 00588 00589 //////////////////////////////////////////////////////////////////// 00590 // Function: GraphicsOutput::make_display_region 00591 // Access: Published 00592 // Description: Creates a new DisplayRegion that covers the indicated 00593 // sub-rectangle within the window. The range on all 00594 // parameters is 0..1. 00595 // 00596 // If is_stereo() is true for this window, and 00597 // default-stereo-camera is configured true, this 00598 // actually makes a StereoDisplayRegion. Call 00599 // make_mono_display_region() or 00600 // make_stereo_display_region() if you want to insist on 00601 // one or the other. 00602 //////////////////////////////////////////////////////////////////// 00603 DisplayRegion *GraphicsOutput:: 00604 make_display_region(PN_stdfloat l, PN_stdfloat r, PN_stdfloat b, PN_stdfloat t) { 00605 return make_display_region(LVecBase4(l, r, b, t)); 00606 } 00607 00608 //////////////////////////////////////////////////////////////////// 00609 // Function: GraphicsOutput::make_mono_display_region 00610 // Access: Published 00611 // Description: Creates a new DisplayRegion that covers the entire 00612 // window. 00613 // 00614 // This generally returns a mono DisplayRegion, even if 00615 // is_stereo() is true. However, if side-by-side stereo 00616 // is enabled, this will return a StereoDisplayRegion 00617 // whose two eyes are both set to SC_mono. (This is 00618 // necessary because in side-by-side stereo mode, it is 00619 // necessary to draw even mono DisplayRegions twice). 00620 //////////////////////////////////////////////////////////////////// 00621 INLINE DisplayRegion *GraphicsOutput:: 00622 make_mono_display_region() { 00623 return make_mono_display_region(0.0f, 1.0f, 0.0f, 1.0f); 00624 } 00625 00626 //////////////////////////////////////////////////////////////////// 00627 // Function: GraphicsOutput::make_mono_display_region 00628 // Access: Published 00629 // Description: Creates a new DisplayRegion that covers the entire 00630 // window. 00631 // 00632 // This generally returns a mono DisplayRegion, even if 00633 // is_stereo() is true. However, if side-by-side stereo 00634 // is enabled, this will return a StereoDisplayRegion 00635 // whose two eyes are both set to SC_mono. (This is 00636 // necessary because in side-by-side stereo mode, it is 00637 // necessary to draw even mono DisplayRegions twice). 00638 //////////////////////////////////////////////////////////////////// 00639 INLINE DisplayRegion *GraphicsOutput:: 00640 make_mono_display_region(PN_stdfloat l, PN_stdfloat r, PN_stdfloat b, PN_stdfloat t) { 00641 return make_mono_display_region(LVecBase4(l, r, b, t)); 00642 } 00643 00644 //////////////////////////////////////////////////////////////////// 00645 // Function: GraphicsOutput::make_stereo_display_region 00646 // Access: Published 00647 // Description: Creates a new DisplayRegion that covers the entire 00648 // window. 00649 // 00650 // This always returns a stereo DisplayRegion, even if 00651 // is_stereo() is false. 00652 //////////////////////////////////////////////////////////////////// 00653 INLINE StereoDisplayRegion *GraphicsOutput:: 00654 make_stereo_display_region() { 00655 return make_stereo_display_region(0.0f, 1.0f, 0.0f, 1.0f); 00656 } 00657 00658 //////////////////////////////////////////////////////////////////// 00659 // Function: GraphicsOutput::make_stereo_display_region 00660 // Access: Published 00661 // Description: Creates a new DisplayRegion that covers the entire 00662 // window. 00663 // 00664 // This always returns a stereo DisplayRegion, even if 00665 // is_stereo() is false. 00666 //////////////////////////////////////////////////////////////////// 00667 INLINE StereoDisplayRegion *GraphicsOutput:: 00668 make_stereo_display_region(PN_stdfloat l, PN_stdfloat r, PN_stdfloat b, PN_stdfloat t) { 00669 return make_stereo_display_region(LVecBase4(l, r, b, t)); 00670 } 00671 00672 //////////////////////////////////////////////////////////////////// 00673 // Function: GraphicsOutput::get_overlay_display_region 00674 // Access: Published 00675 // Description: Returns the special "overlay" DisplayRegion that is 00676 // created for each window or buffer. This 00677 // DisplayRegion covers the entire window, but cannot be 00678 // used for rendering. It is a placeholder only, to 00679 // indicate the dimensions of the window, and is usually 00680 // used internally for purposes such as clearing the 00681 // window, or grabbing a screenshot of the window. 00682 // 00683 // There are very few applications that require access 00684 // to this DisplayRegion. Normally, you should create 00685 // your own DisplayRegion that covers the window, if you 00686 // want to render to the window. 00687 //////////////////////////////////////////////////////////////////// 00688 INLINE DisplayRegion *GraphicsOutput:: 00689 get_overlay_display_region() const { 00690 return _overlay_display_region; 00691 } 00692 00693 //////////////////////////////////////////////////////////////////// 00694 // Function: GraphicsOutput::make_screenshot_filename 00695 // Access: Published, Static 00696 // Description: Saves a screenshot of the region to a default 00697 // filename, and returns the filename, or empty string 00698 // if the screenshot failed. The default filename is 00699 // generated from the supplied prefix and from the 00700 // Config variable screenshot-filename, which contains 00701 // the following strings: 00702 // 00703 // %~p - the supplied prefix 00704 // %~f - the frame count 00705 // %~e - the value of screenshot-extension 00706 // All other % strings in strftime(). 00707 //////////////////////////////////////////////////////////////////// 00708 INLINE Filename GraphicsOutput:: 00709 make_screenshot_filename(const string &prefix) { 00710 return DisplayRegion::make_screenshot_filename(prefix); 00711 } 00712 00713 //////////////////////////////////////////////////////////////////// 00714 // Function: GraphicsOutput::save_screenshot_default 00715 // Access: Published 00716 // Description: Saves a screenshot of the region to a default 00717 // filename, and returns the filename, or empty string 00718 // if the screenshot failed. The filename is generated 00719 // by make_screenshot_filename(). 00720 //////////////////////////////////////////////////////////////////// 00721 INLINE Filename GraphicsOutput:: 00722 save_screenshot_default(const string &prefix) { 00723 return _overlay_display_region->save_screenshot_default(prefix); 00724 } 00725 00726 //////////////////////////////////////////////////////////////////// 00727 // Function: GraphicsOutput::save_screenshot 00728 // Access: Published 00729 // Description: Saves a screenshot of the region to the indicated 00730 // filename. The image comment is an optional user 00731 // readable string that will be saved with the header 00732 // of the image (if the file format supports embedded 00733 // data; for example jpg allows comments). Returns 00734 // true on success, false on failure. 00735 //////////////////////////////////////////////////////////////////// 00736 INLINE bool GraphicsOutput:: 00737 save_screenshot(const Filename &filename, const string &image_comment) { 00738 return _overlay_display_region->save_screenshot(filename, image_comment); 00739 } 00740 00741 //////////////////////////////////////////////////////////////////// 00742 // Function: GraphicsOutput::get_screenshot 00743 // Access: Published 00744 // Description: Captures the most-recently rendered image from the 00745 // framebuffer into the indicated PNMImage. Returns 00746 // true on success, false on failure. 00747 //////////////////////////////////////////////////////////////////// 00748 INLINE bool GraphicsOutput:: 00749 get_screenshot(PNMImage &image) { 00750 return _overlay_display_region->get_screenshot(image); 00751 } 00752 00753 //////////////////////////////////////////////////////////////////// 00754 // Function: GraphicsOutput::get_screenshot 00755 // Access: Published 00756 // Description: Captures the most-recently rendered image from the 00757 // framebuffer and returns it as Texture, or NULL on 00758 // failure. 00759 //////////////////////////////////////////////////////////////////// 00760 INLINE PT(Texture) GraphicsOutput:: 00761 get_screenshot() { 00762 return _overlay_display_region->get_screenshot(); 00763 } 00764 00765 //////////////////////////////////////////////////////////////////// 00766 // Function: GraphicsOutput::operator < 00767 // Access: Public 00768 // Description: The sorting operator is used to order the 00769 // GraphicsOutput object in order by their sort number, 00770 // so that they will render in the correct order in the 00771 // GraphicsEngine. 00772 //////////////////////////////////////////////////////////////////// 00773 INLINE bool GraphicsOutput:: 00774 operator < (const GraphicsOutput &other) const { 00775 if (_sort != other._sort) { 00776 return _sort < other._sort; 00777 } 00778 return _internal_sort_index < other._internal_sort_index; 00779 } 00780 00781 00782 //////////////////////////////////////////////////////////////////// 00783 // Function: GraphicsOutput::determine_display_regions 00784 // Access: Private 00785 // Description: Recomputes the list of active DisplayRegions within 00786 // the window, if they have changed recently. 00787 //////////////////////////////////////////////////////////////////// 00788 INLINE void GraphicsOutput:: 00789 determine_display_regions() const { 00790 // This function isn't strictly speaking const, but we pretend it is 00791 // because it only updates a transparent cache value. 00792 CDLockedReader cdata(_cycler); 00793 if (cdata->_active_display_regions_stale) { 00794 CDWriter cdataw(((GraphicsOutput *)this)->_cycler, cdata, false); 00795 ((GraphicsOutput *)this)->do_determine_display_regions(cdataw); 00796 } 00797 } 00798 00799 //////////////////////////////////////////////////////////////////// 00800 // Function: GraphicsOutput::win_display_regions_changed 00801 // Access: Private 00802 // Description: Intended to be called when the active state on a 00803 // nested display region changes, forcing the window to 00804 // recompute its list of active display regions. 00805 //////////////////////////////////////////////////////////////////// 00806 INLINE void GraphicsOutput:: 00807 win_display_regions_changed() { 00808 CDWriter cdata(_cycler, true); 00809 cdata->_active_display_regions_stale = true; 00810 } 00811 00812 //////////////////////////////////////////////////////////////////// 00813 // Function: GraphicsOutput::get_cull_window_pcollector 00814 // Access: Public 00815 // Description: Returns a PStatCollector for timing the cull 00816 // operation for just this GraphicsOutput. 00817 //////////////////////////////////////////////////////////////////// 00818 INLINE PStatCollector &GraphicsOutput:: 00819 get_cull_window_pcollector() { 00820 return _cull_window_pcollector; 00821 } 00822 00823 //////////////////////////////////////////////////////////////////// 00824 // Function: GraphicsOutput::get_draw_window_pcollector 00825 // Access: Public 00826 // Description: Returns a PStatCollector for timing the draw 00827 // operation for just this GraphicsOutput. 00828 //////////////////////////////////////////////////////////////////// 00829 INLINE PStatCollector &GraphicsOutput:: 00830 get_draw_window_pcollector() { 00831 return _draw_window_pcollector; 00832 } 00833 00834 //////////////////////////////////////////////////////////////////// 00835 // Function: GraphicsOutput::begin_frame_spam 00836 // Access: Public 00837 // Description: Display the spam message associated with begin_frame 00838 //////////////////////////////////////////////////////////////////// 00839 INLINE void GraphicsOutput:: 00840 begin_frame_spam(FrameMode mode) { 00841 if (display_cat.is_spam()) { 00842 display_cat.spam() 00843 << "begin_frame(" << mode << "): " << get_type() << " " 00844 << get_name() << " " << (void *)this << "\n"; 00845 } 00846 } 00847 00848 //////////////////////////////////////////////////////////////////// 00849 // Function: GraphicsOutput::end_frame_spam 00850 // Access: Public 00851 // Description: Display the spam message associated with end_frame 00852 //////////////////////////////////////////////////////////////////// 00853 INLINE void GraphicsOutput:: 00854 end_frame_spam(FrameMode mode) { 00855 if (display_cat.is_spam()) { 00856 display_cat.spam() 00857 << "end_frame(" << mode << "): " << get_type() << " " 00858 << get_name() << " " << (void *)this << "\n"; 00859 } 00860 } 00861 00862 //////////////////////////////////////////////////////////////////// 00863 // Function: GraphicsOutput::clear_cube_map_selection 00864 // Access: Public 00865 // Description: Clear the variables that select a cube-map face. 00866 //////////////////////////////////////////////////////////////////// 00867 INLINE void GraphicsOutput:: 00868 clear_cube_map_selection() { 00869 _cube_map_index = -1; 00870 _cube_map_dr = NULL; 00871 } 00872 00873 //////////////////////////////////////////////////////////////////// 00874 // Function: GraphicsOutput::trigger_flip 00875 // Access: Protected 00876 // Description: To be called at the end of the frame, after the 00877 // window has successfully been drawn and is ready to be 00878 // flipped (if appropriate). 00879 //////////////////////////////////////////////////////////////////// 00880 INLINE void GraphicsOutput:: 00881 trigger_flip() { 00882 if (!_fb_properties.is_single_buffered()) { 00883 _flip_ready = true; 00884 } 00885 } 00886