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