15 #include "graphicsPipeSelection.h" 16 #include "lightMutexHolder.h" 17 #include "string_utils.h" 20 #include "config_display.h" 21 #include "typeRegistry.h" 23 #include "config_util.h" 34 GraphicsPipeSelection::
35 GraphicsPipeSelection() : _lock(
"GraphicsPipeSelection") {
40 PRC_DESC(
"Specify the name of the default graphics display library or " 41 "GraphicsPipe to load. It is the name of a shared library (or * for " 42 "all libraries named in aux-display), optionally followed by the " 43 "name of the particular GraphicsPipe class to create."));
47 PRC_DESC(
"Names each of the graphics display libraries that are available on " 48 "a particular platform. This variable may be repeated several " 49 "times. These libraries will be tried one at a time if the library " 50 "specified by load_display cannot be loaded."));
52 _default_display_module = load_display.get_word(0);
53 _default_pipe_name = load_display.get_word(1);
55 if (_default_display_module ==
"*") {
57 _default_display_module = string();
59 }
else if (!_default_display_module.empty()) {
60 _display_modules.push_back(_default_display_module);
66 int num_aux = aux_display.get_num_unique_values();
67 for (
int i = 0; i < num_aux; i++) {
68 string name = aux_display.get_unique_value(i);
69 if (name != _default_display_module) {
70 _display_modules.push_back(name);
74 _default_module_loaded =
false;
82 GraphicsPipeSelection::
83 ~GraphicsPipeSelection() {
95 load_default_module();
100 result = _pipe_types.size();
113 load_default_module();
118 if (n >= 0 && n < (
int)_pipe_types.size()) {
119 result = _pipe_types[n]._type;
133 load_default_module();
136 nout <<
"Known pipe types:" << endl;
137 PipeTypes::const_iterator pi;
138 for (pi = _pipe_types.begin(); pi != _pipe_types.end(); ++pi) {
139 const PipeType &pipe_type = (*pi);
140 nout <<
" " << pipe_type._type <<
"\n";
142 if (_display_modules.empty()) {
143 nout <<
"(all display modules loaded.)\n";
145 nout <<
"(" << _display_modules.size()
146 <<
" aux display modules not yet loaded.)\n";
163 make_pipe(
const string &type_name,
const string &module_name) {
171 if (!module_name.empty()) {
172 load_named_module(module_name);
179 load_default_module();
193 return make_pipe(type);
207 PipeTypes::const_iterator ti;
210 for (ti = _pipe_types.begin(); ti != _pipe_types.end(); ++ti) {
211 const PipeType &ptype = (*ti);
212 if (ptype._type == type) {
222 for (ti = _pipe_types.begin(); ti != _pipe_types.end(); ++ti) {
223 const PipeType &ptype = (*ti);
224 if (ptype._type.is_derived_from(type)) {
234 load_default_module();
235 for (ti = _pipe_types.begin(); ti != _pipe_types.end(); ++ti) {
236 const PipeType &ptype = (*ti);
237 if (ptype._type.is_derived_from(type)) {
258 make_module_pipe(
const string &module_name) {
259 if (display_cat.is_debug()) {
261 <<
"make_module_pipe(" << module_name <<
")\n";
264 TypeHandle pipe_type = load_named_module(module_name);
269 return make_pipe(pipe_type);
280 make_default_pipe() {
281 load_default_module();
284 PipeTypes::const_iterator ti;
286 if (!_default_pipe_name.empty()) {
289 for (ti = _pipe_types.begin(); ti != _pipe_types.end(); ++ti) {
290 const PipeType &ptype = (*ti);
291 if (cmp_nocase_uh(ptype._type.get_name(), _default_pipe_name) == 0) {
301 string preferred_name = downcase(_default_pipe_name);
302 for (ti = _pipe_types.begin(); ti != _pipe_types.end(); ++ti) {
303 const PipeType &ptype = (*ti);
304 string ptype_name = downcase(ptype._type.get_name());
305 if (ptype_name.find(preferred_name) != string::npos) {
317 for (ti = _pipe_types.begin(); ti != _pipe_types.end(); ++ti) {
318 const PipeType &ptype = (*ti);
338 DisplayModules::iterator di;
339 for (di = _display_modules.begin(); di != _display_modules.end(); ++di) {
340 load_named_module(*di);
343 _display_modules.clear();
344 _default_module_loaded =
true;
358 nassertr(func != NULL,
false);
361 display_cat->warning()
362 <<
"Attempt to register " << type <<
" as a GraphicsPipe type.\n";
369 PipeTypes::const_iterator ti;
370 for (ti = _pipe_types.begin(); ti != _pipe_types.end(); ++ti) {
371 const PipeType &ptype = (*ti);
372 if (ptype._type == type) {
373 display_cat->warning()
374 <<
"Attempt to register GraphicsPipe type " << type
375 <<
" more than once.\n";
380 if (display_cat->is_debug()) {
382 <<
"Registering " << type <<
" as a GraphicsPipe type.\n";
386 _pipe_types.push_back(PipeType(type, func));
400 void GraphicsPipeSelection::
401 do_load_default_module() {
402 if (_default_display_module.empty()) {
407 load_named_module(_default_display_module);
409 DisplayModules::iterator di =
410 find(_display_modules.begin(), _display_modules.end(),
411 _default_display_module);
412 if (di != _display_modules.end()) {
413 _display_modules.erase(di);
416 _default_module_loaded =
true;
418 if (_pipe_types.empty()) {
434 load_named_module(
const string &name) {
437 LoadedModules::iterator mi = _loaded_modules.find(name);
438 if (mi != _loaded_modules.end()) {
441 return (*mi).second._default_pipe_type;
445 Filename dlname = Filename::dso_filename(
"lib" + name +
".so");
448 void *handle = load_dso(get_plugin_path().get_value(), dlname);
449 if (handle == (
void *)NULL) {
450 display_cat.warning()
451 <<
"Unable to load: " << load_dso_error() << endl;
458 string symbol_name =
"get_pipe_type_" + name;
459 void *dso_symbol = get_dso_symbol(handle, symbol_name);
460 if (display_cat.is_debug()) {
462 <<
"symbol of " << symbol_name <<
" = " << dso_symbol <<
"\n";
467 if (dso_symbol == (
void *)NULL) {
469 display_cat.warning()
470 <<
"Unable to find " << symbol_name <<
" in " << dlname.
get_basename()
477 typedef int FuncType();
478 int pipe_type_index = (*(FuncType *)dso_symbol)();
479 if (display_cat.is_debug()) {
481 <<
"pipe_type_index = " << pipe_type_index <<
"\n";
484 if (pipe_type_index != 0) {
487 if (display_cat.is_debug()) {
489 <<
"pipe_type = " << pipe_type <<
"\n";
499 display_cat.warning()
500 <<
"No default pipe type available for " << dlname.
get_basename()
504 LoadedModule &module = _loaded_modules[name];
505 module._module_name = name;
506 module._module_handle = handle;
507 module._default_pipe_type = pipe_type;
string get_basename() const
Returns the basename part of the filename.
static TypeHandle none()
Returns a special zero-valued TypeHandle that is used to indicate no type.
TypeHandle find_type(const string &name) const
Looks for a previously-registered type of the given name.
TypeHandle find_type_by_id(int id) const
Looks for a previously-registered type with the given id number (as returned by TypeHandle::get_index...
bool is_derived_from(TypeHandle parent, TypedObject *object=(TypedObject *) NULL) const
Returns true if this type is derived from the indicated type, false otherwise.
void print_pipe_types() const
Writes a list of the currently known GraphicsPipe types to nout, for the user's information.
This class is similar to ConfigVariable, but it reports its value as a list of strings.
TypeHandle get_pipe_type(int n) const
Returns the nth type of GraphicsPipe available through this interface.
The name of a file, such as a texture file or an Egg file.
This is a convenience class to specialize ConfigVariable as a string type.
This maintains a list of GraphicsPipes by type that are available for creation.
Similar to MutexHolder, but for a light mutex.
An object to create GraphicsOutputs that share a particular 3-D API.
static TypeRegistry * ptr()
Returns the pointer to the global TypeRegistry object.
int get_num_pipe_types() const
Returns the number of different types of GraphicsPipes that are available to create through this inte...
void load_aux_modules()
Loads all the modules named in the aux-display Configrc variable, making as many graphics pipes as po...
The TypeRegistry class maintains all the assigned TypeHandles in a given system.
bool add_pipe_type(TypeHandle type, PipeConstructorFunc *func)
Adds a new kind of GraphicsPipe to the list of available pipes for creation.
TypeHandle is the identifier used to differentiate C++ class types.
string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...