diff --git a/panda/src/pgraph/renderState.cxx b/panda/src/pgraph/renderState.cxx index 220352a351..805892b947 100644 --- a/panda/src/pgraph/renderState.cxx +++ b/panda/src/pgraph/renderState.cxx @@ -746,6 +746,14 @@ get_num_unused_states() { for (size_t si = 0; si < size; ++si) { const RenderState *state = _states.get_key(si); + std::pair ir = + state_count.insert(StateCount::value_type(state, 1)); + if (!ir.second) { + // If the above insert operation fails, then it's already in the + // cache; increment its value. + (*(ir.first)).second++; + } + size_t i; size_t cache_size = state->_composition_cache.get_num_entries(); for (i = 0; i < cache_size; ++i) { @@ -1843,6 +1851,7 @@ init_states() { // is declared globally, and lives forever. RenderState *state = new RenderState; state->local_object(); + state->cache_ref_only(); state->_saved_entry = _states.store(state, nullptr); _empty_state = state; } diff --git a/panda/src/pgraph/renderState.h b/panda/src/pgraph/renderState.h index 027dae3c3f..f096dfee27 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 d0afb0718a..f1aa14615b 100644 --- a/panda/src/pgraph/renderState_ext.cxx +++ b/panda/src/pgraph/renderState_ext.cxx @@ -139,4 +139,29 @@ 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; + 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 diff --git a/panda/src/pgraph/transformState.cxx b/panda/src/pgraph/transformState.cxx index 916280ff1c..aac37c306b 100644 --- a/panda/src/pgraph/transformState.cxx +++ b/panda/src/pgraph/transformState.cxx @@ -1017,6 +1017,14 @@ get_num_unused_states() { for (size_t si = 0; si < size; ++si) { const TransformState *state = _states.get_key(si); + std::pair ir = + state_count.insert(StateCount::value_type(state, 1)); + if (!ir.second) { + // If the above insert operation fails, then it's already in the + // cache; increment its value. + (*(ir.first)).second++; + } + size_t i; size_t cache_size = state->_composition_cache.get_num_entries(); for (i = 0; i < cache_size; ++i) { diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index c8e752700e..871d3f49de 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -860,12 +860,15 @@ set_properties_now(WindowProperties &properties) { int value_mask = 0; if (_properties.get_fullscreen()) { - changes.x = 0; - changes.y = 0; - value_mask |= CWX | CWY; - properties.clear_origin(); - - } else if (properties.has_origin()) { + if (_properties.get_x_origin() != 0 || + _properties.get_y_origin() != 0) { + changes.x = 0; + changes.y = 0; + value_mask |= CWX | CWY; + properties.clear_origin(); + } + } + else if (properties.has_origin()) { changes.x = properties.get_x_origin(); changes.y = properties.get_y_origin(); if (changes.x != -1) value_mask |= CWX; diff --git a/pandatool/src/assimp/assimpLoader.cxx b/pandatool/src/assimp/assimpLoader.cxx index 3e48b9d809..4a106d4497 100644 --- a/pandatool/src/assimp/assimpLoader.cxx +++ b/pandatool/src/assimp/assimpLoader.cxx @@ -619,7 +619,7 @@ load_mesh(size_t index) { PT(GeomVertexArrayFormat) aformat = new GeomVertexArrayFormat; aformat->add_column(InternalName::get_vertex(), 3, Geom::NT_stdfloat, Geom::C_point); if (mesh.HasNormals()) { - aformat->add_column(InternalName::get_normal(), 3, Geom::NT_stdfloat, Geom::C_vector); + aformat->add_column(InternalName::get_normal(), 3, Geom::NT_stdfloat, Geom::C_normal); } if (mesh.HasVertexColors(0)) { aformat->add_column(InternalName::get_color(), 4, Geom::NT_stdfloat, Geom::C_color);