From bddadb843ed466a2a4c7ed480f2e08e59db41c5c Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 31 Jan 2009 03:05:30 +0000 Subject: [PATCH] GraphicsPipeSelection::make_module_pipe --- panda/metalibs/pandadx8/pandadx8.cxx | 11 +++ panda/metalibs/pandadx8/pandadx8.h | 1 + panda/metalibs/pandadx9/pandadx9.cxx | 11 +++ panda/metalibs/pandadx9/pandadx9.h | 1 + panda/metalibs/pandagl/pandagl.cxx | 43 ++++++++--- panda/metalibs/pandagl/pandagl.h | 1 + panda/src/display/graphicsPipeSelection.cxx | 76 +++++++++++++++++++- panda/src/display/graphicsPipeSelection.h | 3 +- panda/src/tinydisplay/config_tinydisplay.cxx | 27 +++++++ panda/src/tinydisplay/config_tinydisplay.h | 1 + 10 files changed, 164 insertions(+), 11 deletions(-) diff --git a/panda/metalibs/pandadx8/pandadx8.cxx b/panda/metalibs/pandadx8/pandadx8.cxx index 672cd089a9..32adf5ad1b 100644 --- a/panda/metalibs/pandadx8/pandadx8.cxx +++ b/panda/metalibs/pandadx8/pandadx8.cxx @@ -6,6 +6,7 @@ #include "pandadx8.h" #include "config_dxgsg8.h" +#include "wdxGraphicsPipe8.h" // By including checkPandaVersion.h, we guarantee that runtime // attempts to load libpandadx8.dll will fail if they @@ -25,3 +26,13 @@ void init_libpandadx8() { init_libdxgsg8(); } + +//////////////////////////////////////////////////////////////////// +// Function: get_pipe_type_pandadx8 +// Description: Returns the TypeHandle index of the recommended +// graphics pipe type defined by this module. +//////////////////////////////////////////////////////////////////// +int +get_pipe_type_pandadx8() { + return wdxGraphicsPipe8::get_class_type().get_index(); +} diff --git a/panda/metalibs/pandadx8/pandadx8.h b/panda/metalibs/pandadx8/pandadx8.h index 844eff64fe..6c6fc75306 100644 --- a/panda/metalibs/pandadx8/pandadx8.h +++ b/panda/metalibs/pandadx8/pandadx8.h @@ -9,5 +9,6 @@ #include "pandabase.h" EXPCL_PANDADX void init_libpandadx8(); +extern "C" EXPCL_PANDADX int get_pipe_type_pandadx8(); #endif diff --git a/panda/metalibs/pandadx9/pandadx9.cxx b/panda/metalibs/pandadx9/pandadx9.cxx index 1c8ec86469..7c3e72bdaa 100755 --- a/panda/metalibs/pandadx9/pandadx9.cxx +++ b/panda/metalibs/pandadx9/pandadx9.cxx @@ -6,6 +6,7 @@ #include "pandadx9.h" #include "config_dxgsg9.h" +#include "wdxGraphicsPipe9.h" // By including checkPandaVersion.h, we guarantee that runtime // attempts to load libpandadx9.dll will fail if they @@ -25,3 +26,13 @@ void init_libpandadx9() { init_libdxgsg9(); } + +//////////////////////////////////////////////////////////////////// +// Function: get_pipe_type_pandadx9 +// Description: Returns the TypeHandle index of the recommended +// graphics pipe type defined by this module. +//////////////////////////////////////////////////////////////////// +int +get_pipe_type_pandadx9() { + return wdxGraphicsPipe9::get_class_type().get_index(); +} diff --git a/panda/metalibs/pandadx9/pandadx9.h b/panda/metalibs/pandadx9/pandadx9.h index dd79e80aba..42c7b8799c 100755 --- a/panda/metalibs/pandadx9/pandadx9.h +++ b/panda/metalibs/pandadx9/pandadx9.h @@ -9,5 +9,6 @@ #include "pandabase.h" EXPCL_PANDADX void init_libpandadx9(); +extern "C" EXPCL_PANDADX int get_pipe_type_pandadx9(); #endif diff --git a/panda/metalibs/pandagl/pandagl.cxx b/panda/metalibs/pandagl/pandagl.cxx index fd9af0bcd5..866c430e59 100644 --- a/panda/metalibs/pandagl/pandagl.cxx +++ b/panda/metalibs/pandagl/pandagl.cxx @@ -5,17 +5,21 @@ #include "pandagl.h" -#ifndef LINK_IN_GL #include "config_glgsg.h" + #ifdef HAVE_WGL #include "config_wgldisplay.h" -#endif // HAVE_WGL - -#endif // LINK_IN_GL - +#include "wglGraphicsPipe.h" +#endif #ifdef IS_OSX #include "config_osxdisplay.h" +#include "osxGraphicsPipe.h" +#endif + +#ifdef IS_LINUX +#include "config_glxdisplay.h" +#include "glxGraphicsPipe.h" #endif // By including checkPandaVersion.h, we guarantee that runtime @@ -34,16 +38,39 @@ //////////////////////////////////////////////////////////////////// void init_libpandagl() { -#ifndef LINK_IN_GL init_libglgsg(); + #ifdef HAVE_WGL init_libwgldisplay(); #endif // HAVE_GL -#endif // LINK_IN_GL - #ifdef IS_OSX init_libosxdisplay(); #endif +#ifdef IS_LINUX + init_libglxdisplay(); +#endif +} + +//////////////////////////////////////////////////////////////////// +// Function: get_pipe_type_pandagl +// Description: Returns the TypeHandle index of the recommended +// graphics pipe type defined by this module. +//////////////////////////////////////////////////////////////////// +int +get_pipe_type_pandagl() { +#ifdef HAVE_WGL + return wglGraphicsPipe::get_class_type().get_index(); +#endif + +#ifdef IS_OSX + return osxGraphicsPipe::get_class_type().get_index(); +#endif + +#ifdef IS_LINUX + return glxGraphicsPipe::get_class_type().get_index(); +#endif + + return 0; } diff --git a/panda/metalibs/pandagl/pandagl.h b/panda/metalibs/pandagl/pandagl.h index 3991794600..4dcd99a30c 100644 --- a/panda/metalibs/pandagl/pandagl.h +++ b/panda/metalibs/pandagl/pandagl.h @@ -9,6 +9,7 @@ #include "pandabase.h" EXPCL_PANDAGL void init_libpandagl(); +extern "C" EXPCL_PANDAGL int get_pipe_type_pandagl(); #endif diff --git a/panda/src/display/graphicsPipeSelection.cxx b/panda/src/display/graphicsPipeSelection.cxx index 5a89862d81..b6673c06b3 100644 --- a/panda/src/display/graphicsPipeSelection.cxx +++ b/panda/src/display/graphicsPipeSelection.cxx @@ -246,6 +246,76 @@ make_pipe(TypeHandle type) { return NULL; } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsPipeSelection::make_module_pipe +// Access: Published +// Description: Returns a new GraphicsPipe of a type defined by the +// indicated module. Returns NULL if the module is not +// found or does not properly recommend a GraphicsPipe. +//////////////////////////////////////////////////////////////////// +PT(GraphicsPipe) GraphicsPipeSelection:: +make_module_pipe(const string &module_name) { + if (display_cat.is_debug()) { + display_cat.debug() + << "make_module_pipe(" << module_name << ")\n"; + } + + void *handle = load_named_module(module_name); + if (display_cat.is_debug()) { + display_cat.debug() + << "module handle = " << handle << "\n"; + } + + if (handle == (void *)NULL) { + // Couldn't load the module. + return NULL; + } + + string symbol_name = "get_pipe_type_" + module_name; + void *dso_symbol = get_dso_symbol(handle, symbol_name); + if (display_cat.is_debug()) { + display_cat.debug() + << "symbol of " << symbol_name << " = " << dso_symbol << "\n"; + } + + if (dso_symbol == (void *)NULL) { + // Couldn't find the module function. + unload_dso(handle); + return NULL; + } + + // We successfully loaded the module, and we found the + // get_pipe_type_* recommendation function. Call it to figure + // out what pipe type we should expect. + typedef int FuncType(); + int pipe_type_index = (*(FuncType *)dso_symbol)(); + if (display_cat.is_debug()) { + display_cat.debug() + << "pipe_type_index = " << pipe_type_index << "\n"; + } + + if (pipe_type_index == 0) { + // The recommendation function had no advice, weird. + unload_dso(handle); + return NULL; + } + + TypeRegistry *type_reg = TypeRegistry::ptr(); + TypeHandle pipe_type = type_reg->find_type_by_id(pipe_type_index); + if (display_cat.is_debug()) { + display_cat.debug() + << "pipe_type = " << pipe_type << "\n"; + } + + if (pipe_type == TypeHandle::none()) { + // The recommendation function returned a bogus type index, weird. + unload_dso(handle); + return NULL; + } + + return make_pipe(pipe_type); +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsPipeSelection::make_default_pipe // Access: Published @@ -396,9 +466,10 @@ do_load_default_module() { // Function: GraphicsPipeSelection::load_named_module // Access: Private // Description: Loads the indicated display module by looking for a -// matching .dll or .so file. +// matching .dll or .so file. Returns the return value +// from load_dso(), or NULL. //////////////////////////////////////////////////////////////////// -void GraphicsPipeSelection:: +void *GraphicsPipeSelection:: load_named_module(const string &name) { Filename dlname = Filename::dso_filename("lib" + name + ".so"); display_cat.info() @@ -408,4 +479,5 @@ load_named_module(const string &name) { display_cat.info() << "Unable to load: " << load_dso_error() << endl; } + return tmp; } diff --git a/panda/src/display/graphicsPipeSelection.h b/panda/src/display/graphicsPipeSelection.h index 22db462022..5d8a23ca47 100644 --- a/panda/src/display/graphicsPipeSelection.h +++ b/panda/src/display/graphicsPipeSelection.h @@ -47,6 +47,7 @@ PUBLISHED: PT(GraphicsPipe) make_pipe(const string &type_name, const string &module_name = string()); PT(GraphicsPipe) make_pipe(TypeHandle type); + PT(GraphicsPipe) make_module_pipe(const string &module_name); PT(GraphicsPipe) make_default_pipe(); INLINE int get_num_aux_modules() const; @@ -61,7 +62,7 @@ public: private: INLINE void load_default_module() const; void do_load_default_module(); - void load_named_module(const string &name); + void *load_named_module(const string &name); class PipeType { public: diff --git a/panda/src/tinydisplay/config_tinydisplay.cxx b/panda/src/tinydisplay/config_tinydisplay.cxx index 0327f67f79..6cda14fd9e 100644 --- a/panda/src/tinydisplay/config_tinydisplay.cxx +++ b/panda/src/tinydisplay/config_tinydisplay.cxx @@ -154,3 +154,30 @@ init_libtinydisplay() { ps->set_system_tag("TinyGL", "SDL", "SDL"); #endif } + +//////////////////////////////////////////////////////////////////// +// Function: get_pipe_type_tinydisplay +// Description: Returns the TypeHandle index of the recommended +// graphics pipe type defined by this module. +//////////////////////////////////////////////////////////////////// +int +get_pipe_type_tinydisplay() { + +#ifdef IS_LINUX + return TinyXGraphicsPipe::get_class_type().get_index(); +#endif + +#ifdef WIN32 + return TinyWinGraphicsPipe::get_class_type().get_index(); +#endif + +#ifdef IS_OSX + return TinyOsxGraphicsPipe::get_class_type().get_index(); +#endif + +#ifdef HAVE_SDL + return TinySDLGraphicsPipe::get_class_type().get_index(); +#endif + + return 0; +} diff --git a/panda/src/tinydisplay/config_tinydisplay.h b/panda/src/tinydisplay/config_tinydisplay.h index f56cd1b974..491221f8ea 100644 --- a/panda/src/tinydisplay/config_tinydisplay.h +++ b/panda/src/tinydisplay/config_tinydisplay.h @@ -24,6 +24,7 @@ NotifyCategoryDecl(tinydisplay, EXPCL_TINYDISPLAY, EXPTP_TINYDISPLAY); extern EXPCL_TINYDISPLAY void init_libtinydisplay(); +extern "C" EXPCL_TINYDISPLAY int get_pipe_type_tinydisplay(); extern ConfigVariableString display_cfg; extern ConfigVariableBool x_error_abort;