0023316: OpenGl package can not be compiled on RedHat40-64
[occt.git] / src / OpenGl / OpenGl_GraphicDriver.cxx
index 8e3a8e0..c5d486f 100755 (executable)
@@ -20,6 +20,7 @@
 
 #include <OpenGl_GraphicDriver.hxx>
 
+#include <OpenGl_Context.hxx>
 #include <OpenGl_View.hxx>
 #include <OpenGl_Workspace.hxx>
 
@@ -28,11 +29,10 @@ IMPLEMENT_STANDARD_RTTIEXT(OpenGl_GraphicDriver,Graphic3d_GraphicDriver)
 
 namespace
 {
-  // Global maps - shared by whole TKOpenGl module. To be removed.
-  static NCollection_DataMap<Standard_Integer, Handle(OpenGl_View)>      TheMapOfView (1, NCollection_BaseAllocator::CommonBaseAllocator());
-  static NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)> TheMapOfWS   (1, NCollection_BaseAllocator::CommonBaseAllocator());
-  static NCollection_DataMap<Standard_Integer, OpenGl_Structure*>        TheMapOfStructure (1, NCollection_BaseAllocator::CommonBaseAllocator());
+  // Global switch - shared by whole TKOpenGl module. To be removed.
   static Standard_Boolean TheToUseVbo = Standard_True;
+
+  static const Handle(OpenGl_Context) TheNullGlCtx;
 };
 
 // Pour eviter de "mangler" MetaGraphicDriverFactory, le nom de la
@@ -41,63 +41,112 @@ namespace
 // classe OSD_SharedLibrary dans la methode SetGraphicDriver de la
 // classe Graphic3d_GraphicDevice
 extern "C" {
-#ifdef WNT /* disable MS VC++ warning on C-style function returning C++ object */
+#if defined(_MSC_VER) // disable MS VC++ warning on C-style function returning C++ object
   #pragma warning(push)
   #pragma warning(disable:4190)
 #endif
-  Standard_EXPORT Handle(Graphic3d_GraphicDriver) MetaGraphicDriverFactory (const Standard_CString AShrName)
+  Standard_EXPORT Handle(Graphic3d_GraphicDriver) MetaGraphicDriverFactory (const Standard_CString theShrName)
   {
-    Handle(OpenGl_GraphicDriver) aOpenDriver = new OpenGl_GraphicDriver (AShrName);
-    return aOpenDriver;
+    Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver (theShrName);
+    return aDriver;
   }
-#ifdef WNT
+#if defined(_MSC_VER)
   #pragma warning(pop)
 #endif
 }
 
+// =======================================================================
+// function : OpenGl_GraphicDriver
+// purpose  :
+// =======================================================================
 OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Standard_CString theShrName)
-: Graphic3d_GraphicDriver (theShrName)
+: Graphic3d_GraphicDriver (theShrName),
+  myMapOfView      (1, NCollection_BaseAllocator::CommonBaseAllocator()),
+  myMapOfWS        (1, NCollection_BaseAllocator::CommonBaseAllocator()),
+  myMapOfStructure (1, NCollection_BaseAllocator::CommonBaseAllocator()),
+  myUserDrawCallback (NULL)
 {
   //
 }
 
-Standard_ShortReal OpenGl_GraphicDriver::DefaultTextHeight() const
-{
-  return 16.;
-}
-
-NCollection_DataMap<Standard_Integer, Handle(OpenGl_View)>& OpenGl_GraphicDriver::GetMapOfViews()
+// =======================================================================
+// function : UserDrawCallback
+// purpose  :
+// =======================================================================
+OpenGl_GraphicDriver::OpenGl_UserDrawCallback_t& OpenGl_GraphicDriver::UserDrawCallback()
 {
-  return TheMapOfView;
+  return myUserDrawCallback;
 }
 
-NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)>& OpenGl_GraphicDriver::GetMapOfWorkspaces()
-{
-  return TheMapOfWS;
-}
-
-NCollection_DataMap<Standard_Integer, OpenGl_Structure*>& OpenGl_GraphicDriver::GetMapOfStructures()
+// =======================================================================
+// function : DefaultTextHeight
+// purpose  :
+// =======================================================================
+Standard_ShortReal OpenGl_GraphicDriver::DefaultTextHeight() const
 {
-  return TheMapOfStructure;
+  return 16.;
 }
 
-//TsmInitUpdateState
+// =======================================================================
+// function : InvalidateAllWorkspaces
+// purpose  : ex-TsmInitUpdateState, deprecated, need to decide what to do with EraseAnimation() call
+// =======================================================================
 void OpenGl_GraphicDriver::InvalidateAllWorkspaces()
 {
-  for (NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)>::Iterator anIt (OpenGl_GraphicDriver::GetMapOfWorkspaces());
+  for (NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)>::Iterator anIt (myMapOfWS);
        anIt.More(); anIt.Next())
   {
-    anIt.ChangeValue()->Invalidate();
     anIt.ChangeValue()->EraseAnimation();
   }
 }
 
+// =======================================================================
+// function : ToUseVBO
+// purpose  :
+// =======================================================================
 Standard_Boolean OpenGl_GraphicDriver::ToUseVBO()
 {
   return TheToUseVbo;
 }
 
+// =======================================================================
+// function : EnableVBO
+// purpose  :
+// =======================================================================
 void OpenGl_GraphicDriver::EnableVBO (const Standard_Boolean theToTurnOn)
 {
   TheToUseVbo = theToTurnOn;
 }
+
+// =======================================================================
+// function : GetSharedContext
+// purpose  :
+// =======================================================================
+const Handle(OpenGl_Context)& OpenGl_GraphicDriver::GetSharedContext() const
+{
+  if (myMapOfWS.IsEmpty())
+  {
+    return TheNullGlCtx;
+  }
+
+  NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)>::Iterator anIter (myMapOfWS);
+  return anIter.Value()->GetGlContext();
+}
+
+// =======================================================================
+// function : MemoryInfo
+// purpose  :
+// =======================================================================
+Standard_Boolean OpenGl_GraphicDriver::MemoryInfo (Standard_Size&           theFreeBytes,
+                                                   TCollection_AsciiString& theInfo) const
+{
+  // this is extra work (for OpenGl_Context initialization)...
+  OpenGl_Context aGlCtx;
+  if (!aGlCtx.Init())
+  {
+    return Standard_False;
+  }
+  theFreeBytes = aGlCtx.AvailableMemory();
+  theInfo      = aGlCtx.MemoryInfo();
+  return !theInfo.IsEmpty();
+}