43 RenderEffects() : _lock(
"RenderEffects") {
44 if (_states ==
nullptr) {
47 _saved_entry = _states->end();
61 nassertv(_saved_entry == _states->end());
70 Effects::const_iterator ai;
71 for (ai = _effects.
begin(); ai != _effects.
end(); ++ai) {
72 const Effect &effect = (*ai);
73 if (!effect._effect->safe_to_transform()) {
87 prepare_flatten_transform(
const TransformState *net_transform)
const {
89 Effects::const_iterator ai;
90 for (ai = _effects.
begin(); ai != _effects.
end(); ++ai) {
91 const Effect &effect = (*ai);
92 result = effect._effect->prepare_flatten_transform(result);
104 safe_to_combine()
const {
105 Effects::const_iterator ai;
106 for (ai = _effects.
begin(); ai != _effects.
end(); ++ai) {
107 const Effect &effect = (*ai);
108 if (!effect._effect->safe_to_combine()) {
120 xform(
const LMatrix4 &mat)
const {
126 std::back_insert_iterator<Effects> result =
127 std::back_inserter(new_state->_effects);
129 Effects::const_iterator ai;
130 for (ai = _effects.
begin(); ai != _effects.
end(); ++ai) {
131 const Effect &effect = (*ai);
132 Effect new_effect(effect);
133 new_effect._effect = effect._effect->xform(mat);
134 *result = new_effect;
138 return return_new(new_state);
153 return lexicographical_compare(_effects.
begin(), _effects.
end(),
154 other._effects.
begin(), other._effects.
end(),
165 Effects::const_iterator ai = _effects.find(Effect(type));
166 if (ai == _effects.
end()) {
169 return ai - _effects.
begin();
179 if (_empty_state ==
nullptr) {
181 _empty_state = return_new(state);
194 state->_effects.insert(Effect(effect));
195 return return_new(state);
206 state->_effects.
push_back(Effect(effect1));
207 state->_effects.
push_back(Effect(effect2));
208 state->_effects.
sort();
209 return return_new(state);
221 state->_effects.
push_back(Effect(effect1));
222 state->_effects.
push_back(Effect(effect2));
223 state->_effects.
push_back(Effect(effect3));
224 state->_effects.
sort();
225 return return_new(state);
238 state->_effects.
push_back(Effect(effect1));
239 state->_effects.
push_back(Effect(effect2));
240 state->_effects.
push_back(Effect(effect3));
241 state->_effects.
push_back(Effect(effect4));
242 state->_effects.
sort();
243 return return_new(state);
254 std::back_insert_iterator<Effects> result =
255 std::back_inserter(new_state->_effects);
257 Effect new_effect(effect);
258 Effects::const_iterator ai = _effects.
begin();
260 while (ai != _effects.
end() && (*ai) < new_effect) {
265 *result = new_effect;
268 if (ai != _effects.
end() && !(new_effect < (*ai))) {
275 while (ai != _effects.
end()) {
281 return return_new(new_state);
291 std::back_insert_iterator<Effects> result =
292 std::back_inserter(new_state->_effects);
294 Effects::const_iterator ai = _effects.
begin();
296 while (ai != _effects.
end()) {
297 if ((*ai)._type != type) {
304 return return_new(new_state);
313 Effects::const_iterator ai;
314 ai = _effects.find(Effect(type));
315 if (ai != _effects.
end()) {
316 return (*ai)._effect;
354 output(std::ostream &out)
const {
356 if (_effects.
empty()) {
360 Effects::const_iterator ai = _effects.
begin();
361 out <<
"(" << (*ai)._type;
363 while (ai != _effects.
end()) {
364 out <<
" " << (*ai)._type;
375 write(std::ostream &out,
int indent_level)
const {
376 indent(out, indent_level) << _effects.
size() <<
" effects:\n";
377 Effects::const_iterator ai;
378 for (ai = _effects.
begin(); ai != _effects.
end(); ++ai) {
379 const Effect &effect = (*ai);
380 effect._effect->write(out, indent_level + 2);
390 if (_states ==
nullptr) {
394 return _states->size();
404 out << _states->size() <<
" states:\n";
405 States::const_iterator si;
406 for (si = _states->begin(); si != _states->end(); ++si) {
408 state->write(out, 2);
419 if (_states->empty()) {
424 States::const_iterator si = _states->begin();
425 States::const_iterator snext = si;
427 while (snext != _states->end()) {
428 if (!(*(*si) < *(*snext))) {
430 <<
"RenderEffects out of order!\n";
431 (*si)->write(pgraph_cat.error(
false), 2);
432 (*snext)->write(pgraph_cat.error(
false), 2);
435 if ((*(*snext) < *(*si))) {
437 <<
"RenderEffects::operator < not defined properly!\n";
438 pgraph_cat.error(
false)
439 <<
"a < b: " << (*(*si) < *(*snext)) <<
"\n";
440 pgraph_cat.error(
false)
441 <<
"b < a: " << (*(*snext) < *(*si)) <<
"\n";
442 (*si)->write(pgraph_cat.error(
false), 2);
443 (*snext)->write(pgraph_cat.error(
false), 2);
461 Effects::const_iterator ei;
462 for (ei = _effects.
begin(); ei != _effects.
end(); ++ei) {
463 (*ei)._effect->cull_callback(trav, data, node_transform, node_state);
480 Effects::const_iterator ei;
481 for (ei = _effects.
begin(); ei != _effects.
end(); ++ei) {
482 (*ei)._effect->adjust_transform(net_transform, node_transform, node);
501 _states_lock =
new LightReMutex(
"RenderEffects::_states_lock");
502 nassertv(Thread::get_current_thread() == Thread::get_main_thread());
517 nassertr(state !=
nullptr, state);
526 if (paranoid_const) {
535 nassertr(state->_saved_entry == _states->end(), state);
541 std::pair<States::iterator, bool> result = _states->insert(state);
544 state->_saved_entry = result.first;
545 nassertr(_states->find(state) == state->_saved_entry, pt_state);
551 return *(result.first);
564 if (_saved_entry != _states->end()) {
565 nassertv(_states->find(
this) == _saved_entry);
566 _states->erase(_saved_entry);
567 _saved_entry = _states->end();
577 if ((_flags & F_checked_decal) != 0) {
583 if (effect !=
nullptr) {
584 _flags |= F_has_decal;
586 _flags |= F_checked_decal;
593 determine_show_bounds() {
595 if ((_flags & F_checked_show_bounds) != 0) {
601 if (effect !=
nullptr) {
602 _flags |= F_has_show_bounds;
605 _flags |= F_has_show_tight_bounds;
608 _flags |= F_checked_show_bounds;
615 determine_cull_callback() {
617 if ((_flags & F_checked_cull_callback) != 0) {
622 _flags |= F_checked_cull_callback;
624 Effects::const_iterator ei;
625 for (ei = _effects.
begin(); ei != _effects.
end(); ++ei) {
626 if ((*ei)._effect->has_cull_callback()) {
627 _flags |= F_has_cull_callback;
637 determine_adjust_transform() {
639 if ((_flags & F_checked_adjust_transform) != 0) {
644 _flags |= F_checked_adjust_transform;
646 Effects::const_iterator ei;
647 for (ei = _effects.
begin(); ei != _effects.
end(); ++ei) {
648 if ((*ei)._effect->has_adjust_transform()) {
649 _flags |= F_has_adjust_transform;
671 int num_effects = _effects.
size();
672 nassertv(num_effects == (
int)(uint16_t)num_effects);
675 Effects::const_iterator ai;
676 for (ai = _effects.
begin(); ai != _effects.
end(); ++ai) {
677 const Effect &effect = (*ai);
693 while (i < _effects.
size()) {
694 Effect &effect = _effects[i];
697 if (effect._effect ==
nullptr) {
700 _effects.erase(_effects.
begin() + i);
704 effect._type = effect._effect->get_type();
714 nassertr(_saved_entry == _states->end(), pi);
753 if (pointer == state) {
793 state->fillin(scan, manager);
812 for (
int i = 0; i < num_effects; i++) {
817 nassertv(_saved_entry == _states->end());
static void list_states(std::ostream &out)
Lists all of the RenderEffects in the cache to the output stream, one per line.
A basic node of the scene graph or data graph.
An STL function object class, this is intended to be used on any ordered collection of classes that c...
get_ref_count
Returns the current reference count.
static TypedWritable * change_this(TypedWritable *old_ptr, BamReader *manager)
Called immediately after complete_pointers(), this gives the object a chance to adjust its own pointe...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CPT(TransformState) RenderEffects
Preprocesses the accumulated transform that is about to be applied to (or through) this node due to a...
bool is_empty() const
Returns true if the state is empty, false otherwise.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool safe_to_transform() const
Returns true if all of the effects in this set can safely be transformed, and therefore the complete ...
static void init_states()
Make sure the global _states map is allocated.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool debug_is_locked() const
Returns true if the current thread has locked the LightReMutex, false otherwise.
A lightweight reentrant mutex.
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.
Applied to a GeomNode to cause a visible bounding volume to be drawn for this node.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the base class for a number of special render effects that may be set on scene graph nodes to...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
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.
bool get_tight() const
Returns true if the "tight" flag was set, meaning the effect should compute and draw the tight boundi...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
void register_change_this(ChangeThisFunc func, TypedWritable *whom)
Called by an object reading itself from the bam file to indicate that the object pointer that will be...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static bool validate_states()
Ensures that the cache is still stored in sorted order.
void cull_callback(CullTraverser *trav, CullTraverserData &data, CPT(TransformState) &node_transform, CPT(RenderState) &node_state) const
Calls cull_callback() on all effects.
void adjust_transform(CPT(TransformState) &net_transform, CPT(TransformState) &node_transform, const PandaNode *node) const
Calls adjust_transform() on all effects.
virtual bool require_fully_complete() const
Some objects require all of their nested pointers to have been completed before the objects themselve...
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.
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 int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Similar to MutexHolder, but for a light mutex.
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 register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
const RenderEffect * get_effect(size_t n) const
Returns the nth effect in the state.
static void register_with_read_factory()
Tells the BamReader how to create objects of type RenderEffects.
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Similar to MutexHolder, but for a light reentrant mutex.
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
virtual bool unref() const
Explicitly decrements the reference count.
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.
This is our own Panda specialization on the default STL set.
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
virtual ~RenderEffects()
The destructor is responsible for removing the RenderEffects from the global set if it is there.
This represents a unique collection of RenderEffect objects that correspond to a particular renderabl...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool unref() const
Explicitly decrements the reference count.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.