15 #include "texGenAttrib.h" 16 #include "texturePool.h" 17 #include "graphicsStateGuardianBase.h" 18 #include "bamReader.h" 19 #include "bamWriter.h" 21 #include "datagramIterator.h" 26 int TexGenAttrib::_attrib_slot;
62 return DCAST(
TexGenAttrib, make())->add_stage(stage, mode);
86 add_stage(
TextureStage *stage, TexGenAttrib::Mode mode)
const {
87 nassertr(mode != M_constant,
this);
92 ModeDef &mode_def = attrib->_stages[stage];
93 mode_def._mode = mode;
94 attrib->record_stage(stage, mode_def);
96 return return_new(attrib);
113 nassertr(mode == M_constant,
this);
118 ModeDef &mode_def = attrib->_stages[stage];
119 mode_def._mode = mode;
120 mode_def._constant_value = constant_value;
121 attrib->record_stage(stage, mode_def);
123 return return_new(attrib);
134 Stages::const_iterator si;
135 si = _stages.find(stage);
136 if (si == _stages.end()) {
140 Mode mode = (*si).second._mode;
142 attrib->_stages.erase(stage);
143 attrib->_no_texcoords.erase(stage);
144 if (mode == M_point_sprite) {
145 attrib->_num_point_sprites--;
146 if (attrib->_num_point_sprites == 0) {
147 attrib->_point_geom_rendering &= ~
Geom::GR_point_sprite;
150 return return_new(attrib);
161 return _stages.empty();
173 Stages::const_iterator mi = _stages.find(stage);
174 return (mi != _stages.end());
184 TexGenAttrib::Mode TexGenAttrib::
186 Stages::const_iterator mi = _stages.find(stage);
187 if (mi != _stages.end()) {
188 return (*mi).second._mode;
203 NoTexCoordStages::const_iterator mi = _no_texcoords.find(stage);
204 return (mi != _no_texcoords.end());
216 Stages::const_iterator mi = _stages.find(stage);
217 if (mi != _stages.end()) {
218 return (*mi).second._constant_value;
229 output(ostream &out)
const {
230 out << get_type() <<
":";
232 Stages::const_iterator mi;
233 for (mi = _stages.begin(); mi != _stages.end(); ++mi) {
235 const ModeDef &mode_def = (*mi).second;
236 out <<
" " << stage->
get_name() <<
"(";
237 switch (mode_def._mode) {
242 case M_eye_sphere_map:
243 out <<
"eye_sphere_map";
246 case M_world_cube_map:
247 out <<
"world_cube_map";
250 out <<
"eye_cube_map";
254 out <<
"world_normal";
260 case M_world_position:
261 out <<
"world_position";
264 out <<
"eye_position";
268 out <<
"point_sprite";
272 out <<
"constant: " << mode_def._constant_value;
301 DCAST_INTO_R(ta, other, 0);
303 Stages::const_iterator ai, bi;
304 ai = _stages.begin();
305 bi = ta->_stages.begin();
306 while (ai != _stages.end() && bi != ta->_stages.end()) {
307 if ((*ai).first < (*bi).first) {
311 }
else if ((*bi).first < (*ai).first) {
317 int compare = (*ai).second.compare_to((*bi).second);
326 if (bi != ta->_stages.end()) {
331 if (ai != _stages.end()) {
349 size_t TexGenAttrib::
350 get_hash_impl()
const {
352 Stages::const_iterator ri;
353 for (ri = _stages.begin(); ri != _stages.end(); ++ri) {
355 const ModeDef &mode_def = (*ri).second;
360 hash = mode_def._light.add_hash(hash);
361 hash = mode_def._constant_value.add_hash(hash);
387 DCAST_INTO_R(ta, other, 0);
394 Stages::const_iterator ai, bi;
395 ai = _stages.begin();
396 bi = ta->_stages.begin();
397 while (ai != _stages.end() && bi != ta->_stages.end()) {
398 if ((*ai).first < (*bi).first) {
400 attrib->_stages.insert(attrib->_stages.end(), *ai);
403 }
else if ((*bi).first < (*ai).first) {
405 attrib->_stages.insert(attrib->_stages.end(), *bi);
410 attrib->_stages.insert(attrib->_stages.end(), *bi);
416 while (ai != _stages.end()) {
418 attrib->_stages.insert(attrib->_stages.end(), *ai);
422 while (bi != ta->_stages.end()) {
424 attrib->_stages.insert(attrib->_stages.end(), *bi);
428 attrib->filled_stages();
430 return return_new(attrib);
445 DCAST_INTO_R(ta, other, 0);
452 Stages::const_iterator ai, bi;
453 ai = _stages.begin();
454 bi = ta->_stages.begin();
455 while (ai != _stages.end() && bi != ta->_stages.end()) {
456 if ((*ai).first < (*bi).first) {
458 attrib->_stages.insert(attrib->_stages.end(), Stages::value_type((*ai).first, ModeDef()));
461 }
else if ((*bi).first < (*ai).first) {
463 attrib->_stages.insert(attrib->_stages.end(), *bi);
468 attrib->_stages.insert(attrib->_stages.end(), *bi);
474 while (ai != _stages.end()) {
476 attrib->_stages.insert(attrib->_stages.end(), Stages::value_type((*ai).first, ModeDef()));
480 while (bi != ta->_stages.end()) {
482 attrib->_stages.insert(attrib->_stages.end(), *bi);
486 attrib->filled_stages();
488 return return_new(attrib);
497 get_auto_shader_attrib_impl(
const RenderState *state)
const {
513 for (ri = _stages.begin(); ri != _stages.end(); ++ri) {
515 ModeDef &mode_def = (*ri).second;
516 record_stage(stage, mode_def);
528 record_stage(
TextureStage *stage, TexGenAttrib::ModeDef &mode_def) {
529 switch (mode_def._mode) {
531 _no_texcoords.insert(stage);
532 _point_geom_rendering |= Geom::GR_point_sprite;
533 _num_point_sprites++;
540 _no_texcoords.insert(stage);
567 Stages::const_iterator si;
568 for (si = _stages.begin(); si != _stages.end(); ++si) {
570 Mode mode = (*si).second._mode;
589 for (mi = _read_modes.begin(); mi != _read_modes.end(); ++mi) {
593 _stages[stage]._mode = mode;
615 parse_params(params, scan, manager);
616 attrib->fillin(scan, manager);
630 RenderAttrib::fillin(scan, manager);
639 _read_modes.reserve(num_stages);
640 for (
size_t i = 0; i < num_stages; i++) {
643 _read_modes.push_back(mode);
static size_t add_hash(size_t start, const void *key)
Adds the indicated key into a running hash.
void add_uint8(PN_uint8 value)
Adds an unsigned 8-bit integer to the datagram.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
static const LPoint3f & zero()
Returns a zero-length point.
Base class for objects that can be written to and read from Bam files.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
PN_uint8 get_uint8()
Extracts an unsigned 8-bit integer.
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
This is our own Panda specialization on the default STL vector.
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 void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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()...
static void register_with_read_factory()
Tells the BamReader how to create objects of type TexGenAttrib.
A container for geometry primitives.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
const string & get_name() const
Returns the name of this texture stage.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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 ...
Computes texture coordinates for geometry automatically based on vertex position and/or normal...
static size_t add_hash(size_t start, const Key &key)
Adds the elements of the indicated key into a running hash.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.