Panda3D
|
00001 // Filename: drawableRegion.I 00002 // Created by: drose (11Jul02) 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: DrawableRegion::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE DrawableRegion:: 00022 DrawableRegion() : 00023 _screenshot_buffer_type(RenderBuffer::T_front), 00024 _draw_buffer_type(RenderBuffer::T_back) 00025 { 00026 for (int i=0; i<RTP_COUNT; i++) { 00027 _clear_active[i] = false; 00028 _clear_value[i] = LColor(0.0f, 0.0f, 0.0f, 0.0f); 00029 } 00030 _clear_value[RTP_depth] = LColor(1.0f,1.0f,1.0f,1.0f); 00031 _pixel_zoom = 1.0f; 00032 _pixel_factor = 1.0f; 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: DrawableRegion::Copy Constructor 00037 // Access: Public 00038 // Description: 00039 //////////////////////////////////////////////////////////////////// 00040 INLINE DrawableRegion:: 00041 DrawableRegion(const DrawableRegion ©) : 00042 _screenshot_buffer_type(copy._screenshot_buffer_type), 00043 _draw_buffer_type(copy._draw_buffer_type), 00044 _pixel_zoom(copy._pixel_zoom), 00045 _pixel_factor(copy._pixel_factor) 00046 { 00047 for (int i=0; i<RTP_COUNT; i++) { 00048 _clear_active[i] = copy._clear_active[i]; 00049 _clear_value[i] = copy._clear_value[i]; 00050 } 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: DrawableRegion::Copy Assignment Operator 00055 // Access: Public 00056 // Description: 00057 //////////////////////////////////////////////////////////////////// 00058 INLINE void DrawableRegion:: 00059 operator = (const DrawableRegion ©) { 00060 _screenshot_buffer_type = copy._screenshot_buffer_type; 00061 _draw_buffer_type = copy._draw_buffer_type; 00062 for (int i=0; i<RTP_COUNT; i++) { 00063 _clear_active[i] = copy._clear_active[i]; 00064 _clear_value[i] = copy._clear_value[i]; 00065 } 00066 _pixel_zoom = copy._pixel_zoom; 00067 _pixel_factor = copy._pixel_factor; 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: DrawableRegion::copy_clear_settings 00072 // Access: Public 00073 // Description: Copies only the clear settings from the other drawable 00074 // region. 00075 //////////////////////////////////////////////////////////////////// 00076 INLINE void DrawableRegion:: 00077 copy_clear_settings(const DrawableRegion ©) { 00078 for (int i=0; i<RTP_COUNT; i++) { 00079 _clear_active[i] = copy._clear_active[i]; 00080 _clear_value[i] = copy._clear_value[i]; 00081 } 00082 update_pixel_factor(); 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: DrawableRegion::set_clear_color_active 00087 // Access: Published 00088 // Description: Toggles the flag that indicates whether the color 00089 // buffer should be cleared every frame. If this is 00090 // true, the color buffer will be cleared to the color 00091 // indicated by set_clear_color(); otherwise, it will be 00092 // left alone. 00093 //////////////////////////////////////////////////////////////////// 00094 INLINE void DrawableRegion:: 00095 set_clear_color_active(bool clear_color_active) { 00096 set_clear_active(RTP_color, clear_color_active); 00097 } 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: DrawableRegion::get_clear_color_active 00101 // Access: Published 00102 // Description: Returns the current setting of the flag that 00103 // indicates whether the color buffer should be cleared 00104 // every frame. See set_clear_color_active(). 00105 //////////////////////////////////////////////////////////////////// 00106 INLINE bool DrawableRegion:: 00107 get_clear_color_active() const { 00108 return get_clear_active(RTP_color); 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: DrawableRegion::set_clear_depth_active 00113 // Access: Published 00114 // Description: Toggles the flag that indicates whether the depth 00115 // buffer should be cleared every frame. If this is 00116 // true, the depth buffer will be cleared to the depth 00117 // value indicated by set_clear_depth(); otherwise, it 00118 // will be left alone. 00119 //////////////////////////////////////////////////////////////////// 00120 INLINE void DrawableRegion:: 00121 set_clear_depth_active(bool clear_depth_active) { 00122 set_clear_active(RTP_depth, clear_depth_active); 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: DrawableRegion::get_clear_depth_active 00127 // Access: Published 00128 // Description: Returns the current setting of the flag that 00129 // indicates whether the depth buffer should be cleared 00130 // every frame. See set_clear_depth_active(). 00131 //////////////////////////////////////////////////////////////////// 00132 INLINE bool DrawableRegion:: 00133 get_clear_depth_active() const { 00134 return get_clear_active(RTP_depth); 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: DrawableRegion::set_clear_stencil_active 00139 // Access: Published 00140 // Description: Toggles the flag that indicates whether the stencil 00141 // buffer should be cleared every frame. If this is 00142 // true, the stencil buffer will be cleared to the value 00143 // indicated by set_clear_stencil(); otherwise, it will be 00144 // left alone. 00145 //////////////////////////////////////////////////////////////////// 00146 INLINE void DrawableRegion:: 00147 set_clear_stencil_active(bool clear_stencil_active) { 00148 set_clear_active(RTP_stencil, clear_stencil_active); 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function: DrawableRegion::get_clear_stencil_active 00153 // Access: Published 00154 // Description: Returns the current setting of the flag that 00155 // indicates whether the color buffer should be cleared 00156 // every frame. See set_clear_stencil_active(). 00157 //////////////////////////////////////////////////////////////////// 00158 INLINE bool DrawableRegion:: 00159 get_clear_stencil_active() const { 00160 return get_clear_active(RTP_stencil); 00161 } 00162 00163 //////////////////////////////////////////////////////////////////// 00164 // Function: DrawableRegion::set_clear_color 00165 // Access: Published 00166 // Description: Sets the clear color to the indicated value. This is 00167 // the value that will be used to clear the color buffer 00168 // every frame, but only if get_clear_color_active() 00169 // returns true. If get_clear_color_active() returns 00170 // false, this is meaningless. 00171 //////////////////////////////////////////////////////////////////// 00172 INLINE void DrawableRegion:: 00173 set_clear_color(const LColor &color) { 00174 set_clear_value(RTP_color, color); 00175 } 00176 00177 //////////////////////////////////////////////////////////////////// 00178 // Function: DrawableRegion::get_clear_color 00179 // Access: Published 00180 // Description: Returns the current clear color value. This is 00181 // the value that will be used to clear the color buffer 00182 // every frame, but only if get_clear_color_active() 00183 // returns true. If get_clear_color_active() returns 00184 // false, this is meaningless. 00185 //////////////////////////////////////////////////////////////////// 00186 INLINE const LColor &DrawableRegion:: 00187 get_clear_color() const { 00188 return get_clear_value(RTP_color); 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: DrawableRegion::set_clear_depth 00193 // Access: Published 00194 // Description: Sets the clear depth to the indicated value. This is 00195 // the value that will be used to clear the depth buffer 00196 // every frame, but only if get_clear_depth_active() 00197 // returns true. If get_clear_depth_active() returns 00198 // false, this is meaningless. 00199 //////////////////////////////////////////////////////////////////// 00200 INLINE void DrawableRegion:: 00201 set_clear_depth(PN_stdfloat depth) { 00202 set_clear_value(RTP_depth, LColor(depth,depth,depth,depth)); 00203 } 00204 00205 //////////////////////////////////////////////////////////////////// 00206 // Function: DrawableRegion::get_clear_depth 00207 // Access: Published 00208 // Description: Returns the current clear depth value. This is 00209 // the value that will be used to clear the depth buffer 00210 // every frame, but only if get_clear_depth_active() 00211 // returns true. If get_clear_depth_active() returns 00212 // false, this is meaningless. 00213 //////////////////////////////////////////////////////////////////// 00214 INLINE PN_stdfloat DrawableRegion:: 00215 get_clear_depth() const { 00216 return get_clear_value(RTP_depth)[0]; 00217 } 00218 //////////////////////////////////////////////////////////////////// 00219 // Function: DrawableRegion::set_clear_stencil 00220 // Access: Published 00221 // Description: Sets the clear stencil to the indicated value. This is 00222 // the value that will be used to clear the stencil buffer 00223 // every frame, but only if get_clear_color_active() 00224 // returns true. If get_clear_stencil_active() returns 00225 // false, this is meaningless. 00226 //////////////////////////////////////////////////////////////////// 00227 INLINE void DrawableRegion:: 00228 set_clear_stencil(const unsigned int stencil) { 00229 set_clear_value(RTP_stencil, LColor(stencil,stencil,stencil,stencil)); 00230 } 00231 00232 //////////////////////////////////////////////////////////////////// 00233 // Function: DrawableRegion::get_clear_stencil 00234 // Access: Published 00235 // Description: Returns the current clear stencil value. This is 00236 // the value that will be used to clear the stencil buffer 00237 // every frame, but only if get_clear_stencil_active() 00238 // returns true. If get_clear_stencil_active() returns 00239 // false, this is meaningless. 00240 //////////////////////////////////////////////////////////////////// 00241 INLINE unsigned int DrawableRegion:: 00242 get_clear_stencil() const { 00243 return (int)(get_clear_value(RTP_stencil)[0]); 00244 } 00245 00246 //////////////////////////////////////////////////////////////////// 00247 // Function: DrawableRegion::get_pixel_zoom 00248 // Access: Published 00249 // Description: Returns the value set by set_pixel_zoom(), regardless 00250 // of whether it is being respected or not. Also see 00251 // get_pixel_factor(). 00252 //////////////////////////////////////////////////////////////////// 00253 INLINE PN_stdfloat DrawableRegion:: 00254 get_pixel_zoom() const { 00255 return _pixel_zoom; 00256 } 00257 00258 //////////////////////////////////////////////////////////////////// 00259 // Function: DrawableRegion::get_pixel_factor 00260 // Access: Published 00261 // Description: Returns the amount by which the height and width of 00262 // the region will be scaled internally, based on the 00263 // zoom factor set by set_pixel_zoom(). This will 00264 // return 1.0 if the pixel_zoom was not set or if it is 00265 // not being respected (for instance, because the 00266 // underlying renderer doesn't support it--see 00267 // supports_pixel_zoom). 00268 //////////////////////////////////////////////////////////////////// 00269 INLINE PN_stdfloat DrawableRegion:: 00270 get_pixel_factor() const { 00271 return _pixel_factor; 00272 } 00273 00274 //////////////////////////////////////////////////////////////////// 00275 // Function: DrawableRegion::get_screenshot_buffer_type 00276 // Access: Public 00277 // Description: Returns the RenderBuffer that should be used for 00278 // capturing screenshots from this particular 00279 // DrawableRegion. 00280 //////////////////////////////////////////////////////////////////// 00281 INLINE int DrawableRegion:: 00282 get_screenshot_buffer_type() const { 00283 return _screenshot_buffer_type; 00284 } 00285 00286 //////////////////////////////////////////////////////////////////// 00287 // Function: DrawableRegion::get_draw_buffer_type 00288 // Access: Public 00289 // Description: Returns the RenderBuffer into which the GSG should 00290 // issue draw commands. Normally, this is the back 00291 // buffer for double-buffered windows, and the front 00292 // buffer for single-buffered windows. 00293 //////////////////////////////////////////////////////////////////// 00294 INLINE int DrawableRegion:: 00295 get_draw_buffer_type() const { 00296 return _draw_buffer_type; 00297 } 00298 00299 //////////////////////////////////////////////////////////////////// 00300 // Function: DrawableRegion::update_pixel_factor 00301 // Access: Protected 00302 // Description: Internal function to reset pixel_factor after it may 00303 // have changed. 00304 //////////////////////////////////////////////////////////////////// 00305 INLINE void DrawableRegion:: 00306 update_pixel_factor() { 00307 PN_stdfloat new_pixel_factor; 00308 if (supports_pixel_zoom()) { 00309 new_pixel_factor = 1.0 / sqrt(max(_pixel_zoom, (PN_stdfloat)1.0)); 00310 } else { 00311 new_pixel_factor = 1.0; 00312 } 00313 if (new_pixel_factor != _pixel_factor) { 00314 _pixel_factor = new_pixel_factor; 00315 pixel_factor_changed(); 00316 } 00317 }