27 int TextureAttrib::_attrib_slot;
36 return DCAST(
TextureAttrib, make())->add_on_stage(TextureStage::get_default(), texture);
45 return make_all_off();
55 if (_empty_attrib ==
nullptr) {
70 if (_all_off_attrib ==
nullptr) {
72 attrib->_off_all_stages =
true;
73 _all_off_attrib = return_new(attrib);
76 return _all_off_attrib;
95 Stages::const_iterator si = _on_stages.find(StageNode(stage));
96 if (si != _on_stages.
end()) {
97 return (
int)(si - _on_stages.
begin());
109 nassertr(tex !=
nullptr,
this);
112 Stages::iterator si = attrib->_on_stages.insert(StageNode(stage)).first;
113 (*si)._override =
override;
114 (*si)._texture = tex;
115 (*si)._implicit_sort = attrib->_next_implicit_sort;
116 (*si)._has_sampler =
false;
117 ++(attrib->_next_implicit_sort);
120 attrib->_sort_seq = UpdateSeq::old();
121 attrib->_filtered_seq = UpdateSeq::old();
123 return return_new(attrib);
132 nassertr(tex !=
nullptr,
this);
135 Stages::iterator si = attrib->_on_stages.insert(StageNode(stage)).first;
136 (*si)._override =
override;
137 (*si)._texture = tex;
138 (*si)._sampler = sampler;
139 (*si)._implicit_sort = attrib->_next_implicit_sort;
140 (*si)._has_sampler =
true;
141 ++(attrib->_next_implicit_sort);
144 attrib->_sort_seq = UpdateSeq::old();
145 attrib->_filtered_seq = UpdateSeq::old();
147 return return_new(attrib);
158 Stages::iterator si = attrib->_on_stages.find(StageNode(stage));
159 if (si != attrib->_on_stages.
end()) {
160 attrib->_on_stages.erase(si);
162 attrib->_sort_seq = UpdateSeq::old();
163 attrib->_filtered_seq = UpdateSeq::old();
166 return return_new(attrib);
174 add_off_stage(
TextureStage *stage,
int override)
const {
176 if (!_off_all_stages) {
178 Stages::iterator sfi = attrib->_off_stages.insert(sn).first;
179 (*sfi)._override =
override;
182 Stages::iterator si = attrib->_on_stages.find(sn);
183 if (si != attrib->_on_stages.
end()) {
184 attrib->_on_stages.erase(si);
185 attrib->_sort_seq = UpdateSeq::old();
186 attrib->_filtered_seq = UpdateSeq::old();
189 return return_new(attrib);
199 attrib->_off_stages.erase(StageNode(stage));
200 return return_new(attrib);
212 attrib->_off_all_stages = _off_all_stages;
213 bool any_changed =
false;
215 Stages::const_iterator si;
216 for (si = _on_stages.
begin(); si != _on_stages.
end(); ++si) {
224 Stages::iterator osi = attrib->_on_stages.insert(StageNode(this_stage)).first;
225 (*osi)._texture = (*si)._texture;
226 (*osi)._ff_tc_index = (*si)._ff_tc_index;
227 (*osi)._implicit_sort = (*si)._implicit_sort;
228 (*osi)._override = (*si)._override;
231 attrib->_next_implicit_sort = _next_implicit_sort;
233 Stages::const_iterator fsi;
234 for (fsi = _off_stages.
begin(); fsi != _off_stages.
end(); ++fsi) {
237 if (this_stage != stage &&
243 attrib->_off_stages.insert(StageNode(this_stage));
250 return return_new(attrib);
259 filter_to_max(
int max_texture_stages)
const {
260 if ((
int)_on_stages.
size() <= max_texture_stages) {
270 Filtered::const_iterator fi;
271 fi = _filtered.find(max_texture_stages);
272 if (fi != _filtered.end()) {
283 RenderStages priority_stages = _render_stages;
286 sort(priority_stages.begin(), priority_stages.end(),
287 CompareTextureStagePriorities());
290 priority_stages.erase(priority_stages.begin() + max_texture_stages,
291 priority_stages.end());
296 RenderStages::const_iterator ri;
297 for (ri = priority_stages.begin(); ri != priority_stages.end(); ++ri) {
298 attrib->_on_stages.insert(*(*ri));
301 attrib->_next_implicit_sort = _next_implicit_sort;
311 ((
TextureAttrib *)
this)->_filtered[max_texture_stages] = tex_attrib;
348 output(std::ostream &out)
const {
351 out << get_type() <<
":";
352 if (_off_stages.
empty()) {
353 if (_on_stages.
empty()) {
354 if (_off_all_stages) {
360 if (_off_all_stages) {
369 Stages::const_iterator fi;
370 for (fi = _off_stages.
begin(); fi != _off_stages.
end(); ++fi) {
373 if ((*fi)._override != 0) {
374 out <<
"^" << (*fi)._override;
378 if (!_on_stages.
empty()) {
383 RenderStages::const_iterator ri;
384 for (ri = _render_stages.begin(); ri != _render_stages.end(); ++ri) {
385 const StageNode &sn = *(*ri);
389 if (tex !=
nullptr) {
390 out <<
":" << tex->get_name();
392 if (sn._override != 0) {
393 out <<
"^" << sn._override;
405 Stages::const_iterator si;
406 for (si = _on_stages.
begin(); si != _on_stages.
end(); ++si) {
407 Texture *texture = (*si)._texture;
427 Stages::const_iterator si;
428 for (si = _on_stages.
begin(); si != _on_stages.
end(); ++si) {
429 Texture *texture = (*si)._texture;
454 if (_off_all_stages != ta->_off_all_stages) {
455 return (
int)_off_all_stages - (int)ta->_off_all_stages;
458 Stages::const_iterator si = _on_stages.
begin();
459 Stages::const_iterator osi = ta->_on_stages.
begin();
461 while (si != _on_stages.
end() && osi != ta->_on_stages.
end()) {
465 if (stage != other_stage) {
466 return stage < other_stage ? -1 : 1;
469 Texture *texture = (*si)._texture;
470 Texture *other_texture = (*osi)._texture;
472 if (texture != other_texture) {
473 return texture < other_texture ? -1 : 1;
476 int implicit_sort = (*si)._implicit_sort;
477 int other_implicit_sort = (*osi)._implicit_sort;
479 if (implicit_sort != other_implicit_sort) {
480 return implicit_sort < other_implicit_sort ? -1 : 1;
483 int override = (*si)._override;
484 int other_override = (*osi)._override;
486 if (
override != other_override) {
487 return override < other_override ? -1 : 1;
490 int has_sampler = (*si)._has_sampler;
491 int other_has_sampler = (*osi)._has_sampler;
493 if (has_sampler != other_has_sampler) {
494 return has_sampler < other_has_sampler ? -1 : 1;
501 if (sampler != other_sampler) {
502 return sampler < other_sampler ? -1 : 1;
510 if (si != _on_stages.
end()) {
513 if (osi != ta->_on_stages.
end()) {
518 Stages::const_iterator fi = _off_stages.
begin();
519 Stages::const_iterator ofi = ta->_off_stages.
begin();
521 while (fi != _off_stages.
end() && ofi != ta->_off_stages.
end()) {
525 if (stage != other_stage) {
526 return stage < other_stage ? -1 : 1;
529 int override = (*fi)._override;
530 int other_override = (*ofi)._override;
532 if (
override != other_override) {
533 return override < other_override ? -1 : 1;
540 if (fi != _off_stages.
end()) {
543 if (ofi != ta->_off_stages.
end()) {
556 size_t TextureAttrib::
557 get_hash_impl()
const {
561 Stages::const_iterator si;
562 for (si = _on_stages.
begin(); si != _on_stages.
end(); ++si) {
563 const StageNode &sn = (*si);
575 for (si = _off_stages.
begin(); si != _off_stages.
end(); ++si) {
576 const StageNode &sn = (*si);
600 if (ta->_off_all_stages) {
608 Stages::const_iterator ai = _on_stages.
begin();
609 Stages::const_iterator bi = ta->_on_stages.
begin();
610 Stages::const_iterator ci = ta->_off_stages.
begin();
615 while (ai != _on_stages.
end() &&
616 bi != ta->_on_stages.
end() &&
617 ci != ta->_off_stages.
end()) {
618 if ((*ai)._stage < (*bi)._stage) {
619 if ((*ai)._stage < (*ci)._stage) {
622 attrib->_on_stages.insert(attrib->_on_stages.
end(), *ai);
625 }
else if ((*ci)._stage < (*ai)._stage) {
633 if ((*ai)._override > (*ci)._override) {
635 attrib->_on_stages.insert(attrib->_on_stages.
end(), *ai);
642 }
else if ((*bi)._stage < (*ai)._stage) {
645 attrib->_on_stages.insert(attrib->_on_stages.
end(), *bi);
650 if ((*ai)._override > (*bi)._override) {
651 attrib->_on_stages.insert(attrib->_on_stages.
end(), *ai);
653 attrib->_on_stages.insert(attrib->_on_stages.
end(), *bi);
660 while (ai != _on_stages.
end() && bi != ta->_on_stages.
end()) {
661 if ((*ai)._stage < (*bi)._stage) {
664 attrib->_on_stages.insert(attrib->_on_stages.
end(), *ai);
667 }
else if ((*bi)._stage < (*ai)._stage) {
670 attrib->_on_stages.insert(attrib->_on_stages.
end(), *bi);
675 if ((*ai)._override > (*bi)._override) {
676 attrib->_on_stages.insert(attrib->_on_stages.
end(), *ai);
678 attrib->_on_stages.insert(attrib->_on_stages.
end(), *bi);
685 while (ai != _on_stages.
end() && ci != ta->_off_stages.
end()) {
686 if ((*ai)._stage < (*ci)._stage) {
689 attrib->_on_stages.insert(attrib->_on_stages.
end(), *ai);
692 }
else if ((*ci)._stage < (*ai)._stage) {
700 if ((*ai)._override > (*ci)._override) {
702 attrib->_on_stages.insert(attrib->_on_stages.
end(), *ai);
709 while (ai != _on_stages.
end()) {
710 attrib->_on_stages.insert(attrib->_on_stages.
end(), *ai);
714 while (bi != ta->_on_stages.
end()) {
715 attrib->_on_stages.insert(attrib->_on_stages.
end(), *bi);
719 attrib->_next_implicit_sort = _next_implicit_sort + ta->_next_implicit_sort;
720 attrib->_sort_seq = UpdateSeq::old();
721 attrib->_filtered_seq = UpdateSeq::old();
723 return return_new(attrib);
744 register_with_read_factory() {
759 Stages::const_iterator fi;
760 for (fi = _off_stages.
begin(); fi != _off_stages.
end(); ++fi) {
767 Stages::const_iterator si;
768 for (si = _on_stages.
begin(); si != _on_stages.
end(); ++si) {
771 nassertv(tex !=
nullptr);
783 if ((*si)._has_sampler) {
784 (*si)._sampler.write_datagram(dg);
799 for (ci = _off_stages.
begin(); ci != _off_stages.
end(); ++ci) {
805 while (sni < _on_stages.
size()) {
814 if (tex !=
nullptr) {
815 StageNode &sn = _on_stages[sni];
824 _on_stages.erase(_on_stages.
begin() + sni);
829 _sort_seq = UpdateSeq::old();
830 _filtered_seq = UpdateSeq::old();
847 attrib->fillin(scan, manager);
858 RenderAttrib::fillin(scan, manager);
867 _off_stages.
reserve(num_off_stages);
868 for (i = 0; i < num_off_stages; i++) {
870 _off_stages.
push_back(StageNode(
nullptr));
878 _on_stages.
reserve(num_on_stages);
879 _next_implicit_sort = 0;
880 for (i = 0; i < num_on_stages; i++) {
883 unsigned int implicit_sort;
887 implicit_sort = (
unsigned int)i;
894 _next_implicit_sort = std::max(_next_implicit_sort, implicit_sort + 1);
895 Stages::iterator si =
896 _on_stages.insert_nonunique(StageNode(
nullptr, _next_implicit_sort,
override));
897 ++_next_implicit_sort;
900 (*si)._has_sampler = scan.
get_bool();
901 if ((*si)._has_sampler) {
902 (*si)._sampler.read_datagram(scan, manager);
916 UsedTexcoordIndex used_texcoord_index;
918 _render_stages.clear();
919 _render_ff_stages.clear();
922 for (si = _on_stages.
begin(); si != _on_stages.
end(); ++si) {
923 StageNode &sn = (*si);
925 Texture *texture = sn._texture;
926 nassertv(stage !=
nullptr);
927 nassertv(texture !=
nullptr);
935 UsedTexcoordIndex::iterator ti = used_texcoord_index.insert(UsedTexcoordIndex::value_type(name, (
int)used_texcoord_index.size())).first;
936 (*si)._ff_tc_index = (*ti).second;
938 _render_ff_stages.push_back(&sn);
940 (*si)._ff_tc_index = -1;
943 _render_stages.push_back(&sn);
946 sort(_render_stages.begin(), _render_stages.end(), CompareTextureStageSort());
947 sort(_render_ff_stages.begin(), _render_ff_stages.end(), CompareTextureStageSort());
static size_t add_hash(size_t start, const void *key)
Adds the indicated key into a running hash.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
get_name
Returns the name of this texture stage.
bool get_bool()
Extracts a boolean value.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
static UpdateSeq get_sort_seq()
Returns a global sequence number that is incremented any time any TextureStage in the world changes s...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
size_type_0 size() const
Returns the number of elements in the ordered vector.
get_num_on_stages
Returns the number of stages that are turned on by the attribute.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
get_texture_type
Returns the overall interpretation of the texture.
Base class for objects that can be written to and read from Bam files.
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
int32_t get_int32()
Extracts a signed 32-bit integer.
void reserve(size_type_0 n)
Informs the vector of a planned change in size; ensures that the capacity of the vector is greater th...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
virtual bool lower_attrib_can_override() const
Intended to be overridden by derived RenderAttrib types to specify how two consecutive RenderAttrib o...
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
virtual bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined.
Indicates the set of TextureStages and their associated Textures that should be applied to (or remove...
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
void add_bool(bool value)
Adds a boolean value to the datagram.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
int find_on_stage(const TextureStage *stage) const
Returns the index number of the indicated TextureStage within the list of on_stages,...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_fixed_function() const
Returns true if the TextureStage is relevant to the classic fixed function pipeline.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void sort()
Maps to sort_unique().
An instance of this class is passed to the Factory when requesting it to do its business and construc...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
Encodes a string name in a hash table, mapping it to a pointer.
Represents a set of settings that indicate how a texture is sampled.
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
get_num_off_stages
Returns the number of stages that are turned off by the attribute.
A class to retrieve the individual data elements previously stored in a Datagram.
CPT(RenderAttrib) TextureAttrib
Constructs a new TextureAttrib object suitable for rendering the indicated texture onto geometry,...
TypeHandle is the identifier used to differentiate C++ class types.
Defines the properties of a named stage of the multitexture pipeline.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
get_texcoord_name
See set_texcoord_name.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined.
static TextureStage * get_stage(TextureStage *temp)
Returns a TextureStage pointer that represents the same TextureStage described by temp,...
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.