0023186: Unable to display Graphic3d_ArrayOfPoints after migrating from OCCT 6.5.2
[occt.git] / src / OpenGl / OpenGl_GraphicDriver.cxx
1 // Created on: 2011-10-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
4 //
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
9 //
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 //
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
19
20
21 #include <OpenGl_GraphicDriver.hxx>
22
23 #include <OpenGl_Context.hxx>
24 #include <OpenGl_View.hxx>
25 #include <OpenGl_Workspace.hxx>
26
27 IMPLEMENT_STANDARD_HANDLE(OpenGl_GraphicDriver,Graphic3d_GraphicDriver)
28 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_GraphicDriver,Graphic3d_GraphicDriver)
29
30 namespace
31 {
32   // Global maps - shared by whole TKOpenGl module. To be removed.
33   static NCollection_DataMap<Standard_Integer, Handle(OpenGl_View)>      TheMapOfView (1, NCollection_BaseAllocator::CommonBaseAllocator());
34   static NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)> TheMapOfWS   (1, NCollection_BaseAllocator::CommonBaseAllocator());
35   static NCollection_DataMap<Standard_Integer, OpenGl_Structure*>        TheMapOfStructure (1, NCollection_BaseAllocator::CommonBaseAllocator());
36   static Standard_Boolean TheToUseVbo = Standard_True;
37 };
38
39 // Pour eviter de "mangler" MetaGraphicDriverFactory, le nom de la
40 // fonction qui cree un Graphic3d_GraphicDriver.
41 // En effet, ce nom est recherche par la methode DlSymb de la
42 // classe OSD_SharedLibrary dans la methode SetGraphicDriver de la
43 // classe Graphic3d_GraphicDevice
44 extern "C" {
45 #ifdef WNT /* disable MS VC++ warning on C-style function returning C++ object */
46   #pragma warning(push)
47   #pragma warning(disable:4190)
48 #endif
49   Standard_EXPORT Handle(Graphic3d_GraphicDriver) MetaGraphicDriverFactory (const Standard_CString AShrName)
50   {
51     Handle(OpenGl_GraphicDriver) aOpenDriver = new OpenGl_GraphicDriver (AShrName);
52     return aOpenDriver;
53   }
54 #ifdef WNT
55   #pragma warning(pop)
56 #endif
57 }
58
59 // =======================================================================
60 // function : OpenGl_GraphicDriver
61 // purpose  :
62 // =======================================================================
63 OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Standard_CString theShrName)
64 : Graphic3d_GraphicDriver (theShrName)
65 {
66   //
67 }
68
69 // =======================================================================
70 // function : DefaultTextHeight
71 // purpose  :
72 // =======================================================================
73 Standard_ShortReal OpenGl_GraphicDriver::DefaultTextHeight() const
74 {
75   return 16.;
76 }
77
78 // =======================================================================
79 // function : GetMapOfViews
80 // purpose  :
81 // =======================================================================
82 NCollection_DataMap<Standard_Integer, Handle(OpenGl_View)>& OpenGl_GraphicDriver::GetMapOfViews()
83 {
84   return TheMapOfView;
85 }
86
87 // =======================================================================
88 // function : GetMapOfWorkspaces
89 // purpose  :
90 // =======================================================================
91 NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)>& OpenGl_GraphicDriver::GetMapOfWorkspaces()
92 {
93   return TheMapOfWS;
94 }
95
96 // =======================================================================
97 // function : GetMapOfStructures
98 // purpose  :
99 // =======================================================================
100 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>& OpenGl_GraphicDriver::GetMapOfStructures()
101 {
102   return TheMapOfStructure;
103 }
104
105 // =======================================================================
106 // function : InvalidateAllWorkspaces
107 // purpose  : ex-TsmInitUpdateState, deprecated, need to decide what to do with EraseAnimation() call
108 // =======================================================================
109 void OpenGl_GraphicDriver::InvalidateAllWorkspaces()
110 {
111   for (NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)>::Iterator anIt (OpenGl_GraphicDriver::GetMapOfWorkspaces());
112        anIt.More(); anIt.Next())
113   {
114     anIt.ChangeValue()->EraseAnimation();
115   }
116 }
117
118 // =======================================================================
119 // function : ToUseVBO
120 // purpose  :
121 // =======================================================================
122 Standard_Boolean OpenGl_GraphicDriver::ToUseVBO()
123 {
124   return TheToUseVbo;
125 }
126
127 // =======================================================================
128 // function : EnableVBO
129 // purpose  :
130 // =======================================================================
131 void OpenGl_GraphicDriver::EnableVBO (const Standard_Boolean theToTurnOn)
132 {
133   TheToUseVbo = theToTurnOn;
134 }
135
136 // =======================================================================
137 // function : MemoryInfo
138 // purpose  :
139 // =======================================================================
140 Standard_Boolean OpenGl_GraphicDriver::MemoryInfo (Standard_Size&           theFreeBytes,
141                                                    TCollection_AsciiString& theInfo) const
142 {
143   // this is extra work (for OpenGl_Context initialization)...
144   OpenGl_Context aGlCtx;
145   if (!aGlCtx.Init())
146   {
147     return Standard_False;
148   }
149   theFreeBytes = aGlCtx.AvailableMemory();
150   theInfo      = aGlCtx.MemoryInfo();
151   return !theInfo.IsEmpty();
152 }