Panda3D
drawableRegion.cxx
1 // Filename: drawableRegion.cxx
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 #include "drawableRegion.h"
16 #include "config_display.h"
17 
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: DrawableRegion::Destructor
21 // Access: Public, Virtual
22 // Description:
23 ////////////////////////////////////////////////////////////////////
24 DrawableRegion::
25 ~DrawableRegion() {
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: DrawableRegion::set_clear_active
30 // Access: Published, Virtual
31 // Description: Sets the clear-active flag for any bitplane.
32 ////////////////////////////////////////////////////////////////////
34 set_clear_active(int n, bool clear_active) {
35  nassertv((n >= 0)&&(n < RTP_COUNT));
36  _clear_active[n] = clear_active;
37  update_pixel_factor();
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: DrawableRegion::get_clear_active
42 // Access: Published, Virtual
43 // Description: Gets the clear-active flag for any bitplane.
44 ////////////////////////////////////////////////////////////////////
46 get_clear_active(int n) const {
47  nassertr((n >= 0)&&(n < RTP_COUNT), false);
48  return _clear_active[n];
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: DrawableRegion::set_clear_value
53 // Access: Published, Virtual
54 // Description: Sets the clear value for any bitplane.
55 ////////////////////////////////////////////////////////////////////
57 set_clear_value(int n, const LColor &clear_value) {
58  nassertv((n >= 0) && (n < RTP_COUNT));
59  _clear_value[n] = clear_value;
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: DrawableRegion::get_clear_value
64 // Access: Published, Virtual
65 // Description: Returns the clear value for any bitplane.
66 ////////////////////////////////////////////////////////////////////
68 get_clear_value(int n) const {
69  static LColor blank(0.5,0.5,0.5,0.0);
70  nassertr((n >= 0) && (n < RTP_COUNT), blank);
71  return _clear_value[n];
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: DrawableRegion::disable_clears
76 // Access: Published, Virtual
77 // Description: Disables both the color and depth clear. See
78 // set_clear_color_active and set_clear_depth_active.
79 ////////////////////////////////////////////////////////////////////
82  for (int i = 0; i < RTP_COUNT; ++i) {
83  _clear_active[i] = false;
84  }
85  update_pixel_factor();
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: DrawableRegion::is_any_clear_active
90 // Access: Published, Virtual
91 // Description: Returns true if any of the clear types (so far there
92 // are just color or depth) have been set active, or
93 // false if none of them are active and there is no need
94 // to clear.
95 ////////////////////////////////////////////////////////////////////
98  for (int i = 0; i < RTP_COUNT; ++i) {
99  if (get_clear_active(i)) {
100  return true;
101  }
102  }
103  return false;
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: DrawableRegion::set_pixel_zoom
108 // Access: Published, Virtual
109 // Description: Sets the amount by which the pixels of the region are
110 // scaled internally when filling the image interally.
111 // Setting this number larger makes the pixels blockier,
112 // but may make the rendering faster, particularly for
113 // software renderers. Setting this number to 2.0
114 // reduces the number of pixels that have to be filled
115 // by the renderer by a factor of 2.0. It doesn't make
116 // sense to set this lower than 1.0.
117 //
118 // It is possible to set this on either individual
119 // DisplayRegions or on overall GraphicsWindows, but you
120 // will get better performance for setting it on the
121 // window rather than its individual DisplayRegions.
122 // Also, you may not set it on a DisplayRegion that
123 // doesn't have both clear_color() and clear_depth()
124 // enabled.
125 //
126 // This property is only supported on renderers for
127 // which it is particularly useful--currently, this is
128 // the tinydisplay software renderer. Other kinds of
129 // renderers allow you to set this property, but ignore
130 // it.
131 ////////////////////////////////////////////////////////////////////
132 void DrawableRegion::
133 set_pixel_zoom(PN_stdfloat pixel_zoom) {
134  _pixel_zoom = pixel_zoom;
135  update_pixel_factor();
136 }
137 
138 ////////////////////////////////////////////////////////////////////
139 // Function: DrawableRegion::supports_pixel_zoom
140 // Access: Published, Virtual
141 // Description: Returns true if a call to set_pixel_zoom() will be
142 // respected, false if it will be ignored. If this
143 // returns false, then get_pixel_factor() will always
144 // return 1.0, regardless of what value you specify for
145 // set_pixel_zoom().
146 //
147 // This may return false if the underlying renderer
148 // doesn't support pixel zooming, or if you have called
149 // this on a DisplayRegion that doesn't have both
150 // set_clear_color() and set_clear_depth() enabled.
151 ////////////////////////////////////////////////////////////////////
152 bool DrawableRegion::
154  return false;
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: DrawableRegion::get_renderbuffer_type
159 // Access: Static, Published
160 // Description: Returns the RenderBuffer::Type that corresponds
161 // to a RenderTexturePlane.
162 ////////////////////////////////////////////////////////////////////
165  switch(rtp) {
166  case RTP_stencil: return RenderBuffer::T_stencil;
167  case RTP_depth: return RenderBuffer::T_depth;
168  case RTP_depth_stencil: return RenderBuffer::T_depth | RenderBuffer::T_stencil;
169  case RTP_color: return RenderBuffer::T_color;
170  case RTP_aux_rgba_0: return RenderBuffer::T_aux_rgba_0;
171  case RTP_aux_rgba_1: return RenderBuffer::T_aux_rgba_1;
172  case RTP_aux_rgba_2: return RenderBuffer::T_aux_rgba_2;
173  case RTP_aux_rgba_3: return RenderBuffer::T_aux_rgba_3;
174  case RTP_aux_hrgba_0: return RenderBuffer::T_aux_hrgba_0;
175  case RTP_aux_hrgba_1: return RenderBuffer::T_aux_hrgba_1;
176  case RTP_aux_hrgba_2: return RenderBuffer::T_aux_hrgba_2;
177  case RTP_aux_hrgba_3: return RenderBuffer::T_aux_hrgba_3;
178  case RTP_aux_float_0: return RenderBuffer::T_aux_float_0;
179  case RTP_aux_float_1: return RenderBuffer::T_aux_float_1;
180  case RTP_aux_float_2: return RenderBuffer::T_aux_float_2;
181  case RTP_aux_float_3: return RenderBuffer::T_aux_float_3;
182  default:
183  display_cat.error() << "DrawableRegion::get_renderbuffer_type unexpected case!\n";
184  return 0;
185  };
186 }
187 
188 ////////////////////////////////////////////////////////////////////
189 // Function: DrawableRegion::pixel_factor_changed
190 // Access: Protected, Virtual
191 // Description: Called internally when the pixel factor changes.
192 ////////////////////////////////////////////////////////////////////
193 void DrawableRegion::
194 pixel_factor_changed() {
195 }
static int get_renderbuffer_type(int plane)
Returns the RenderBuffer::Type that corresponds to a RenderTexturePlane.
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.
virtual void set_clear_value(int n, const LColor &clear_value)
Sets the clear value for any bitplane.
virtual void disable_clears()
Disables both the color and depth clear.
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...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
virtual bool is_any_clear_active() const
Returns true if any of the clear types (so far there are just color or depth) have been set active...
virtual void set_pixel_zoom(PN_stdfloat pixel_zoom)
Sets the amount by which the pixels of the region are scaled internally when filling the image intera...