|
|
@@ -14,7 +14,6 @@
|
|
|
#include "renderAttrib.h"
|
|
|
#include "bamReader.h"
|
|
|
#include "indent.h"
|
|
|
-#include "config_pgraph.h"
|
|
|
#include "lightReMutexHolder.h"
|
|
|
#include "pStatTimer.h"
|
|
|
|
|
|
@@ -22,6 +21,7 @@ using std::ostream;
|
|
|
|
|
|
LightReMutex *RenderAttrib::_attribs_lock = nullptr;
|
|
|
RenderAttrib::Attribs RenderAttrib::_attribs;
|
|
|
+bool RenderAttrib::_uniquify_attribs = false;
|
|
|
TypeHandle RenderAttrib::_type_handle;
|
|
|
|
|
|
size_t RenderAttrib::_garbage_index = 0;
|
|
|
@@ -180,6 +180,10 @@ list_attribs(ostream &out) {
|
|
|
*/
|
|
|
int RenderAttrib::
|
|
|
garbage_collect() {
|
|
|
+ // This gets called periodically, so use this opportunity to reload the value
|
|
|
+ // from the Config.prc file.
|
|
|
+ _uniquify_attribs = uniquify_attribs && state_cache;
|
|
|
+
|
|
|
if (!garbage_collect_states) {
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -305,54 +309,15 @@ validate_attribs() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * This function is used by derived RenderAttrib types to share a common
|
|
|
- * RenderAttrib pointer for all equivalent RenderAttrib objects.
|
|
|
- *
|
|
|
- * This is different from return_unique() in that it does not actually
|
|
|
- * guarantee a unique pointer, unless uniquify-attribs is set.
|
|
|
- */
|
|
|
-CPT(RenderAttrib) RenderAttrib::
|
|
|
-return_new(RenderAttrib *attrib) {
|
|
|
- nassertr(attrib != nullptr, attrib);
|
|
|
- if (!uniquify_attribs) {
|
|
|
- attrib->calc_hash();
|
|
|
- return attrib;
|
|
|
- }
|
|
|
-
|
|
|
- return return_unique(attrib);
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * This function is used by derived RenderAttrib types to share a common
|
|
|
- * RenderAttrib pointer for all equivalent RenderAttrib objects.
|
|
|
- *
|
|
|
- * The make() function of the derived type should create a new RenderAttrib
|
|
|
- * and pass it through return_new(), which will either save the pointer and
|
|
|
- * return it unchanged (if this is the first similar such object) or delete it
|
|
|
- * and return an equivalent pointer (if there was already a similar object
|
|
|
- * saved).
|
|
|
+ * Private implementation of return_new, return_unique, and get_unique.
|
|
|
*/
|
|
|
CPT(RenderAttrib) RenderAttrib::
|
|
|
-return_unique(RenderAttrib *attrib) {
|
|
|
- nassertr(attrib != nullptr, attrib);
|
|
|
-
|
|
|
- attrib->calc_hash();
|
|
|
-
|
|
|
- if (!state_cache) {
|
|
|
- return attrib;
|
|
|
- }
|
|
|
-
|
|
|
-#ifndef NDEBUG
|
|
|
- if (paranoid_const) {
|
|
|
- nassertr(validate_attribs(), attrib);
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
+do_uniquify(const RenderAttrib *attrib) {
|
|
|
LightReMutexHolder holder(*_attribs_lock);
|
|
|
|
|
|
if (attrib->_saved_entry != -1) {
|
|
|
- // This attrib is already in the cache. nassertr(_attribs.find(attrib)
|
|
|
- // == attrib->_saved_entry, attrib);
|
|
|
+ // This attrib is already in the cache.
|
|
|
+ //nassertr(_attribs.find(attrib) == attrib->_saved_entry, attrib);
|
|
|
return attrib;
|
|
|
}
|
|
|
|
|
|
@@ -503,6 +468,12 @@ release_new() {
|
|
|
*/
|
|
|
void RenderAttrib::
|
|
|
init_attribs() {
|
|
|
+ // These are copied here so that we can be sure that they are constructed.
|
|
|
+ ALIGN_16BYTE ConfigVariableBool uniquify_attribs("uniquify-attribs", true);
|
|
|
+ ALIGN_16BYTE ConfigVariableBool state_cache("state-cache", true);
|
|
|
+
|
|
|
+ _uniquify_attribs = uniquify_attribs && state_cache;
|
|
|
+
|
|
|
// TODO: we should have a global Panda mutex to allow us to safely create
|
|
|
// _attribs_lock without a startup race condition. For the meantime, this
|
|
|
// is OK because we guarantee that this method is called at static init
|