Panda3D
graphicsOutput.I
1 // Filename: graphicsOutput.I
2 // Created by: drose (06Feb04)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: GraphicsOutput::get_gsg
18 // Access: Published
19 // Description: Returns the GSG that is associated with this window.
20 // There is a one-to-one association between windows and
21 // GSG's.
22 //
23 // This may return NULL if the graphics context has not
24 // yet been created for the window, e.g. before the
25 // first frame has rendered; or after the window has
26 // been closed.
27 ////////////////////////////////////////////////////////////////////
29 get_gsg() const {
30  return _gsg;
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: GraphicsOutput::get_pipe
35 // Access: Published
36 // Description: Returns the GraphicsPipe that this window is
37 // associated with. It is possible that the
38 // GraphicsPipe might have been deleted while an
39 // outstanding PT(GraphicsOutput) prevented all of its
40 // children windows from also being deleted; in this
41 // unlikely case, get_pipe() may return NULL.
42 ////////////////////////////////////////////////////////////////////
44 get_pipe() const {
45  return _pipe;
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: GraphicsOutput::get_engine
50 // Access: Published
51 // Description: Returns the graphics engine that created this output.
52 // Since there is normally only one GraphicsEngine
53 // object in an application, this is usually the same as
54 // the global GraphicsEngine.
55 ////////////////////////////////////////////////////////////////////
57 get_engine() const {
58  return _engine;
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: GraphicsOutput::get_name
63 // Access: Published
64 // Description: Returns the name that was passed to the
65 // GraphicsOutput constructor.
66 ////////////////////////////////////////////////////////////////////
67 INLINE const string &GraphicsOutput::
68 get_name() const {
69  return _name;
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: GraphicsOutput::count_textures
74 // Access: Published
75 // Description: If the GraphicsOutput is set to render into a
76 // texture, returns the number of textures that are
77 // being rendered into. Normally, the textures would
78 // be associated with different buffers - a color
79 // texture, a depth texture, and a stencil texture.
80 ////////////////////////////////////////////////////////////////////
81 INLINE int GraphicsOutput::
82 count_textures() const {
83  CDReader cdata(_cycler);
84  return cdata->_textures.size();
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: GraphicsOutput::has_texture
89 // Access: Published
90 // Description: Returns true if the GraphicsOutput is rendering
91 // into any textures at all.
92 ////////////////////////////////////////////////////////////////////
93 INLINE bool GraphicsOutput::
94 has_texture() const {
95  CDReader cdata(_cycler);
96  return (cdata->_textures.size() > 0);
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: GraphicsOutput::get_texture
101 // Access: Published
102 // Description: Returns the nth texture into which the GraphicsOutput
103 // renders. Returns NULL if there is no such texture.
104 //
105 // If the texture is non-NULL, it may be applied to
106 // geometry to be rendered for any other windows or
107 // outputs that share the same GSG as this
108 // GraphicsOutput. The effect is undefined for windows
109 // that share a different GSG; usually in these cases
110 // the texture will be invalid.
111 ////////////////////////////////////////////////////////////////////
113 get_texture(int i) const {
114  CDReader cdata(_cycler);
115  if ((i < 0) || (i >= ((int)cdata->_textures.size()))) {
116  return (Texture *)NULL;
117  }
118  return cdata->_textures[i]._texture;
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: GraphicsOutput::get_texture_plane
123 // Access: Published
124 // Description: Returns the RenderTexturePlane associated with the
125 // nth render-texture. Returns 0 if there is no such
126 // texture.
127 ////////////////////////////////////////////////////////////////////
128 INLINE GraphicsOutput::RenderTexturePlane GraphicsOutput::
129 get_texture_plane(int i) const {
130  CDReader cdata(_cycler);
131  if ((i < 0) || (i >= ((int)cdata->_textures.size()))) {
132  return (RenderTexturePlane)0;
133  }
134  return cdata->_textures[i]._plane;
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function: GraphicsOutput::get_rtm_mode
139 // Access: Published
140 // Description: Returns the RenderTextureMode associated with the
141 // nth render-texture. Returns RTM_none if there is
142 // no such texture.
143 ////////////////////////////////////////////////////////////////////
144 INLINE GraphicsOutput::RenderTextureMode GraphicsOutput::
145 get_rtm_mode(int i) const {
146  CDReader cdata(_cycler);
147  if ((i < 0) || (i >= ((int)cdata->_textures.size()))) {
148  return RTM_none;
149  }
150  return cdata->_textures[i]._rtm_mode;
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: GraphicsOutput::get_size
155 // Access: Published
156 // Description: Returns the visible size of the window or buffer, if
157 // it is known. In certain cases (e.g. fullscreen
158 // windows), the size may not be known until after the
159 // object has been fully created. Check has_size()
160 // first.
161 //
162 // Certain objects (like windows) may change size
163 // spontaneously; this method is not thread-safe. To
164 // get the size of a window in a thread-safe manner,
165 // query get_properties().
166 ////////////////////////////////////////////////////////////////////
167 INLINE const LVecBase2i &GraphicsOutput::
168 get_size() const {
169  return _size;
170 }
171 
172 ////////////////////////////////////////////////////////////////////
173 // Function: GraphicsOutput::get_x_size
174 // Access: Published
175 // Description: Returns the visible width of the window or buffer, if
176 // it is known. In certain cases (e.g. fullscreen
177 // windows), the size may not be known until after the
178 // object has been fully created. Check has_size()
179 // first.
180 //
181 // Certain objects (like windows) may change size
182 // spontaneously; this method is not thread-safe. To
183 // get the size of a window in a thread-safe manner,
184 // query get_properties().
185 ////////////////////////////////////////////////////////////////////
186 INLINE int GraphicsOutput::
187 get_x_size() const {
188  return _size.get_x();
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: GraphicsOutput::get_y_size
193 // Access: Published
194 // Description: Returns the visible height of the window or buffer,
195 // if it is known. In certain cases (e.g. fullscreen
196 // windows), the size may not be known until after the
197 // object has been fully created. Check has_size()
198 // first.
199 //
200 // Certain objects (like windows) may change size
201 // spontaneously; this method is not thread-safe. To
202 // get the size of a window in a thread-safe manner,
203 // query get_properties().
204 ////////////////////////////////////////////////////////////////////
205 INLINE int GraphicsOutput::
206 get_y_size() const {
207  return _size.get_y();
208 }
209 
210 ////////////////////////////////////////////////////////////////////
211 // Function: GraphicsOutput::get_fb_size
212 // Access: Published
213 // Description: Returns the internal size of the window or buffer.
214 // This is almost always the same as get_size(),
215 // except when a pixel_zoom is in effect--see
216 // set_pixel_zoom().
217 ////////////////////////////////////////////////////////////////////
219 get_fb_size() const {
220  return LVecBase2i(max(int(_size.get_x() * get_pixel_factor()), 1),
221  max(int(_size.get_y() * get_pixel_factor()), 1));
222 }
223 
224 ////////////////////////////////////////////////////////////////////
225 // Function: GraphicsOutput::get_fb_x_size
226 // Access: Published
227 // Description: Returns the internal width of the window or buffer.
228 // This is almost always the same as get_x_size(),
229 // except when a pixel_zoom is in effect--see
230 // set_pixel_zoom().
231 ////////////////////////////////////////////////////////////////////
232 INLINE int GraphicsOutput::
233 get_fb_x_size() const {
234  return max(int(_size.get_x() * get_pixel_factor()), 1);
235 }
236 
237 ////////////////////////////////////////////////////////////////////
238 // Function: GraphicsOutput::get_fb_y_size
239 // Access: Published
240 // Description: Returns the internal height of the window or buffer.
241 // This is almost always the same as get_y_size(),
242 // except when a pixel_zoom is in effect--see
243 // set_pixel_zoom().
244 ////////////////////////////////////////////////////////////////////
245 INLINE int GraphicsOutput::
246 get_fb_y_size() const {
247  return max(int(_size.get_y() * get_pixel_factor()), 1);
248 }
249 
250 ////////////////////////////////////////////////////////////////////
251 // Function: GraphicsOutput::get_sbs_left_size
252 // Access: Published
253 // Description: If side-by-side stereo is enabled, this returns the
254 // pixel size of the left eye, based on scaling
255 // get_size() by get_sbs_left_dimensions(). If
256 // side-by-side stereo is not enabled, this returns the
257 // same as get_size().
258 ////////////////////////////////////////////////////////////////////
261  PN_stdfloat left_w = _sbs_left_dimensions[1] - _sbs_left_dimensions[0];
262  PN_stdfloat left_h = _sbs_left_dimensions[3] - _sbs_left_dimensions[2];
263  return LVecBase2i(max(int(_size.get_x() * left_w), 1),
264  max(int(_size.get_y() * left_h), 1));
265 }
266 
267 ////////////////////////////////////////////////////////////////////
268 // Function: GraphicsOutput::get_sbs_left_x_size
269 // Access: Published
270 // Description: If side-by-side stereo is enabled, this returns the
271 // pixel width of the left eye, based on scaling
272 // get_x_size() by get_sbs_left_dimensions(). If
273 // side-by-side stereo is not enabled, this returns the
274 // same as get_x_size().
275 ////////////////////////////////////////////////////////////////////
276 INLINE int GraphicsOutput::
278  PN_stdfloat left_w = _sbs_left_dimensions[1] - _sbs_left_dimensions[0];
279  return max(int(_size.get_x() * left_w), 1);
280 }
281 
282 ////////////////////////////////////////////////////////////////////
283 // Function: GraphicsOutput::get_sbs_left_y_size
284 // Access: Published
285 // Description: If side-by-side stereo is enabled, this returns the
286 // pixel height of the left eye, based on scaling
287 // get_y_size() by get_sbs_left_dimensions(). If
288 // side-by-side stereo is not enabled, this returns the
289 // same as get_y_size().
290 ////////////////////////////////////////////////////////////////////
291 INLINE int GraphicsOutput::
293  PN_stdfloat left_h = _sbs_left_dimensions[3] - _sbs_left_dimensions[2];
294  return max(int(_size.get_y() * left_h), 1);
295 }
296 
297 ////////////////////////////////////////////////////////////////////
298 // Function: GraphicsOutput::get_sbs_right_size
299 // Access: Published
300 // Description: If side-by-side stereo is enabled, this returns the
301 // pixel size of the right eye, based on scaling
302 // get_size() by get_sbs_right_dimensions(). If
303 // side-by-side stereo is not enabled, this returns the
304 // same as get_size().
305 ////////////////////////////////////////////////////////////////////
308  PN_stdfloat right_w = _sbs_right_dimensions[1] - _sbs_right_dimensions[0];
309  PN_stdfloat right_h = _sbs_right_dimensions[3] - _sbs_right_dimensions[2];
310  return LVecBase2i(max(int(_size.get_x() * right_w), 1),
311  max(int(_size.get_y() * right_h), 1));
312 }
313 
314 ////////////////////////////////////////////////////////////////////
315 // Function: GraphicsOutput::get_sbs_right_x_size
316 // Access: Published
317 // Description: If side-by-side stereo is enabled, this returns the
318 // pixel width of the right eye, based on scaling
319 // get_x_size() by get_sbs_right_dimensions(). If
320 // side-by-side stereo is not enabled, this returns the
321 // same as get_x_size().
322 ////////////////////////////////////////////////////////////////////
323 INLINE int GraphicsOutput::
325  PN_stdfloat right_w = _sbs_right_dimensions[1] - _sbs_right_dimensions[0];
326  return max(int(_size.get_x() * right_w), 1);
327 }
328 
329 ////////////////////////////////////////////////////////////////////
330 // Function: GraphicsOutput::get_sbs_right_y_size
331 // Access: Published
332 // Description: If side-by-side stereo is enabled, this returns the
333 // pixel height of the right eye, based on scaling
334 // get_y_size() by get_sbs_right_dimensions(). If
335 // side-by-side stereo is not enabled, this returns the
336 // same as get_y_size().
337 ////////////////////////////////////////////////////////////////////
338 INLINE int GraphicsOutput::
340  PN_stdfloat right_h = _sbs_right_dimensions[3] - _sbs_right_dimensions[2];
341  return max(int(_size.get_y() * right_h), 1);
342 }
343 
344 ////////////////////////////////////////////////////////////////////
345 // Function: GraphicsOutput::has_size
346 // Access: Published
347 // Description: Returns true if the size of the window/frame buffer
348 // is known, false otherwise. In certain cases the size
349 // may not be known until after the object has been
350 // fully created. Also, certain objects (like windows)
351 // may change size spontaneously.
352 ////////////////////////////////////////////////////////////////////
353 INLINE bool GraphicsOutput::
354 has_size() const {
355  return _has_size;
356 }
357 
358 ////////////////////////////////////////////////////////////////////
359 // Function: GraphicsOutput::is_valid
360 // Access: Published
361 // Description: Returns true if the output is fully created and ready
362 // for rendering, false otherwise.
363 ////////////////////////////////////////////////////////////////////
364 INLINE bool GraphicsOutput::
365 is_valid() const {
366  return _is_valid && _is_nonzero_size;
367 }
368 
369 ////////////////////////////////////////////////////////////////////
370 // Function: GraphicsOutput::is_nonzero_size
371 // Access: Published
372 // Description: Returns true if the output has a nonzero size in both
373 // X and Y, or false if it is zero (and therefore
374 // invalid).
375 ////////////////////////////////////////////////////////////////////
376 INLINE bool GraphicsOutput::
378  return _is_nonzero_size;
379 }
380 
381 ////////////////////////////////////////////////////////////////////
382 // Function: GraphicsOutput::get_inverted
383 // Access: Published
384 // Description: Returns the current setting of the inverted flag.
385 // When this is true, the scene is rendered into the
386 // window upside-down, flipped like a mirror along the X
387 // axis. See set_inverted().
388 ////////////////////////////////////////////////////////////////////
389 INLINE bool GraphicsOutput::
390 get_inverted() const {
391  return _inverted;
392 }
393 
394 ////////////////////////////////////////////////////////////////////
395 // Function: GraphicsOutput::set_swap_eyes
396 // Access: Public
397 // Description: Changes the "swap eyes" flag. This flag is normally
398 // false. When it is true, the left and right channels
399 // of a stereo DisplayRegion are sent to the opposite
400 // channels in the rendering backend. This is meant to
401 // work around hardware that inadvertently swaps the
402 // output channels, or hardware for which it cannot be
403 // determined which channel is which until runtime.
404 ////////////////////////////////////////////////////////////////////
405 INLINE void GraphicsOutput::
406 set_swap_eyes(bool swap_eyes) {
407  _swap_eyes = swap_eyes;
408 }
409 
410 ////////////////////////////////////////////////////////////////////
411 // Function: GraphicsOutput::get_swap_eyes
412 // Access: Public
413 // Description: Returns the current setting of the "swap eyes" flag.
414 // See set_swap_eyes().
415 ////////////////////////////////////////////////////////////////////
416 INLINE bool GraphicsOutput::
417 get_swap_eyes() const {
418  return _swap_eyes;
419 }
420 
421 ////////////////////////////////////////////////////////////////////
422 // Function: GraphicsOutput::set_red_blue_stereo
423 // Access: Published
424 // Description: Enables red-blue stereo mode on this particular
425 // window. When red-blue stereo mode is in effect,
426 // DisplayRegions that have the "left" channel set will
427 // render in the red (or specified) channel only, while
428 // DisplayRegions that have the "right" channel set will
429 // render in the blue (or specified) channel only.
430 //
431 // The remaining two parameters specify the particular
432 // color channel(s) to associate with each eye. Use the
433 // bits defined in ColorWriteAttrib::Channels.
434 //
435 // This can be used to achieve a cheesy stereo mode in
436 // the absence of hardware-supported stereo.
437 ////////////////////////////////////////////////////////////////////
438 INLINE void GraphicsOutput::
439 set_red_blue_stereo(bool red_blue_stereo,
440  unsigned int left_eye_color_mask,
441  unsigned int right_eye_color_mask) {
442  _red_blue_stereo = red_blue_stereo;
443  if (_red_blue_stereo) {
444  _left_eye_color_mask = left_eye_color_mask;
445  _right_eye_color_mask = right_eye_color_mask;
446  } else {
447  _left_eye_color_mask = 0x0f;
448  _right_eye_color_mask = 0x0f;
449  }
450 }
451 
452 ////////////////////////////////////////////////////////////////////
453 // Function: GraphicsOutput::get_red_blue_stereo
454 // Access: Published
455 // Description: Returns whether red-blue stereo mode is in effect for
456 // this particular window. See set_red_blue_stereo().
457 ////////////////////////////////////////////////////////////////////
458 INLINE bool GraphicsOutput::
460  return _red_blue_stereo;
461 }
462 
463 ////////////////////////////////////////////////////////////////////
464 // Function: GraphicsOutput::get_left_eye_color_mask
465 // Access: Published
466 // Description: Returns the color mask in effect when rendering a
467 // left-eye view in red_blue stereo mode. This is one
468 // or more bits defined in ColorWriteAttrib::Channels.
469 // See set_red_blue_stereo().
470 ////////////////////////////////////////////////////////////////////
471 INLINE unsigned int GraphicsOutput::
473  return _left_eye_color_mask;
474 }
475 
476 ////////////////////////////////////////////////////////////////////
477 // Function: GraphicsOutput::get_right_eye_color_mask
478 // Access: Published
479 // Description: Returns the color mask in effect when rendering a
480 // right-eye view in red_blue stereo mode. This is one
481 // or more bits defined in ColorWriteAttrib::Channels.
482 // See set_red_blue_stereo().
483 ////////////////////////////////////////////////////////////////////
484 INLINE unsigned int GraphicsOutput::
486  return _right_eye_color_mask;
487 }
488 
489 ////////////////////////////////////////////////////////////////////
490 // Function: GraphicsOutput::get_side_by_side_stereo
491 // Access: Published
492 // Description: Returns whether side-by-side stereo mode is in effect for
493 // this particular window. See set_side_by_side_stereo().
494 ////////////////////////////////////////////////////////////////////
495 INLINE bool GraphicsOutput::
497  return _side_by_side_stereo;
498 }
499 
500 ////////////////////////////////////////////////////////////////////
501 // Function: GraphicsOutput::get_sbs_left_dimensions
502 // Access: Published
503 // Description: Returns the effective sub-region of the window for
504 // displaying the left channel, if side-by-side stereo
505 // mode is in effect for the window. See
506 // set_side_by_side_stereo().
507 ////////////////////////////////////////////////////////////////////
508 INLINE const LVecBase4 &GraphicsOutput::
510  return _sbs_left_dimensions;
511 }
512 
513 ////////////////////////////////////////////////////////////////////
514 // Function: GraphicsOutput::get_sbs_right_dimensions
515 // Access: Published
516 // Description: Returns the effective sub-region of the window for
517 // displaying the right channel, if side-by-side stereo
518 // mode is in effect for the window. See
519 // set_side_by_side_stereo().
520 ////////////////////////////////////////////////////////////////////
521 INLINE const LVecBase4 &GraphicsOutput::
523  return _sbs_right_dimensions;
524 }
525 
526 ////////////////////////////////////////////////////////////////////
527 // Function: GraphicsOutput::get_fb_properties
528 // Access: Published
529 // Description: Returns the framebuffer properties of the window.
530 ////////////////////////////////////////////////////////////////////
533  return _fb_properties;
534 }
535 
536 ////////////////////////////////////////////////////////////////////
537 // Function: GraphicsOutput::is_stereo
538 // Access: Published
539 // Description: Returns Returns true if this window can render stereo
540 // DisplayRegions, either through red-blue stereo (see
541 // set_red_blue_stereo()) or through true hardware
542 // stereo rendering.
543 ////////////////////////////////////////////////////////////////////
544 INLINE bool GraphicsOutput::
545 is_stereo() const {
546  return _red_blue_stereo || _side_by_side_stereo || _fb_properties.is_stereo();
547 }
548 
549 ////////////////////////////////////////////////////////////////////
550 // Function: GraphicsOutput::clear_delete_flag
551 // Access: Published
552 // Description: Resets the delete flag, so the GraphicsOutput will
553 // not be automatically deleted before the beginning of
554 // the next frame.
555 ////////////////////////////////////////////////////////////////////
556 INLINE void GraphicsOutput::
558  _delete_flag = false;
559 }
560 
561 ////////////////////////////////////////////////////////////////////
562 // Function: GraphicsOutput::get_sort
563 // Access: Published
564 // Description: Returns the sorting order of this particular
565 // GraphicsOutput. The various GraphicsOutputs within a
566 // particular thread will be rendered in the indicated
567 // order.
568 ////////////////////////////////////////////////////////////////////
569 INLINE int GraphicsOutput::
570 get_sort() const {
571  return _sort;
572 }
573 
574 ////////////////////////////////////////////////////////////////////
575 // Function: GraphicsOutput::set_child_sort
576 // Access: Published
577 // Description: Specifies the sort value of future offscreen buffers
578 // created by make_texture_sort().
579 //
580 // The purpose of this method is to allow the user to
581 // limit the sort value chosen for a buffer created via
582 // make_texture_buffer(). Normally, this buffer will be
583 // assigned a value of get_sort() - 1, so that it
584 // will be rendered before this window is rendered; but
585 // sometimes this isn't sufficiently early, especially
586 // if other buffers also have a view into the same
587 // scene.
588 //
589 // If you specify a value here, then new buffers created
590 // via make_texture_buffer() will be given that sort
591 // value instead of get_sort() - 1.
592 ////////////////////////////////////////////////////////////////////
593 INLINE void GraphicsOutput::
594 set_child_sort(int child_sort) {
595  _child_sort = child_sort;
596  _got_child_sort = true;
597 }
598 
599 ////////////////////////////////////////////////////////////////////
600 // Function: GraphicsOutput::clear_child_sort
601 // Access: Published
602 // Description: Resets the sort value of future offscreen buffers
603 // created by make_texture_sort() to the default value.
604 // See set_child_sort().
605 ////////////////////////////////////////////////////////////////////
606 INLINE void GraphicsOutput::
608  _got_child_sort = false;
609 }
610 
611 ////////////////////////////////////////////////////////////////////
612 // Function: GraphicsOutput::get_child_sort
613 // Access: Published
614 // Description: Returns the sort value of future offscreen buffers
615 // created by make_texture_sort(). See set_child_sort().
616 ////////////////////////////////////////////////////////////////////
617 INLINE int GraphicsOutput::
618 get_child_sort() const {
619  if (_got_child_sort) {
620  return _child_sort;
621  } else {
622  return get_sort() - 1;
623  }
624 }
625 
626 ////////////////////////////////////////////////////////////////////
627 // Function: GraphicsOutput::trigger_copy
628 // Access: Published
629 // Description: When the GraphicsOutput is in triggered copy mode,
630 // this function triggers the copy (at the end of the
631 // next frame).
632 ////////////////////////////////////////////////////////////////////
633 INLINE void GraphicsOutput::
635  _trigger_copy = true;
636 }
637 
638 ////////////////////////////////////////////////////////////////////
639 // Function: GraphicsOutput::make_display_region
640 // Access: Published
641 // Description: Creates a new DisplayRegion that covers the entire
642 // window.
643 //
644 // If is_stereo() is true for this window, and
645 // default-stereo-camera is configured true, this
646 // actually makes a StereoDisplayRegion. Call
647 // make_mono_display_region() or
648 // make_stereo_display_region() if you want to insist on
649 // one or the other.
650 ////////////////////////////////////////////////////////////////////
653  return make_display_region(0.0f, 1.0f, 0.0f, 1.0f);
654 }
655 
656 ////////////////////////////////////////////////////////////////////
657 // Function: GraphicsOutput::make_display_region
658 // Access: Published
659 // Description: Creates a new DisplayRegion that covers the indicated
660 // sub-rectangle within the window. The range on all
661 // parameters is 0..1.
662 //
663 // If is_stereo() is true for this window, and
664 // default-stereo-camera is configured true, this
665 // actually makes a StereoDisplayRegion. Call
666 // make_mono_display_region() or
667 // make_stereo_display_region() if you want to insist on
668 // one or the other.
669 ////////////////////////////////////////////////////////////////////
671 make_display_region(PN_stdfloat l, PN_stdfloat r, PN_stdfloat b, PN_stdfloat t) {
672  return make_display_region(LVecBase4(l, r, b, t));
673 }
674 
675 ////////////////////////////////////////////////////////////////////
676 // Function: GraphicsOutput::make_mono_display_region
677 // Access: Published
678 // Description: Creates a new DisplayRegion that covers the entire
679 // window.
680 //
681 // This generally returns a mono DisplayRegion, even if
682 // is_stereo() is true. However, if side-by-side stereo
683 // is enabled, this will return a StereoDisplayRegion
684 // whose two eyes are both set to SC_mono. (This is
685 // necessary because in side-by-side stereo mode, it is
686 // necessary to draw even mono DisplayRegions twice).
687 ////////////////////////////////////////////////////////////////////
690  return make_mono_display_region(0.0f, 1.0f, 0.0f, 1.0f);
691 }
692 
693 ////////////////////////////////////////////////////////////////////
694 // Function: GraphicsOutput::make_mono_display_region
695 // Access: Published
696 // Description: Creates a new DisplayRegion that covers the entire
697 // window.
698 //
699 // This generally returns a mono DisplayRegion, even if
700 // is_stereo() is true. However, if side-by-side stereo
701 // is enabled, this will return a StereoDisplayRegion
702 // whose two eyes are both set to SC_mono. (This is
703 // necessary because in side-by-side stereo mode, it is
704 // necessary to draw even mono DisplayRegions twice).
705 ////////////////////////////////////////////////////////////////////
707 make_mono_display_region(PN_stdfloat l, PN_stdfloat r, PN_stdfloat b, PN_stdfloat t) {
708  return make_mono_display_region(LVecBase4(l, r, b, t));
709 }
710 
711 ////////////////////////////////////////////////////////////////////
712 // Function: GraphicsOutput::make_stereo_display_region
713 // Access: Published
714 // Description: Creates a new DisplayRegion that covers the entire
715 // window.
716 //
717 // This always returns a stereo DisplayRegion, even if
718 // is_stereo() is false.
719 ////////////////////////////////////////////////////////////////////
722  return make_stereo_display_region(0.0f, 1.0f, 0.0f, 1.0f);
723 }
724 
725 ////////////////////////////////////////////////////////////////////
726 // Function: GraphicsOutput::make_stereo_display_region
727 // Access: Published
728 // Description: Creates a new DisplayRegion that covers the entire
729 // window.
730 //
731 // This always returns a stereo DisplayRegion, even if
732 // is_stereo() is false.
733 ////////////////////////////////////////////////////////////////////
735 make_stereo_display_region(PN_stdfloat l, PN_stdfloat r, PN_stdfloat b, PN_stdfloat t) {
736  return make_stereo_display_region(LVecBase4(l, r, b, t));
737 }
738 
739 ////////////////////////////////////////////////////////////////////
740 // Function: GraphicsOutput::get_overlay_display_region
741 // Access: Published
742 // Description: Returns the special "overlay" DisplayRegion that is
743 // created for each window or buffer. This
744 // DisplayRegion covers the entire window, but cannot be
745 // used for rendering. It is a placeholder only, to
746 // indicate the dimensions of the window, and is usually
747 // used internally for purposes such as clearing the
748 // window, or grabbing a screenshot of the window.
749 //
750 // There are very few applications that require access
751 // to this DisplayRegion. Normally, you should create
752 // your own DisplayRegion that covers the window, if you
753 // want to render to the window.
754 ////////////////////////////////////////////////////////////////////
757  return _overlay_display_region;
758 }
759 
760 ////////////////////////////////////////////////////////////////////
761 // Function: GraphicsOutput::make_screenshot_filename
762 // Access: Published, Static
763 // Description: Saves a screenshot of the region to a default
764 // filename, and returns the filename, or empty string
765 // if the screenshot failed. The default filename is
766 // generated from the supplied prefix and from the
767 // Config variable screenshot-filename, which contains
768 // the following strings:
769 //
770 // %~p - the supplied prefix
771 // %~f - the frame count
772 // %~e - the value of screenshot-extension
773 // All other % strings in strftime().
774 ////////////////////////////////////////////////////////////////////
776 make_screenshot_filename(const string &prefix) {
778 }
779 
780 ////////////////////////////////////////////////////////////////////
781 // Function: GraphicsOutput::save_screenshot_default
782 // Access: Published
783 // Description: Saves a screenshot of the region to a default
784 // filename, and returns the filename, or empty string
785 // if the screenshot failed. The filename is generated
786 // by make_screenshot_filename().
787 ////////////////////////////////////////////////////////////////////
789 save_screenshot_default(const string &prefix) {
790  return _overlay_display_region->save_screenshot_default(prefix);
791 }
792 
793 ////////////////////////////////////////////////////////////////////
794 // Function: GraphicsOutput::save_screenshot
795 // Access: Published
796 // Description: Saves a screenshot of the region to the indicated
797 // filename. The image comment is an optional user
798 // readable string that will be saved with the header
799 // of the image (if the file format supports embedded
800 // data; for example jpg allows comments). Returns
801 // true on success, false on failure.
802 ////////////////////////////////////////////////////////////////////
803 INLINE bool GraphicsOutput::
804 save_screenshot(const Filename &filename, const string &image_comment) {
805  return _overlay_display_region->save_screenshot(filename, image_comment);
806 }
807 
808 ////////////////////////////////////////////////////////////////////
809 // Function: GraphicsOutput::get_screenshot
810 // Access: Published
811 // Description: Captures the most-recently rendered image from the
812 // framebuffer into the indicated PNMImage. Returns
813 // true on success, false on failure.
814 ////////////////////////////////////////////////////////////////////
815 INLINE bool GraphicsOutput::
817  return _overlay_display_region->get_screenshot(image);
818 }
819 
820 ////////////////////////////////////////////////////////////////////
821 // Function: GraphicsOutput::get_screenshot
822 // Access: Published
823 // Description: Captures the most-recently rendered image from the
824 // framebuffer and returns it as Texture, or NULL on
825 // failure.
826 ////////////////////////////////////////////////////////////////////
827 INLINE PT(Texture) GraphicsOutput::
828 get_screenshot() {
829  return _overlay_display_region->get_screenshot();
830 }
831 
832 ////////////////////////////////////////////////////////////////////
833 // Function: GraphicsOutput::operator <
834 // Access: Public
835 // Description: The sorting operator is used to order the
836 // GraphicsOutput object in order by their sort number,
837 // so that they will render in the correct order in the
838 // GraphicsEngine.
839 ////////////////////////////////////////////////////////////////////
840 INLINE bool GraphicsOutput::
841 operator < (const GraphicsOutput &other) const {
842  if (_sort != other._sort) {
843  return _sort < other._sort;
844  }
845  return _internal_sort_index < other._internal_sort_index;
846 }
847 
848 
849 ////////////////////////////////////////////////////////////////////
850 // Function: GraphicsOutput::determine_display_regions
851 // Access: Private
852 // Description: Recomputes the list of active DisplayRegions within
853 // the window, if they have changed recently.
854 ////////////////////////////////////////////////////////////////////
855 INLINE void GraphicsOutput::
856 determine_display_regions() const {
857  // This function isn't strictly speaking const, but we pretend it is
858  // because it only updates a transparent cache value.
859  CDLockedReader cdata(_cycler);
860  if (cdata->_active_display_regions_stale) {
861  CDWriter cdataw(((GraphicsOutput *)this)->_cycler, cdata, false);
862  ((GraphicsOutput *)this)->do_determine_display_regions(cdataw);
863  }
864 }
865 
866 ////////////////////////////////////////////////////////////////////
867 // Function: GraphicsOutput::win_display_regions_changed
868 // Access: Private
869 // Description: Intended to be called when the active state on a
870 // nested display region changes, forcing the window to
871 // recompute its list of active display regions.
872 ////////////////////////////////////////////////////////////////////
873 INLINE void GraphicsOutput::
874 win_display_regions_changed() {
875  CDWriter cdata(_cycler, true);
876  cdata->_active_display_regions_stale = true;
877 }
878 
879 ////////////////////////////////////////////////////////////////////
880 // Function: GraphicsOutput::get_cull_window_pcollector
881 // Access: Public
882 // Description: Returns a PStatCollector for timing the cull
883 // operation for just this GraphicsOutput.
884 ////////////////////////////////////////////////////////////////////
887  return _cull_window_pcollector;
888 }
889 
890 ////////////////////////////////////////////////////////////////////
891 // Function: GraphicsOutput::get_draw_window_pcollector
892 // Access: Public
893 // Description: Returns a PStatCollector for timing the draw
894 // operation for just this GraphicsOutput.
895 ////////////////////////////////////////////////////////////////////
898  return _draw_window_pcollector;
899 }
900 
901 ////////////////////////////////////////////////////////////////////
902 // Function: GraphicsOutput::begin_frame_spam
903 // Access: Public
904 // Description: Display the spam message associated with begin_frame
905 ////////////////////////////////////////////////////////////////////
906 INLINE void GraphicsOutput::
907 begin_frame_spam(FrameMode mode) {
908  if (display_cat.is_spam()) {
909  display_cat.spam()
910  << "begin_frame(" << mode << "): " << get_type() << " "
911  << get_name() << " " << (void *)this << "\n";
912  }
913 }
914 
915 ////////////////////////////////////////////////////////////////////
916 // Function: GraphicsOutput::end_frame_spam
917 // Access: Public
918 // Description: Display the spam message associated with end_frame
919 ////////////////////////////////////////////////////////////////////
920 INLINE void GraphicsOutput::
921 end_frame_spam(FrameMode mode) {
922  if (display_cat.is_spam()) {
923  display_cat.spam()
924  << "end_frame(" << mode << "): " << get_type() << " "
925  << get_name() << " " << (void *)this << "\n";
926  }
927 }
928 
929 ////////////////////////////////////////////////////////////////////
930 // Function: GraphicsOutput::clear_cube_map_selection
931 // Access: Public
932 // Description: Clear the variables that select a cube-map face (or
933 // other multipage texture face).
934 ////////////////////////////////////////////////////////////////////
935 INLINE void GraphicsOutput::
936 clear_cube_map_selection() {
937  _target_tex_page = -1;
938  _prev_page_dr = NULL;
939 }
940 
941 ////////////////////////////////////////////////////////////////////
942 // Function: GraphicsOutput::trigger_flip
943 // Access: Protected
944 // Description: To be called at the end of the frame, after the
945 // window has successfully been drawn and is ready to be
946 // flipped (if appropriate).
947 ////////////////////////////////////////////////////////////////////
948 INLINE void GraphicsOutput::
949 trigger_flip() {
950  if (!_fb_properties.is_single_buffered()) {
951  _flip_ready = true;
952  }
953 }
954 
void set_child_sort(int child_sort)
Specifies the sort value of future offscreen buffers created by make_texture_sort().
bool save_screenshot(const Filename &filename, const string &image_comment="")
Saves a screenshot of the region to the indicated filename.
static Filename make_screenshot_filename(const string &prefix="screenshot")
Synthesizes a suitable default filename for passing to save_screenshot().
LVecBase2i get_sbs_left_size() const
If side-by-side stereo is enabled, this returns the pixel size of the left eye, based on scaling get_...
bool operator<(const GraphicsOutput &other) const
The sorting operator is used to order the GraphicsOutput object in order by their sort number...
int get_sbs_right_y_size() const
If side-by-side stereo is enabled, this returns the pixel height of the right eye, based on scaling get_y_size() by get_sbs_right_dimensions().
void set_swap_eyes(bool swap_eyes)
Changes the "swap eyes" flag.
const LVecBase4 & get_sbs_left_dimensions() const
Returns the effective sub-region of the window for displaying the left channel, if side-by-side stere...
GraphicsPipe * get_pipe() const
Returns the GraphicsPipe that this window is associated with.
const LVecBase2i & get_size() const
Returns the visible size of the window or buffer, if it is known.
StereoDisplayRegion * make_stereo_display_region()
Creates a new DisplayRegion that covers the entire window.
LVecBase2i get_fb_size() const
Returns the internal size of the window or buffer.
virtual Texture * get_texture(int i=0) const
Returns the nth texture into which the GraphicsOutput renders.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:68
int get_sbs_left_y_size() const
If side-by-side stereo is enabled, this returns the pixel height of the left eye, based on scaling ge...
Filename save_screenshot_default(const string &prefix="screenshot")
Saves a screenshot of the region to a default filename, and returns the filename, or empty string if ...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
int get_y_size() const
Returns the visible height of the window or buffer, if it is known.
PN_stdfloat get_pixel_factor() const
Returns the amount by which the height and width of the region will be scaled internally, based on the zoom factor set by set_pixel_zoom().
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:2360
int get_child_sort() const
Returns the sort value of future offscreen buffers created by make_texture_sort().
int get_fb_y_size() const
Returns the internal height of the window or buffer.
static Filename make_screenshot_filename(const string &prefix="screenshot")
Saves a screenshot of the region to a default filename, and returns the filename, or empty string if ...
DisplayRegion * make_display_region()
Creates a new DisplayRegion that covers the entire window.
void trigger_copy()
When the GraphicsOutput is in triggered copy mode, this function triggers the copy (at the end of the...
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
bool is_valid() const
Returns true if the output is fully created and ready for rendering, false otherwise.
GraphicsEngine * get_engine() const
Returns the graphics engine that created this output.
PStatCollector & get_draw_window_pcollector()
Returns a PStatCollector for timing the draw operation for just this GraphicsOutput.
A lightweight class that represents a single element that may be timed and/or counted via stats...
DisplayRegion * make_mono_display_region()
Creates a new DisplayRegion that covers the entire window.
int get_sort() const
Returns the sorting order of this particular GraphicsOutput.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
int get_sbs_left_x_size() const
If side-by-side stereo is enabled, this returns the pixel width of the left eye, based on scaling get...
bool get_inverted() const
Returns the current setting of the inverted flag.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
int count_textures() const
If the GraphicsOutput is set to render into a texture, returns the number of textures that are being ...
unsigned int get_left_eye_color_mask() const
Returns the color mask in effect when rendering a left-eye view in red_blue stereo mode...
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
LVecBase2i get_sbs_right_size() const
If side-by-side stereo is enabled, this returns the pixel size of the right eye, based on scaling get...
bool get_screenshot(PNMImage &image)
Captures the most-recently rendered image from the framebuffer into the indicated PNMImage...
This is a base class for the various different classes that represent the result of a frame of render...
This is a special DisplayRegion wrapper that actually includes a pair of DisplayRegions internally: t...
int get_x_size() const
Returns the visible width of the window or buffer, if it is known.
bool is_nonzero_size() const
Returns true if the output has a nonzero size in both X and Y, or false if it is zero (and therefore ...
bool is_stereo() const
Returns Returns true if this window can render stereo DisplayRegions, either through red-blue stereo ...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
int get_fb_x_size() const
Returns the internal width of the window or buffer.
GraphicsStateGuardian * get_gsg() const
Returns the GSG that is associated with this window.
unsigned int get_right_eye_color_mask() const
Returns the color mask in effect when rendering a right-eye view in red_blue stereo mode...
RenderTextureMode get_rtm_mode(int i=0) const
Returns the RenderTextureMode associated with the nth render-texture.
Encapsulates all the communication with a particular instance of a given rendering backend...
void clear_child_sort()
Resets the sort value of future offscreen buffers created by make_texture_sort() to the default value...
const string & get_name() const
Returns the name that was passed to the GraphicsOutput constructor.
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:61
bool get_red_blue_stereo() const
Returns whether red-blue stereo mode is in effect for this particular window.
This class is the main interface to controlling the render process.
PStatCollector & get_cull_window_pcollector()
Returns a PStatCollector for timing the cull operation for just this GraphicsOutput.
bool has_texture() const
Returns true if the GraphicsOutput is rendering into any textures at all.
bool has_size() const
Returns true if the size of the window/frame buffer is known, false otherwise.
const LVecBase4 & get_sbs_right_dimensions() const
Returns the effective sub-region of the window for displaying the right channel, if side-by-side ster...
bool get_swap_eyes() const
Returns the current setting of the "swap eyes" flag.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
DisplayRegion * get_overlay_display_region() const
Returns the special "overlay" DisplayRegion that is created for each window or buffer.
void clear_delete_flag()
Resets the delete flag, so the GraphicsOutput will not be automatically deleted before the beginning ...
RenderTexturePlane get_texture_plane(int i=0) const
Returns the RenderTexturePlane associated with the nth render-texture.
void set_red_blue_stereo(bool red_blue_stereo, unsigned int left_eye_color_mask, unsigned int right_eye_color_mask)
Enables red-blue stereo mode on this particular window.
const FrameBufferProperties & get_fb_properties() const
Returns the framebuffer properties of the window.
bool get_side_by_side_stereo() const
Returns whether side-by-side stereo mode is in effect for this particular window. ...
int get_sbs_right_x_size() const
If side-by-side stereo is enabled, this returns the pixel width of the right eye, based on scaling ge...