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