Panda3D
drawableRegion.I
1 // Filename: drawableRegion.I
2 // Created by: drose (11Jul02)
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: DrawableRegion::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE DrawableRegion::
22 DrawableRegion() :
23  _screenshot_buffer_type(RenderBuffer::T_front),
24  _draw_buffer_type(RenderBuffer::T_back)
25 {
26  for (int i=0; i<RTP_COUNT; i++) {
27  _clear_active[i] = false;
28  _clear_value[i] = LColor(0.0f, 0.0f, 0.0f, 0.0f);
29  }
30  _clear_value[RTP_depth] = LColor(1.0f,1.0f,1.0f,1.0f);
31  _pixel_zoom = 1.0f;
32  _pixel_factor = 1.0f;
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: DrawableRegion::Copy Constructor
37 // Access: Public
38 // Description:
39 ////////////////////////////////////////////////////////////////////
40 INLINE DrawableRegion::
41 DrawableRegion(const DrawableRegion &copy) :
42  _screenshot_buffer_type(copy._screenshot_buffer_type),
43  _draw_buffer_type(copy._draw_buffer_type),
44  _pixel_zoom(copy._pixel_zoom),
45  _pixel_factor(copy._pixel_factor)
46 {
47  for (int i=0; i<RTP_COUNT; i++) {
48  _clear_active[i] = copy._clear_active[i];
49  _clear_value[i] = copy._clear_value[i];
50  }
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: DrawableRegion::Copy Assignment Operator
55 // Access: Public
56 // Description:
57 ////////////////////////////////////////////////////////////////////
58 INLINE void DrawableRegion::
59 operator = (const DrawableRegion &copy) {
60  _screenshot_buffer_type = copy._screenshot_buffer_type;
61  _draw_buffer_type = copy._draw_buffer_type;
62  for (int i=0; i<RTP_COUNT; i++) {
63  _clear_active[i] = copy._clear_active[i];
64  _clear_value[i] = copy._clear_value[i];
65  }
66  _pixel_zoom = copy._pixel_zoom;
67  _pixel_factor = copy._pixel_factor;
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: DrawableRegion::copy_clear_settings
72 // Access: Public
73 // Description: Copies only the clear settings from the other drawable
74 // region.
75 ////////////////////////////////////////////////////////////////////
76 INLINE void DrawableRegion::
78  for (int i=0; i<RTP_COUNT; i++) {
79  _clear_active[i] = copy._clear_active[i];
80  _clear_value[i] = copy._clear_value[i];
81  }
82  update_pixel_factor();
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: DrawableRegion::set_clear_color_active
87 // Access: Published
88 // Description: Toggles the flag that indicates whether the color
89 // buffer should be cleared every frame. If this is
90 // true, the color buffer will be cleared to the color
91 // indicated by set_clear_color(); otherwise, it will be
92 // left alone.
93 ////////////////////////////////////////////////////////////////////
94 INLINE void DrawableRegion::
95 set_clear_color_active(bool clear_color_active) {
96  set_clear_active(RTP_color, clear_color_active);
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: DrawableRegion::get_clear_color_active
101 // Access: Published
102 // Description: Returns the current setting of the flag that
103 // indicates whether the color buffer should be cleared
104 // every frame. See set_clear_color_active().
105 ////////////////////////////////////////////////////////////////////
106 INLINE bool DrawableRegion::
108  return get_clear_active(RTP_color);
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: DrawableRegion::set_clear_depth_active
113 // Access: Published
114 // Description: Toggles the flag that indicates whether the depth
115 // buffer should be cleared every frame. If this is
116 // true, the depth buffer will be cleared to the depth
117 // value indicated by set_clear_depth(); otherwise, it
118 // will be left alone.
119 ////////////////////////////////////////////////////////////////////
120 INLINE void DrawableRegion::
121 set_clear_depth_active(bool clear_depth_active) {
122  set_clear_active(RTP_depth, clear_depth_active);
123 }
124 
125 ////////////////////////////////////////////////////////////////////
126 // Function: DrawableRegion::get_clear_depth_active
127 // Access: Published
128 // Description: Returns the current setting of the flag that
129 // indicates whether the depth buffer should be cleared
130 // every frame. See set_clear_depth_active().
131 ////////////////////////////////////////////////////////////////////
132 INLINE bool DrawableRegion::
134  return get_clear_active(RTP_depth);
135 }
136 
137 ////////////////////////////////////////////////////////////////////
138 // Function: DrawableRegion::set_clear_stencil_active
139 // Access: Published
140 // Description: Toggles the flag that indicates whether the stencil
141 // buffer should be cleared every frame. If this is
142 // true, the stencil buffer will be cleared to the value
143 // indicated by set_clear_stencil(); otherwise, it will be
144 // left alone.
145 ////////////////////////////////////////////////////////////////////
146 INLINE void DrawableRegion::
147 set_clear_stencil_active(bool clear_stencil_active) {
148  set_clear_active(RTP_stencil, clear_stencil_active);
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: DrawableRegion::get_clear_stencil_active
153 // Access: Published
154 // Description: Returns the current setting of the flag that
155 // indicates whether the color buffer should be cleared
156 // every frame. See set_clear_stencil_active().
157 ////////////////////////////////////////////////////////////////////
158 INLINE bool DrawableRegion::
160  return get_clear_active(RTP_stencil);
161 }
162 
163 ////////////////////////////////////////////////////////////////////
164 // Function: DrawableRegion::set_clear_color
165 // Access: Published
166 // Description: Sets the clear color to the indicated value. This is
167 // the value that will be used to clear the color buffer
168 // every frame, but only if get_clear_color_active()
169 // returns true. If get_clear_color_active() returns
170 // false, this is meaningless.
171 ////////////////////////////////////////////////////////////////////
172 INLINE void DrawableRegion::
174  set_clear_value(RTP_color, color);
175 }
176 
177 ////////////////////////////////////////////////////////////////////
178 // Function: DrawableRegion::get_clear_color
179 // Access: Published
180 // Description: Returns the current clear color value. This is
181 // the value that will be used to clear the color buffer
182 // every frame, but only if get_clear_color_active()
183 // returns true. If get_clear_color_active() returns
184 // false, this is meaningless.
185 ////////////////////////////////////////////////////////////////////
186 INLINE const LColor &DrawableRegion::
188  return get_clear_value(RTP_color);
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: DrawableRegion::set_clear_depth
193 // Access: Published
194 // Description: Sets the clear depth to the indicated value. This is
195 // the value that will be used to clear the depth buffer
196 // every frame, but only if get_clear_depth_active()
197 // returns true. If get_clear_depth_active() returns
198 // false, this is meaningless.
199 ////////////////////////////////////////////////////////////////////
200 INLINE void DrawableRegion::
201 set_clear_depth(PN_stdfloat depth) {
202  set_clear_value(RTP_depth, LColor(depth,depth,depth,depth));
203 }
204 
205 ////////////////////////////////////////////////////////////////////
206 // Function: DrawableRegion::get_clear_depth
207 // Access: Published
208 // Description: Returns the current clear depth value. This is
209 // the value that will be used to clear the depth buffer
210 // every frame, but only if get_clear_depth_active()
211 // returns true. If get_clear_depth_active() returns
212 // false, this is meaningless.
213 ////////////////////////////////////////////////////////////////////
214 INLINE PN_stdfloat DrawableRegion::
216  return get_clear_value(RTP_depth)[0];
217 }
218 ////////////////////////////////////////////////////////////////////
219 // Function: DrawableRegion::set_clear_stencil
220 // Access: Published
221 // Description: Sets the clear stencil to the indicated value. This is
222 // the value that will be used to clear the stencil buffer
223 // every frame, but only if get_clear_color_active()
224 // returns true. If get_clear_stencil_active() returns
225 // false, this is meaningless.
226 ////////////////////////////////////////////////////////////////////
227 INLINE void DrawableRegion::
228 set_clear_stencil(const unsigned int stencil) {
229  set_clear_value(RTP_stencil, LColor(stencil,stencil,stencil,stencil));
230 }
231 
232 ////////////////////////////////////////////////////////////////////
233 // Function: DrawableRegion::get_clear_stencil
234 // Access: Published
235 // Description: Returns the current clear stencil value. This is
236 // the value that will be used to clear the stencil buffer
237 // every frame, but only if get_clear_stencil_active()
238 // returns true. If get_clear_stencil_active() returns
239 // false, this is meaningless.
240 ////////////////////////////////////////////////////////////////////
241 INLINE unsigned int DrawableRegion::
243  return (unsigned int)(get_clear_value(RTP_stencil)[0]);
244 }
245 
246 ////////////////////////////////////////////////////////////////////
247 // Function: DrawableRegion::get_pixel_zoom
248 // Access: Published
249 // Description: Returns the value set by set_pixel_zoom(), regardless
250 // of whether it is being respected or not. Also see
251 // get_pixel_factor().
252 ////////////////////////////////////////////////////////////////////
253 INLINE PN_stdfloat DrawableRegion::
254 get_pixel_zoom() const {
255  return _pixel_zoom;
256 }
257 
258 ////////////////////////////////////////////////////////////////////
259 // Function: DrawableRegion::get_pixel_factor
260 // Access: Published
261 // Description: Returns the amount by which the height and width of
262 // the region will be scaled internally, based on the
263 // zoom factor set by set_pixel_zoom(). This will
264 // return 1.0 if the pixel_zoom was not set or if it is
265 // not being respected (for instance, because the
266 // underlying renderer doesn't support it--see
267 // supports_pixel_zoom).
268 ////////////////////////////////////////////////////////////////////
269 INLINE PN_stdfloat DrawableRegion::
271  return _pixel_factor;
272 }
273 
274 ////////////////////////////////////////////////////////////////////
275 // Function: DrawableRegion::get_screenshot_buffer_type
276 // Access: Public
277 // Description: Returns the RenderBuffer that should be used for
278 // capturing screenshots from this particular
279 // DrawableRegion.
280 ////////////////////////////////////////////////////////////////////
281 INLINE int DrawableRegion::
283  return _screenshot_buffer_type;
284 }
285 
286 ////////////////////////////////////////////////////////////////////
287 // Function: DrawableRegion::get_draw_buffer_type
288 // Access: Public
289 // Description: Returns the RenderBuffer into which the GSG should
290 // issue draw commands. Normally, this is the back
291 // buffer for double-buffered windows, and the front
292 // buffer for single-buffered windows.
293 ////////////////////////////////////////////////////////////////////
294 INLINE int DrawableRegion::
296  return _draw_buffer_type;
297 }
298 
299 ////////////////////////////////////////////////////////////////////
300 // Function: DrawableRegion::update_pixel_factor
301 // Access: Protected
302 // Description: Internal function to reset pixel_factor after it may
303 // have changed.
304 ////////////////////////////////////////////////////////////////////
305 INLINE void DrawableRegion::
306 update_pixel_factor() {
307  PN_stdfloat new_pixel_factor;
308  if (supports_pixel_zoom()) {
309  new_pixel_factor = (PN_stdfloat)1 / sqrt(max(_pixel_zoom, (PN_stdfloat)1.0));
310  } else {
311  new_pixel_factor = 1;
312  }
313  if (new_pixel_factor != _pixel_factor) {
314  _pixel_factor = new_pixel_factor;
315  pixel_factor_changed();
316  }
317 }
PN_stdfloat get_pixel_zoom() const
Returns the value set by set_pixel_zoom(), regardless of whether it is being respected or not...
This is a base class for GraphicsWindow (actually, GraphicsOutput) and DisplayRegion, both of which are conceptually rectangular regions into which drawing commands may be issued.
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.
PN_stdfloat get_clear_depth() const
Returns the current clear depth value.
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().
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_color(const LColor &color)
Sets the clear color to the indicated value.
void set_clear_depth_active(bool clear_depth_active)
Toggles the flag that indicates whether the depth buffer should be cleared every frame.
const LColor & get_clear_color() const
Returns the current clear color value.
void set_clear_stencil(unsigned int stencil)
Sets the clear stencil to the indicated value.
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...
void set_clear_depth(PN_stdfloat depth)
Sets the clear depth to the indicated value.
int get_draw_buffer_type() const
Returns the RenderBuffer into which the GSG should issue draw commands.
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
unsigned int get_clear_stencil() const
Returns the current clear stencil value.
A RenderBuffer is an arbitrary subset of the various layers (depth buffer, color buffer, etc.) of a drawing region.
Definition: renderBuffer.h:30