0032308: Configuration - make Xlib dependency optional
[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
05e2200b 71 //! Initialize default OpenGL context using existing one.
72 //! @param theEglDisplay EGL connection to the Display
73 //! @param theEglContext EGL rendering context
74 //! @param theEglConfig EGL configuration
75 Standard_EXPORT Standard_Boolean InitEglContext (Aspect_Display theEglDisplay,
76 Aspect_RenderingContext theEglContext,
77 void* theEglConfig);
65993a95 78
3bffef55 79 //! Request limit of graphic resource of specific type.
80 Standard_EXPORT virtual Standard_Integer InquireLimit (const Graphic3d_TypeOfLimit theType) const Standard_OVERRIDE;
2166f0fa 81
c357e426 82public:
2166f0fa 83
c357e426 84 Standard_EXPORT virtual Handle(Graphic3d_CStructure) CreateStructure (const Handle(Graphic3d_StructureManager)& theManager) Standard_OVERRIDE;
2166f0fa 85
c357e426 86 Standard_EXPORT virtual void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) Standard_OVERRIDE;
679ecdee 87
c357e426 88 Standard_EXPORT virtual Handle(Graphic3d_CView) CreateView (const Handle(Graphic3d_StructureManager)& theMgr) Standard_OVERRIDE;
2166f0fa 89
c357e426 90 Standard_EXPORT virtual void RemoveView (const Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
91
92 Standard_EXPORT virtual Handle(OpenGl_Window) CreateRenderWindow (const Handle(Aspect_Window)& theWindow, const Aspect_RenderingContext theContext);
93
94public:
a79f67f8 95
4b1c8733 96 Standard_EXPORT void TextSize (const Handle(Graphic3d_CView)& theView,
97 const Standard_CString theText,
98 const Standard_ShortReal theHeight,
99 Standard_ShortReal& theWidth,
100 Standard_ShortReal& theAscent,
79104795 101 Standard_ShortReal& theDescent) const Standard_OVERRIDE;
ebc93ae7 102
79104795 103 Standard_EXPORT Standard_ShortReal DefaultTextHeight() const Standard_OVERRIDE;
ebc93ae7 104
c357e426 105 Standard_EXPORT Standard_Boolean ViewExists (const Handle(Aspect_Window)& theWindow, Handle(Graphic3d_CView)& theView) Standard_OVERRIDE;
ebc93ae7 106
c357e426 107public:
ebc93ae7 108
1c728f2d 109 //! Adds a layer to all views.
110 //! @param theLayerId [in] id of new layer, should be > 0 (negative values are reserved for default layers).
111 //! @param theSettings [in] new layer settings
112 //! @param theLayerAfter [in] id of layer to append new layer before
113 Standard_EXPORT virtual void InsertLayerBefore (const Graphic3d_ZLayerId theNewLayerId,
114 const Graphic3d_ZLayerSettings& theSettings,
115 const Graphic3d_ZLayerId theLayerAfter) Standard_OVERRIDE;
116
117 //! Adds a layer to all views.
118 //! @param theLayerId [in] id of created layer
119 //! @param theSettings [in] new layer settings
120 //! @param theLayerBefore [in] id of layer to append new layer after
121 Standard_EXPORT virtual void InsertLayerAfter (const Graphic3d_ZLayerId theNewLayerId,
122 const Graphic3d_ZLayerSettings& theSettings,
123 const Graphic3d_ZLayerId theLayerBefore) Standard_OVERRIDE;
ebc93ae7 124
c357e426 125 //! Removes Z layer. All structures displayed at the moment in layer will be displayed in
126 //! default layer (the bottom-level z layer). By default, there are always default
127 //! bottom-level layer that can't be removed. The passed theLayerId should be not less than 0
128 //! (reserved for default layers that can not be removed).
129 Standard_EXPORT void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
ebc93ae7 130
c357e426 131 //! Sets the settings for a single Z layer.
132 Standard_EXPORT void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
c5751993 133
2166f0fa
SK
134public:
135
58655684 136 //! @return the visualization options
137 inline const OpenGl_Caps& Options() const
138 {
139 return *myCaps.operator->();
140 }
141
142 //! @return the visualization options
143 inline OpenGl_Caps& ChangeOptions()
144 {
145 return *myCaps.operator->();
146 }
2166f0fa 147
62e1beed 148 //! Specify swap buffer behavior.
149 Standard_EXPORT void SetBuffersNoSwap (const Standard_Boolean theIsNoSwap);
150
2166f0fa
SK
151 //! VBO usage can be forbidden by this method even if it is supported by GL driver.
152 //! Notice that disabling of VBO will cause rendering performance degradation.
153 //! Warning! This method should be called only before any primitives are displayed in GL scene!
b8db9379 154 Standard_EXPORT virtual void EnableVBO (const Standard_Boolean theToTurnOn) Standard_OVERRIDE;
155
156
157 //! Returns TRUE if vertical synchronization with display refresh rate (VSync) should be used; TRUE by default.
158 Standard_EXPORT virtual bool IsVerticalSync() const Standard_OVERRIDE;
159
160 //! Set if vertical synchronization with display refresh rate (VSync) should be used.
161 Standard_EXPORT virtual void SetVerticalSync (bool theToEnable) Standard_OVERRIDE;
2166f0fa 162
f0430952 163 //! Returns information about GPU memory usage.
164 //! Please read OpenGl_Context::MemoryInfo() for more description.
165 Standard_EXPORT Standard_Boolean MemoryInfo (Standard_Size& theFreeBytes,
79104795 166 TCollection_AsciiString& theInfo) const Standard_OVERRIDE;
f0430952 167
e276548b 168public:
e276548b 169
5e27df78 170 //! Method to retrieve valid GL context.
171 //! Could return NULL-handle if no window created by this driver.
b30b2c13 172 //! @param theBound if TRUE then currently bound context will be returned,
173 //! any context will be returned otherwise
174 Standard_EXPORT const Handle(OpenGl_Context)& GetSharedContext (bool theBound = false) const;
2166f0fa 175
25b97fac 176 Aspect_Display getRawGlDisplay() const { return myEglDisplay; }
177 Aspect_RenderingContext getRawGlContext() const { return myEglContext; }
178 void* getRawGlConfig() const { return myEglConfig; }
25b97fac 179
851dacdb 180 //! Set device lost flag for redrawn views.
181 Standard_EXPORT void setDeviceLost();
5e27df78 182
99cfc277 183public:
184
185 //! State counter for OpenGl structures.
186 OpenGl_StateCounter* GetStateCounter() const { return &myStateCounter; }
187
188 //! Returns unique ID for primitive arrays.
189 Standard_Size GetNextPrimitiveArrayUID() const { return myUIDGenerator.Increment(); }
190
3ae8c60b 191protected:
192
193 //! Choose default visual for new windows created by Aspect_DisplayConnection.
194 Standard_EXPORT void chooseVisualInfo();
195
62e1beed 196protected:
5e27df78 197
05e2200b 198 Standard_Boolean myIsOwnContext; //!< indicates that shared context has been created within OpenGl_GraphicDriver
b8ef513c 199
05e2200b 200 Aspect_Display myEglDisplay; //!< EGL connection to the Display : EGLDisplay
201 Aspect_RenderingContext myEglContext; //!< EGL rendering context : EGLContext
202 void* myEglConfig; //!< EGL configuration : EGLConfig
25b97fac 203
99cfc277 204 Handle(OpenGl_Caps) myCaps;
205 NCollection_Map<Handle(OpenGl_View)> myMapOfView;
206 NCollection_DataMap<Standard_Integer, OpenGl_Structure*> myMapOfStructure;
c357e426 207
8d3f219f 208 mutable OpenGl_StateCounter myStateCounter; //!< State counter for OpenGl structures.
209 mutable OpenGl_StateCounter myUIDGenerator; //!< Unique ID counter for primitive arrays.
392ac980 210
2166f0fa
SK
211};
212
851dacdb 213DEFINE_STANDARD_HANDLE(OpenGl_GraphicDriver, Graphic3d_GraphicDriver)
214
2166f0fa 215#endif //_OpenGl_GraphicDriver_HeaderFile