GraphicsPipeSelection::make_module_pipe

This commit is contained in:
David Rose 2009-01-31 03:05:30 +00:00
parent 811c45a786
commit bddadb843e
10 changed files with 164 additions and 11 deletions

View File

@ -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();
}

View File

@ -9,5 +9,6 @@
#include "pandabase.h"
EXPCL_PANDADX void init_libpandadx8();
extern "C" EXPCL_PANDADX int get_pipe_type_pandadx8();
#endif

View File

@ -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();
}

View File

@ -9,5 +9,6 @@
#include "pandabase.h"
EXPCL_PANDADX void init_libpandadx9();
extern "C" EXPCL_PANDADX int get_pipe_type_pandadx9();
#endif

View File

@ -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;
}

View File

@ -9,6 +9,7 @@
#include "pandabase.h"
EXPCL_PANDAGL void init_libpandagl();
extern "C" EXPCL_PANDAGL int get_pipe_type_pandagl();
#endif

View File

@ -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;
}

View File

@ -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:

View File

@ -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;
}

View File

@ -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;