Browse Source

display: properly prioritize preferred pipe

Previously, load-display of a module with more than one pipe would cause the first available pipe to be loaded, rather than the one returned by `get_pipe_type_<module>()`
rdb 2 years ago
parent
commit
deb24afe18

+ 20 - 3
panda/src/display/graphicsPipeSelection.cxx

@@ -49,6 +49,7 @@ GraphicsPipeSelection() : _lock("GraphicsPipeSelection") {
 
 
   _default_display_module = load_display.get_word(0);
   _default_display_module = load_display.get_word(0);
   _default_pipe_name = load_display.get_word(1);
   _default_pipe_name = load_display.get_word(1);
+  _default_pipe_type = TypeHandle::none();
 
 
   if (_default_display_module == "*") {
   if (_default_display_module == "*") {
     // '*' or empty string is the key for all display modules.
     // '*' or empty string is the key for all display modules.
@@ -124,7 +125,11 @@ print_pipe_types() const {
   LightMutexHolder holder(_lock);
   LightMutexHolder holder(_lock);
   nout << "Known pipe types:" << std::endl;
   nout << "Known pipe types:" << std::endl;
   for (const PipeType &pipe_type : _pipe_types) {
   for (const PipeType &pipe_type : _pipe_types) {
-    nout << "  " << pipe_type._type << "\n";
+    nout << "  " << pipe_type._type;
+    if (_pipe_types.size() > 1 && pipe_type._type == _default_pipe_type) {
+      nout << " (default)";
+    }
+    nout << "\n";
   }
   }
   if (_display_modules.empty()) {
   if (_display_modules.empty()) {
     nout << "(all display modules loaded.)\n";
     nout << "(all display modules loaded.)\n";
@@ -256,7 +261,7 @@ make_default_pipe() {
 
 
   if (!_default_pipe_name.empty()) {
   if (!_default_pipe_name.empty()) {
     // First, look for an exact match of the default type name from the
     // First, look for an exact match of the default type name from the
-    // Configrc file (excepting case and hyphenunderscore).
+    // Config.prc file (excepting case and hyphen / underscore).
     for (const PipeType &ptype : _pipe_types) {
     for (const PipeType &ptype : _pipe_types) {
       if (cmp_nocase_uh(ptype._type.get_name(), _default_pipe_name) == 0) {
       if (cmp_nocase_uh(ptype._type.get_name(), _default_pipe_name) == 0) {
         // Here's an exact match.
         // Here's an exact match.
@@ -281,6 +286,18 @@ make_default_pipe() {
     }
     }
   }
   }
 
 
+  // Look for the preferred type of the default display module.
+  if (_default_pipe_type != TypeHandle::none()) {
+    for (const PipeType &ptype : _pipe_types) {
+      if (ptype._type == _default_pipe_type) {
+        PT(GraphicsPipe) pipe = (*ptype._constructor)();
+        if (pipe != nullptr) {
+          return pipe;
+        }
+      }
+    }
+  }
+
   // Couldn't find a matching pipe type; choose the first one on the list.
   // Couldn't find a matching pipe type; choose the first one on the list.
   for (const PipeType &ptype : _pipe_types) {
   for (const PipeType &ptype : _pipe_types) {
     PT(GraphicsPipe) pipe = (*ptype._constructor)();
     PT(GraphicsPipe) pipe = (*ptype._constructor)();
@@ -358,7 +375,7 @@ do_load_default_module() {
     return;
     return;
   }
   }
 
 
-  load_named_module(_default_display_module);
+  _default_pipe_type = load_named_module(_default_display_module);
 
 
   DisplayModules::iterator di =
   DisplayModules::iterator di =
     std::find(_display_modules.begin(), _display_modules.end(),
     std::find(_display_modules.begin(), _display_modules.end(),

+ 1 - 0
panda/src/display/graphicsPipeSelection.h

@@ -87,6 +87,7 @@ private:
   DisplayModules _display_modules;
   DisplayModules _display_modules;
   std::string _default_display_module;
   std::string _default_display_module;
   std::string _default_pipe_name;
   std::string _default_pipe_name;
+  TypeHandle _default_pipe_type;
   bool _default_module_loaded;
   bool _default_module_loaded;
 
 
   static GraphicsPipeSelection *_global_ptr;
   static GraphicsPipeSelection *_global_ptr;