mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
add named make_pipe()
This commit is contained in:
parent
e44724fc4b
commit
62e24ff632
@ -22,6 +22,7 @@
|
||||
#include "filename.h"
|
||||
#include "load_dso.h"
|
||||
#include "config_display.h"
|
||||
#include "typeRegistry.h"
|
||||
#include "pset.h"
|
||||
|
||||
#include <algorithm>
|
||||
@ -149,6 +150,52 @@ print_pipe_types() const {
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// 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.
|
||||
//
|
||||
// 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(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
|
||||
@ -159,8 +206,6 @@ print_pipe_types() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(GraphicsPipe) GraphicsPipeSelection::
|
||||
make_pipe(TypeHandle type) {
|
||||
load_default_module();
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user