1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 /***********************************************************************
23 Classe Graphic3d_GraphicDevice.cxx :
26 HISTORIQUE DES MODIFICATIONS :
27 --------------------------------
28 Janvier 1994 : CAL ; Creation.
29 04-02-97 : FMN ; Suppression appel call_tox_set_colormap_mapping()
30 10-09-00 : GG ; NEW OpenGl driver loading specification
31 when nothing is defined the driver libTKOpenGl[.so|.sl]
32 is loading from the current PATH
34 ************************************************************************/
35 #if (!defined(_WIN32) && !defined(__WIN32__))
38 #include <sys/utsname.h>
40 /*----------------------------------------------------------------------*/
45 #include <Graphic3d_GraphicDevice.ixx>
46 #include <Graphic3d_GraphicDriver.hxx>
47 #include <OSD_Function.hxx>
48 #include <OSD_Environment.hxx>
49 #include <TCollection_AsciiString.hxx>
51 #include <Xw_Cextern.hxx>
53 //-Static data definitions
55 static char LocalMessag[80] ;
59 //-Global data definitions
63 Graphic3d_GraphicDevice::Graphic3d_GraphicDevice (const Standard_CString Connexion, const Xw_TypeOfMapping /*Mapping*/, const Standard_Integer Ncolors, const Standard_Boolean UseDefault ):
65 Standard_CString connexion = (Connexion) ? Connexion : Standard_CString("") ;
66 Standard_Boolean status ;
68 MyExtendedDisplay = Xw_open_display((Standard_PCharacter)connexion) ;
70 if( !MyExtendedDisplay ) {
71 sprintf(LocalMessag,"Cannot connect to server '%s'",connexion) ;
72 Aspect_GraphicDeviceDefinitionError::Raise (LocalMessag);
77 status = MyGraphicDriver->Begin (connexion);
80 sprintf(LocalMessag,"Cannot connect to graphic library from '%s'",
82 Aspect_GraphicDeviceDefinitionError::Raise (LocalMessag);
85 this->InitMaps (connexion,Xw_TOM_READONLY,Ncolors,UseDefault);
90 Graphic3d_GraphicDevice::Graphic3d_GraphicDevice (const Aspect_Display pdisplay)
93 Standard_Boolean status ;
96 Aspect_GraphicDeviceDefinitionError::Raise ("Bad display pointer");
97 MyExtendedDisplay = Xw_set_display(pdisplay) ;
98 Standard_CString connexion = Xw_get_display_name(MyExtendedDisplay);
100 if( !MyExtendedDisplay ) {
102 sprintf(LocalMessag,"Cannot connect to server '%s'",connexion) ;
104 sprintf(LocalMessag,"Cannot connect to an UNKNOWN server") ;
105 Aspect_GraphicDeviceDefinitionError::Raise (LocalMessag);
110 status = MyGraphicDriver->Begin (pdisplay);
113 sprintf(LocalMessag,"Cannot connect to graphic library from '%s'",
115 Aspect_GraphicDeviceDefinitionError::Raise (LocalMessag);
118 this->InitMaps (connexion,Xw_TOM_READONLY,0,Standard_True);
122 void Graphic3d_GraphicDevice::Destroy()
124 MyGraphicDriver->End();
129 Handle(Aspect_GraphicDriver) Graphic3d_GraphicDevice::GraphicDriver () const {
131 return MyGraphicDriver;
135 void Graphic3d_GraphicDevice::SetGraphicDriver () {
137 TCollection_AsciiString aShr = ShrEnvString ();
139 OSD_SharedLibrary TheSharedLibrary (aShr.ToCString());
141 Standard_Boolean Result = TheSharedLibrary.DlOpen (OSD_RTLD_LAZY);
144 Aspect_GraphicDeviceDefinitionError::Raise
145 (TheSharedLibrary.DlError ());
148 // Management of traces
149 char *tracevalue = NULL;
150 tracevalue = (char *)(getenv ("CSF_GraphicTrace"));
152 cout << "Information : " << aShr << " loaded\n" << flush;
154 OSD_Function new_GLGraphicDriver =
155 TheSharedLibrary.DlSymb ("MetaGraphicDriverFactory");
157 cout << "Information : MetaGraphicDriverFactory "
158 << (new_GLGraphicDriver ? "found\n" : "not found\n") << flush;
159 if (! new_GLGraphicDriver) {
160 Aspect_GraphicDeviceDefinitionError::Raise
161 (TheSharedLibrary.DlError ());
165 // new_GLGraphicDriver is OSD_Function :
166 // typedef int (* OSD_Function)(...);
167 // that is why good cast in GraphicDriver.
168 Handle(Graphic3d_GraphicDriver)
169 (*fp) (Standard_CString) = NULL;
170 fp = (Handle(Graphic3d_GraphicDriver)
171 (*) (Standard_CString)) new_GLGraphicDriver;
172 if (tracevalue) cout << "FP == "<<(void *) fp<<endl;
173 Standard_CString aSharedName = TheSharedLibrary.Name ();
174 MyGraphicDriver = (*fp) (aSharedName);
176 // MyGraphicDriver = (*fp) (TheSharedLibrary.Name ());
178 // Management of traces
180 MyGraphicDriver->SetTrace
181 ((Standard_Integer) atoi (tracevalue));
187 TCollection_AsciiString Graphic3d_GraphicDevice::ShrEnvString() const
189 OSD_Environment aEnvShr ("CSF_GraphicShr");
190 if (!aEnvShr.Value().IsEmpty())
192 return aEnvShr.Value();
195 // load TKOpenGl using default searching mechanisms in system
196 #if defined(__hpux) || defined(HPUX)
197 return TCollection_AsciiString ("libTKOpenGl.sl");
198 #elif defined(__APPLE__)
199 return TCollection_AsciiString ("libTKOpenGl.dylib");
201 return TCollection_AsciiString ("libTKOpenGl.so");