0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / Graphic3d / Graphic3d_GraphicDriver.hxx
... / ...
CommitLineData
1// Created on: 1997-01-28
2// Created by: CAL
3// Copyright (c) 1997-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _Graphic3d_GraphicDriver_HeaderFile
18#define _Graphic3d_GraphicDriver_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_Type.hxx>
22
23#include <Standard_Integer.hxx>
24#include <Aspect_DisplayConnection.hxx>
25#include <Standard_Boolean.hxx>
26#include <MMgt_TShared.hxx>
27#include <Graphic3d_CView.hxx>
28#include <Graphic3d_CStructure.hxx>
29#include <Aspect_GradientFillMethod.hxx>
30#include <Standard_CString.hxx>
31#include <Aspect_FillMethod.hxx>
32#include <Aspect_CLayer2d.hxx>
33#include <Standard_Size.hxx>
34#include <Quantity_NameOfColor.hxx>
35#include <Standard_Real.hxx>
36#include <Aspect_TypeOfTriedronPosition.hxx>
37#include <Aspect_TypeOfTriedronEcho.hxx>
38#include <Graphic3d_GraduatedTrihedron.hxx>
39#include <Graphic3d_Vec3.hxx>
40#include <Standard_ShortReal.hxx>
41#include <Standard_Address.hxx>
42#include <Graphic3d_PtrFrameBuffer.hxx>
43#include <Image_PixMap.hxx>
44#include <Graphic3d_BufferType.hxx>
45#include <Aspect_Handle.hxx>
46#include <Aspect_PrintAlgo.hxx>
47#include <Graphic3d_ExportFormat.hxx>
48#include <Graphic3d_SortType.hxx>
49#include <Graphic3d_ZLayerId.hxx>
50#include <Graphic3d_ZLayerSettings.hxx>
51#include <Graphic3d_CLight.hxx>
52#include <TColStd_Array2OfReal.hxx>
53class Graphic3d_TransformError;
54class Graphic3d_Structure;
55class Graphic3d_StructureManager;
56class Quantity_Color;
57class TCollection_AsciiString;
58
59
60class Graphic3d_GraphicDriver;
61DEFINE_STANDARD_HANDLE(Graphic3d_GraphicDriver, MMgt_TShared)
62
63//! This class allows the definition of a graphic driver
64//! for 3d interface (currently only OpenGl driver is used).
65class Graphic3d_GraphicDriver : public MMgt_TShared
66{
67
68public:
69
70
71 //! call_togl_inquirelight
72 Standard_EXPORT virtual Standard_Integer InquireLightLimit() = 0;
73
74 //! call_togl_inquireplane
75 Standard_EXPORT virtual Standard_Integer InquirePlaneLimit() = 0;
76
77 //! call_togl_inquireview
78 Standard_EXPORT virtual Standard_Integer InquireViewLimit() = 0;
79
80 //! call_togl_displaystructure
81 Standard_EXPORT virtual void DisplayStructure (const Graphic3d_CView& theCView, const Handle(Graphic3d_Structure)& theStructure, const Standard_Integer thePriority) = 0;
82
83 //! call_togl_erasestructure
84 Standard_EXPORT virtual void EraseStructure (const Graphic3d_CView& theCView, const Handle(Graphic3d_Structure)& theStructure) = 0;
85
86 //! call_togl_removestructure
87 Standard_EXPORT virtual void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) = 0;
88
89 //! Creates new empty graphic structure
90 Standard_EXPORT virtual Handle(Graphic3d_CStructure) Structure (const Handle(Graphic3d_StructureManager)& theManager) = 0;
91
92 //! call_togl_activateview
93 Standard_EXPORT virtual void ActivateView (const Graphic3d_CView& ACView) = 0;
94
95 //! call_togl_antialiasing
96 Standard_EXPORT virtual void AntiAliasing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) = 0;
97
98 //! call_togl_background
99 Standard_EXPORT virtual void Background (const Graphic3d_CView& ACView) = 0;
100
101 //! call_togl_gradient_background
102 Standard_EXPORT virtual void GradientBackground (const Graphic3d_CView& ACView, const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod FillStyle) = 0;
103
104 Standard_EXPORT virtual void BackgroundImage (const Standard_CString FileName, const Graphic3d_CView& ACView, const Aspect_FillMethod FillStyle) = 0;
105
106 Standard_EXPORT virtual void SetBgImageStyle (const Graphic3d_CView& ACView, const Aspect_FillMethod FillStyle) = 0;
107
108 Standard_EXPORT virtual void SetBgGradientStyle (const Graphic3d_CView& ACView, const Aspect_GradientFillMethod FillStyle) = 0;
109
110 //! call_togl_cliplimit
111 Standard_EXPORT virtual void ClipLimit (const Graphic3d_CView& ACView, const Standard_Boolean AWait) = 0;
112
113 //! call_togl_deactivateview
114 Standard_EXPORT virtual void DeactivateView (const Graphic3d_CView& ACView) = 0;
115
116 //! call_togl_cliplimit
117 Standard_EXPORT virtual void DepthCueing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) = 0;
118
119 //! call_togl_ratio_window
120 Standard_EXPORT virtual void RatioWindow (const Graphic3d_CView& ACView) = 0;
121
122 //! Redraw content of the view
123 Standard_EXPORT virtual void Redraw (const Graphic3d_CView& theCView, const Aspect_CLayer2d& theCUnderLayer, const Aspect_CLayer2d& theCOverLayer, const Standard_Integer theX = 0, const Standard_Integer theY = 0, const Standard_Integer theWidth = 0, const Standard_Integer theHeight = 0) = 0;
124
125 //! Redraw layer of immediate presentations
126 Standard_EXPORT virtual void RedrawImmediate (const Graphic3d_CView& theCView, const Aspect_CLayer2d& theCUnderLayer, const Aspect_CLayer2d& theCOverLayer) = 0;
127
128 //! Invalidates content of the view but does not redraw it
129 Standard_EXPORT virtual void Invalidate (const Graphic3d_CView& theCView) = 0;
130
131 //! call_togl_removeview
132 Standard_EXPORT virtual void RemoveView (const Graphic3d_CView& ACView) = 0;
133
134 //! call_togl_setlight
135 Standard_EXPORT virtual void SetLight (const Graphic3d_CView& ACView) = 0;
136
137 //! Pass clip planes to the associated graphic driver view.
138 Standard_EXPORT virtual void SetClipPlanes (const Graphic3d_CView& theCView) = 0;
139
140 //! Inform graphic driver if camera assigned to view changes.
141 Standard_EXPORT virtual void SetCamera (const Graphic3d_CView& theCView) = 0;
142
143 //! call_togl_setvisualisation
144 Standard_EXPORT virtual void SetVisualisation (const Graphic3d_CView& ACView) = 0;
145
146 //! call_togl_view
147 Standard_EXPORT virtual Standard_Boolean View (Graphic3d_CView& ACView) = 0;
148
149 Standard_EXPORT virtual void Environment (const Graphic3d_CView& ACView) = 0;
150
151 //! enables/disables usage of OpenGL vertex buffer arrays while drawing primitiev arrays
152 Standard_EXPORT virtual void EnableVBO (const Standard_Boolean status) = 0;
153
154 //! Returns information about GPU memory usage.
155 Standard_EXPORT virtual Standard_Boolean MemoryInfo (Standard_Size& theFreeBytes, TCollection_AsciiString& theInfo) const = 0;
156
157 //! call_togl_ztriedron_setup
158 Standard_EXPORT virtual void ZBufferTriedronSetup (const Graphic3d_CView& theCView, 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) = 0;
159
160 //! call_togl_triedron_display
161 Standard_EXPORT virtual 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) = 0;
162
163 //! call_togl_triedron_erase
164 Standard_EXPORT virtual void TriedronErase (const Graphic3d_CView& ACView) = 0;
165
166 //! call_togl_triedron_echo
167 Standard_EXPORT virtual void TriedronEcho (const Graphic3d_CView& ACView, const Aspect_TypeOfTriedronEcho AType = Aspect_TOTE_NONE) = 0;
168
169 //! call_togl_graduatedtrihedron_display
170 Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_CView& theView, const Graphic3d_GraduatedTrihedron& theCubic) = 0;
171
172 //! call_togl_graduatedtrihedron_erase
173 Standard_EXPORT virtual void GraduatedTrihedronErase (const Graphic3d_CView& theView) = 0;
174
175 //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron
176 //! stored in graphic view object.
177 //! @param theView [in] current graphic view
178 //! @param theMin [in] the minimum point of scene.
179 //! @param theMax [in] the maximum point of scene.
180 Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_CView& theView, const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) = 0;
181
182 //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
183 //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image.
184 //! Fast, so preferred for interactive work (used by default).
185 //! However these extra drawings will be missed in image dump since it is performed from back buffer.
186 //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen
187 //! in run-time (in case of slow hardware) and/or tearing may appear.
188 //! So this is strongly recommended to draw only simple (fast) structures.
189 //! 2. FALSE. Drawing immediate mode structures to the back buffer.
190 //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync is turned on.
191 //! But it works in any case and is especially useful for view dump because the dump image is read from the back buffer.
192 //! @return previous mode.
193 Standard_EXPORT virtual Standard_Boolean SetImmediateModeDrawToFront (const Graphic3d_CView& theCView, const Standard_Boolean theDrawToFrontBuffer) = 0;
194
195 //! Display structure in immediate mode on top of general presentation
196 Standard_EXPORT virtual void DisplayImmediateStructure (const Graphic3d_CView& theCView, const Handle(Graphic3d_Structure)& theStructure) = 0;
197
198 //! Erases immediate structure
199 Standard_EXPORT virtual void EraseImmediateStructure (const Graphic3d_CView& theCView, const Graphic3d_CStructure& theCStructure) = 0;
200
201 //! call_togl_layer2d
202 Standard_EXPORT virtual void Layer (Aspect_CLayer2d& ACLayer) = 0;
203
204 //! call_togl_removelayer2d
205 Standard_EXPORT virtual void RemoveLayer (const Aspect_CLayer2d& ACLayer) = 0;
206
207 //! call_togl_begin_layer2d
208 Standard_EXPORT virtual void BeginLayer (const Aspect_CLayer2d& ACLayer) = 0;
209
210 //! call_togl_begin_polygon2d
211 Standard_EXPORT virtual void BeginPolygon2d() = 0;
212
213 //! call_togl_begin_polyline2d
214 Standard_EXPORT virtual void BeginPolyline2d() = 0;
215
216 //! call_togl_clear_layer2d
217 Standard_EXPORT virtual void ClearLayer (const Aspect_CLayer2d& ACLayer) = 0;
218
219 //! call_togl_draw2d
220 Standard_EXPORT virtual void Draw (const Standard_ShortReal X, const Standard_ShortReal Y) = 0;
221
222 //! call_togl_edge2d
223 Standard_EXPORT virtual void Edge (const Standard_ShortReal X, const Standard_ShortReal Y) = 0;
224
225 //! call_togl_end_layer2d
226 Standard_EXPORT virtual void EndLayer() = 0;
227
228 //! call_togl_end_polygon2d
229 Standard_EXPORT virtual void EndPolygon2d() = 0;
230
231 //! call_togl_end_polyline2d
232 Standard_EXPORT virtual void EndPolyline2d() = 0;
233
234 //! call_togl_move2d
235 Standard_EXPORT virtual void Move (const Standard_ShortReal X, const Standard_ShortReal Y) = 0;
236
237 //! call_togl_rectangle2d
238 Standard_EXPORT virtual void Rectangle (const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Width, const Standard_ShortReal Height) = 0;
239
240 //! call_togl_set_color
241 Standard_EXPORT virtual void SetColor (const Standard_ShortReal R, const Standard_ShortReal G, const Standard_ShortReal B) = 0;
242
243 //! call_togl_set_transparency
244 Standard_EXPORT virtual void SetTransparency (const Standard_ShortReal ATransparency) = 0;
245
246 //! call_togl_unset_transparency
247 Standard_EXPORT virtual void UnsetTransparency() = 0;
248
249 //! call_togl_set_line_attributes
250 Standard_EXPORT virtual void SetLineAttributes (const Standard_Integer Type, const Standard_ShortReal Width) = 0;
251
252 //! Set text attributes for under-/overlayer.
253 //! <Font> argument defines the name of the font to be used,
254 //! <Type> argument defines the display type of the text,
255 //! <R> <G> <B> values define the color of decal or subtitle background.
256 //! To set the color of the text you can use the SetColor method.
257 Standard_EXPORT virtual void SetTextAttributes (const Standard_CString Font, const Standard_Integer Type, const Standard_ShortReal R, const Standard_ShortReal G, const Standard_ShortReal B) = 0;
258
259 //! call_togl_text2d
260 //! If AHeight < 0 default text height is used by driver (DefaultTextHeight method)
261 Standard_EXPORT virtual void Text (const Standard_CString AText, const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal AHeight) = 0;
262
263 Standard_EXPORT virtual Standard_ShortReal DefaultTextHeight() const = 0;
264
265 //! call_togl_textsize2d
266 Standard_EXPORT virtual void TextSize (const Standard_CString AText, const Standard_ShortReal AHeight, Standard_ShortReal& AWidth, Standard_ShortReal& AnAscent, Standard_ShortReal& ADescent) const = 0;
267
268 //! call_togl_backfacing
269 Standard_EXPORT virtual void SetBackFacingModel (const Graphic3d_CView& aView) = 0;
270
271 //! Reads depths of shown pixels of the given
272 //! rectangle (glReadPixels with GL_DEPTH_COMPONENT)
273 Standard_EXPORT virtual 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 = 0;
274
275 //! Generate offscreen FBO in the graphic library.
276 //! If not supported on hardware returns NULL.
277 Standard_EXPORT virtual Graphic3d_PtrFrameBuffer FBOCreate (const Graphic3d_CView& view, const Standard_Integer width, const Standard_Integer height) = 0;
278
279 //! Remove offscreen FBO from the graphic library
280 Standard_EXPORT virtual void FBORelease (const Graphic3d_CView& view, Graphic3d_PtrFrameBuffer& fboPtr) = 0;
281
282 //! Read offscreen FBO configuration.
283 Standard_EXPORT virtual void FBOGetDimensions (const Graphic3d_CView& view, const Graphic3d_PtrFrameBuffer fboPtr, Standard_Integer& width, Standard_Integer& height, Standard_Integer& widthMax, Standard_Integer& heightMax) = 0;
284
285 //! Change offscreen FBO viewport.
286 Standard_EXPORT virtual void FBOChangeViewport (const Graphic3d_CView& view, Graphic3d_PtrFrameBuffer& fboPtr, const Standard_Integer width, const Standard_Integer height) = 0;
287
288 //! Dump active rendering buffer into specified memory buffer.
289 Standard_EXPORT virtual Standard_Boolean BufferDump (const Graphic3d_CView& theCView, Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0;
290
291 //! call_togl_gllight
292 Standard_EXPORT virtual void SetGLLightEnabled (const Graphic3d_CView& view, const Standard_Boolean isEnabled) const = 0;
293
294 //! call_togl_isgllight
295 Standard_EXPORT virtual Standard_Boolean IsGLLightEnabled (const Graphic3d_CView& view) const = 0;
296
297 //! print the contents of all layers of the view to the printer.
298 //! <hPrnDC> : Pass the PrinterDeviceContext (HDC),
299 //! <showBackground> : When set to FALSE then print the view without background color
300 //! (background is white)
301 //! else set to TRUE for printing with current background color.
302 //! <filename>: If != NULL, then the view will be printed to a file.
303 //! <printAlgorithm>: Select print algorithm: stretch, tile.
304 //! <theScaleFactor>: Scaling coefficient, used internally to scale the
305 //! printings accordingly to the scale factor selected in the printer
306 //! properties dialog.
307 //! Returns Standard_True if the data is passed to the printer, otherwise
308 //! Standard_False if the print operation failed due to the printer errors,
309 //! or insufficient system memory available.
310 Standard_EXPORT virtual Standard_Boolean Print (const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACUnderLayer, const Aspect_CLayer2d& ACOverLayer, const Aspect_Handle hPrnDC, const Standard_Boolean showBackground, const Standard_CString filename, const Aspect_PrintAlgo printAlgorithm = Aspect_PA_STRETCH, const Standard_Real theScaleFactor = 1.0) const = 0;
311
312
313 //! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...).
314 //! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits on printing to laser printer).
315 //! Notice however that results may differ a lot and do not contain some elements.
316 Standard_EXPORT virtual 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) = 0;
317
318
319 //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
320 Standard_EXPORT virtual void InvalidateBVHData (Graphic3d_CView& theCView, const Standard_Integer theLayerId) = 0;
321
322 //! Add a new top-level z layer with ID <theLayerId> for
323 //! the view. Z layers allow drawing structures in higher layers
324 //! in foreground of structures in lower layers. To add a structure
325 //! to desired layer on display it is necessary to set the layer
326 //! ID for the structure.
327 Standard_EXPORT virtual void AddZLayer (const Graphic3d_CView& theCView, const Graphic3d_ZLayerId theLayerId) = 0;
328
329 //! Remove Z layer from the specified view. All structures
330 //! displayed at the moment in layer will be displayed in default layer
331 //! ( the bottom-level z layer ). To unset layer ID from associated
332 //! structures use method UnsetZLayer (...).
333 Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_CView& theCView, const Graphic3d_ZLayerId theLayerId) = 0;
334
335 //! Unset Z layer ID for all structures. The structure
336 //! indexes will be set to default layer ( the bottom-level z layer
337 //! with ID = 0 ).
338 Standard_EXPORT virtual void UnsetZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
339
340 //! Change Z layer of a structure already presented in view.
341 Standard_EXPORT virtual void ChangeZLayer (const Graphic3d_CStructure& theCStructure, const Graphic3d_CView& theCView, const Graphic3d_ZLayerId theNewLayerId) = 0;
342
343 //! Sets the settings for a single Z layer of specified view.
344 Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_CView& theCView, const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) = 0;
345
346 //! Changes the priority of a structure within its Z layer in the specified view.
347 Standard_EXPORT virtual void ChangePriority (const Graphic3d_CStructure& theCStructure, const Graphic3d_CView& theCView, const Standard_Integer theNewPriority) = 0;
348
349 Standard_EXPORT void PrintBoolean (const Standard_CString AComment, const Standard_Boolean AValue) const;
350
351 Standard_EXPORT void PrintCLight (const Graphic3d_CLight& ACLight, const Standard_Integer AField) const;
352
353 Standard_EXPORT void PrintCStructure (const Graphic3d_CStructure& ACStructure, const Standard_Integer AField) const;
354
355 Standard_EXPORT void PrintCView (const Graphic3d_CView& ACView, const Standard_Integer AField) const;
356
357 Standard_EXPORT void PrintFunction (const Standard_CString AFunc) const;
358
359 Standard_EXPORT void PrintInteger (const Standard_CString AComment, const Standard_Integer AValue) const;
360
361 Standard_EXPORT void PrintIResult (const Standard_CString AFunc, const Standard_Integer AResult) const;
362
363 Standard_EXPORT void PrintShortReal (const Standard_CString AComment, const Standard_ShortReal AValue) const;
364
365 Standard_EXPORT void PrintMatrix (const Standard_CString AComment, const TColStd_Array2OfReal& AMatrix) const;
366
367 Standard_EXPORT void PrintString (const Standard_CString AComment, const Standard_CString AString) const;
368
369 Standard_EXPORT void SetTrace (const Standard_Integer ALevel);
370
371 Standard_EXPORT Standard_Integer Trace() const;
372
373 //! returns Handle to display connection
374 Standard_EXPORT const Handle(Aspect_DisplayConnection)& GetDisplayConnection() const;
375
376 Standard_EXPORT Standard_Boolean IsDeviceLost() const;
377
378 Standard_EXPORT void ResetDeviceLostFlag();
379
380
381
382
383 DEFINE_STANDARD_RTTI(Graphic3d_GraphicDriver,MMgt_TShared)
384
385protected:
386
387
388 //! Initialises the Driver
389 Standard_EXPORT Graphic3d_GraphicDriver(const Handle(Aspect_DisplayConnection)& theDisp);
390
391 Standard_Integer MyTraceLevel;
392 Handle(Aspect_DisplayConnection) myDisplayConnection;
393 Standard_Boolean myDeviceLostFlag;
394
395
396private:
397
398
399
400
401};
402
403
404
405
406
407
408
409#endif // _Graphic3d_GraphicDriver_HeaderFile