43RenderEffects() : _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()) {
87prepare_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);
104safe_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()) {
120xform(
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;
354output(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;
375write(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");
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;
593determine_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;
615determine_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;
637determine_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());
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
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...
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
An STL function object class, this is intended to be used on any ordered collection of classes that c...
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
A class to retrieve the individual data elements previously stored in a Datagram.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
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.
Similar to MutexHolder, but for a light mutex.
bool debug_is_locked() const
Returns true if the current thread has locked the LightReMutex, false otherwise.
Similar to MutexHolder, but for a light reentrant mutex.
A lightweight reentrant mutex.
A basic node of the scene graph or data graph.
get_ref_count
Returns the current reference count.
virtual bool unref() const
Explicitly decrements the reference count.
This is the base class for a number of special render effects that may be set on scene graph nodes to...
This represents a unique collection of RenderEffect objects that correspond to a particular renderabl...
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
static void list_states(std::ostream &out)
Lists all of the RenderEffects in the cache to the output stream, one per line.
void adjust_transform(CPT(TransformState) &net_transform, CPT(TransformState) &node_transform, const PandaNode *node) const
Calls adjust_transform() on all effects.
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 ~RenderEffects()
The destructor is responsible for removing the RenderEffects from the global set if it is there.
bool is_empty() const
Returns true if the state is empty, false otherwise.
static bool validate_states()
Ensures that the cache is still stored in sorted order.
virtual bool unref() const
Explicitly decrements the reference count.
const RenderEffect * get_effect(size_t n) const
Returns the nth effect in the state.
bool safe_to_transform() const
Returns true if all of the effects in this set can safely be transformed, and therefore the complete ...
virtual bool require_fully_complete() const
Some objects require all of their nested pointers to have been completed before the objects themselve...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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...
void cull_callback(CullTraverser *trav, CullTraverserData &data, CPT(TransformState) &node_transform, CPT(RenderState) &node_state) const
Calls cull_callback() on all effects.
static void init_states()
Make sure the global _states map is allocated.
static void register_with_read_factory()
Tells the BamReader how to create objects of type RenderEffects.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Applied to a GeomNode to cause a visible bounding volume to be drawn for this node.
bool get_tight() const
Returns true if the "tight" flag was set, meaning the effect should compute and draw the tight boundi...
get_main_thread
Returns a pointer to the "main" Thread object–this is the Thread that started the whole process.
get_current_thread
Returns a pointer to the currently-executing Thread object.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
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...
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().
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...
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
size_type_0 size() const
Returns the number of elements in the ordered vector.
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
void sort()
Maps to sort_unique().
This is our own Panda specialization on the default STL set.
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.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.