1 // Copyright (c) 2013-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Graphic3d.ixx>
16 #include <Aspect_DisplayConnection.hxx>
17 #include <Aspect_DriverDefinitionError.hxx>
18 #include <OSD_Environment.hxx>
20 //=======================================================================
21 //function : InitGraphicDriver
23 //=======================================================================
24 Handle(Graphic3d_GraphicDriver) Graphic3d::InitGraphicDriver (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
26 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
27 if (theDisplayConnection.IsNull())
29 Aspect_DriverDefinitionError::Raise ("Null display connection.");
33 TCollection_AsciiString aGraphicLibName;
35 // Setting the library name. Depends on the platform.
36 #if defined(_WIN32) || defined(__WIN32__)
37 aGraphicLibName = "TKOpenGl.dll";
38 #elif defined(__hpux) || defined(HPUX)
39 aGraphicLibName = "libTKOpenGl.sl";
40 #elif defined(__APPLE__)
41 aGraphicLibName = "libTKOpenGl.dylib";
43 aGraphicLibName = "libTKOpenGl.so";
46 // Loading the library.
47 OSD_SharedLibrary aSharedLibrary (aGraphicLibName.ToCString());
48 if (!aSharedLibrary.DlOpen (OSD_RTLD_LAZY))
50 Aspect_DriverDefinitionError::Raise (aSharedLibrary.DlError());
53 // Retrieving factory function pointer.
54 typedef Handle(Graphic3d_GraphicDriver) (*GraphicDriverFactoryPointer) (Standard_CString);
55 GraphicDriverFactoryPointer aGraphicDriverConstructor = (GraphicDriverFactoryPointer )aSharedLibrary.DlSymb ("MetaGraphicDriverFactory");
56 if (aGraphicDriverConstructor == NULL)
58 Aspect_DriverDefinitionError::Raise (aSharedLibrary.DlError());
61 // Creating driver instance.
62 Handle(Graphic3d_GraphicDriver) aGraphicDriver = aGraphicDriverConstructor (aSharedLibrary.Name());
64 // Management of traces.
65 OSD_Environment aTraceEnv ("CSF_GraphicTrace");
66 TCollection_AsciiString aTrace = aTraceEnv.Value();
67 if (aTrace.IsIntegerValue())
69 aGraphicDriver->SetTrace (aTrace.IntegerValue());
72 // Starting graphic driver.
73 if (!aGraphicDriver->Begin (theDisplayConnection))
75 Aspect_DriverDefinitionError::Raise ("Cannot connect to graphic library.");
78 return aGraphicDriver;