Panda3D
Loading...
Searching...
No Matches
cullBinManager.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 cullBinManager.I
10 * @author drose
11 * @date 2002-02-28
12 */
13
14/**
15 * This is a function object whose sole purpose is to put the _sorted_bins
16 * vector in the proper order for rendering the bins.
17 */
18INLINE CullBinManager::SortBins::
19SortBins(CullBinManager *manager) :
20 _manager(manager)
21{
22}
23
24/**
25 * The function call method of the function object. Returns true if the two
26 * bin indices are already in sorted order with a < b, or false otherwise.
27 */
28INLINE bool CullBinManager::SortBins::
29operator () (int a, int b) const {
30 return _manager->_bin_definitions[a]._sort < _manager->_bin_definitions[b]._sort;
31}
32
33
34
35/**
36 * Returns the number of bins in the world.
37 */
38INLINE int CullBinManager::
39get_num_bins() const {
40 // We quietly sort the bins in order if they are not already sorted. This
41 // is a non-const operation, but we pretend it's const because it's intended
42 // to be a transparent update.
43 if (!_bins_are_sorted) {
44 ((CullBinManager *)this)->do_sort_bins();
45 }
46 return _sorted_bins.size();
47}
48
49/**
50 * Returns the bin_index of the nth bin in the set, where n is a number
51 * between 0 and get_num_bins(). This returns the list of bin_index numbers,
52 * in sorted order (that is, in the order in which the bins should be
53 * rendered).
54 */
55INLINE int CullBinManager::
56get_bin(int n) const {
57 nassertr(n >= 0 && n < (int)_sorted_bins.size(), -1);
58 return _sorted_bins[n];
59}
60
61/**
62 * Returns the name of the bin with the indicated bin_index (where bin_index
63 * was retrieved by get_bin() or find_bin()). The bin's name may not be
64 * changed during the life of the bin.
65 */
66INLINE std::string CullBinManager::
67get_bin_name(int bin_index) const {
68 nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), std::string());
69 nassertr(_bin_definitions[bin_index]._in_use, std::string());
70 return _bin_definitions[bin_index]._name;
71}
72
73/**
74 * Returns the type of the bin with the indicated bin_index (where bin_index
75 * was retrieved by get_bin() or find_bin()).
76 */
77INLINE CullBinManager::BinType CullBinManager::
78get_bin_type(int bin_index) const {
79 nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), BT_invalid);
80 nassertr(_bin_definitions[bin_index]._in_use, BT_invalid);
81 return _bin_definitions[bin_index]._type;
82}
83
84/**
85 * Returns the type of the bin with the indicated name.
86 */
87INLINE CullBinManager::BinType CullBinManager::
88get_bin_type(const std::string &name) const {
89 int bin_index = find_bin(name);
90 nassertr(bin_index != -1, BT_invalid);
91 return get_bin_type(bin_index);
92}
93
94/**
95 * Changes the type of the bin with the indicated bin_index (where bin_index
96 * was retrieved by get_bin() or find_bin()).
97 *
98 * The change might be effective immediately, or it might take place next
99 * frame, depending on the bin type.
100 */
102set_bin_type(int bin_index, CullBinManager::BinType type) {
103 nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
104 nassertv(_bin_definitions[bin_index]._in_use);
105 _bin_definitions[bin_index]._type = type;
106}
107
108/**
109 * Changes the type of the bin with the indicated name.
110 *
111 * The change might be effective immediately, or it might take place next
112 * frame, depending on the bin type.
113 */
115set_bin_type(const std::string &name, CullBinManager::BinType type) {
116 int bin_index = find_bin(name);
117 nassertv(bin_index != -1);
118 set_bin_type(bin_index, type);
119}
120
121/**
122 * Returns the sort order of the bin with the indicated bin_index (where
123 * bin_index was retrieved by get_bin() or find_bin()).
124 *
125 * The bins are rendered in increasing order by their sort order; this number
126 * may be changed from time to time to reorder the bins.
127 */
129get_bin_sort(int bin_index) const {
130 nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), 0);
131 nassertr(_bin_definitions[bin_index]._in_use, 0);
132 return _bin_definitions[bin_index]._sort;
133}
134
135/**
136 * Returns the sort order of the bin with the indicated name.
137 *
138 * The bins are rendered in increasing order by their sort order; this number
139 * may be changed from time to time to reorder the bins.
140 */
142get_bin_sort(const std::string &name) const {
143 int bin_index = find_bin(name);
144 nassertr(bin_index != -1, 0);
145 return get_bin_sort(bin_index);
146}
147
148/**
149 * Changes the sort order of the bin with the indicated bin_index (where
150 * bin_index was retrieved by get_bin() or find_bin()).
151 *
152 * The bins are rendered in increasing order by their sort order; this number
153 * may be changed from time to time to reorder the bins.
154 */
156set_bin_sort(int bin_index, int sort) {
157 nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
158 nassertv(_bin_definitions[bin_index]._in_use);
159 _bin_definitions[bin_index]._sort = sort;
160 _bins_are_sorted = false;
161}
162
163/**
164 * Changes the sort order of the bin with the indicated name.
165 *
166 * The bins are rendered in increasing order by their sort order; this number
167 * may be changed from time to time to reorder the bins.
168 */
170set_bin_sort(const std::string &name, int sort) {
171 int bin_index = find_bin(name);
172 nassertv(bin_index != -1);
173 set_bin_sort(bin_index, sort);
174}
175
176/**
177 * Returns the active flag of the bin with the indicated bin_index (where
178 * bin_index was retrieved by get_bin() or find_bin()).
179 *
180 * When a bin is marked inactive, all geometry assigned to it is not rendered.
181 */
183get_bin_active(int bin_index) const {
184 nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), false);
185 nassertr(_bin_definitions[bin_index]._in_use, false);
186 return _bin_definitions[bin_index]._active;
187}
188
189/**
190 * Returns the active flag of the bin with the indicated name.
191 *
192 * When a bin is marked inactive, all geometry assigned to it is not rendered.
193 */
195get_bin_active(const std::string &name) const {
196 int bin_index = find_bin(name);
197 nassertr(bin_index != -1, false);
198 return get_bin_active(bin_index);
199}
200
201/**
202 * Changes the active flag of the bin with the indicated bin_index (where
203 * bin_index was retrieved by get_bin() or find_bin()).
204 *
205 * When a bin is marked inactive, all geometry assigned to it is not rendered.
206 */
208set_bin_active(int bin_index, bool active) {
209 nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
210 nassertv(_bin_definitions[bin_index]._in_use);
211 _bin_definitions[bin_index]._active = active;
212}
213
214/**
215 * Changes the active flag of the bin with the indicated name.
216 *
217 * When a bin is marked inactive, all geometry assigned to it is not rendered.
218 */
220set_bin_active(const std::string &name, bool active) {
221 int bin_index = find_bin(name);
222 nassertv(bin_index != -1);
223 set_bin_active(bin_index, active);
224}
225
226#ifndef NDEBUG
227/**
228 * Returns true if the bin with the given bin_index is configured to flash at
229 * a predetermined color (where bin_index was retrieved by get_bin() or
230 * find_bin()).
231 *
232 * This method is not available in release builds.
233 */
235get_bin_flash_active(int bin_index) const {
236 nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), false);
237 return _bin_definitions[bin_index]._flash_active;
238}
239
240/**
241 * Returns the color that this bin has been configured to flash to, if
242 * configured.
243 *
244 * This method is not available in release builds.
245 */
246INLINE const LColor &CullBinManager::
247get_bin_flash_color(int bin_index) const {
248 nassertr(bin_index >= 0 && bin_index < (int)_bin_definitions.size(), LColor::zero());
249 return _bin_definitions[bin_index]._flash_color;
250}
251
252/**
253 * When set to true, the given bin_index is configured to flash at a
254 * predetermined color (where bin_index was retrieved by get_bin() or
255 * find_bin()).
256 *
257 * This method is not available in release builds.
258 */
260set_bin_flash_active(int bin_index, bool active) {
261 nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
262 _bin_definitions[bin_index]._flash_active = active;
263}
264
265/**
266 * Changes the flash color for the given bin index.
267 *
268 * This method is not available in release builds.
269 */
271set_bin_flash_color(int bin_index, const LColor &color) {
272 nassertv(bin_index >= 0 && bin_index < (int)_bin_definitions.size());
273 _bin_definitions[bin_index]._flash_color = color;
274}
275#endif // NDEBUG
276
277/**
278 * Returns the pointer to the global CullBinManager object.
279 */
282 if (_global_ptr == nullptr) {
283 _global_ptr = new CullBinManager;
284 }
285 return _global_ptr;
286}
This is a global object that maintains the collection of named CullBins in the world.
BinType get_bin_type(int bin_index) const
Returns the type of the bin with the indicated bin_index (where bin_index was retrieved by get_bin() ...
static CullBinManager * get_global_ptr()
Returns the pointer to the global CullBinManager object.
bool get_bin_active(int bin_index) const
Returns the active flag of the bin with the indicated bin_index (where bin_index was retrieved by get...
void set_bin_flash_color(int bin_index, const LColor &color)
Changes the flash color for the given bin index.
const LColor & get_bin_flash_color(int bin_index) const
Returns the color that this bin has been configured to flash to, if configured.
int get_bin_sort(int bin_index) const
Returns the sort order of the bin with the indicated bin_index (where bin_index was retrieved by get_...
bool get_bin_flash_active(int bin_index) const
Returns true if the bin with the given bin_index is configured to flash at a predetermined color (whe...
get_bin
Returns the bin_index of the nth bin in the set, where n is a number between 0 and get_num_bins().
void set_bin_type(int bin_index, BinType type)
Changes the type of the bin with the indicated bin_index (where bin_index was retrieved by get_bin() ...
void set_bin_sort(int bin_index, int sort)
Changes the sort order of the bin with the indicated bin_index (where bin_index was retrieved by get_...
void set_bin_flash_active(int bin_index, bool active)
When set to true, the given bin_index is configured to flash at a predetermined color (where bin_inde...
void set_bin_active(int bin_index, bool active)
Changes the active flag of the bin with the indicated bin_index (where bin_index was retrieved by get...
std::string get_bin_name(int bin_index) const
Returns the name of the bin with the indicated bin_index (where bin_index was retrieved by get_bin() ...
get_num_bins
Returns the number of bins in the world.
int find_bin(const std::string &name) const
Returns the bin_index associated with the bin of the given name, or -1 if no bin has that name.