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