0029520: Visualization - drop deprecated V3d_View::Export() functionality and depende...
[occt.git] / src / OpenGl / OpenGl_GraphicDriver.hxx
CommitLineData
b311480e 1// Created on: 2011-10-20
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
2166f0fa
SK
16#ifndef _OpenGl_GraphicDriver_HeaderFile
17#define _OpenGl_GraphicDriver_HeaderFile
18
19#include <Graphic3d_GraphicDriver.hxx>
2166f0fa
SK
20
21#include <Aspect_Display.hxx>
dc3fe572 22#include <Aspect_DisplayConnection.hxx>
2166f0fa
SK
23#include <Aspect_GradientFillMethod.hxx>
24#include <Aspect_FillMethod.hxx>
2166f0fa 25#include <Aspect_TypeOfTriedronPosition.hxx>
2166f0fa 26#include <Aspect_Handle.hxx>
c357e426 27#include <Aspect_RenderingContext.hxx>
938d4544 28#include <gp_Ax2.hxx>
2166f0fa
SK
29#include <Graphic3d_CView.hxx>
30#include <Graphic3d_CStructure.hxx>
2166f0fa
SK
31#include <Graphic3d_TextPath.hxx>
32#include <Graphic3d_HorizontalTextAlignment.hxx>
33#include <Graphic3d_VerticalTextAlignment.hxx>
a79f67f8 34#include <Graphic3d_GraduatedTrihedron.hxx>
2166f0fa 35#include <Graphic3d_TypeOfComposition.hxx>
692613e5 36#include <Graphic3d_BufferType.hxx>
2166f0fa 37#include <NCollection_DataMap.hxx>
c357e426 38#include <OpenGl_Context.hxx>
39#include <OpenGl_MapOfZLayerSettings.hxx>
c357e426 40#include <Quantity_NameOfColor.hxx>
41#include <Standard_CString.hxx>
b7c077b9 42#include <TColStd_Array1OfInteger.hxx>
b7c077b9 43#include <TColStd_Array2OfReal.hxx>
44#include <TColStd_HArray1OfByte.hxx>
c357e426 45#include <TColStd_HArray1OfReal.hxx>
46#include <TColStd_MapOfInteger.hxx>
b7c077b9 47
c357e426 48class Aspect_Window;
2166f0fa
SK
49class Quantity_Color;
50class Graphic3d_Vertex;
2166f0fa 51class TCollection_ExtendedString;
692613e5 52class Image_PixMap;
5e27df78 53class OpenGl_Element;
2166f0fa 54class OpenGl_Structure;
a174a3c5 55class OpenGl_Text;
c04c30b3 56class OpenGl_View;
c357e426 57class OpenGl_Window;
2166f0fa 58
392ac980 59//! Tool class to implement consistent state counter
60//! for objects inside the same driver instance.
61class OpenGl_StateCounter
62{
63public:
64
65 OpenGl_StateCounter() : myCounter (0) { }
66
67 Standard_Size Increment() { return ++myCounter; }
68
69private:
25b97fac 70
392ac980 71 Standard_Size myCounter;
72};
73
ebc93ae7 74//! This class defines an OpenGl graphic driver
2166f0fa
SK
75class OpenGl_GraphicDriver : public Graphic3d_GraphicDriver
76{
851dacdb 77 DEFINE_STANDARD_RTTIEXT(OpenGl_GraphicDriver, Graphic3d_GraphicDriver)
bf75be98 78public:
2166f0fa 79
25b97fac 80 //! Constructor.
81 //! @param theDisp connection to display, required on Linux but optional on other systems
05e2200b 82 //! @param theToInitialize perform initialization of default OpenGL context on construction
25b97fac 83 Standard_EXPORT OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp,
05e2200b 84 const Standard_Boolean theToInitialize = Standard_True);
85
86 //! Destructor.
87 Standard_EXPORT virtual ~OpenGl_GraphicDriver();
88
89 //! Release default context.
90 Standard_EXPORT void ReleaseContext();
91
92 //! Perform initialization of default OpenGL context.
93 Standard_EXPORT Standard_Boolean InitContext();
94
1ce0716b 95#if defined(HAVE_EGL) || defined(HAVE_GLES2) || defined(OCCT_UWP) || defined(__ANDROID__) || defined(__QNX__)
05e2200b 96 //! Initialize default OpenGL context using existing one.
97 //! @param theEglDisplay EGL connection to the Display
98 //! @param theEglContext EGL rendering context
99 //! @param theEglConfig EGL configuration
100 Standard_EXPORT Standard_Boolean InitEglContext (Aspect_Display theEglDisplay,
101 Aspect_RenderingContext theEglContext,
102 void* theEglConfig);
103#endif
65993a95 104
3bffef55 105 //! Request limit of graphic resource of specific type.
106 Standard_EXPORT virtual Standard_Integer InquireLimit (const Graphic3d_TypeOfLimit theType) const Standard_OVERRIDE;
2166f0fa 107
c357e426 108public:
2166f0fa 109
c357e426 110 Standard_EXPORT virtual Handle(Graphic3d_CStructure) CreateStructure (const Handle(Graphic3d_StructureManager)& theManager) Standard_OVERRIDE;
2166f0fa 111
c357e426 112 Standard_EXPORT virtual void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) Standard_OVERRIDE;
679ecdee 113
c357e426 114 Standard_EXPORT virtual Handle(Graphic3d_CView) CreateView (const Handle(Graphic3d_StructureManager)& theMgr) Standard_OVERRIDE;
2166f0fa 115
c357e426 116 Standard_EXPORT virtual void RemoveView (const Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
117
118 Standard_EXPORT virtual Handle(OpenGl_Window) CreateRenderWindow (const Handle(Aspect_Window)& theWindow, const Aspect_RenderingContext theContext);
119
120public:
a79f67f8 121
4b1c8733 122 Standard_EXPORT void TextSize (const Handle(Graphic3d_CView)& theView,
123 const Standard_CString theText,
124 const Standard_ShortReal theHeight,
125 Standard_ShortReal& theWidth,
126 Standard_ShortReal& theAscent,
79104795 127 Standard_ShortReal& theDescent) const Standard_OVERRIDE;
ebc93ae7 128
79104795 129 Standard_EXPORT Standard_ShortReal DefaultTextHeight() const Standard_OVERRIDE;
ebc93ae7 130
c357e426 131 Standard_EXPORT Standard_Boolean ViewExists (const Handle(Aspect_Window)& theWindow, Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
ebc93ae7 132
c357e426 133public:
ebc93ae7 134
c357e426 135 //! Adds a new top-level z layer with ID theLayerId for all views. Z layers allow drawing structures in higher layers
136 //! in foreground of structures in lower layers. To add a structure to desired layer on display it is necessary to
137 //! set the layer index for the structure. The passed theLayerId should be not less than 0 (reserved for default layers).
138 Standard_EXPORT void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
ebc93ae7 139
c357e426 140 //! Removes Z layer. All structures displayed at the moment in layer will be displayed in
141 //! default layer (the bottom-level z layer). By default, there are always default
142 //! bottom-level layer that can't be removed. The passed theLayerId should be not less than 0
143 //! (reserved for default layers that can not be removed).
144 Standard_EXPORT void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
ebc93ae7 145
c357e426 146 //! Returns list of Z layers defined for the graphical driver.
147 Standard_EXPORT void ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const Standard_OVERRIDE;
2166f0fa 148
c357e426 149 //! Sets the settings for a single Z layer.
150 Standard_EXPORT void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
c5751993 151
c357e426 152 //! Returns the settings of a single Z layer.
7c3ef2f7 153 Standard_EXPORT virtual const Graphic3d_ZLayerSettings& ZLayerSettings (const Graphic3d_ZLayerId theLayerId) const Standard_OVERRIDE;
b7cd4ba7 154
2166f0fa
SK
155public:
156
58655684 157 //! @return the visualization options
158 inline const OpenGl_Caps& Options() const
159 {
160 return *myCaps.operator->();
161 }
162
163 //! @return the visualization options
164 inline OpenGl_Caps& ChangeOptions()
165 {
166 return *myCaps.operator->();
167 }
2166f0fa 168
62e1beed 169 //! Specify swap buffer behavior.
170 Standard_EXPORT void SetBuffersNoSwap (const Standard_Boolean theIsNoSwap);
171
2166f0fa
SK
172 //! VBO usage can be forbidden by this method even if it is supported by GL driver.
173 //! Notice that disabling of VBO will cause rendering performance degradation.
174 //! Warning! This method should be called only before any primitives are displayed in GL scene!
79104795 175 Standard_EXPORT void EnableVBO (const Standard_Boolean theToTurnOn) Standard_OVERRIDE;
2166f0fa 176
f0430952 177 //! Returns information about GPU memory usage.
178 //! Please read OpenGl_Context::MemoryInfo() for more description.
179 Standard_EXPORT Standard_Boolean MemoryInfo (Standard_Size& theFreeBytes,
79104795 180 TCollection_AsciiString& theInfo) const Standard_OVERRIDE;
f0430952 181
e276548b 182public:
e276548b 183
5e27df78 184 //! Method to retrieve valid GL context.
185 //! Could return NULL-handle if no window created by this driver.
186 Standard_EXPORT const Handle(OpenGl_Context)& GetSharedContext() const;
2166f0fa 187
1ce0716b 188#if defined(HAVE_EGL) || defined(HAVE_GLES2) || defined(OCCT_UWP) || defined(__ANDROID__) || defined(__QNX__)
25b97fac 189 Aspect_Display getRawGlDisplay() const { return myEglDisplay; }
190 Aspect_RenderingContext getRawGlContext() const { return myEglContext; }
191 void* getRawGlConfig() const { return myEglConfig; }
192#endif
193
1593b4ee 194 //! Insert index layer at proper position.
195 Standard_EXPORT void addZLayerIndex (const Graphic3d_ZLayerId theLayerId);
196
851dacdb 197 //! Set device lost flag for redrawn views.
198 Standard_EXPORT void setDeviceLost();
5e27df78 199
99cfc277 200public:
201
202 //! State counter for OpenGl structures.
203 OpenGl_StateCounter* GetStateCounter() const { return &myStateCounter; }
204
205 //! Returns unique ID for primitive arrays.
206 Standard_Size GetNextPrimitiveArrayUID() const { return myUIDGenerator.Increment(); }
207
62e1beed 208protected:
5e27df78 209
05e2200b 210 Standard_Boolean myIsOwnContext; //!< indicates that shared context has been created within OpenGl_GraphicDriver
1ce0716b 211#if defined(HAVE_EGL) || defined(HAVE_GLES2) || defined(OCCT_UWP) || defined(__ANDROID__) || defined(__QNX__)
05e2200b 212 Aspect_Display myEglDisplay; //!< EGL connection to the Display : EGLDisplay
213 Aspect_RenderingContext myEglContext; //!< EGL rendering context : EGLContext
214 void* myEglConfig; //!< EGL configuration : EGLConfig
25b97fac 215#endif
216
99cfc277 217 Handle(OpenGl_Caps) myCaps;
218 NCollection_Map<Handle(OpenGl_View)> myMapOfView;
219 NCollection_DataMap<Standard_Integer, OpenGl_Structure*> myMapOfStructure;
392ac980 220
c357e426 221 TColStd_MapOfInteger myLayerIds;
222 TColStd_SequenceOfInteger myLayerSeq;
223 OpenGl_MapOfZLayerSettings myMapOfZLayerSettings;
224
8d3f219f 225 mutable OpenGl_StateCounter myStateCounter; //!< State counter for OpenGl structures.
226 mutable OpenGl_StateCounter myUIDGenerator; //!< Unique ID counter for primitive arrays.
392ac980 227
2166f0fa
SK
228};
229
851dacdb 230DEFINE_STANDARD_HANDLE(OpenGl_GraphicDriver, Graphic3d_GraphicDriver)
231
2166f0fa 232#endif //_OpenGl_GraphicDriver_HeaderFile