From 7e8972ef58c27981260fb3cbae53cf53e32cb4f3 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 27 Aug 2002 22:02:04 +0000 Subject: [PATCH] respect bins when deciding mouse region order --- panda/src/pgui/pgItem.cxx | 40 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/panda/src/pgui/pgItem.cxx b/panda/src/pgui/pgItem.cxx index 5b3e7c1a6d..883b9d9318 100644 --- a/panda/src/pgui/pgItem.cxx +++ b/panda/src/pgui/pgItem.cxx @@ -28,6 +28,7 @@ #include "nodePath.h" #include "cullTraverser.h" #include "cullTraverserData.h" +#include "cullBinManager.h" #include "dcast.h" #ifdef HAVE_AUDIO @@ -182,9 +183,44 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) { DCAST_INTO_R(pg_trav, trav, true); const LMatrix4f &transform = data._net_transform->get_mat(); - activate_region(transform, pg_trav->_sort_index); - pg_trav->_sort_index++; + // Consider the cull bin this object is in. Since the binning + // affects the render order, we want bins that render later to + // get higher sort values. + int bin_index = data._state->get_bin_index(); + int sort; + + CullBinManager *bin_manager = CullBinManager::get_global_ptr(); + CullBinManager::BinType bin_type = bin_manager->get_bin_type(bin_index); + if (bin_type == CullBinManager::BT_fixed) { + // If the bin is a "fixed" type bin, our local sort is based + // on the fixed order. + sort = data._state->get_draw_order(); + + } else if (bin_type == CullBinManager::BT_unsorted) { + // If the bin is an "unsorted" type bin, we base the local + // sort on the scene graph order. + sort = pg_trav->_sort_index; + pg_trav->_sort_index++; + + } else { + // Otherwise, the local sort is irrelevant. + sort = 0; + } + + // Now what order does this bin sort relative to the other bins? + // This becomes the high-order part of the final sort count. + int bin_sort = bin_manager->get_bin_sort(data._state->get_bin_index()); + + // Combine the two sorts into a single int. This assumes we + // only need 16 bits for each sort number, possibly an erroneous + // assumption. We should really provide two separate sort + // values, both ints, in the MouseWatcherRegion; but in the + // interest of expediency we work within the existing interface + // which only provides one. + sort = (bin_sort << 16) | (sort & 0xffff); + + activate_region(transform, sort); pg_trav->_top->add_region(get_region()); } }