33 _bins_are_sorted =
true;
34 _unused_bin_index =
false;
52add_bin(
const string &name, BinType type,
int sort) {
53 BinsByName::const_iterator bni = _bins_by_name.find(name);
54 if (bni != _bins_by_name.end()) {
57 int bin_index = (*bni).second;
58 nassertr(bin_index >= 0 && bin_index < (
int)_bin_definitions.size(), -1);
59 const BinDefinition &def = _bin_definitions[bin_index];
60 nassertr(def._in_use, -1);
61 if (def._type == type && def._sort == sort) {
67 <<
"Cannot create a bin named " << name
68 <<
"; already have a bin by that name.\n";
74 int new_bin_index = -1;
75 if (_unused_bin_index) {
78 for (i = 0; i < (int)_bin_definitions.size() && new_bin_index == -1; i++) {
79 if (!_bin_definitions[i]._in_use) {
84 if (new_bin_index == -1) {
86 _unused_bin_index =
false;
90 if (new_bin_index == -1) {
92 new_bin_index = _bin_definitions.size();
93 _bin_definitions.push_back(BinDefinition());
96 BinDefinition &def = _bin_definitions[new_bin_index];
106 (
"flash-bin-" + name,
"",
"", ConfigVariable::F_dynamic);
108 def._flash_active =
false;
110 def._flash_active =
true;
111 def._flash_color = flash_bin.
get_value();
115 _bins_by_name.insert(BinsByName::value_type(name, new_bin_index));
116 _sorted_bins.push_back(new_bin_index);
117 _bins_are_sorted =
false;
119 return new_bin_index;
131 nassertv(bin_index >= 0 && bin_index < (
int)_bin_definitions.size());
132 nassertv(_bin_definitions[bin_index]._in_use);
134 _bin_definitions[bin_index]._in_use =
false;
135 SortedBins::iterator si =
136 find(_sorted_bins.begin(), _sorted_bins.end(), bin_index);
137 nassertv(si != _sorted_bins.end());
138 _sorted_bins.erase(si);
139 _bins_by_name.erase(_bin_definitions[bin_index]._name);
158 BinsByName::const_iterator bni;
159 bni = _bins_by_name.find(name);
160 if (bni != _bins_by_name.end()) {
161 return (*bni).second;
170write(std::ostream &out)
const {
171 if (!_bins_are_sorted) {
174 SortedBins::const_iterator sbi;
175 for (sbi = _sorted_bins.begin(); sbi != _sorted_bins.end(); ++sbi) {
176 int bin_index = (*sbi);
190 nassertr(bin_index >= 0 && bin_index < (
int)_bin_definitions.size(),
nullptr);
191 nassertr(_bin_definitions[bin_index]._in_use,
nullptr);
194 BinType type = _bin_definitions[bin_index]._type;
195 BinConstructors::const_iterator ci = _bin_constructors.find(type);
196 if (ci != _bin_constructors.end()) {
197 BinConstructor *constructor = (*ci).second;
198 return constructor(name, gsg, draw_region_pcollector);
202 nassert_raise(
"unknown bin type");
212 bool inserted = _bin_constructors.insert(BinConstructors::value_type(type, constructor)).second;
221 sort(_sorted_bins.begin(), _sorted_bins.end(), SortBins(
this));
222 _bins_are_sorted =
true;
230setup_initial_bins() {
233 PRC_DESC(
"Creates a new cull bin by name, with the specified properties. "
234 "This is a string in three tokens, separated by whitespace: "
235 "'bin_name sort type'."));
238 int num_bins = cull_bin.get_num_unique_values();
240 for (
int bi = 0; bi < num_bins; bi++) {
241 string def = cull_bin.get_unique_value(bi);
249 if (words.size() != 3) {
251 <<
"Invalid cull-bin definition: " << def <<
"\n"
252 <<
"Definition should be three words: bin_name sort type\n";
257 <<
"Invalid cull-bin definition: " << def <<
"\n"
258 <<
"Sort token " << words[1] <<
" is not an integer.\n";
261 BinType type = parse_bin_type(words[2]);
262 if (type == BT_invalid) {
264 <<
"Invalid cull-bin definition: " << def <<
"\n"
265 <<
"Bin type " << words[2] <<
" is not known.\n";
276 add_bin(
"background", BT_fixed, 10);
279 add_bin(
"opaque", BT_state_sorted, 20);
281 if (
find_bin(
"transparent") == -1) {
282 add_bin(
"transparent", BT_back_to_front, 30);
285 add_bin(
"fixed", BT_fixed, 40);
288 add_bin(
"unsorted", BT_unsorted, 50);
296CullBinManager::BinType CullBinManager::
297parse_bin_type(
const string &bin_type) {
298 if (cmp_nocase_uh(bin_type,
"unsorted") == 0) {
301 }
else if (cmp_nocase_uh(bin_type,
"state_sorted") == 0) {
302 return BT_state_sorted;
304 }
else if (cmp_nocase_uh(bin_type,
"fixed") == 0) {
307 }
else if (cmp_nocase_uh(bin_type,
"back_to_front") == 0) {
308 return BT_back_to_front;
310 }
else if (cmp_nocase_uh(bin_type,
"front_to_back") == 0) {
311 return BT_front_to_back;
322operator << (std::ostream &out, CullBinManager::BinType bin_type) {
324 case CullBinManager::BT_invalid:
325 return out <<
"invalid";
327 case CullBinManager::BT_unsorted:
328 return out <<
"unsorted";
330 case CullBinManager::BT_state_sorted:
331 return out <<
"state_sorted";
333 case CullBinManager::BT_back_to_front:
334 return out <<
"back_to_front";
336 case CullBinManager::BT_front_to_back:
337 return out <<
"front_to_back";
339 case CullBinManager::BT_fixed:
340 return out <<
"fixed";
343 return out <<
"**invalid BinType(" << (int)bin_type <<
")**";
This is a convenience class to specialize ConfigVariable as a set of floating-point types representin...
const LColor & get_value() const
Returns the variable's value.
This class is similar to ConfigVariable, but it reports its value as a list of strings.
size_t get_num_words() const
Returns the number of words in the variable's value.
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() ...
void register_bin_type(BinType type, BinConstructor *constructor)
Intended to be called at startup type by each CullBin type, to register the constructor for each type...
void remove_bin(int bin_index)
Permanently removes the indicated bin.
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_...
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() ...
int add_bin(const std::string &name, BinType type, int sort)
Defines a new bin with the indicated name, and returns the new bin_index.
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.
A collection of Geoms and their associated state, for a particular scene.
static void bin_removed(int bin_index)
Intended to be called by CullBinManager::remove_bin(), this informs all the CullResults in the world ...
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A lightweight class that represents a single element that may be timed and/or counted via stats.
static void bin_removed(int bin_index)
Intended to be called by CullBinManager::remove_bin(), this informs all the RenderStates in the world...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int extract_words(const string &str, vector_string &words)
Divides the string into a number of words according to whitespace.
int string_to_int(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.