0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[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>
c357e426 23#include <Aspect_RenderingContext.hxx>
2166f0fa
SK
24#include <Graphic3d_CView.hxx>
25#include <Graphic3d_CStructure.hxx>
2166f0fa 26#include <NCollection_DataMap.hxx>
c357e426 27#include <OpenGl_Context.hxx>
b7c077b9 28
c357e426 29class Aspect_Window;
2166f0fa 30class Quantity_Color;
2166f0fa 31class OpenGl_Structure;
c04c30b3 32class OpenGl_View;
c357e426 33class OpenGl_Window;
2166f0fa 34
392ac980 35//! Tool class to implement consistent state counter
36//! for objects inside the same driver instance.
37class OpenGl_StateCounter
38{
39public:
40
41 OpenGl_StateCounter() : myCounter (0) { }
42
43 Standard_Size Increment() { return ++myCounter; }
44
45private:
25b97fac 46
392ac980 47 Standard_Size myCounter;
48};
49
ebc93ae7 50//! This class defines an OpenGl graphic driver
2166f0fa
SK
51class OpenGl_GraphicDriver : public Graphic3d_GraphicDriver
52{
851dacdb 53 DEFINE_STANDARD_RTTIEXT(OpenGl_GraphicDriver, Graphic3d_GraphicDriver)
bf75be98 54public:
2166f0fa 55
25b97fac 56 //! Constructor.
57 //! @param theDisp connection to display, required on Linux but optional on other systems
05e2200b 58 //! @param theToInitialize perform initialization of default OpenGL context on construction
25b97fac 59 Standard_EXPORT OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisp,
05e2200b 60 const Standard_Boolean theToInitialize = Standard_True);
61
62 //! Destructor.
63 Standard_EXPORT virtual ~OpenGl_GraphicDriver();
64
65 //! Release default context.
66 Standard_EXPORT void ReleaseContext();
67
68 //! Perform initialization of default OpenGL context.
69 Standard_EXPORT Standard_Boolean InitContext();
70
1ce0716b 71#if defined(HAVE_EGL) || defined(HAVE_GLES2) || defined(OCCT_UWP) || defined(__ANDROID__) || defined(__QNX__)
05e2200b 72 //! Initialize default OpenGL context using existing one.
73 //! @param theEglDisplay EGL connection to the Display
74 //! @param theEglContext EGL rendering context
75 //! @param theEglConfig EGL configuration
76 Standard_EXPORT Standard_Boolean InitEglContext (Aspect_Display theEglDisplay,
77 Aspect_RenderingContext theEglContext,
78 void* theEglConfig);
79#endif
65993a95 80
3bffef55 81 //! Request limit of graphic resource of specific type.
82 Standard_EXPORT virtual Standard_Integer InquireLimit (const Graphic3d_TypeOfLimit theType) const Standard_OVERRIDE;
2166f0fa 83
c357e426 84public:
2166f0fa 85
c357e426 86 Standard_EXPORT virtual Handle(Graphic3d_CStructure) CreateStructure (const Handle(Graphic3d_StructureManager)& theManager) Standard_OVERRIDE;
2166f0fa 87
c357e426 88 Standard_EXPORT virtual void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) Standard_OVERRIDE;
679ecdee 89
c357e426 90 Standard_EXPORT virtual Handle(Graphic3d_CView) CreateView (const Handle(Graphic3d_StructureManager)& theMgr) Standard_OVERRIDE;
2166f0fa 91
c357e426 92 Standard_EXPORT virtual void RemoveView (const Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
93
94 Standard_EXPORT virtual Handle(OpenGl_Window) CreateRenderWindow (const Handle(Aspect_Window)& theWindow, const Aspect_RenderingContext theContext);
95
96public:
a79f67f8 97
4b1c8733 98 Standard_EXPORT void TextSize (const Handle(Graphic3d_CView)& theView,
99 const Standard_CString theText,
100 const Standard_ShortReal theHeight,
101 Standard_ShortReal& theWidth,
102 Standard_ShortReal& theAscent,
79104795 103 Standard_ShortReal& theDescent) const Standard_OVERRIDE;
ebc93ae7 104
79104795 105 Standard_EXPORT Standard_ShortReal DefaultTextHeight() const Standard_OVERRIDE;
ebc93ae7 106
c357e426 107 Standard_EXPORT Standard_Boolean ViewExists (const Handle(Aspect_Window)& theWindow, Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
ebc93ae7 108
c357e426 109public:
ebc93ae7 110
c357e426 111 //! Adds a new top-level z layer with ID theLayerId for all views. Z layers allow drawing structures in higher layers
112 //! in foreground of structures in lower layers. To add a structure to desired layer on display it is necessary to
113 //! set the layer index for the structure. The passed theLayerId should be not less than 0 (reserved for default layers).
114 Standard_EXPORT void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
ebc93ae7 115
c357e426 116 //! Removes Z layer. All structures displayed at the moment in layer will be displayed in
117 //! default layer (the bottom-level z layer). By default, there are always default
118 //! bottom-level layer that can't be removed. The passed theLayerId should be not less than 0
119 //! (reserved for default layers that can not be removed).
120 Standard_EXPORT void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
ebc93ae7 121
c357e426 122 //! Sets the settings for a single Z layer.
123 Standard_EXPORT void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
c5751993 124
2166f0fa
SK
125public:
126
58655684 127 //! @return the visualization options
128 inline const OpenGl_Caps& Options() const
129 {
130 return *myCaps.operator->();
131 }
132
133 //! @return the visualization options
134 inline OpenGl_Caps& ChangeOptions()
135 {
136 return *myCaps.operator->();
137 }
2166f0fa 138
62e1beed 139 //! Specify swap buffer behavior.
140 Standard_EXPORT void SetBuffersNoSwap (const Standard_Boolean theIsNoSwap);
141
2166f0fa
SK
142 //! VBO usage can be forbidden by this method even if it is supported by GL driver.
143 //! Notice that disabling of VBO will cause rendering performance degradation.
144 //! Warning! This method should be called only before any primitives are displayed in GL scene!
79104795 145 Standard_EXPORT void EnableVBO (const Standard_Boolean theToTurnOn) Standard_OVERRIDE;
2166f0fa 146
f0430952 147 //! Returns information about GPU memory usage.
148 //! Please read OpenGl_Context::MemoryInfo() for more description.
149 Standard_EXPORT Standard_Boolean MemoryInfo (Standard_Size& theFreeBytes,
79104795 150 TCollection_AsciiString& theInfo) const Standard_OVERRIDE;
f0430952 151
e276548b 152public:
e276548b 153
5e27df78 154 //! Method to retrieve valid GL context.
155 //! Could return NULL-handle if no window created by this driver.
b30b2c13 156 //! @param theBound if TRUE then currently bound context will be returned,
157 //! any context will be returned otherwise
158 Standard_EXPORT const Handle(OpenGl_Context)& GetSharedContext (bool theBound = false) const;
2166f0fa 159
1ce0716b 160#if defined(HAVE_EGL) || defined(HAVE_GLES2) || defined(OCCT_UWP) || defined(__ANDROID__) || defined(__QNX__)
25b97fac 161 Aspect_Display getRawGlDisplay() const { return myEglDisplay; }
162 Aspect_RenderingContext getRawGlContext() const { return myEglContext; }
163 void* getRawGlConfig() const { return myEglConfig; }
164#endif
165
851dacdb 166 //! Set device lost flag for redrawn views.
167 Standard_EXPORT void setDeviceLost();
5e27df78 168
99cfc277 169public:
170
171 //! State counter for OpenGl structures.
172 OpenGl_StateCounter* GetStateCounter() const { return &myStateCounter; }
173
174 //! Returns unique ID for primitive arrays.
175 Standard_Size GetNextPrimitiveArrayUID() const { return myUIDGenerator.Increment(); }
176
62e1beed 177protected:
5e27df78 178
05e2200b 179 Standard_Boolean myIsOwnContext; //!< indicates that shared context has been created within OpenGl_GraphicDriver
1ce0716b 180#if defined(HAVE_EGL) || defined(HAVE_GLES2) || defined(OCCT_UWP) || defined(__ANDROID__) || defined(__QNX__)
05e2200b 181 Aspect_Display myEglDisplay; //!< EGL connection to the Display : EGLDisplay
182 Aspect_RenderingContext myEglContext; //!< EGL rendering context : EGLContext
183 void* myEglConfig; //!< EGL configuration : EGLConfig
25b97fac 184#endif
185
99cfc277 186 Handle(OpenGl_Caps) myCaps;
187 NCollection_Map<Handle(OpenGl_View)> myMapOfView;
188 NCollection_DataMap<Standard_Integer, OpenGl_Structure*> myMapOfStructure;
392ac980 189
8d3f219f 190 mutable OpenGl_StateCounter myStateCounter; //!< State counter for OpenGl structures.
191 mutable OpenGl_StateCounter myUIDGenerator; //!< Unique ID counter for primitive arrays.
392ac980 192
2166f0fa
SK
193};
194
851dacdb 195DEFINE_STANDARD_HANDLE(OpenGl_GraphicDriver, Graphic3d_GraphicDriver)
196
2166f0fa 197#endif //_OpenGl_GraphicDriver_HeaderFile