From 8f45e49fa0c473e99ed5116d6ea2608fecca2dfd Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 29 Jul 2013 21:35:48 +0200 Subject: [PATCH] GL3 driver can now be instantiated. --HG-- branch : gsoc2013-dfighter --- code/nel/include/nel/3d/dru.h | 31 +++++++++++ code/nel/include/nel/3d/u_driver.h | 2 +- .../src/3d/driver/OpenGL3/driver_opengl.cpp | 2 +- code/nel/src/3d/driver_user.cpp | 3 + code/nel/src/3d/dru.cpp | 55 +++++++++++++++++++ .../material_editor/nel3d_interface.cpp | 3 +- 6 files changed, 93 insertions(+), 3 deletions(-) diff --git a/code/nel/include/nel/3d/dru.h b/code/nel/include/nel/3d/dru.h index 115f86432..d28022a8e 100644 --- a/code/nel/include/nel/3d/dru.h +++ b/code/nel/include/nel/3d/dru.h @@ -27,10 +27,12 @@ #ifdef NL_OS_WINDOWS # define NL3D_GL_DLL_NAME "nel_drv_opengl_win" +# define NL3D_GL3_DLL_NAME "nel_drv_opengl3_win" # define NL3D_GLES_DLL_NAME "nel_drv_opengles_win" # define NL3D_D3D_DLL_NAME "nel_drv_direct3d_win" #elif defined (NL_OS_UNIX) # define NL3D_GL_DLL_NAME "nel_drv_opengl" +# define NL3D_GL3_DLL_NAME "nel_drv_opengl3" # define NL3D_GLES_DLL_NAME "nel_drv_opengles" #else # error "Unknown system" @@ -71,6 +73,32 @@ struct EDruOpenglDriverCantCreateDriver : public EDru EDruOpenglDriverCantCreateDriver() : EDru( NL3D_GL_DLL_NAME " can't create driver" ) {} }; +// OpenGL 3 +struct EDruOpengl3DriverNotFound : public EDru +{ + EDruOpengl3DriverNotFound() : EDru( NL3D_GL3_DLL_NAME " not found" ) {} +}; + +struct EDruOpengl3DriverCorrupted : public EDru +{ + EDruOpengl3DriverCorrupted() : EDru( "Can't get NL3D_createIDriverInstance from " NL3D_GL3_DLL_NAME " (Bad dll?)" ) {} +}; + +struct EDruOpengl3DriverOldVersion : public EDru +{ + EDruOpengl3DriverOldVersion() : EDru( NL3D_GL3_DLL_NAME " is a too old version. Ask for a more recent file" ) {} +}; + +struct EDruOpengl3DriverUnknownVersion : public EDru +{ + EDruOpengl3DriverUnknownVersion() : EDru( NL3D_GL3_DLL_NAME " is more recent than the application" ) {} +}; + +struct EDruOpengl3DriverCantCreateDriver : public EDru +{ + EDruOpengl3DriverCantCreateDriver() : EDru( NL3D_GL3_DLL_NAME " can't create driver" ) {} +}; + // OpenGL ES struct EDruOpenglEsDriverNotFound : public EDru { @@ -133,6 +161,9 @@ public: /// Portable Function which create a GL Driver (using gl dll...). static IDriver *createGlDriver() throw(EDru); + /// Portable Function which create a GL3 Driver (using gl dll...). + static IDriver *createGl3Driver() throw(EDru); + /// Portable Function which create a GL ES Driver (using gl dll...). static IDriver *createGlEsDriver() throw(EDru); diff --git a/code/nel/include/nel/3d/u_driver.h b/code/nel/include/nel/3d/u_driver.h index d66a72e47..d11602bbb 100644 --- a/code/nel/include/nel/3d/u_driver.h +++ b/code/nel/include/nel/3d/u_driver.h @@ -140,7 +140,7 @@ public: enum TStencilFunc { never = 0, less, lessequal, equal, notequal, greaterequal, greater, always}; // Existing drivers - enum TDriver { Direct3d = 0, OpenGl, OpenGlEs }; + enum TDriver { Direct3d = 0, OpenGl, OpenGlEs, OpenGl3 }; public: /// The EventServer of this driver. Init after setDisplay()!! diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp index 8fbf1862c..acd002f86 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.cpp @@ -77,7 +77,7 @@ namespace NL3D { #ifdef NL_STATIC -IDriver* createGlDriverInstance () +IDriver* createGl3DriverInstance () { return new NLDRIVERGL::CDriverGL3; } diff --git a/code/nel/src/3d/driver_user.cpp b/code/nel/src/3d/driver_user.cpp index b45ebbd37..c3e494e7d 100644 --- a/code/nel/src/3d/driver_user.cpp +++ b/code/nel/src/3d/driver_user.cpp @@ -147,6 +147,9 @@ CDriverUser::CDriverUser (uint windowIcon, TDriver driver, emptyProc exitFunc) if (!_Driver && driver == OpenGlEs) _Driver= CDRU::createGlEsDriver(); + if( !_Driver && driver == OpenGl3 ) + _Driver = CDRU::createGl3Driver(); + nlassert(_Driver); _Driver->init (windowIcon, exitFunc); diff --git a/code/nel/src/3d/dru.cpp b/code/nel/src/3d/dru.cpp index 321429b2d..8132769ac 100644 --- a/code/nel/src/3d/dru.cpp +++ b/code/nel/src/3d/dru.cpp @@ -58,6 +58,7 @@ const char *IDRV_VERSION_PROC_NAME = "NL3D_interfaceVersion"; #ifdef NL_OPENGL_AVAILABLE extern IDriver* createGlDriverInstance (); +extern IDriver* createGl3DriverInstance (); #endif #if defined(NL_OS_WINDOWS) && defined(NL_DIRECT3D_AVAILABLE) @@ -124,6 +125,60 @@ IDriver *CDRU::createGlDriver() throw (EDru) #endif } +// *************************************************************************** +IDriver *CDRU::createGl3Driver() throw (EDru) +{ +#ifdef NL_STATIC + +#ifdef NL_OPENGL_AVAILABLE + return createGl3DriverInstance (); +#else + return NULL; +#endif // NL_OPENGL_AVAILABLE + +#else + + IDRV_CREATE_PROC createDriver = NULL; + IDRV_VERSION_PROC versionDriver = NULL; + + CLibrary driverLib; + +#if defined(NL_OS_UNIX) && defined(NL_DRIVER_PREFIX) + driverLib.addLibPath(NL_DRIVER_PREFIX); +#endif + + if (!driverLib.loadLibrary(NL3D_GL3_DLL_NAME, true, true, false)) + { + throw EDruOpengl3DriverNotFound(); + } + + nlinfo ("Using the library '"NL3D_GL3_DLL_NAME"' that is in the directory: '%s'", driverLib.getLibFileName().c_str()); + + createDriver = (IDRV_CREATE_PROC) driverLib.getSymbolAddress(IDRV_CREATE_PROC_NAME); + if (createDriver == NULL) + { + throw EDruOpengl3DriverCorrupted(); + } + + versionDriver = (IDRV_VERSION_PROC) driverLib.getSymbolAddress(IDRV_VERSION_PROC_NAME); + if (versionDriver != NULL) + { + if (versionDriver()IDriver::InterfaceVersion) + throw EDruOpengl3DriverUnknownVersion(); + } + + IDriver *ret= createDriver(); + if (ret == NULL) + { + throw EDruOpengl3DriverCantCreateDriver(); + } + + return ret; +#endif +} + // *************************************************************************** IDriver *CDRU::createGlEsDriver() throw (EDru) { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp index 62492f61e..03f15b528 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp @@ -397,7 +397,8 @@ namespace MaterialEditor void CNel3DInterface::initViewPort( unsigned long wnd, unsigned long w, unsigned long h ) { - driver = NL3D::UDriver::createDriver( 0, false, 0 ); + //driver = NL3D::UDriver::createDriver( 0, false, 0 ); + driver = NL3D::UDriver::createDriver( 0, NL3D::UDriver::OpenGl3, 0 ); nlassert( driver != NULL ); driver->setDisplay( (nlWindow)wnd, NL3D::UDriver::CMode( w, h, 32 ) );