summaryrefslogtreecommitdiff
path: root/src/Graphic3d/Graphic3d_WNTGraphicDevice.cxx
blob: abc00aae4740c1d1272a6c1e149b3b3b915f5ebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
10-09-00  : GG  ; NEW OpenGl driver loading specification
when nothing is defined the driver TKOpenGl.dll
is loaded from the current PATH.
*/

#define XDESTROY

#include <stdlib.h>


#ifdef WNT
# include <Graphic3d_WNTGraphicDevice.ixx>
# include <InterfaceGraphic_wntio.hxx>
#include <OSD_Environment.hxx>
#include <TCollection_AsciiString.hxx>


typedef Handle_Graphic3d_GraphicDriver ( *GET_DRIVER_PROC ) ( const char* );

Graphic3d_WNTGraphicDevice::Graphic3d_WNTGraphicDevice (): WNT_GraphicDevice (Standard_True) {

  SetGraphicDriver ();

  if (! MyGraphicDriver->Begin (""))
    Aspect_GraphicDeviceDefinitionError::Raise
    ("Cannot connect to graphic library");

}

void Graphic3d_WNTGraphicDevice::Destroy () {

#ifdef DESTROY
  cout << "Graphic3d_WNTGraphicDevice::Destroy ()\n";
#endif

  MyGraphicDriver->End ();

}

Handle(Aspect_GraphicDriver) Graphic3d_WNTGraphicDevice::GraphicDriver () const {

  return MyGraphicDriver;

}

#if !defined(OCE_BUILD_STATIC_LIB) && !defined(HAVE_NO_DLL)
void Graphic3d_WNTGraphicDevice::SetGraphicDriver () 
{

  Standard_Boolean Result;
  OSD_Function new_GLGraphicDriver;
  Standard_CString TheShr = getenv("CSF_GraphicShr");
  if ( ! TheShr || ( strlen( TheShr ) == 0 ) )
#ifdef OCE_DEBUG_POSTFIX
	  TheShr = "TKOpenGl" OCE_DEBUG_POSTFIX ".dll";
#else
	  TheShr = "TKOpenGl.dll";
#endif /* OCE_DEBUG_POSTFIX */

  MySharedLibrary.SetName ( TheShr );
  Result = MySharedLibrary.DlOpen (OSD_RTLD_LAZY);

  if (! Result) {
    Aspect_GraphicDeviceDefinitionError::Raise
      (MySharedLibrary.DlError ());
  }
  else {
    // Management of traces
    OSD_Environment beurk("CSF_GraphicTrace");
    TCollection_AsciiString val = beurk.Value();
    if (val.Length() > 0 )
      cout << "Information : " << TheShr << " loaded\n" << flush;

    new_GLGraphicDriver =
      MySharedLibrary.DlSymb ("MetaGraphicDriverFactory");
    if (! new_GLGraphicDriver) {
      Aspect_GraphicDeviceDefinitionError::Raise
        (MySharedLibrary.DlError ());
    }
    else {
      // Sequence :
      // new_GLGraphicDriver is OSD_Function :
      // typedef int (* OSD_Function)(...);
      // wherefrom a good cast in GraphicDriver.
      //Handle( Graphic3d_GraphicDriver ) ADriver = new Graphic3d_GraphicDriver ( TheShr );

      GET_DRIVER_PROC fp = ( GET_DRIVER_PROC )new_GLGraphicDriver;
      //ADriver = ( *fp ) ( TheShr );
      if (!fp)
        Aspect_GraphicDeviceDefinitionError::Raise
        (MySharedLibrary.DlError ());
      MyGraphicDriver = ( *fp ) ( TheShr );

      // Management of traces
      if ( val.Length() > 0 && val.IsIntegerValue() )
        MyGraphicDriver->SetTrace(val.IntegerValue());
    }
  }

}
#else

extern "C"
{
     Handle(Graphic3d_GraphicDriver) MetaGraphicDriverFactory(const Standard_CString AShrName);
}

void Graphic3d_WNTGraphicDevice::SetGraphicDriver ()
{
     MyGraphicDriver = MetaGraphicDriverFactory("");
}
#endif

#endif  // WNT