Panda3D
drawableRegion.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file drawableRegion.I
10  * @author drose
11  * @date 2002-07-11
12  */
13 
14 /**
15  *
16  */
17 INLINE DrawableRegion::
18 DrawableRegion() :
19  _screenshot_buffer_type(RenderBuffer::T_front),
20  _draw_buffer_type(RenderBuffer::T_back),
21  _clear_mask(0)
22 {
23  for (int i = 0; i < RTP_COUNT; ++i) {
24  _clear_value[i] = LColor(0.0f, 0.0f, 0.0f, 0.0f);
25  }
26  _clear_value[RTP_depth] = LColor(1.0f,1.0f,1.0f,1.0f);
27  _pixel_zoom = 1.0f;
28  _pixel_factor = 1.0f;
29 }
30 
31 /**
32  *
33  */
34 INLINE DrawableRegion::
35 DrawableRegion(const DrawableRegion &copy) :
36  _screenshot_buffer_type(copy._screenshot_buffer_type),
37  _draw_buffer_type(copy._draw_buffer_type),
38  _clear_mask(copy._clear_mask),
39  _pixel_zoom(copy._pixel_zoom),
40  _pixel_factor(copy._pixel_factor)
41 {
42  for (int i = 0; i < RTP_COUNT; ++i) {
43  _clear_value[i] = copy._clear_value[i];
44  }
45 }
46 
47 /**
48  *
49  */
50 INLINE void DrawableRegion::
51 operator = (const DrawableRegion &copy) {
52  _screenshot_buffer_type = copy._screenshot_buffer_type;
53  _draw_buffer_type = copy._draw_buffer_type;
54  _clear_mask = copy._clear_mask;
55  for (int i = 0; i < RTP_COUNT; ++i) {
56  _clear_value[i] = copy._clear_value[i];
57  }
58  _pixel_zoom = copy._pixel_zoom;
59  _pixel_factor = copy._pixel_factor;
60 }
61 
62 /**
63  * Copies only the clear settings from the other drawable region.
64  */
65 INLINE void DrawableRegion::
67  _clear_mask = copy._clear_mask;
68  for (int i = 0; i < RTP_COUNT; ++i) {
69  _clear_value[i] = copy._clear_value[i];
70  }
71  update_pixel_factor();
72 }
73 
74 /**
75  * Toggles the flag that indicates whether the color buffer should be cleared
76  * every frame. If this is true, the color buffer will be cleared to the
77  * color indicated by set_clear_color(); otherwise, it will be left alone.
78  */
79 INLINE void DrawableRegion::
80 set_clear_color_active(bool clear_color_active) {
81  set_clear_active(RTP_color, clear_color_active);
82 }
83 
84 /**
85  * Returns the current setting of the flag that indicates whether the color
86  * buffer should be cleared every frame. See set_clear_color_active().
87  */
88 INLINE bool DrawableRegion::
90  return get_clear_active(RTP_color);
91 }
92 
93 /**
94  * Toggles the flag that indicates whether the depth buffer should be cleared
95  * every frame. If this is true, the depth buffer will be cleared to the
96  * depth value indicated by set_clear_depth(); otherwise, it will be left
97  * alone.
98  */
99 INLINE void DrawableRegion::
100 set_clear_depth_active(bool clear_depth_active) {
101  set_clear_active(RTP_depth, clear_depth_active);
102 }
103 
104 /**
105  * Returns the current setting of the flag that indicates whether the depth
106  * buffer should be cleared every frame. See set_clear_depth_active().
107  */
108 INLINE bool DrawableRegion::
110  return get_clear_active(RTP_depth);
111 }
112 
113 /**
114  * Toggles the flag that indicates whether the stencil buffer should be
115  * cleared every frame. If this is true, the stencil buffer will be cleared
116  * to the value indicated by set_clear_stencil(); otherwise, it will be left
117  * alone.
118  */
119 INLINE void DrawableRegion::
120 set_clear_stencil_active(bool clear_stencil_active) {
121  set_clear_active(RTP_stencil, clear_stencil_active);
122 }
123 
124 /**
125  * Returns the current setting of the flag that indicates whether the color
126  * buffer should be cleared every frame. See set_clear_stencil_active().
127  */
128 INLINE bool DrawableRegion::
130  return get_clear_active(RTP_stencil);
131 }
132 
133 /**
134  * Sets the clear color to the indicated value. This is the value that will
135  * be used to clear the color buffer every frame, but only if
136  * get_clear_color_active() returns true. If get_clear_color_active() returns
137  * false, this is meaningless.
138  */
139 INLINE void DrawableRegion::
140 set_clear_color(const LColor &color) {
141  set_clear_value(RTP_color, color);
142 }
143 
144 /**
145  * Returns the current clear color value. This is the value that will be used
146  * to clear the color buffer every frame, but only if get_clear_color_active()
147  * returns true. If get_clear_color_active() returns false, this is
148  * meaningless.
149  */
150 INLINE const LColor &DrawableRegion::
151 get_clear_color() const {
152  return get_clear_value(RTP_color);
153 }
154 
155 /**
156  * Sets the clear depth to the indicated value. This is the value that will
157  * be used to clear the depth buffer every frame, but only if
158  * get_clear_depth_active() returns true. If get_clear_depth_active() returns
159  * false, this is meaningless.
160  */
161 INLINE void DrawableRegion::
162 set_clear_depth(PN_stdfloat depth) {
163  set_clear_value(RTP_depth, LColor(depth,depth,depth,depth));
164 }
165 
166 /**
167  * Returns the current clear depth value. This is the value that will be used
168  * to clear the depth buffer every frame, but only if get_clear_depth_active()
169  * returns true. If get_clear_depth_active() returns false, this is
170  * meaningless.
171  */
172 INLINE PN_stdfloat DrawableRegion::
173 get_clear_depth() const {
174  return get_clear_value(RTP_depth)[0];
175 }
176 /**
177  * Sets the clear stencil to the indicated value. This is the value that will
178  * be used to clear the stencil buffer every frame, but only if
179  * get_clear_color_active() returns true. If get_clear_stencil_active()
180  * returns false, this is meaningless.
181  */
182 INLINE void DrawableRegion::
183 set_clear_stencil(const unsigned int stencil) {
184  set_clear_value(RTP_stencil, LColor(stencil,stencil,stencil,stencil));
185 }
186 
187 /**
188  * Returns the current clear stencil value. This is the value that will be
189  * used to clear the stencil buffer every frame, but only if
190  * get_clear_stencil_active() returns true. If get_clear_stencil_active()
191  * returns false, this is meaningless.
192  */
193 INLINE unsigned int DrawableRegion::
194 get_clear_stencil() const {
195  return (unsigned int)(get_clear_value(RTP_stencil)[0]);
196 }
197 
198 /**
199  * Returns the value set by set_pixel_zoom(), regardless of whether it is
200  * being respected or not. Also see get_pixel_factor().
201  */
202 INLINE PN_stdfloat DrawableRegion::
203 get_pixel_zoom() const {
204  return _pixel_zoom;
205 }
206 
207 /**
208  * Returns the amount by which the height and width of the region will be
209  * scaled internally, based on the zoom factor set by set_pixel_zoom(). This
210  * will return 1.0 if the pixel_zoom was not set or if it is not being
211  * respected (for instance, because the underlying renderer doesn't support it
212  * --see supports_pixel_zoom).
213  */
214 INLINE PN_stdfloat DrawableRegion::
215 get_pixel_factor() const {
216  return _pixel_factor;
217 }
218 
219 /**
220  * Returns the RenderBuffer that should be used for capturing screenshots from
221  * this particular DrawableRegion.
222  */
223 INLINE int DrawableRegion::
225  return _screenshot_buffer_type;
226 }
227 
228 /**
229  * Returns the RenderBuffer into which the GSG should issue draw commands.
230  * Normally, this is the back buffer for double-buffered windows, and the
231  * front buffer for single-buffered windows.
232  */
233 INLINE int DrawableRegion::
235  return _draw_buffer_type;
236 }
237 
238 /**
239  * Internal function to reset pixel_factor after it may have changed.
240  */
241 INLINE void DrawableRegion::
242 update_pixel_factor() {
243  PN_stdfloat new_pixel_factor;
244  if (supports_pixel_zoom()) {
245  new_pixel_factor = (PN_stdfloat)1 / sqrt(std::max(_pixel_zoom, (PN_stdfloat)1.0));
246  } else {
247  new_pixel_factor = 1;
248  }
249  if (new_pixel_factor != _pixel_factor) {
250  _pixel_factor = new_pixel_factor;
251  pixel_factor_changed();
252  }
253 }
This is a base class for GraphicsWindow (actually, GraphicsOutput) and DisplayRegion,...
virtual void set_clear_active(int n, bool clear_aux_active)
Sets the clear-active flag for any bitplane.
virtual bool get_clear_active(int n) const
Gets the clear-active flag for any bitplane.
void set_clear_color_active(bool clear_color_active)
Toggles the flag that indicates whether the color buffer should be cleared every frame.
virtual void set_clear_value(int n, const LColor &clear_value)
Sets the clear value for any bitplane.
void set_clear_stencil_active(bool clear_stencil_active)
Toggles the flag that indicates whether the stencil buffer should be cleared every frame.
virtual const LColor & get_clear_value(int n) const
Returns the clear value for any bitplane.
virtual bool supports_pixel_zoom() const
Returns true if a call to set_pixel_zoom() will be respected, false if it will be ignored.
bool get_clear_color_active() const
Returns the current setting of the flag that indicates whether the color buffer should be cleared eve...
void copy_clear_settings(const DrawableRegion &copy)
Copies only the clear settings from the other drawable region.
bool get_clear_depth_active() const
Returns the current setting of the flag that indicates whether the depth buffer should be cleared eve...
void set_clear_depth_active(bool clear_depth_active)
Toggles the flag that indicates whether the depth buffer should be cleared every frame.
int get_screenshot_buffer_type() const
Returns the RenderBuffer that should be used for capturing screenshots from this particular DrawableR...
bool get_clear_stencil_active() const
Returns the current setting of the flag that indicates whether the color buffer should be cleared eve...
int get_draw_buffer_type() const
Returns the RenderBuffer into which the GSG should issue draw commands.
set_clear_stencil
Sets the clear stencil to the indicated value.
set_clear_depth
Sets the clear depth to the indicated value.
set_clear_color
Sets the clear color to the indicated value.
A RenderBuffer is an arbitrary subset of the various layers (depth buffer, color buffer,...
Definition: renderBuffer.h:27