0023000: Improve the way the gradient and textured background is managed in 3d viewer
[occt.git] / src / OpenGl / OpenGl_GraphicDriver.cxx
1 // File:      OpenGl_GraphicDriver.cxx
2 // Created:   20 October 2011
3 // Author:    Sergey ZERCHANINOV
4 // Copyright: OPEN CASCADE 2011
5
6 #include <OpenGl_GraphicDriver.hxx>
7
8 #include <OpenGl_View.hxx>
9 #include <OpenGl_Workspace.hxx>
10
11 IMPLEMENT_STANDARD_HANDLE(OpenGl_GraphicDriver,Graphic3d_GraphicDriver)
12 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_GraphicDriver,Graphic3d_GraphicDriver)
13
14 namespace
15 {
16   // Global maps - shared by whole TKOpenGl module. To be removed.
17   static NCollection_DataMap<Standard_Integer, Handle(OpenGl_View)>      TheMapOfView (1, NCollection_BaseAllocator::CommonBaseAllocator());
18   static NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)> TheMapOfWS   (1, NCollection_BaseAllocator::CommonBaseAllocator());
19   static NCollection_DataMap<Standard_Integer, OpenGl_Structure*>        TheMapOfStructure (1, NCollection_BaseAllocator::CommonBaseAllocator());
20   static Standard_Boolean TheToUseVbo = Standard_True;
21 };
22
23 // Pour eviter de "mangler" MetaGraphicDriverFactory, le nom de la
24 // fonction qui cree un Graphic3d_GraphicDriver.
25 // En effet, ce nom est recherche par la methode DlSymb de la
26 // classe OSD_SharedLibrary dans la methode SetGraphicDriver de la
27 // classe Graphic3d_GraphicDevice
28 extern "C" {
29 #ifdef WNT /* disable MS VC++ warning on C-style function returning C++ object */
30   #pragma warning(push)
31   #pragma warning(disable:4190)
32 #endif
33   Standard_EXPORT Handle(Graphic3d_GraphicDriver) MetaGraphicDriverFactory (const Standard_CString AShrName)
34   {
35     Handle(OpenGl_GraphicDriver) aOpenDriver = new OpenGl_GraphicDriver (AShrName);
36     return aOpenDriver;
37   }
38 #ifdef WNT
39   #pragma warning(pop)
40 #endif
41 }
42
43 OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Standard_CString theShrName)
44 : Graphic3d_GraphicDriver (theShrName)
45 {
46   //
47 }
48
49 Standard_ShortReal OpenGl_GraphicDriver::DefaultTextHeight() const
50 {
51   return 16.;
52 }
53
54 NCollection_DataMap<Standard_Integer, Handle(OpenGl_View)>& OpenGl_GraphicDriver::GetMapOfViews()
55 {
56   return TheMapOfView;
57 }
58
59 NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)>& OpenGl_GraphicDriver::GetMapOfWorkspaces()
60 {
61   return TheMapOfWS;
62 }
63
64 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>& OpenGl_GraphicDriver::GetMapOfStructures()
65 {
66   return TheMapOfStructure;
67 }
68
69 //TsmInitUpdateState
70 void OpenGl_GraphicDriver::InvalidateAllWorkspaces()
71 {
72   for (NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)>::Iterator anIt (OpenGl_GraphicDriver::GetMapOfWorkspaces());
73        anIt.More(); anIt.Next())
74   {
75     anIt.ChangeValue()->Invalidate();
76     anIt.ChangeValue()->EraseAnimation();
77   }
78 }
79
80 Standard_Boolean OpenGl_GraphicDriver::ToUseVBO()
81 {
82   return TheToUseVbo;
83 }
84
85 void OpenGl_GraphicDriver::EnableVBO (const Standard_Boolean theToTurnOn)
86 {
87   TheToUseVbo = theToTurnOn;
88 }