2
0
David Rose 18 жил өмнө
parent
commit
62e24ff632

+ 60 - 2
panda/src/display/graphicsPipeSelection.cxx

@@ -22,6 +22,7 @@
 #include "filename.h"
 #include "load_dso.h"
 #include "config_display.h"
+#include "typeRegistry.h"
 #include "pset.h"
 
 #include <algorithm>
@@ -156,11 +157,55 @@ print_pipe_types() const {
 //               a type more specific than the indicated type, if
 //               necessary) and returns it.  Returns NULL if the type
 //               cannot be matched.
+//
+//               If the type is not already defined, this will
+//               implicitly load the named module, or if module_name
+//               is empty, it will call load_aux_modules().
 ////////////////////////////////////////////////////////////////////
 PT(GraphicsPipe) GraphicsPipeSelection::
-make_pipe(TypeHandle type) {
-  load_default_module();
+make_pipe(const string &type_name, const string &module_name) {
+  TypeRegistry *type_reg = TypeRegistry::ptr();
+
+  // First, see if the type is already available.
+  TypeHandle type = type_reg->find_type(type_name);
+
+  // If it isn't, try the named module.
+  if (type == TypeHandle::none()) {
+    if (!module_name.empty()) {
+      load_named_module(module_name);
+      type = type_reg->find_type(type_name);
+    }
+  }
 
+  // If that didn't help, try the default module.
+  if (type == TypeHandle::none()) {
+    load_default_module();
+    type = type_reg->find_type(type_name);
+  }
+
+  // Still not enough, try all modules.
+  if (type == TypeHandle::none()) {
+    load_aux_modules();
+    type = type_reg->find_type(type_name);
+  }
+
+  if (type == TypeHandle::none()) {
+    return NULL;
+  }
+
+  return make_pipe(type);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsPipeSelection::make_pipe
+//       Access: Published
+//  Description: Creates a new GraphicsPipe of the indicated type (or
+//               a type more specific than the indicated type, if
+//               necessary) and returns it.  Returns NULL if the type
+//               cannot be matched.
+////////////////////////////////////////////////////////////////////
+PT(GraphicsPipe) GraphicsPipeSelection::
+make_pipe(TypeHandle type) {
   MutexHolder holder(_lock);
   PipeTypes::const_iterator ti;
 
@@ -188,6 +233,19 @@ make_pipe(TypeHandle type) {
     }
   }
 
+  // Couldn't find any match; load the default module and try again.
+  load_default_module();
+  for (ti = _pipe_types.begin(); ti != _pipe_types.end(); ++ti) {
+    const PipeType &ptype = (*ti);
+    if (ptype._type.is_derived_from(type)) {
+      // Here's an approximate match.
+      PT(GraphicsPipe) pipe = (*ptype._constructor)();
+      if (pipe != (GraphicsPipe *)NULL) {
+        return pipe;
+      }
+    }
+  }
+
   // Couldn't find a matching pipe type.
   return NULL;
 }

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

@@ -47,6 +47,8 @@ PUBLISHED:
   TypeHandle get_pipe_type(int n) const;
   void print_pipe_types() const;
 
+  PT(GraphicsPipe) make_pipe(const string &type_name,
+                             const string &module_name = string());
   PT(GraphicsPipe) make_pipe(TypeHandle type);
   PT(GraphicsPipe) make_default_pipe();