0024752: Visualization - inherit OpenGl_Group from Graphic3d_Group
[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>
20#include <Handle_OpenGl_GraphicDriver.hxx>
fd4a6963 21#include <Handle_OpenGl_Display.hxx>
5e27df78 22#include <OpenGl_Context.hxx>
a174a3c5 23#include <OpenGl_PrinterContext.hxx>
2166f0fa
SK
24
25#include <Standard_CString.hxx>
26
27#include <Handle_TColStd_HArray1OfByte.hxx>
28#include <Handle_TColStd_HArray1OfReal.hxx>
29#include <Quantity_PlaneAngle.hxx>
30#include <Quantity_NameOfColor.hxx>
bf75be98 31#include <Handle_OpenGl_View.hxx>
1981cb22 32#include <Handle_OpenGl_Workspace.hxx>
2166f0fa
SK
33
34#include <Aspect_Display.hxx>
dc3fe572 35#include <Aspect_DisplayConnection.hxx>
2166f0fa
SK
36#include <Aspect_GradientFillMethod.hxx>
37#include <Aspect_FillMethod.hxx>
38#include <Aspect_CLayer2d.hxx>
39#include <Aspect_TypeOfTriedronPosition.hxx>
40#include <Aspect_TypeOfTriedronEcho.hxx>
41#include <Aspect_Handle.hxx>
42#include <Aspect_PrintAlgo.hxx>
938d4544 43#include <gp_Ax2.hxx>
2166f0fa
SK
44#include <Graphic3d_CView.hxx>
45#include <Graphic3d_CStructure.hxx>
2166f0fa
SK
46#include <Graphic3d_TypeOfPrimitive.hxx>
47#include <Graphic3d_CPick.hxx>
2166f0fa
SK
48#include <Graphic3d_TextPath.hxx>
49#include <Graphic3d_HorizontalTextAlignment.hxx>
50#include <Graphic3d_VerticalTextAlignment.hxx>
51#include <Graphic3d_PrimitiveArray.hxx>
52#include <Graphic3d_CUserDraw.hxx>
53#include <Graphic3d_CGraduatedTrihedron.hxx>
54#include <Graphic3d_TypeOfComposition.hxx>
2166f0fa
SK
55#include <Graphic3d_ExportFormat.hxx>
56#include <Graphic3d_SortType.hxx>
57#include <Graphic3d_PtrFrameBuffer.hxx>
58#include <Graphic3d_Array1OfVertex.hxx>
2166f0fa 59#include <Graphic3d_Array2OfVertex.hxx>
692613e5 60#include <Graphic3d_BufferType.hxx>
2166f0fa
SK
61#include <NCollection_DataMap.hxx>
62
63class TColStd_Array1OfInteger;
64class TColStd_Array1OfReal;
65class TColStd_Array2OfReal;
66class TColStd_HArray1OfByte;
2166f0fa
SK
67class Graphic3d_Vector;
68class Quantity_Color;
69class Graphic3d_Vertex;
70class Aspect_Array1OfEdge;
71class TCollection_ExtendedString;
692613e5 72class Image_PixMap;
2166f0fa 73class TColStd_HArray1OfReal;
2166f0fa 74class Handle(OpenGl_Workspace);
5e27df78 75class OpenGl_Element;
2166f0fa 76class OpenGl_Structure;
a174a3c5 77class OpenGl_Text;
2166f0fa 78
392ac980 79//! Tool class to implement consistent state counter
80//! for objects inside the same driver instance.
81class OpenGl_StateCounter
82{
83public:
84
85 OpenGl_StateCounter() : myCounter (0) { }
86
87 Standard_Size Increment() { return ++myCounter; }
88
89private:
90
91 Standard_Size myCounter;
92};
93
ebc93ae7 94//! This class defines an OpenGl graphic driver
2166f0fa
SK
95class OpenGl_GraphicDriver : public Graphic3d_GraphicDriver
96{
bf75be98 97public:
2166f0fa
SK
98
99 //! Constructor
65993a95 100 Standard_EXPORT OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnection)& theDisplayConnection);
2166f0fa 101
65993a95 102 //! Constructor
103 Standard_EXPORT OpenGl_GraphicDriver (const Standard_CString theShrName = "TKOpenGl");
dc3fe572 104 Standard_EXPORT Standard_Boolean Begin (const Handle(Aspect_DisplayConnection)& theDisplayConnection);
2166f0fa 105 Standard_EXPORT void End ();
65993a95 106
2166f0fa 107 Standard_EXPORT Standard_Integer InquireLightLimit ();
2166f0fa 108 Standard_EXPORT Standard_Integer InquireViewLimit ();
2166f0fa 109
2166f0fa
SK
110public: // Methods for graphical structures
111
63bcc448 112 Standard_EXPORT void DisplayStructure (const Graphic3d_CView& theCView,
113 Graphic3d_CStructure& theCStructure,
114 const Standard_Integer thePriority);
115 Standard_EXPORT void EraseStructure (const Graphic3d_CView& theCView,
116 Graphic3d_CStructure& theCStructure);
117 Standard_EXPORT void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure);
118 Standard_EXPORT Handle(Graphic3d_CStructure) Structure (const Handle(Graphic3d_StructureManager)& theManager);
2166f0fa 119
679ecdee 120 Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Graphic3d_CView& theCView,
121 const Standard_Boolean theDrawToFrontBuffer);
122 Standard_EXPORT void DisplayImmediateStructure (const Graphic3d_CView& theCView,
123 const Graphic3d_CStructure& theCStructure);
124 Standard_EXPORT void EraseImmediateStructure (const Graphic3d_CView& theCView,
125 const Graphic3d_CStructure& theCStructure);
126
2166f0fa
SK
127public:
128
2166f0fa
SK
129 Standard_EXPORT void ActivateView (const Graphic3d_CView& ACView);
130 Standard_EXPORT void AntiAliasing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag);
131 Standard_EXPORT void Background (const Graphic3d_CView& ACView);
132 Standard_EXPORT void GradientBackground (const Graphic3d_CView& ACView, const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod FillStyle);
133 Standard_EXPORT void BackgroundImage (const Standard_CString FileName, const Graphic3d_CView& ACView, const Aspect_FillMethod FillStyle);
134 Standard_EXPORT void SetBgImageStyle (const Graphic3d_CView& ACView, const Aspect_FillMethod FillStyle);
135 Standard_EXPORT void SetBgGradientStyle (const Graphic3d_CView& ACView, const Aspect_GradientFillMethod FillStyle);
136 Standard_EXPORT void ClipLimit (const Graphic3d_CView& ACView, const Standard_Boolean AWait);
137 Standard_EXPORT void DeactivateView (const Graphic3d_CView& ACView);
138 Standard_EXPORT void DepthCueing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag);
2166f0fa 139 Standard_EXPORT void RatioWindow (const Graphic3d_CView& ACView);
679ecdee 140 Standard_EXPORT void Redraw (const Graphic3d_CView& theCView,
141 const Aspect_CLayer2d& theCUnderLayer,
142 const Aspect_CLayer2d& theCOverLayer,
143 const Standard_Integer theX = 0,
144 const Standard_Integer theY = 0,
145 const Standard_Integer theWidth = 0,
146 const Standard_Integer theHeight = 0);
147 Standard_EXPORT void RedrawImmediate (const Graphic3d_CView& theCView,
148 const Aspect_CLayer2d& theCUnderLayer,
149 const Aspect_CLayer2d& theCOverLayer);
150 Standard_EXPORT void Invalidate (const Graphic3d_CView& theCView);
2166f0fa
SK
151 Standard_EXPORT void RemoveView (const Graphic3d_CView& ACView);
152 Standard_EXPORT void SetLight (const Graphic3d_CView& ACView);
4269bd1b 153 Standard_EXPORT void SetClipPlanes (const Graphic3d_CView& theCView);
b5ac8292 154 Standard_EXPORT void SetCamera (const Graphic3d_CView& theCView);
2166f0fa 155 Standard_EXPORT void SetVisualisation (const Graphic3d_CView& ACView);
2166f0fa 156 Standard_EXPORT void Transparency (const Graphic3d_CView& ACView, const Standard_Boolean AFlag);
2166f0fa 157 Standard_EXPORT Standard_Boolean View (Graphic3d_CView& ACView);
2166f0fa 158 Standard_EXPORT void Environment (const Graphic3d_CView& ACView);
2166f0fa
SK
159 Standard_EXPORT void ZBufferTriedronSetup (const Quantity_NameOfColor XColor = Quantity_NOC_RED, const Quantity_NameOfColor YColor = Quantity_NOC_GREEN, const Quantity_NameOfColor ZColor = Quantity_NOC_BLUE1, const Standard_Real SizeRatio = 0.8, const Standard_Real AxisDiametr = 0.05, const Standard_Integer NbFacettes = 12);
160 Standard_EXPORT void TriedronDisplay (const Graphic3d_CView& ACView, const Aspect_TypeOfTriedronPosition APosition = Aspect_TOTP_CENTER, const Quantity_NameOfColor AColor = Quantity_NOC_WHITE, const Standard_Real AScale = 0.02, const Standard_Boolean AsWireframe = Standard_True);
161 Standard_EXPORT void TriedronErase (const Graphic3d_CView& ACView);
162 Standard_EXPORT void TriedronEcho (const Graphic3d_CView& ACView, const Aspect_TypeOfTriedronEcho AType = Aspect_TOTE_NONE);
163 Standard_EXPORT void GraduatedTrihedronDisplay (const Graphic3d_CView& view, const Graphic3d_CGraduatedTrihedron& cubic);
164 Standard_EXPORT void GraduatedTrihedronErase (const Graphic3d_CView& view);
165 Standard_EXPORT void GraduatedTrihedronMinMaxValues (const Standard_ShortReal xmin, const Standard_ShortReal ymin, const Standard_ShortReal zmin, const Standard_ShortReal xmax, const Standard_ShortReal ymax, const Standard_ShortReal zmax);
2166f0fa
SK
166 Standard_EXPORT void Layer (Aspect_CLayer2d& ACLayer);
167 Standard_EXPORT void RemoveLayer (const Aspect_CLayer2d& ACLayer);
168 Standard_EXPORT void BeginLayer (const Aspect_CLayer2d& ACLayer);
169 Standard_EXPORT void BeginPolygon2d ();
170 Standard_EXPORT void BeginPolyline2d ();
171 Standard_EXPORT void ClearLayer (const Aspect_CLayer2d& ACLayer);
172 Standard_EXPORT void Draw (const Standard_ShortReal X,const Standard_ShortReal Y);
173 Standard_EXPORT void Edge (const Standard_ShortReal X,const Standard_ShortReal Y);
174 Standard_EXPORT void EndLayer ();
175 Standard_EXPORT void EndPolygon2d ();
176 Standard_EXPORT void EndPolyline2d ();
177 Standard_EXPORT void Move (const Standard_ShortReal X,const Standard_ShortReal Y);
178 Standard_EXPORT void Rectangle (const Standard_ShortReal X,const Standard_ShortReal Y,const Standard_ShortReal Width,const Standard_ShortReal Height);
179 Standard_EXPORT void SetColor (const Standard_ShortReal R,const Standard_ShortReal G,const Standard_ShortReal B);
180 Standard_EXPORT void SetTransparency (const Standard_ShortReal ATransparency);
181 Standard_EXPORT void UnsetTransparency ();
182 Standard_EXPORT void SetLineAttributes (const Standard_Integer Type,const Standard_ShortReal Width);
25289ec1 183
ebc93ae7 184 //! Set text attributes for under-/overlayer.
185 //! @param theFontName the name of the font to be used
186 //! @param theType the display type of the text
187 //! theR theG theB values define the color of decal or subtitle background
188 //! To set the color of the text you can use the SetColor method.
189 Standard_EXPORT void SetTextAttributes (const Standard_CString theFontName,
190 const Standard_Integer theType,
191 const Standard_ShortReal theR,
192 const Standard_ShortReal theG,
193 const Standard_ShortReal theB);
2166f0fa
SK
194 Standard_EXPORT void Text (const Standard_CString AText,const Standard_ShortReal X,const Standard_ShortReal Y,const Standard_ShortReal AHeight);
195 Standard_EXPORT void TextSize (const Standard_CString AText,const Standard_ShortReal AHeight,Standard_ShortReal& AWidth,Standard_ShortReal& AnAscent,Standard_ShortReal& ADescent) const;
196 Standard_EXPORT void SetBackFacingModel (const Graphic3d_CView& aView);
ebc93ae7 197
198 //! Print the contents of all layers of the view to the printer.
199 //! @param thePrinterDC pass the PrinterDeviceContext (HDC)
200 //! @param theToShowBackground when set to FALSE then print the view without background color (background is white) else set to TRUE for printing with current background color
201 //! @param theFileName if != NULL, then the view will be printed to a file
202 //! @param thePrintAlgorithm select print algorithm: stretch, tile
203 //! @param theScaleFactor scaling coefficient, used internally to scale the printings accordingly to the scale factor selected in the printer properties dialog
204 //! @return Standard_True if the data is passed to the printer, otherwise Standard_False if the print operation failed due to the printer errors,
205 //! or lack of system memory. This might be related to insufficient memory or some internal errors.
206 //! All this errors are indicated by the message boxes (on level of OpenGl_GraphicDriver).
207 //! Warning: This function can reuse FBO assigned to the view, please take it into account if you use it for your purposes.
208 Standard_EXPORT Standard_Boolean Print (const Graphic3d_CView& theCView,
209 const Aspect_CLayer2d& theCUnderLayer,
210 const Aspect_CLayer2d& theCOverLayer,
211 const Aspect_Handle thePrinterDC,
212 const Standard_Boolean theToShowBackground,
213 const Standard_CString theFileName,
214 const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH,
215 const Standard_Real theScaleFactor = 1.0) const;
2166f0fa
SK
216 Standard_EXPORT void SetDepthTestEnabled (const Graphic3d_CView& view,const Standard_Boolean isEnabled) const;
217 Standard_EXPORT Standard_Boolean IsDepthTestEnabled (const Graphic3d_CView& view) const;
ebc93ae7 218
219 //! Reads depths of shown pixels of the given rectangle (glReadPixels with GL_DEPTH_COMPONENT)
2166f0fa 220 Standard_EXPORT void ReadDepths (const Graphic3d_CView& view,const Standard_Integer x,const Standard_Integer y,const Standard_Integer width,const Standard_Integer height,const Standard_Address buffer) const;
ebc93ae7 221
222 //! Generate offscreen FBO (needs OpenGL2+ hardware).
223 //! If not supported on hardware returns NULL.
2166f0fa 224 Standard_EXPORT Graphic3d_PtrFrameBuffer FBOCreate (const Graphic3d_CView& view, const Standard_Integer width, const Standard_Integer height);
ebc93ae7 225
226 //! Remove offscreen FBO
2166f0fa 227 Standard_EXPORT void FBORelease (const Graphic3d_CView& view, Graphic3d_PtrFrameBuffer& fboPtr);
ebc93ae7 228
229 //! Dump active rendering buffer into specified memory buffer.
692613e5 230 Standard_EXPORT Standard_Boolean BufferDump (const Graphic3d_CView& theCView,
231 Image_PixMap& theImage,
232 const Graphic3d_BufferType& theBufferType);
ebc93ae7 233
2166f0fa 234 Standard_EXPORT void SetGLLightEnabled (const Graphic3d_CView& view,const Standard_Boolean isEnabled) const;
ebc93ae7 235
2166f0fa 236 Standard_EXPORT Standard_Boolean IsGLLightEnabled (const Graphic3d_CView& view) const;
ebc93ae7 237
2166f0fa 238 Standard_EXPORT Standard_Integer InquirePlaneLimit();
ebc93ae7 239
2166f0fa 240 Standard_EXPORT Standard_ShortReal DefaultTextHeight() const;
ebc93ae7 241
2166f0fa 242 Standard_EXPORT void FBOGetDimensions(const Graphic3d_CView& view,const Graphic3d_PtrFrameBuffer fboPtr,Standard_Integer& width,Standard_Integer& height,Standard_Integer& widthMax,Standard_Integer& heightMax);
ebc93ae7 243
2166f0fa 244 Standard_EXPORT void FBOChangeViewport(const Graphic3d_CView& view,Graphic3d_PtrFrameBuffer& fboPtr,const Standard_Integer width,const Standard_Integer height);
ebc93ae7 245
2166f0fa 246 Standard_EXPORT Standard_Boolean Export(const Standard_CString theFileName,const Graphic3d_ExportFormat theFormat,const Graphic3d_SortType theSortType,const Standard_Integer theWidth,const Standard_Integer theHeight,const Graphic3d_CView& theView,const Aspect_CLayer2d& theLayerUnder,const Aspect_CLayer2d& theLayerOver,const Standard_Real thePrecision = 0.005,const Standard_Address theProgressBarFunc = NULL,const Standard_Address theProgressObject = NULL);
3c3131a0 247
ebc93ae7 248 //! Add a new top-level z layer with ID theLayerId for the view. Z layers allow drawing structures in higher layers in foreground of structures in lower layers.
249 //! To add a structure to desired layer on display it is necessary to set the layer index for the structure.
250 Standard_EXPORT void AddZLayer (const Graphic3d_CView& theCView,
251 const Standard_Integer theLayerId);
252
253 //! Remove Z layer from the specified view.
254 //! All structures displayed at the moment in layer will be displayed in default layer (the bottom-level z layer).
255 //! To unset layer index from associated structures use method UnsetZLayer (...).
256 Standard_EXPORT void RemoveZLayer (const Graphic3d_CView& theCView,
257 const Standard_Integer theLayerId);
258
259 //! Unset Z layer ID for all structures.
260 //! The structure indexes will be set to default layer (the bottom-level z layer with ID = 0).
261 Standard_EXPORT void UnsetZLayer (const Standard_Integer theLayerId);
262
263 //! Change Z layer of a structure.
264 //! The new z layer ID will be used to define the associated layer for structure on display.
265 //! It is recommended to take care of redisplaying the structures already presented in view with previously set layer index.
266 //! This is usually done by viewer manager. Z layers allow drawing structures in higher layers in foreground of structures in lower layers.
267 Standard_EXPORT void ChangeZLayer (const Graphic3d_CStructure& theCStructure,
268 const Standard_Integer theLayerId);
269
270 //! Change Z layer of a structure already presented in view.
271 //! It is recommended to update z layer of already displayed structures with this method before setting new z layer index to the structure.
272 //! This is usually done by viewer manager.
273 Standard_EXPORT void ChangeZLayer (const Graphic3d_CStructure& theCStructure,
274 const Graphic3d_CView& theCView,
275 const Standard_Integer theNewLayerId);
276
277 //! Get Z layer ID of the structure. If the structure doesn't exists in graphic driver, the method returns -1.
278 Standard_EXPORT Standard_Integer GetZLayer (const Graphic3d_CStructure& theCStructure) const;
2166f0fa
SK
279
280public:
281
58655684 282 //! @return the visualization options
283 inline const OpenGl_Caps& Options() const
284 {
285 return *myCaps.operator->();
286 }
287
288 //! @return the visualization options
289 inline OpenGl_Caps& ChangeOptions()
290 {
291 return *myCaps.operator->();
292 }
2166f0fa
SK
293
294 //! VBO usage can be forbidden by this method even if it is supported by GL driver.
295 //! Notice that disabling of VBO will cause rendering performance degradation.
296 //! Warning! This method should be called only before any primitives are displayed in GL scene!
297 Standard_EXPORT void EnableVBO (const Standard_Boolean theToTurnOn);
298
f0430952 299 //! Returns information about GPU memory usage.
300 //! Please read OpenGl_Context::MemoryInfo() for more description.
301 Standard_EXPORT Standard_Boolean MemoryInfo (Standard_Size& theFreeBytes,
302 TCollection_AsciiString& theInfo) const;
303
5e27df78 304 //! UserDraw function prototype
305 typedef OpenGl_Element* (*OpenGl_UserDrawCallback_t )(const CALL_DEF_USERDRAW* );
2166f0fa 306
5e27df78 307 //! Method to setup UserDraw callback
308 Standard_EXPORT OpenGl_UserDrawCallback_t& UserDrawCallback();
2166f0fa 309
e276548b 310public:
311
312 //! Returns information about OpenCL device used for computations.
313 Standard_EXPORT Standard_Boolean GetOpenClDeviceInfo (const Graphic3d_CView& theCView,
314 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>& theInfo);
315
5e27df78 316 //! Method to retrieve valid GL context.
317 //! Could return NULL-handle if no window created by this driver.
318 Standard_EXPORT const Handle(OpenGl_Context)& GetSharedContext() const;
2166f0fa 319
2166f0fa
SK
320public:
321
322 DEFINE_STANDARD_RTTI(OpenGl_GraphicDriver)
5e27df78 323
324private:
325
fd4a6963 326 Handle(OpenGl_Display) myGlDisplay;
58655684 327 Handle(OpenGl_Caps) myCaps;
5e27df78 328 NCollection_DataMap<Standard_Integer, Handle(OpenGl_View)> myMapOfView;
329 NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)> myMapOfWS;
330 NCollection_DataMap<Standard_Integer, OpenGl_Structure*> myMapOfStructure;
a174a3c5 331 mutable Handle(OpenGl_PrinterContext) myPrintContext;
5e27df78 332 OpenGl_UserDrawCallback_t myUserDrawCallback;
a174a3c5 333 OpenGl_Text* myTempText; //!< variable for compatibility (drawing text in layers)
5e27df78 334
392ac980 335public:
336
337 OpenGl_StateCounter* GetStateCounter() const { return &myStateCounter; }
338
339private:
340
341 mutable OpenGl_StateCounter myStateCounter;
342
2166f0fa
SK
343};
344
345#endif //_OpenGl_GraphicDriver_HeaderFile