0023428: Extend OpenGl_Context to use Geometry Shaders extension
[occt.git] / src / OpenGl / OpenGl_GraphicDriver.cxx
CommitLineData
b311480e 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
7fd59977 20
2166f0fa 21#include <OpenGl_GraphicDriver.hxx>
7fd59977 22
f0430952 23#include <OpenGl_Context.hxx>
2166f0fa
SK
24#include <OpenGl_View.hxx>
25#include <OpenGl_Workspace.hxx>
7fd59977 26
2166f0fa
SK
27IMPLEMENT_STANDARD_HANDLE(OpenGl_GraphicDriver,Graphic3d_GraphicDriver)
28IMPLEMENT_STANDARD_RTTIEXT(OpenGl_GraphicDriver,Graphic3d_GraphicDriver)
7fd59977 29
2166f0fa
SK
30namespace
31{
5e27df78 32 // Global switch - shared by whole TKOpenGl module. To be removed.
2166f0fa 33 static Standard_Boolean TheToUseVbo = Standard_True;
5e27df78 34
35 static const Handle(OpenGl_Context) TheNullGlCtx;
2166f0fa 36};
7fd59977 37
38// Pour eviter de "mangler" MetaGraphicDriverFactory, le nom de la
39// fonction qui cree un Graphic3d_GraphicDriver.
40// En effet, ce nom est recherche par la methode DlSymb de la
41// classe OSD_SharedLibrary dans la methode SetGraphicDriver de la
42// classe Graphic3d_GraphicDevice
43extern "C" {
5e27df78 44#if defined(_MSC_VER) // disable MS VC++ warning on C-style function returning C++ object
2166f0fa
SK
45 #pragma warning(push)
46 #pragma warning(disable:4190)
7fd59977 47#endif
5e27df78 48 Standard_EXPORT Handle(Graphic3d_GraphicDriver) MetaGraphicDriverFactory (const Standard_CString theShrName)
2166f0fa 49 {
5e27df78 50 Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver (theShrName);
51 return aDriver;
2166f0fa 52 }
5e27df78 53#if defined(_MSC_VER)
2166f0fa 54 #pragma warning(pop)
7fd59977 55#endif
56}
57
f0430952 58// =======================================================================
59// function : OpenGl_GraphicDriver
60// purpose :
61// =======================================================================
2166f0fa 62OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Standard_CString theShrName)
5e27df78 63: Graphic3d_GraphicDriver (theShrName),
64 myMapOfView (1, NCollection_BaseAllocator::CommonBaseAllocator()),
65 myMapOfWS (1, NCollection_BaseAllocator::CommonBaseAllocator()),
66 myMapOfStructure (1, NCollection_BaseAllocator::CommonBaseAllocator()),
67 myUserDrawCallback (NULL)
7fd59977 68{
2166f0fa 69 //
7fd59977 70}
71
f0430952 72// =======================================================================
5e27df78 73// function : UserDrawCallback
f0430952 74// purpose :
75// =======================================================================
5e27df78 76OpenGl_GraphicDriver::OpenGl_UserDrawCallback_t& OpenGl_GraphicDriver::UserDrawCallback()
2166f0fa 77{
5e27df78 78 return myUserDrawCallback;
2166f0fa
SK
79}
80
f0430952 81// =======================================================================
5e27df78 82// function : DefaultTextHeight
f0430952 83// purpose :
84// =======================================================================
5e27df78 85Standard_ShortReal OpenGl_GraphicDriver::DefaultTextHeight() const
2166f0fa 86{
5e27df78 87 return 16.;
2166f0fa
SK
88}
89
f0430952 90// =======================================================================
91// function : InvalidateAllWorkspaces
92// purpose : ex-TsmInitUpdateState, deprecated, need to decide what to do with EraseAnimation() call
93// =======================================================================
2166f0fa
SK
94void OpenGl_GraphicDriver::InvalidateAllWorkspaces()
95{
5e27df78 96 for (NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)>::Iterator anIt (myMapOfWS);
2166f0fa
SK
97 anIt.More(); anIt.Next())
98 {
2166f0fa
SK
99 anIt.ChangeValue()->EraseAnimation();
100 }
101}
102
f0430952 103// =======================================================================
104// function : ToUseVBO
105// purpose :
106// =======================================================================
2166f0fa 107Standard_Boolean OpenGl_GraphicDriver::ToUseVBO()
7fd59977 108{
2166f0fa 109 return TheToUseVbo;
7fd59977 110}
111
f0430952 112// =======================================================================
113// function : EnableVBO
114// purpose :
115// =======================================================================
2166f0fa 116void OpenGl_GraphicDriver::EnableVBO (const Standard_Boolean theToTurnOn)
7fd59977 117{
2166f0fa 118 TheToUseVbo = theToTurnOn;
7fd59977 119}
f0430952 120
121// =======================================================================
5e27df78 122// function : GetSharedContext
123// purpose :
124// =======================================================================
125const Handle(OpenGl_Context)& OpenGl_GraphicDriver::GetSharedContext() const
126{
127 if (myMapOfWS.IsEmpty())
128 {
129 return TheNullGlCtx;
130 }
131
132 NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)>::Iterator anIter (myMapOfWS);
133 return anIter.Value()->GetGlContext();
134}
135
136// =======================================================================
f0430952 137// function : MemoryInfo
138// purpose :
139// =======================================================================
140Standard_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}