0025059: Visualization - mutable transformed structure still invalidates BVH tree...
[occt.git] / src / Graphic3d / Graphic3d.cxx
1 // Copyright (c) 2013-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <Graphic3d.ixx>
15
16 #include <Aspect_DisplayConnection.hxx>
17 #include <Aspect_DriverDefinitionError.hxx>
18 #include <OSD_Environment.hxx>
19
20 //=======================================================================
21 //function : InitGraphicDriver
22 //purpose  :
23 //=======================================================================
24 Handle(Graphic3d_GraphicDriver) Graphic3d::InitGraphicDriver (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
25 {
26 #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
27   if (theDisplayConnection.IsNull())
28   {
29     Aspect_DriverDefinitionError::Raise ("Null display connection.");
30   }
31 #endif
32
33   TCollection_AsciiString aGraphicLibName;
34
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";
42 #else
43   aGraphicLibName = "libTKOpenGl.so";
44 #endif
45
46   // Loading the library.
47   OSD_SharedLibrary aSharedLibrary (aGraphicLibName.ToCString());
48   if (!aSharedLibrary.DlOpen (OSD_RTLD_LAZY))
49   {
50     Aspect_DriverDefinitionError::Raise (aSharedLibrary.DlError());
51   }
52
53   // Retrieving factory function pointer.
54   typedef Handle(Graphic3d_GraphicDriver) (*GraphicDriverFactoryPointer) (Standard_CString);
55   GraphicDriverFactoryPointer aGraphicDriverConstructor = (GraphicDriverFactoryPointer )aSharedLibrary.DlSymb ("MetaGraphicDriverFactory");
56   if (aGraphicDriverConstructor == NULL)
57   {
58     Aspect_DriverDefinitionError::Raise (aSharedLibrary.DlError());
59   }
60
61   // Creating driver instance.
62   Handle(Graphic3d_GraphicDriver) aGraphicDriver = aGraphicDriverConstructor (aSharedLibrary.Name());
63
64   // Management of traces.
65   OSD_Environment aTraceEnv ("CSF_GraphicTrace");
66   TCollection_AsciiString aTrace = aTraceEnv.Value();
67   if (aTrace.IsIntegerValue())
68   {
69     aGraphicDriver->SetTrace (aTrace.IntegerValue());
70   }
71
72   // Starting graphic driver.
73   if (!aGraphicDriver->Begin (theDisplayConnection))
74   {
75     Aspect_DriverDefinitionError::Raise ("Cannot connect to graphic library.");
76   }
77
78   return aGraphicDriver;
79 }