diff --git a/panda/src/pgraph/renderState.h b/panda/src/pgraph/renderState.h index 03f4b01ca4..fc953f2118 100644 --- a/panda/src/pgraph/renderState.h +++ b/panda/src/pgraph/renderState.h @@ -145,6 +145,7 @@ PUBLISHED: static void list_states(std::ostream &out); static bool validate_states(); EXTENSION(static PyObject *get_states()); + EXTENSION(static PyObject *get_unused_states()); PUBLISHED: // These methods are intended for use by low-level code, but they're also diff --git a/panda/src/pgraph/renderState_ext.cxx b/panda/src/pgraph/renderState_ext.cxx index 2b7e3a4791..ef196aa7ff 100644 --- a/panda/src/pgraph/renderState_ext.cxx +++ b/panda/src/pgraph/renderState_ext.cxx @@ -142,6 +142,32 @@ get_states() { return list; } +/** + * Returns a list of all of the "unused" RenderState objects in the state + * cache. See get_num_unused_states(). + */ +PyObject *Extension:: +get_unused_states() { + extern struct Dtool_PyTypedObject Dtool_RenderState; + if (RenderState::_states == nullptr) { + return PyList_New(0); + } + LightReMutexHolder holder(*RenderState::_states_lock); + PyObject *list = PyList_New(0); + size_t size = RenderState::_states->get_num_entries(); + for (size_t si = 0; si < size; ++si) { + const RenderState *state = RenderState::_states->get_key(si); + if (state->get_cache_ref_count() == state->get_ref_count()) { + state->ref(); + PyObject *a = + DTool_CreatePyInstanceTyped((void *)state, Dtool_RenderState, + true, true, state->get_type_index()); + PyList_Append(list, a); + Py_DECREF(a); + } + } + return list; +} #endif // HAVE_PYTHON diff --git a/panda/src/pgraph/renderState_ext.h b/panda/src/pgraph/renderState_ext.h index c452a025af..f7854d8646 100644 --- a/panda/src/pgraph/renderState_ext.h +++ b/panda/src/pgraph/renderState_ext.h @@ -32,6 +32,7 @@ public: PyObject *get_composition_cache() const; PyObject *get_invert_composition_cache() const; static PyObject *get_states(); + static PyObject *get_unused_states(); }; #endif // HAVE_PYTHON