00001 // Filename: drawableRegion.cxx 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 #include "drawableRegion.h" 00016 00017 00018 //////////////////////////////////////////////////////////////////// 00019 // Function: DrawableRegion::Destructor 00020 // Access: Public, Virtual 00021 // Description: 00022 //////////////////////////////////////////////////////////////////// 00023 DrawableRegion:: 00024 ~DrawableRegion() { 00025 } 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: DrawableRegion::set_clear_active 00029 // Access: Published, Virtual 00030 // Description: Sets the clear-active flag for any bitplane. 00031 //////////////////////////////////////////////////////////////////// 00032 void DrawableRegion:: 00033 set_clear_active(int n, bool clear_active) { 00034 nassertv((n >= 0)&&(n < RTP_COUNT)); 00035 _clear_active[n] = clear_active; 00036 update_pixel_factor(); 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function: DrawableRegion::get_clear_active 00041 // Access: Published, Virtual 00042 // Description: Gets the clear-active flag for any bitplane. 00043 //////////////////////////////////////////////////////////////////// 00044 bool DrawableRegion:: 00045 get_clear_active(int n) const { 00046 nassertr((n >= 0)&&(n < RTP_COUNT), false); 00047 return _clear_active[n]; 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: DrawableRegion::set_clear_value 00052 // Access: Published, Virtual 00053 // Description: Sets the clear value for any bitplane. 00054 //////////////////////////////////////////////////////////////////// 00055 void DrawableRegion:: 00056 set_clear_value(int n, const LColor &clear_value) { 00057 nassertv((n >= 0) && (n < RTP_COUNT)); 00058 _clear_value[n] = clear_value; 00059 } 00060 00061 //////////////////////////////////////////////////////////////////// 00062 // Function: DrawableRegion::get_clear_value 00063 // Access: Published, Virtual 00064 // Description: Returns the clear value for any bitplane. 00065 //////////////////////////////////////////////////////////////////// 00066 const LColor &DrawableRegion:: 00067 get_clear_value(int n) const { 00068 static LColor blank(0.5,0.5,0.5,0.0); 00069 nassertr((n >= 0) && (n < RTP_COUNT), blank); 00070 return _clear_value[n]; 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: DrawableRegion::disable_clears 00075 // Access: Published, Virtual 00076 // Description: Disables both the color and depth clear. See 00077 // set_clear_color_active and set_clear_depth_active. 00078 //////////////////////////////////////////////////////////////////// 00079 void DrawableRegion:: 00080 disable_clears() { 00081 for (int i = 0; i < RTP_COUNT; ++i) { 00082 _clear_active[i] = false; 00083 } 00084 update_pixel_factor(); 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: DrawableRegion::is_any_clear_active 00089 // Access: Published, Virtual 00090 // Description: Returns true if any of the clear types (so far there 00091 // are just color or depth) have been set active, or 00092 // false if none of them are active and there is no need 00093 // to clear. 00094 //////////////////////////////////////////////////////////////////// 00095 bool DrawableRegion:: 00096 is_any_clear_active() const { 00097 for (int i = 0; i < RTP_COUNT; ++i) { 00098 if (get_clear_active(i)) { 00099 return true; 00100 } 00101 } 00102 return false; 00103 } 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: DrawableRegion::set_pixel_zoom 00107 // Access: Published, Virtual 00108 // Description: Sets the amount by which the pixels of the region are 00109 // scaled internally when filling the image interally. 00110 // Setting this number larger makes the pixels blockier, 00111 // but may make the rendering faster, particularly for 00112 // software renderers. Setting this number to 2.0 00113 // reduces the number of pixels that have to be filled 00114 // by the renderer by a factor of 2.0. It doesn't make 00115 // sense to set this lower than 1.0. 00116 // 00117 // It is possible to set this on either individual 00118 // DisplayRegions or on overall GraphicsWindows, but you 00119 // will get better performance for setting it on the 00120 // window rather than its individual DisplayRegions. 00121 // Also, you may not set it on a DisplayRegion that 00122 // doesn't have both clear_color() and clear_depth() 00123 // enabled. 00124 // 00125 // This property is only supported on renderers for 00126 // which it is particularly useful--currently, this is 00127 // the tinydisplay software renderer. Other kinds of 00128 // renderers allow you to set this property, but ignore 00129 // it. 00130 //////////////////////////////////////////////////////////////////// 00131 void DrawableRegion:: 00132 set_pixel_zoom(PN_stdfloat pixel_zoom) { 00133 _pixel_zoom = pixel_zoom; 00134 update_pixel_factor(); 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: DrawableRegion::supports_pixel_zoom 00139 // Access: Published, Virtual 00140 // Description: Returns true if a call to set_pixel_zoom() will be 00141 // respected, false if it will be ignored. If this 00142 // returns false, then get_pixel_factor() will always 00143 // return 1.0, regardless of what value you specify for 00144 // set_pixel_zoom(). 00145 // 00146 // This may return false if the underlying renderer 00147 // doesn't support pixel zooming, or if you have called 00148 // this on a DisplayRegion that doesn't have both 00149 // set_clear_color() and set_clear_depth() enabled. 00150 //////////////////////////////////////////////////////////////////// 00151 bool DrawableRegion:: 00152 supports_pixel_zoom() const { 00153 return false; 00154 } 00155 00156 //////////////////////////////////////////////////////////////////// 00157 // Function: DrawableRegion::get_renderbuffer_type 00158 // Access: Static, Published 00159 // Description: Returns the RenderBuffer::Type that corresponds 00160 // to a RenderTexturePlane. 00161 //////////////////////////////////////////////////////////////////// 00162 int DrawableRegion:: 00163 get_renderbuffer_type(int rtp) { 00164 switch(rtp) { 00165 case RTP_stencil: return RenderBuffer::T_stencil; 00166 case RTP_depth: return RenderBuffer::T_depth; 00167 case RTP_depth_stencil: return RenderBuffer::T_depth | RenderBuffer::T_stencil; 00168 case RTP_color: return RenderBuffer::T_color; 00169 case RTP_aux_rgba_0: return RenderBuffer::T_aux_rgba_0; 00170 case RTP_aux_rgba_1: return RenderBuffer::T_aux_rgba_1; 00171 case RTP_aux_rgba_2: return RenderBuffer::T_aux_rgba_2; 00172 case RTP_aux_rgba_3: return RenderBuffer::T_aux_rgba_3; 00173 case RTP_aux_hrgba_0: return RenderBuffer::T_aux_hrgba_0; 00174 case RTP_aux_hrgba_1: return RenderBuffer::T_aux_hrgba_1; 00175 case RTP_aux_hrgba_2: return RenderBuffer::T_aux_hrgba_2; 00176 case RTP_aux_hrgba_3: return RenderBuffer::T_aux_hrgba_3; 00177 case RTP_aux_float_0: return RenderBuffer::T_aux_float_0; 00178 case RTP_aux_float_1: return RenderBuffer::T_aux_float_1; 00179 case RTP_aux_float_2: return RenderBuffer::T_aux_float_2; 00180 case RTP_aux_float_3: return RenderBuffer::T_aux_float_3; 00181 default: 00182 display_cat.error() << "DrawableRegion::get_renderbuffer_type unexpected case!\n"; 00183 return 0; 00184 }; 00185 } 00186 00187 //////////////////////////////////////////////////////////////////// 00188 // Function: DrawableRegion::pixel_factor_changed 00189 // Access: Protected, Virtual 00190 // Description: Called internally when the pixel factor changes. 00191 //////////////////////////////////////////////////////////////////// 00192 void DrawableRegion:: 00193 pixel_factor_changed() { 00194 }