From dac04bfa3825ff2b3332fc7ff259ea418a34b707 Mon Sep 17 00:00:00 2001 From: kgv Date: Thu, 24 Jan 2013 14:42:36 +0400 Subject: [PATCH] 0023668: OCCT automated testing: Using Mesa3d for 3D visualization on virtual Windows machines Added advanced Draw Harness environment variable CSF_UserDllPath to prepend DLL search path for system libraries like "opengl32.dll". Added new Draw Harness command vglinfo to print OpenGL self info. --- src/Draw/Draw.cxx | 33 ++++++++- src/ViewerTest/ViewerTest_OpenGlCommands.cxx | 77 ++++++++++++++++++++ 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/src/Draw/Draw.cxx b/src/Draw/Draw.cxx index d5e3ff70ef..8e57404ce4 100755 --- a/src/Draw/Draw.cxx +++ b/src/Draw/Draw.cxx @@ -31,6 +31,7 @@ #include #include +#include #include #ifdef HAVE_SYS_TIME_H @@ -159,13 +160,41 @@ void exitProc(ClientData /*dc*/) // ******************************************************************* // main // ******************************************************************* -#ifdef WNT +#ifdef _WIN32 //Standard_EXPORT void Draw_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lps Standard_EXPORT void Draw_Appli(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszLine, int nShow,const FDraw_InitAppli Draw_InitAppli) #else void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_InitAppli) #endif { + +// prepend extra DLL search path to override system libraries like opengl32.dll +#ifdef _WIN32 + OSD_Environment aUserDllEnv ("CSF_UserDllPath"); + TCollection_AsciiString aUserDllPath = aUserDllEnv.Value(); + if (!aUserDllPath.IsEmpty()) + { + // This function available since Win XP SP1 #if (_WIN32_WINNT >= 0x0502). + // We retrieve dynamically here (kernel32 should be always preloaded). + typedef BOOL (WINAPI *SetDllDirectoryA_t)(const char* thePathName); + HMODULE aKern32Module = GetModuleHandleA ("kernel32"); + SetDllDirectoryA_t aFunc = (aKern32Module != NULL) + ? (SetDllDirectoryA_t )GetProcAddress (aKern32Module, "SetDllDirectoryA") : NULL; + if (aFunc != NULL) + { + aFunc (aUserDllPath.ToCString()); + } + else + { + //std::cerr << "SetDllDirectoryA() is not available on this system!\n"; + } + if (aKern32Module != NULL) + { + FreeLibrary (aKern32Module); + } + } +#endif + // ***************************************************************** // analyze arguments // ***************************************************************** @@ -174,7 +203,7 @@ void Draw_Appli(Standard_Integer argc, char** argv,const FDraw_InitAppli Draw_In Standard_Integer i; Standard_Boolean isInteractiveForced = Standard_False; -#ifdef WNT +#ifdef _WIN32 // On NT command line arguments are in the lpzline and not in argv int argc = 0; const int MAXARGS = 1024; diff --git a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx index 9a152b7cdd..7921522189 100644 --- a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx +++ b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx @@ -432,6 +432,79 @@ static int VImmediateFront (Draw_Interpretor& theDI, return 0; } +//============================================================================== +//function : VGlInfo +//purpose : +//============================================================================== + +static int VGlInfo (Draw_Interpretor& theDI, + Standard_Integer theArgNb, + const char** theArgVec) +{ + // get the active view + Handle(V3d_View) aView = ViewerTest::CurrentView(); + if (aView.IsNull()) + { + std::cerr << "No active view. Please call vinit.\n"; + return 1; + } + + if (theArgNb <= 1) + { + theDI << "OpenGL info:\n" + << " GLvendor = '" << (const char* )glGetString(GL_VENDOR) << "'\n" + << " GLdevice = '" << (const char* )glGetString(GL_RENDERER) << "'\n" + << " GLversion = '" << (const char* )glGetString(GL_VERSION) << "'\n" + << " GLSLversion = '" << (const char* )glGetString(GL_SHADING_LANGUAGE_VERSION) << "'\n"; + return 0; + } + + const Standard_Boolean isList = theArgNb >= 3; + for (Standard_Integer anIter = 1; anIter < theArgNb; ++anIter) + { + TCollection_AsciiString aName (theArgVec[anIter]); + aName.UpperCase(); + const char* aValue = NULL; + if (aName.Search ("VENDOR") != -1) + { + aValue = (const char* )glGetString (GL_VENDOR); + } + else if (aName.Search ("RENDERER") != -1) + { + aValue = (const char* )glGetString (GL_RENDERER); + } + else if (aName.Search ("SHADING_LANGUAGE_VERSION") != -1 + || aName.Search ("GLSL") != -1) + { + aValue = (const char* )glGetString (GL_SHADING_LANGUAGE_VERSION); + } + else if (aName.Search ("VERSION") != -1) + { + aValue = (const char* )glGetString (GL_VERSION); + } + else if (aName.Search ("EXTENSIONS") != -1) + { + aValue = (const char* )glGetString (GL_EXTENSIONS); + } + else + { + std::cerr << "Unknown key '" << aName.ToCString() << "'\n"; + return 1; + } + + if (isList) + { + theDI << "{" << aValue << "} "; + } + else + { + theDI << aValue; + } + } + + return 0; +} + //======================================================================= //function : OpenGlCommands //purpose : @@ -451,4 +524,8 @@ void ViewerTest::OpenGlCommands(Draw_Interpretor& theCommands) "vimmediatefront : render immediate mode to front buffer or to back buffer", __FILE__, VImmediateFront, aGroup); + theCommands.Add("vglinfo", + "vglinfo [GL_VENDOR] [GL_RENDERER] [GL_VERSION] [GL_SHADING_LANGUAGE_VERSION] [GL_EXTENSIONS]" + " : prints GL info", + __FILE__, VGlInfo, aGroup); }