From 388ddda9d74ab6366e9423ed8cb49cb68ed7d3d5 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 2 Jul 2021 14:04:57 +0200 Subject: [PATCH 1/4] x11: Fix black screen when switching fullscreen without WM Reconfiguring the window to origin 0, 0 is unnecessary and if the win origin is already 0, 0 this results in Panda waiting for a ConfigureNotify that never comes. --- panda/src/x11display/x11GraphicsWindow.cxx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index f63a5b263a..25d18a96cf 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -768,12 +768,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; From 1415ccca61fc7295a4a20b59c55d2f2450dab928 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 2 Jul 2021 15:11:33 +0200 Subject: [PATCH 2/4] pgraph: Fix assertion error in get_num_unused_states() Fixes #1172 --- panda/src/pgraph/renderState.cxx | 9 +++++++++ panda/src/pgraph/transformState.cxx | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/panda/src/pgraph/renderState.cxx b/panda/src/pgraph/renderState.cxx index fdc187ecbb..3bdb4096f1 100644 --- a/panda/src/pgraph/renderState.cxx +++ b/panda/src/pgraph/renderState.cxx @@ -752,6 +752,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) { @@ -1865,6 +1873,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/transformState.cxx b/panda/src/pgraph/transformState.cxx index efbb97f2bb..5a95e6871d 100644 --- a/panda/src/pgraph/transformState.cxx +++ b/panda/src/pgraph/transformState.cxx @@ -1025,6 +1025,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) { From bcbef3f6c8082be81511ac45f91597d58524b412 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 2 Jul 2021 15:22:44 +0200 Subject: [PATCH 3/4] pgraph: Add RenderState::get_unused_states() by analogy with TransformState --- panda/src/pgraph/renderState.h | 1 + panda/src/pgraph/renderState_ext.cxx | 26 ++++++++++++++++++++++++++ panda/src/pgraph/renderState_ext.h | 1 + 3 files changed, 28 insertions(+) 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 From 14e95eec723f97611e7ecf8d174c1698b70a7c5a Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 2 Jul 2021 15:45:56 +0200 Subject: [PATCH 4/4] assimp: Load normal column as C_normal instead of C_vector Fixes #1163 --- pandatool/src/assimp/assimpLoader.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandatool/src/assimp/assimpLoader.cxx b/pandatool/src/assimp/assimpLoader.cxx index ec0dc40b7d..8547bb7c56 100644 --- a/pandatool/src/assimp/assimpLoader.cxx +++ b/pandatool/src/assimp/assimpLoader.cxx @@ -603,7 +603,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);