15 #include "texMatrixAttrib.h"
16 #include "graphicsStateGuardianBase.h"
18 #include "bamReader.h"
19 #include "bamWriter.h"
21 #include "datagramIterator.h"
22 #include "textureStagePool.h"
64 <<
"Using deprecated TexMatrixAttrib interface.\n";
65 if (mat.is_identity()) {
68 CPT(TransformState) transform = TransformState::make_mat(mat);
79 make(
TextureStage *stage, const TransformState *transform) {
103 add_stage(
TextureStage *stage, const TransformState *transform,
104 int override)
const {
106 Stages::iterator si = attrib->_stages.insert(StageNode(stage)).first;
107 (*si)._transform = transform;
108 (*si)._override =
override;
110 return return_new(attrib);
122 attrib->_stages.erase(StageNode(stage));
123 return return_new(attrib);
145 return _stages.
empty();
158 Stages::const_iterator mi = _stages.find(StageNode(stage));
159 return (mi != _stages.
end());
170 return _stages.
size();
182 nassertr(n >= 0 && n < (
int)_stages.
size(), NULL);
183 return _stages[n]._stage;
195 return get_transform(stage)->get_mat();
207 Stages::const_iterator mi = _stages.find(StageNode(stage));
208 if (mi != _stages.end()) {
209 return (*mi)._transform;
211 return TransformState::make_identity();
219 void TexMatrixAttrib::
220 output(ostream &out)
const {
221 out << get_type() <<
":";
223 Stages::const_iterator mi;
224 for (mi = _stages.
begin(); mi != _stages.
end(); ++mi) {
225 const StageNode &sn = (*mi);
226 out <<
" " << sn._stage->
get_name() <<
"(" << *sn._transform <<
")";
227 if (sn._override != 0) {
228 out <<
"^" << sn._override;
248 int TexMatrixAttrib::
251 DCAST_INTO_R(ta, other, 0);
253 Stages::const_iterator ai, bi;
254 ai = _stages.
begin();
255 bi = ta->_stages.
begin();
256 while (ai != _stages.
end() && bi != ta->_stages.
end()) {
261 }
else if ((*bi) < (*ai)) {
272 if (bi != ta->_stages.
end()) {
277 if (ai != _stages.
end()) {
295 size_t TexMatrixAttrib::
296 get_hash_impl()
const {
298 Stages::const_iterator si;
299 for (si = _stages.
begin(); si != _stages.
end(); ++si) {
300 const StageNode &sn = (*si);
330 DCAST_INTO_R(ta, other, 0);
337 Stages::const_iterator ai, bi;
338 ai = _stages.begin();
339 bi = ta->_stages.
begin();
340 while (ai != _stages.end() && bi != ta->_stages.
end()) {
341 if ((*ai)._stage < (*bi)._stage) {
343 attrib->_stages.insert(attrib->_stages.
end(), *ai);
346 }
else if ((*bi)._stage < (*ai)._stage) {
348 attrib->_stages.insert(attrib->_stages.
end(), *bi);
353 if ((*ai)._override == (*bi)._override) {
355 CPT(TransformState) new_transform = (*ai)._transform->compose((*bi)._transform);
356 StageNode sn((*ai)._stage);
357 sn._transform = new_transform;
358 sn._override = (*ai)._override;
359 attrib->_stages.insert(attrib->_stages.end(), sn);
360 } else if ((*ai)._override < (*bi)._override) {
362 attrib->_stages.insert(attrib->_stages.
end(), *bi);
365 attrib->_stages.insert(attrib->_stages.
end(), *ai);
373 while (ai != _stages.end()) {
375 attrib->_stages.insert(attrib->_stages.
end(), *ai);
379 while (bi != ta->_stages.
end()) {
381 attrib->_stages.insert(attrib->_stages.
end(), *bi);
385 return return_new(attrib);
400 DCAST_INTO_R(ta, other, 0);
407 Stages::const_iterator ai, bi;
408 ai = _stages.begin();
409 bi = ta->_stages.
begin();
410 while (ai != _stages.end() && bi != ta->_stages.
end()) {
411 if ((*ai)._stage < (*bi)._stage) {
413 CPT(TransformState) inv_a =
414 (*ai)._transform->invert_compose(TransformState::make_identity());
415 StageNode sn((*ai)._stage);
416 sn._transform = inv_a;
417 sn._override = (*ai)._override;
418 attrib->_stages.insert(attrib->_stages.end(), sn);
421 } else if ((*bi)._stage < (*ai)._stage) {
423 attrib->_stages.insert(attrib->_stages.
end(), *bi);
428 if ((*ai)._override == (*bi)._override) {
430 CPT(TransformState) new_transform = (*ai)._transform->invert_compose((*bi)._transform);
431 StageNode sn((*ai)._stage);
432 sn._transform = new_transform;
433 sn._override = (*ai)._override;
434 attrib->_stages.insert(attrib->_stages.end(), sn);
436 } else if ((*ai)._override < (*bi)._override) {
438 attrib->_stages.insert(attrib->_stages.
end(), *bi);
442 CPT(TransformState) inv_a =
443 (*ai)._transform->invert_compose(TransformState::make_identity());
444 StageNode sn((*ai)._stage);
445 sn._transform = inv_a;
446 sn._override = (*ai)._override;
447 attrib->_stages.insert(attrib->_stages.end(), sn);
455 while (ai != _stages.end()) {
457 CPT(TransformState) inv_a =
458 (*ai)._transform->invert_compose(TransformState::make_identity());
459 StageNode sn((*ai)._stage);
460 sn._transform = inv_a;
461 sn._override = (*ai)._override;
462 attrib->_stages.insert(attrib->_stages.end(), sn);
466 while (bi != ta->_stages.end()) {
468 attrib->_stages.insert(attrib->_stages.
end(), *bi);
472 return return_new(attrib);
481 get_auto_shader_attrib_impl(const
RenderState *state)
const {
489 Stages::const_iterator ai;
490 for (ai = _stages.begin(); ai != _stages.end(); ++ai) {
491 StageNode sn((*ai)._stage);
492 sn._transform = TransformState::make_identity();
493 attrib->_stages.insert(attrib->_stages.
end(), sn);
496 return return_new(attrib);
522 Stages::const_iterator si;
523 for (si = _stages.
begin(); si != _stages.
end(); ++si) {
524 const StageNode &sn = (*si);
543 for (
size_t sni = 0; sni < _stages.
size(); ++sni) {
548 const TransformState *transform = DCAST(TransformState, p_list[pi++]);
550 StageNode &sn = _stages[sni];
552 sn._transform = transform;
573 parse_params(params, scan, manager);
574 attrib->fillin(scan, manager);
586 void TexMatrixAttrib::
588 RenderAttrib::fillin(scan, manager);
591 for (
size_t i = 0; i < num_stages; i++) {
600 sn._override =
override;
static size_t add_hash(size_t start, const void *key)
Adds the indicated key into a running hash.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
bool is_empty() const
Returns true if no stages are defined in the TexMatrixAttrib, false if at least one is...
TextureStage * get_stage(int n) const
Returns the nth stage that is represented by this attrib.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
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.
string get_name(TypedObject *object=(TypedObject *) NULL) const
Returns the name of the type.
static void register_with_read_factory()
Tells the BamReader how to create objects of type TexMatrixAttrib.
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.
PN_int32 get_int32()
Extracts a signed 32-bit integer.
int get_num_stages() const
Returns the number of stages that are represented by this attrib.
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
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()...
This is a 4-by-4 transform matrix.
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...
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
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.
const LMatrix4 & get_mat() const
Returns the transformation matrix associated with the default texture stage.
bool has_stage(TextureStage *stage) const
Returns true if there is a transform associated with the indicated stage, or false otherwise (in whic...
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
Applies a transform matrix to UV's before they are rendered.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
size_type_0 size() const
Returns the number of elements in the ordered vector.
void add_int32(PN_int32 value)
Adds a signed 32-bit integer to the datagram.
A class to retrieve the individual data elements previously stored in a Datagram. ...
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
TypeHandle is the identifier used to differentiate C++ class types.
static TextureStage * get_default()
Returns the default TextureStage that will be used for all texturing that does not name a particular ...
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 ...
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.
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.