Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-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_View_Header |
17 | #define _OpenGl_View_Header | |
18 | ||
19 | #include <MMgt_TShared.hxx> | |
ec357c5c | 20 | #include <Standard_Type.hxx> |
2166f0fa SK |
21 | |
22 | #include <TColStd_Array2OfReal.hxx> | |
23 | #include <NCollection_List.hxx> | |
189f85a3 | 24 | #include <math_BullardGenerator.hxx> |
2166f0fa SK |
25 | |
26 | #include <Quantity_NameOfColor.hxx> | |
27 | #include <Aspect_FillMethod.hxx> | |
28 | #include <Aspect_GradientFillMethod.hxx> | |
29 | #include <Aspect_TypeOfTriedronPosition.hxx> | |
2166f0fa SK |
30 | |
31 | #include <InterfaceGraphic_Graphic3d.hxx> | |
2166f0fa SK |
32 | |
33 | #include <Graphic3d_CView.hxx> | |
a79f67f8 | 34 | #include <Graphic3d_GraduatedTrihedron.hxx> |
51b10cd4 | 35 | #include <Graphic3d_SequenceOfHClipPlane.hxx> |
c357e426 | 36 | #include <Graphic3d_TypeOfShadingModel.hxx> |
37 | #include <Graphic3d_TypeOfSurfaceDetail.hxx> | |
825aa485 | 38 | #include <Graphic3d_WorldViewProjState.hxx> |
c5751993 | 39 | #include <Graphic3d_ZLayerSettings.hxx> |
2166f0fa | 40 | |
0b0320e7 | 41 | #include <OpenGl_AspectFace.hxx> |
42 | #include <OpenGl_BackgroundArray.hxx> | |
b7cd4ba7 | 43 | #include <OpenGl_BVHTreeSelector.hxx> |
c357e426 | 44 | #include <OpenGl_Context.hxx> |
45 | #include <OpenGl_FrameBuffer.hxx> | |
46 | #include <OpenGl_GraduatedTrihedron.hxx> | |
59f45b7c | 47 | #include <OpenGl_LayerList.hxx> |
2166f0fa | 48 | #include <OpenGl_Light.hxx> |
73192b37 | 49 | #include <OpenGl_LineAttributes.hxx> |
c357e426 | 50 | #include <OpenGl_SceneGeometry.hxx> |
51 | #include <OpenGl_Structure.hxx> | |
536d98e2 | 52 | #include <OpenGl_Trihedron.hxx> |
c357e426 | 53 | #include <OpenGl_Window.hxx> |
54 | #include <OpenGl_Workspace.hxx> | |
2166f0fa | 55 | |
c357e426 | 56 | #include <map> |
57 | #include <set> | |
2166f0fa | 58 | |
2166f0fa SK |
59 | struct OPENGL_ZCLIP |
60 | { | |
61 | struct { | |
62 | Standard_Boolean IsOn; | |
63 | Standard_ShortReal Limit; /* in the range [0., 1.] */ | |
64 | } Back; | |
65 | struct { | |
66 | Standard_Boolean IsOn; | |
67 | Standard_ShortReal Limit; /* in the range [0., 1.] */ | |
68 | } Front; | |
69 | }; | |
70 | ||
71 | struct OPENGL_FOG | |
72 | { | |
73 | Standard_Boolean IsOn; | |
74 | Standard_ShortReal Front; /* in the range [0., 1.] */ | |
75 | Standard_ShortReal Back; /* in the range [0., 1.] */ | |
76 | TEL_COLOUR Color; | |
77 | }; | |
78 | ||
b5ac8292 | 79 | struct OpenGl_Matrix; |
2166f0fa | 80 | |
c357e426 | 81 | class Graphic3d_StructureManager; |
82 | class OpenGl_GraphicDriver; | |
83 | class OpenGl_StateCounter; | |
84 | class OpenGl_RaytraceMaterial; | |
85 | class OpenGl_TriangleSet; | |
86 | class OpenGl_Workspace; | |
c04c30b3 | 87 | class OpenGl_View; |
c357e426 | 88 | DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView) |
c04c30b3 | 89 | |
c357e426 | 90 | //! Implementation of OpenGl view. |
91 | class OpenGl_View : public Graphic3d_CView | |
2166f0fa | 92 | { |
c357e426 | 93 | |
94 | public: | |
95 | ||
96 | //! Constructor. | |
97 | Standard_EXPORT OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr, | |
98 | const Handle(OpenGl_GraphicDriver)& theDriver, | |
99 | const Handle(OpenGl_Caps)& theCaps, | |
100 | Standard_Boolean& theDeviceLostFlag, | |
101 | OpenGl_StateCounter* theCounter); | |
102 | ||
103 | //! Default destructor. | |
104 | Standard_EXPORT virtual ~OpenGl_View(); | |
2166f0fa | 105 | |
62e1beed | 106 | Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx); |
bf75be98 | 107 | |
c357e426 | 108 | //! Deletes and erases the view. |
109 | Standard_EXPORT virtual void Remove() Standard_OVERRIDE; | |
110 | ||
111 | //! @param theDrawToFrontBuffer Advanced option to modify rendering mode: | |
112 | //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image. | |
113 | //! Fast, so preferred for interactive work (used by default). | |
114 | //! However these extra drawings will be missed in image dump since it is performed from back buffer. | |
115 | //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen | |
116 | //! in run-time (in case of slow hardware) and/or tearing may appear. | |
117 | //! So this is strongly recommended to draw only simple (fast) structures. | |
118 | //! 2. FALSE. Drawing immediate mode structures to the back buffer. | |
119 | //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync | |
120 | //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read | |
121 | //! from the back buffer. | |
122 | //! @return previous mode. | |
123 | Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) Standard_OVERRIDE; | |
124 | ||
125 | //! Creates and maps rendering window to the view. | |
c357e426 | 126 | //! @param theWindow [in] the window. |
127 | //! @param theContext [in] the rendering context. If NULL the context will be created internally. | |
a521d90d | 128 | Standard_EXPORT virtual void SetWindow (const Handle(Aspect_Window)& theWindow, |
129 | const Aspect_RenderingContext theContext) Standard_OVERRIDE; | |
c357e426 | 130 | |
131 | //! Returns window associated with the view. | |
79104795 | 132 | virtual Handle(Aspect_Window) Window() const Standard_OVERRIDE |
133 | { return myWindow->PlatformWindow(); } | |
c357e426 | 134 | |
135 | //! Returns True if the window associated to the view is defined. | |
79104795 | 136 | virtual Standard_Boolean IsDefined() const Standard_OVERRIDE |
137 | { return !myWindow.IsNull(); } | |
c357e426 | 138 | |
139 | //! Handle changing size of the rendering window. | |
140 | Standard_EXPORT virtual void Resized() Standard_OVERRIDE; | |
141 | ||
142 | //! Redraw content of the view. | |
143 | Standard_EXPORT virtual void Redraw() Standard_OVERRIDE; | |
144 | ||
145 | //! Redraw immediate content of the view. | |
146 | Standard_EXPORT virtual void RedrawImmediate() Standard_OVERRIDE; | |
147 | ||
148 | //! Marks BVH tree for given priority list as dirty and marks primitive set for rebuild. | |
149 | Standard_EXPORT virtual void Invalidate() Standard_OVERRIDE; | |
150 | ||
151 | //! Return true if view content cache has been invalidated. | |
d2eddacc | 152 | virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return !myBackBufferRestored; } |
c357e426 | 153 | |
154 | //! Displays z-buffer trihedron. | |
155 | Standard_EXPORT virtual void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition = Aspect_TOTP_CENTER, | |
156 | const Quantity_NameOfColor theColor = Quantity_NOC_WHITE, | |
157 | const Standard_Real theScale = 0.02, | |
158 | const Standard_Boolean theAsWireframe = Standard_True) Standard_OVERRIDE; | |
159 | ||
160 | //! Erases z-buffer trihedron. | |
161 | Standard_EXPORT virtual void TriedronErase() Standard_OVERRIDE; | |
162 | ||
163 | //! Setup parameters of z-buffer trihedron. | |
164 | Standard_EXPORT virtual void ZBufferTriedronSetup (const Quantity_NameOfColor theXColor = Quantity_NOC_RED, | |
165 | const Quantity_NameOfColor theYColor = Quantity_NOC_GREEN, | |
166 | const Quantity_NameOfColor theZColor = Quantity_NOC_BLUE1, | |
167 | const Standard_Real theSizeRatio = 0.8, | |
168 | const Standard_Real theAxisDiametr = 0.05, | |
169 | const Standard_Integer theNbFacettes = 12) Standard_OVERRIDE; | |
170 | ||
171 | //! Displays trihedron echo. | |
172 | Standard_EXPORT virtual void TriedronEcho (const Aspect_TypeOfTriedronEcho theType = Aspect_TOTE_NONE) Standard_OVERRIDE; | |
173 | ||
174 | //! Returns data of a graduated trihedron | |
79104795 | 175 | const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() Standard_OVERRIDE |
176 | { return myGTrihedronData; } | |
c357e426 | 177 | |
178 | //! Displays Graduated Trihedron. | |
179 | Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) Standard_OVERRIDE; | |
180 | ||
181 | //! Erases Graduated Trihedron. | |
182 | Standard_EXPORT virtual void GraduatedTrihedronErase() Standard_OVERRIDE; | |
183 | ||
184 | //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object. | |
185 | //! @param theMin [in] the minimum point of scene. | |
186 | //! @param theMax [in] the maximum point of scene. | |
187 | Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE; | |
188 | ||
c357e426 | 189 | //! Dump active rendering buffer into specified memory buffer. |
190 | Standard_EXPORT virtual Standard_Boolean BufferDump (Image_PixMap& theImage, | |
191 | const Graphic3d_BufferType& theBufferType) Standard_OVERRIDE; | |
192 | ||
193 | //! Print the contents of the view to the printer. | |
194 | //! @param thePrinterDC pass the PrinterDeviceContext (HDC) | |
195 | //! @param theToShowBackground when set to FALSE then print the view without background | |
196 | //! color (background is white) else set to TRUE for printing | |
197 | //! with current background color | |
198 | //! @param theFileName if != NULL, then the view will be printed to a file | |
199 | //! @param thePrintAlgorithm select print algorithm: stretch, tile | |
200 | //! @param theScaleFactor scaling coefficient, used internally to scale the printings | |
201 | //! accordingly to the scale factor selected in the printer properties dialog | |
202 | //! @return Standard_True if the data is passed to the printer, otherwise Standard_False if | |
203 | //! the print operation failed due to the printer errors, or lack of system memory. This might be related | |
204 | //! to insufficient memory or some internal errors. | |
205 | //! All this errors are indicated by the message boxes (on level of OpenGl_GraphicDriver). | |
206 | //! Warning: This function can reuse FBO assigned to the view, please take it into account | |
207 | //! if you use it for your purposes. | |
208 | Standard_EXPORT virtual Standard_Boolean Print (const Aspect_Handle thePrinterDC, | |
209 | const Standard_Boolean theToShowBackground, | |
210 | const Standard_CString theFileName, | |
211 | const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH, | |
212 | const Standard_Real theScaleFactor = 1.0) Standard_OVERRIDE; | |
213 | ||
214 | //! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...). | |
215 | //! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits | |
216 | //! on printing to laser printer). Notice however that results may differ a lot and | |
217 | //! do not contain some elements. | |
218 | Standard_EXPORT virtual Standard_Boolean Export (const Standard_CString theFileName, | |
219 | const Graphic3d_ExportFormat theFormat, | |
220 | const Graphic3d_SortType theSortType = Graphic3d_ST_BSP_Tree) Standard_OVERRIDE; | |
221 | ||
222 | //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated. | |
223 | Standard_EXPORT virtual void InvalidateBVHData (const Standard_Integer theLayerId) Standard_OVERRIDE; | |
224 | ||
225 | //! Insert a new top-level z layer with the given ID. | |
226 | Standard_EXPORT virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE; | |
227 | ||
228 | //! Remove a z layer with the given ID. | |
229 | Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE; | |
2166f0fa | 230 | |
c357e426 | 231 | //! Sets the settings for a single Z layer of specified view. |
232 | Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, | |
233 | const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE; | |
b5ac8292 | 234 | |
c357e426 | 235 | //! Returns pointer to an assigned framebuffer object. |
b128c892 | 236 | Standard_EXPORT virtual Handle(Standard_Transient) FBO() const Standard_OVERRIDE; |
2166f0fa | 237 | |
c357e426 | 238 | //! Sets framebuffer object for offscreen rendering. |
b128c892 | 239 | Standard_EXPORT virtual void SetFBO (const Handle(Standard_Transient)& theFbo) Standard_OVERRIDE; |
2166f0fa | 240 | |
c357e426 | 241 | //! Generate offscreen FBO in the graphic library. |
242 | //! If not supported on hardware returns NULL. | |
b128c892 | 243 | Standard_EXPORT virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth, |
244 | const Standard_Integer theHeight) Standard_OVERRIDE; | |
2166f0fa | 245 | |
c357e426 | 246 | //! Remove offscreen FBO from the graphic library |
b128c892 | 247 | Standard_EXPORT virtual void FBORelease (Handle(Standard_Transient)& theFbo) Standard_OVERRIDE; |
2166f0fa | 248 | |
c357e426 | 249 | //! Read offscreen FBO configuration. |
b128c892 | 250 | Standard_EXPORT virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo, |
c357e426 | 251 | Standard_Integer& theWidth, |
252 | Standard_Integer& theHeight, | |
253 | Standard_Integer& theWidthMax, | |
254 | Standard_Integer& theHeightMax) Standard_OVERRIDE; | |
255 | ||
256 | //! Change offscreen FBO viewport. | |
b128c892 | 257 | Standard_EXPORT virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo, |
c357e426 | 258 | const Standard_Integer theWidth, |
259 | const Standard_Integer theHeight) Standard_OVERRIDE; | |
2166f0fa | 260 | |
c357e426 | 261 | public: |
2166f0fa | 262 | |
c357e426 | 263 | //! Returns true if anti-aliasing is enabled for the view. |
264 | Standard_Boolean virtual IsAntialiasingEnabled() const Standard_OVERRIDE { return myAntiAliasing; } | |
59f45b7c | 265 | |
c357e426 | 266 | //! Enable or disable anti-aliasing in the view. |
267 | virtual void SetAntialiasingEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myAntiAliasing = theIsEnabled; } | |
679ecdee | 268 | |
c357e426 | 269 | //! Returns background fill color. |
270 | Standard_EXPORT virtual Aspect_Background Background() const Standard_OVERRIDE; | |
59f45b7c | 271 | |
c357e426 | 272 | //! Sets background fill color. |
273 | Standard_EXPORT virtual void SetBackground (const Aspect_Background& theBackground) Standard_OVERRIDE; | |
59f45b7c | 274 | |
c357e426 | 275 | //! Returns gradient background fill colors. |
276 | Standard_EXPORT virtual Aspect_GradientBackground GradientBackground() const Standard_OVERRIDE; | |
2166f0fa | 277 | |
c357e426 | 278 | //! Sets gradient background fill colors. |
279 | Standard_EXPORT virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) Standard_OVERRIDE; | |
280 | ||
281 | //! Returns background image texture file path. | |
282 | Standard_EXPORT virtual TCollection_AsciiString BackgroundImage() Standard_OVERRIDE { return myBackgroundImagePath; } | |
283 | ||
284 | //! Sets background image texture file path. | |
285 | Standard_EXPORT virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) Standard_OVERRIDE; | |
286 | ||
287 | //! Returns background image fill style. | |
288 | Standard_EXPORT virtual Aspect_FillMethod BackgroundImageStyle() const Standard_OVERRIDE; | |
289 | ||
290 | //! Sets background image fill style. | |
291 | Standard_EXPORT virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) Standard_OVERRIDE; | |
292 | ||
293 | //! Returns environment texture set for the view. | |
294 | Standard_EXPORT virtual Handle(Graphic3d_TextureEnv) TextureEnv() const Standard_OVERRIDE { return myTextureEnvData; } | |
295 | ||
296 | //! Sets environment texture for the view. | |
297 | Standard_EXPORT virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) Standard_OVERRIDE; | |
298 | ||
299 | //! Returns the state of frustum culling optimization. | |
300 | virtual Standard_Boolean IsCullingEnabled() const Standard_OVERRIDE { return myCulling; } | |
301 | ||
302 | //! Enables or disables frustum culling optimization. | |
303 | virtual void SetCullingEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myCulling = theIsEnabled; } | |
304 | ||
305 | //! Returns shading model of the view. | |
306 | virtual Graphic3d_TypeOfShadingModel ShadingModel() const Standard_OVERRIDE { return myShadingModel; } | |
307 | ||
308 | //! Sets shading model of the view. | |
309 | virtual void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel) Standard_OVERRIDE { myShadingModel = theModel; } | |
310 | ||
311 | //! Returns surface detail type of the view. | |
312 | virtual Graphic3d_TypeOfSurfaceDetail SurfaceDetailType() const Standard_OVERRIDE { return mySurfaceDetail; } | |
313 | ||
314 | //! Sets surface detail type of the view. | |
315 | virtual void SetSurfaceDetailType (const Graphic3d_TypeOfSurfaceDetail theType) Standard_OVERRIDE | |
316 | { | |
317 | mySurfaceDetail = theType; | |
318 | myToUpdateEnvironmentMap = Standard_True; | |
319 | } | |
320 | ||
321 | //! Return backfacing model used for the view. | |
322 | virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const Standard_OVERRIDE { return myBackfacing; } | |
323 | ||
324 | //! Sets backfacing model for the view. | |
325 | virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) Standard_OVERRIDE { myBackfacing = theModel; } | |
326 | ||
327 | //! Returns camera object of the view. | |
328 | virtual const Handle(Graphic3d_Camera)& Camera() const Standard_OVERRIDE { return myCamera; } | |
329 | ||
330 | //! Sets camera used by the view. | |
331 | virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) Standard_OVERRIDE { myCamera = theCamera; } | |
332 | ||
333 | //! Returns the activity of back z-clipping plane. | |
334 | virtual Standard_Boolean BackZClippingIsOn() const Standard_OVERRIDE { return myZClip.Back.IsOn; } | |
335 | ||
336 | //! Activates the back Z-clipping plane. | |
337 | virtual void SetBackZClippingOn (const Standard_Boolean theIsOn) Standard_OVERRIDE { myZClip.Back.IsOn = theIsOn; } | |
338 | ||
339 | //! Returns the definition of the back Z-clipping plane. | |
340 | virtual Standard_Real ZClippingBackPlane() const Standard_OVERRIDE { return myZClip.Back.Limit; } | |
341 | ||
342 | //! Sets the definition of the back Z-clipping plane. | |
343 | virtual void SetZClippingBackPlane (const Standard_Real theValue) Standard_OVERRIDE | |
344 | { | |
345 | myZClip.Back.Limit = static_cast<Standard_ShortReal> (theValue); | |
346 | } | |
347 | ||
348 | //! Returns the activity of front z-clipping plane. | |
349 | virtual Standard_Boolean FrontZClippingIsOn() const Standard_OVERRIDE { return myZClip.Front.IsOn; } | |
350 | ||
351 | //! Activates the front Z-clipping plane. | |
352 | virtual void SetFrontZClippingOn (const Standard_Boolean theIsOn) Standard_OVERRIDE{ myZClip.Front.IsOn = theIsOn; } | |
353 | ||
354 | //! Returns the definition of the front Z-clipping plane. | |
355 | virtual Standard_Real ZClippingFrontPlane() const Standard_OVERRIDE { return myZClip.Front.Limit; } | |
356 | ||
357 | //! Sets the definition of the front Z-clipping plane. | |
358 | virtual void SetZClippingFrontPlane (const Standard_Real theValue) Standard_OVERRIDE | |
359 | { | |
360 | myZClip.Front.Limit = static_cast<Standard_ShortReal> (theValue); | |
361 | } | |
362 | ||
363 | //! Returns the activity of depth cueing. | |
364 | virtual Standard_Boolean DepthCueingIsOn() const Standard_OVERRIDE { return myFog.IsOn; } | |
365 | ||
366 | //! Sets the activity of depth cueing. | |
367 | virtual void SetDepthCueingOn (const Standard_Boolean theIsOn) Standard_OVERRIDE { myFog.IsOn = theIsOn; } | |
c5751993 | 368 | |
c357e426 | 369 | //! Returns the back depth cueing plane. |
370 | virtual Standard_Real DepthCueingBackPlane() const Standard_OVERRIDE { return myFog.Back; } | |
b7cd4ba7 | 371 | |
c357e426 | 372 | //! Set the back depth cueing plane. |
373 | virtual void SetDepthCueingBackPlane (const Standard_Real theValue) Standard_OVERRIDE | |
374 | { | |
375 | myFog.Back = static_cast<Standard_ShortReal> (theValue); | |
376 | } | |
377 | ||
378 | //! Returns the front depth cueing plane. | |
379 | virtual Standard_Real DepthCueingFrontPlane() const Standard_OVERRIDE { return myFog.Front; } | |
380 | ||
381 | //! Set the front depth cueing plane. | |
382 | virtual void SetDepthCueingFrontPlane (const Standard_Real theValue) Standard_OVERRIDE | |
383 | { | |
384 | myFog.Front = static_cast<Standard_ShortReal> (theValue); | |
385 | } | |
386 | ||
387 | //! Returns true if GL lighting is enabled. | |
388 | virtual Standard_Boolean IsGLLightEnabled() const Standard_OVERRIDE { return myUseGLLight; } | |
389 | ||
390 | //! Sets GL lighting enabled or disable state. | |
391 | virtual void SetGLLightEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myUseGLLight = theIsEnabled; } | |
392 | ||
393 | //! Returns list of lights of the view. | |
394 | virtual const Graphic3d_ListOfCLight& Lights() const Standard_OVERRIDE { return myLights; } | |
395 | ||
396 | //! Sets list of lights for the view. | |
397 | virtual void SetLights (const Graphic3d_ListOfCLight& theLights) Standard_OVERRIDE | |
398 | { | |
399 | myLights = theLights; | |
400 | myCurrLightSourceState = myStateCounter->Increment(); | |
401 | } | |
402 | ||
403 | //! Returns list of clip planes set for the view. | |
404 | virtual const Graphic3d_SequenceOfHClipPlane& ClipPlanes() const Standard_OVERRIDE { return myClipPlanes; } | |
405 | ||
406 | //! Sets list of clip planes for the view. | |
407 | virtual void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes) Standard_OVERRIDE { myClipPlanes = thePlanes; } | |
408 | ||
409 | public: | |
410 | ||
411 | //! Returns background color. | |
412 | const TEL_COLOUR& BackgroundColor() const { return myBgColor; } | |
413 | ||
414 | //! Change trihedron. | |
415 | OpenGl_Trihedron& ChangeTrihedron() { return myTrihedron; } | |
416 | ||
417 | //! Change graduated trihedron. | |
418 | OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; } | |
419 | ||
420 | void SetTextureEnv (const Handle(OpenGl_Context)& theCtx, | |
421 | const Handle(Graphic3d_TextureEnv)& theTexture); | |
422 | ||
423 | //! Returns height of view volume. | |
424 | Standard_Real Height () const { return myCamera->ViewDimensions().X(); } | |
425 | ||
426 | //! Returns width of view volume. | |
427 | Standard_Real Width () const { return myCamera->ViewDimensions().Y(); } | |
0b0320e7 | 428 | |
2166f0fa | 429 | void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle); |
c357e426 | 430 | |
2166f0fa | 431 | void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType); |
2166f0fa | 432 | |
c357e426 | 433 | void SetBackgroundGradientType (const Aspect_GradientFillMethod AType); |
2166f0fa | 434 | |
e276548b | 435 | //! Returns list of OpenGL Z-layers. |
436 | const OpenGl_LayerList& LayerList() const { return myZLayers; } | |
437 | ||
438 | //! Returns list of openGL light sources. | |
439 | const OpenGl_ListOfLight& LightList() const { return myLights; } | |
440 | ||
c357e426 | 441 | //! Returns OpenGL window implementation. |
442 | const Handle(OpenGl_Window) GlWindow() const { return myWindow; } | |
e276548b | 443 | |
c357e426 | 444 | //! Returns OpenGL environment map. |
445 | const Handle(OpenGl_Texture)& GlTextureEnv() const { return myTextureEnv; } | |
e276548b | 446 | |
b7cd4ba7 | 447 | //! Returns selector for BVH tree, providing a possibility to store information |
448 | //! about current view volume and to detect which objects are overlapping it. | |
449 | OpenGl_BVHTreeSelector& BVHTreeSelector() { return myBVHSelector; } | |
450 | ||
a1954302 | 451 | //! Returns true if there are immediate structures to display |
452 | bool HasImmediateStructures() const | |
453 | { | |
c3282ec1 | 454 | return myZLayers.NbImmediateStructures() != 0; |
a1954302 | 455 | } |
456 | ||
c357e426 | 457 | protected: //! @name Internal methods for managing GL resources |
458 | ||
459 | //! Initializes OpenGl resource for environment texture. | |
460 | void initTextureEnv (const Handle(OpenGl_Context)& theContext); | |
461 | ||
a521d90d | 462 | protected: //! @name low-level redrawing sub-routines |
c357e426 | 463 | |
464 | //! Redraws view for the given monographic camera projection, or left/right eye. | |
a521d90d | 465 | Standard_EXPORT virtual void redraw (const Graphic3d_Camera::Projection theProjection, |
466 | OpenGl_FrameBuffer* theReadDrawFbo); | |
2166f0fa | 467 | |
c357e426 | 468 | //! Redraws view for the given monographic camera projection, or left/right eye. |
469 | //! | |
470 | //! Method will blit snapshot containing main scene (myMainSceneFbos or BackBuffer) | |
471 | //! into presentation buffer (myMainSceneFbos -> offscreen FBO or | |
472 | //! myMainSceneFbos -> BackBuffer or BackBuffer -> FrontBuffer), | |
473 | //! and redraw immediate structures on top. | |
474 | //! | |
475 | //! When scene caching is disabled (myTransientDrawToFront, no double buffer in window, etc.), | |
476 | //! the first step (blitting) will be skipped. | |
477 | //! | |
478 | //! @return false if immediate structures has been rendered directly into FrontBuffer | |
479 | //! and Buffer Swap should not be called. | |
a521d90d | 480 | Standard_EXPORT virtual bool redrawImmediate (const Graphic3d_Camera::Projection theProjection, |
481 | OpenGl_FrameBuffer* theReadFbo, | |
482 | OpenGl_FrameBuffer* theDrawFbo, | |
483 | const Standard_Boolean theIsPartialUpdate = Standard_False); | |
b5ac8292 | 484 | |
c357e426 | 485 | //! Blit image from/to specified buffers. |
a521d90d | 486 | Standard_EXPORT bool blitBuffers (OpenGl_FrameBuffer* theReadFbo, |
487 | OpenGl_FrameBuffer* theDrawFbo, | |
488 | const Standard_Boolean theToFlip = Standard_False); | |
2166f0fa | 489 | |
c357e426 | 490 | //! Setup default FBO. |
a521d90d | 491 | Standard_EXPORT void bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo = NULL); |
2166f0fa | 492 | |
c357e426 | 493 | protected: //! @name Rendering of GL graphics (with prepared drawing buffer). |
2166f0fa | 494 | |
c357e426 | 495 | //! Renders the graphical contents of the view into the preprepared window or framebuffer. |
496 | //! @param theProjection [in] the projection that should be used for rendering. | |
497 | //! @param theReadDrawFbo [in] the framebuffer for rendering graphics. | |
498 | //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode. | |
a521d90d | 499 | Standard_EXPORT virtual void render (Graphic3d_Camera::Projection theProjection, |
500 | OpenGl_FrameBuffer* theReadDrawFbo, | |
501 | const Standard_Boolean theToDrawImmediate); | |
2166f0fa | 502 | |
c357e426 | 503 | //! Renders the graphical scene. |
bf02aa7d | 504 | //! @param theProjection [in] the projection that is used for rendering. |
c357e426 | 505 | //! @param theReadDrawFbo [in] the framebuffer for rendering graphics. |
506 | //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode. | |
bf02aa7d | 507 | Standard_EXPORT virtual void renderScene (Graphic3d_Camera::Projection theProjection, |
508 | OpenGl_FrameBuffer* theReadDrawFbo, | |
a521d90d | 509 | const Standard_Boolean theToDrawImmediate); |
510 | ||
511 | //! Draw background (gradient / image) | |
512 | Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace); | |
2166f0fa | 513 | |
c357e426 | 514 | //! Render set of structures presented in the view. |
bf02aa7d | 515 | //! @param theProjection [in] the projection that is used for rendering. |
c357e426 | 516 | //! @param theReadDrawFbo [in] the framebuffer for rendering graphics. |
517 | //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode. | |
bf02aa7d | 518 | Standard_EXPORT virtual void renderStructs (Graphic3d_Camera::Projection theProjection, |
519 | OpenGl_FrameBuffer* theReadDrawFbo, | |
a521d90d | 520 | const Standard_Boolean theToDrawImmediate); |
2166f0fa | 521 | |
c357e426 | 522 | //! Renders trihedron. |
523 | void renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace); | |
2166f0fa | 524 | |
c357e426 | 525 | private: |
392ac980 | 526 | |
c357e426 | 527 | //! Adds the structure to display lists of the view. |
528 | Standard_EXPORT virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure, | |
529 | const Standard_Integer thePriority) Standard_OVERRIDE; | |
530 | ||
531 | //! Erases the structure from display lists of the view. | |
532 | Standard_EXPORT virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) Standard_OVERRIDE; | |
533 | ||
534 | //! Change Z layer of a structure already presented in view. | |
535 | Standard_EXPORT virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure, | |
536 | const Graphic3d_ZLayerId theNewLayerId) Standard_OVERRIDE; | |
537 | ||
538 | //! Changes the priority of a structure within its Z layer in the specified view. | |
539 | Standard_EXPORT virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure, | |
540 | const Standard_Integer theNewPriority) Standard_OVERRIDE; | |
541 | ||
a521d90d | 542 | private: |
543 | ||
544 | //! Copy content of Back buffer to the Front buffer. | |
545 | void copyBackToFront(); | |
546 | ||
547 | //! Initialize blit quad. | |
548 | OpenGl_VertexBuffer* initBlitQuad (const Standard_Boolean theToFlip); | |
549 | ||
550 | //! Blend together views pair into stereo image. | |
3c4b62a4 | 551 | void drawStereoPair (OpenGl_FrameBuffer* theDrawFbo); |
a521d90d | 552 | |
c357e426 | 553 | protected: |
554 | ||
555 | OpenGl_GraphicDriver* myDriver; | |
556 | Handle(OpenGl_Window) myWindow; | |
557 | Handle(OpenGl_Workspace) myWorkspace; | |
558 | Handle(OpenGl_Caps) myCaps; | |
559 | Standard_Boolean& myDeviceLostFlag; | |
560 | Standard_Boolean myWasRedrawnGL; | |
561 | ||
562 | Standard_Boolean myAntiAliasing; | |
563 | Standard_Boolean myCulling; | |
564 | Graphic3d_TypeOfShadingModel myShadingModel; | |
565 | Graphic3d_TypeOfSurfaceDetail mySurfaceDetail; | |
566 | Graphic3d_TypeOfBackfacingModel myBackfacing; | |
567 | TEL_COLOUR myBgColor; | |
568 | OPENGL_FOG myFog; | |
569 | OPENGL_ZCLIP myZClip; | |
570 | Graphic3d_SequenceOfHClipPlane myClipPlanes; | |
571 | Handle(Graphic3d_Camera) myCamera; | |
b128c892 | 572 | Handle(OpenGl_FrameBuffer) myFBO; |
c357e426 | 573 | Standard_Boolean myUseGLLight; |
574 | Standard_Boolean myToShowTrihedron; | |
575 | Standard_Boolean myToShowGradTrihedron; | |
576 | TCollection_AsciiString myBackgroundImagePath; | |
577 | Handle(Graphic3d_TextureEnv) myTextureEnvData; | |
578 | Graphic3d_GraduatedTrihedron myGTrihedronData; | |
579 | ||
580 | OpenGl_ListOfLight myLights; | |
581 | OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers | |
582 | ||
583 | Graphic3d_WorldViewProjState myWorldViewProjState; //!< camera modification state | |
584 | OpenGl_StateCounter* myStateCounter; | |
585 | Standard_Size myCurrLightSourceState; | |
392ac980 | 586 | |
587 | typedef std::pair<Standard_Size, Standard_Size> StateInfo; | |
588 | ||
589 | StateInfo myLastOrientationState; | |
590 | StateInfo myLastViewMappingState; | |
591 | StateInfo myLastLightSourceState; | |
30f0ad28 | 592 | |
b7cd4ba7 | 593 | //! Is needed for selection of overlapping objects and storage of the current view volume |
594 | OpenGl_BVHTreeSelector myBVHSelector; | |
595 | ||
c357e426 | 596 | OpenGl_Trihedron myTrihedron; |
597 | OpenGl_GraduatedTrihedron myGraduatedTrihedron; | |
598 | ||
599 | Handle(OpenGl_Texture) myTextureEnv; | |
600 | ||
c357e426 | 601 | protected: //! @name Rendering properties |
602 | ||
603 | //! Two framebuffers (left and right views) store cached main presentation | |
604 | //! of the view (without presentation of immediate layers). | |
3c4b62a4 | 605 | GLint myFboColorFormat; //!< sized format for color attachments |
606 | GLint myFboDepthFormat; //!< sized format for depth-stencil attachments | |
c357e426 | 607 | Handle(OpenGl_FrameBuffer) myMainSceneFbos[2]; |
608 | Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2]; //!< Additional buffers for immediate layer in stereo mode. | |
609 | OpenGl_VertexBuffer myFullScreenQuad; //!< Vertices for full-screen quad rendering. | |
610 | OpenGl_VertexBuffer myFullScreenQuadFlip; | |
611 | Standard_Boolean myToFlipOutput; //!< Flag to draw result image upside-down | |
612 | unsigned int myFrameCounter; //!< redraw counter, for debugging | |
613 | Standard_Boolean myHasFboBlit; | |
614 | Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer) | |
615 | Standard_Boolean myBackBufferRestored; | |
616 | Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data | |
617 | ||
0b0320e7 | 618 | protected: //! @name Background parameters |
619 | ||
620 | OpenGl_AspectFace* myTextureParams; //!< Stores texture and its parameters for textured background | |
621 | OpenGl_BackgroundArray* myBgGradientArray; //!< Primitive array for gradient background | |
622 | OpenGl_BackgroundArray* myBgTextureArray; //!< Primitive array for texture background | |
623 | ||
91c60b57 | 624 | protected: //! @name data types related to ray-tracing |
625 | ||
626 | //! Result of OpenGL shaders initialization. | |
627 | enum RaytraceInitStatus | |
628 | { | |
629 | OpenGl_RT_NONE, | |
630 | OpenGl_RT_INIT, | |
631 | OpenGl_RT_FAIL | |
632 | }; | |
633 | ||
634 | //! Describes update mode (state). | |
635 | enum RaytraceUpdateMode | |
636 | { | |
637 | OpenGl_GUM_CHECK, //!< check geometry state | |
638 | OpenGl_GUM_PREPARE, //!< collect unchanged objects | |
639 | OpenGl_GUM_REBUILD //!< rebuild changed and new objects | |
640 | }; | |
641 | ||
642 | //! Defines frequently used shader variables. | |
643 | enum ShaderVariableIndex | |
644 | { | |
645 | OpenGl_RT_aPosition, | |
646 | ||
189f85a3 | 647 | // camera position |
91c60b57 | 648 | OpenGl_RT_uOriginLT, |
649 | OpenGl_RT_uOriginLB, | |
650 | OpenGl_RT_uOriginRT, | |
651 | OpenGl_RT_uOriginRB, | |
652 | OpenGl_RT_uDirectLT, | |
653 | OpenGl_RT_uDirectLB, | |
654 | OpenGl_RT_uDirectRT, | |
655 | OpenGl_RT_uDirectRB, | |
1d865689 | 656 | OpenGl_RT_uViewMat, |
91c60b57 | 657 | OpenGl_RT_uUnviewMat, |
658 | ||
189f85a3 | 659 | // 3D scene params |
91c60b57 | 660 | OpenGl_RT_uSceneRad, |
661 | OpenGl_RT_uSceneEps, | |
662 | OpenGl_RT_uLightAmbnt, | |
663 | OpenGl_RT_uLightCount, | |
664 | ||
189f85a3 | 665 | // background params |
666 | OpenGl_RT_uBackColorTop, | |
667 | OpenGl_RT_uBackColorBot, | |
91c60b57 | 668 | |
189f85a3 | 669 | // ray-tracing params |
670 | OpenGl_RT_uShadowsEnabled, | |
671 | OpenGl_RT_uReflectEnabled, | |
672 | OpenGl_RT_uSphereMapEnabled, | |
673 | OpenGl_RT_uSphereMapForBack, | |
674 | OpenGl_RT_uTexSamplersArray, | |
8c820969 | 675 | OpenGl_RT_uBlockedRngEnabled, |
189f85a3 | 676 | |
677 | // sampled frame params | |
678 | OpenGl_RT_uSampleWeight, | |
679 | OpenGl_RT_uFrameRndSeed, | |
680 | ||
681 | // adaptive FSAA params | |
91c60b57 | 682 | OpenGl_RT_uOffsetX, |
683 | OpenGl_RT_uOffsetY, | |
684 | OpenGl_RT_uSamples, | |
91c60b57 | 685 | |
686 | OpenGl_RT_NbVariables // special field | |
687 | }; | |
688 | ||
689 | //! Defines texture samplers. | |
690 | enum ShaderSamplerNames | |
691 | { | |
692 | OpenGl_RT_SceneNodeInfoTexture = 0, | |
693 | OpenGl_RT_SceneMinPointTexture = 1, | |
694 | OpenGl_RT_SceneMaxPointTexture = 2, | |
695 | OpenGl_RT_SceneTransformTexture = 3, | |
696 | ||
697 | OpenGl_RT_GeometryVertexTexture = 4, | |
698 | OpenGl_RT_GeometryNormalTexture = 5, | |
699 | OpenGl_RT_GeometryTexCrdTexture = 6, | |
700 | OpenGl_RT_GeometryTriangTexture = 7, | |
701 | ||
702 | OpenGl_RT_EnvironmentMapTexture = 8, | |
703 | ||
704 | OpenGl_RT_RaytraceMaterialTexture = 9, | |
705 | OpenGl_RT_RaytraceLightSrcTexture = 10, | |
706 | ||
189f85a3 | 707 | OpenGl_RT_FsaaInputTexture = 11, |
708 | OpenGl_RT_PrevAccumTexture = 12, | |
1d865689 | 709 | OpenGl_RT_DepthTexture = 13, |
91c60b57 | 710 | |
1d865689 | 711 | OpenGl_RT_OpenGlColorTexture = 14, |
712 | OpenGl_RT_OpenGlDepthTexture = 15 | |
91c60b57 | 713 | }; |
714 | ||
715 | //! Tool class for management of shader sources. | |
716 | class ShaderSource | |
717 | { | |
718 | public: | |
719 | ||
189f85a3 | 720 | //! Default shader prefix - empty string. |
721 | static const TCollection_AsciiString EMPTY_PREFIX; | |
722 | ||
91c60b57 | 723 | //! Creates new uninitialized shader source. |
724 | ShaderSource() | |
725 | { | |
726 | // | |
727 | } | |
728 | ||
73722cc9 | 729 | public: |
189f85a3 | 730 | |
73722cc9 | 731 | //! Returns error description in case of load fail. |
732 | const TCollection_AsciiString& ErrorDescription() const | |
733 | { | |
734 | return myError; | |
91c60b57 | 735 | } |
736 | ||
91c60b57 | 737 | //! Returns prefix to insert before the source. |
738 | const TCollection_AsciiString& Prefix() const | |
739 | { | |
740 | return myPrefix; | |
741 | } | |
742 | ||
743 | //! Sets prefix to insert before the source. | |
744 | void SetPrefix (const TCollection_AsciiString& thePrefix) | |
745 | { | |
746 | myPrefix = thePrefix; | |
747 | } | |
748 | ||
749 | //! Returns shader source combined with prefix. | |
750 | TCollection_AsciiString Source() const; | |
751 | ||
752 | //! Loads shader source from specified files. | |
73722cc9 | 753 | Standard_Boolean Load (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX); |
91c60b57 | 754 | |
755 | private: | |
756 | ||
757 | TCollection_AsciiString mySource; //!< Source string of the shader object | |
758 | TCollection_AsciiString myPrefix; //!< Prefix to insert before the source | |
73722cc9 | 759 | TCollection_AsciiString myError; //!< error state |
91c60b57 | 760 | |
761 | }; | |
762 | ||
763 | //! Default ray-tracing depth. | |
764 | static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3; | |
765 | ||
766 | //! Default size of traversal stack. | |
767 | static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24; | |
768 | ||
769 | //! Compile-time ray-tracing parameters. | |
770 | struct RaytracingParams | |
771 | { | |
772 | //! Actual size of traversal stack in shader program. | |
773 | Standard_Integer StackSize; | |
774 | ||
775 | //! Actual ray-tracing depth (number of ray bounces). | |
776 | Standard_Integer NbBounces; | |
777 | ||
f483f2ed | 778 | //! Enables/disables light propagation through transparent media. |
91c60b57 | 779 | Standard_Boolean TransparentShadows; |
780 | ||
189f85a3 | 781 | //! Enables/disables global illumination (GI) effects. |
782 | Standard_Boolean GlobalIllumination; | |
783 | ||
f483f2ed | 784 | //! Enables/disables the use of OpenGL bindless textures. |
785 | Standard_Boolean UseBindlessTextures; | |
786 | ||
91c60b57 | 787 | //! Creates default compile-time ray-tracing parameters. |
788 | RaytracingParams() | |
789 | : StackSize (THE_DEFAULT_STACK_SIZE), | |
790 | NbBounces (THE_DEFAULT_NB_BOUNCES), | |
f483f2ed | 791 | TransparentShadows (Standard_False), |
189f85a3 | 792 | GlobalIllumination (Standard_False), |
f483f2ed | 793 | UseBindlessTextures (Standard_False) |
91c60b57 | 794 | { |
795 | // | |
796 | } | |
797 | }; | |
798 | ||
d4aaad5b | 799 | //! Describes state of OpenGL structure. |
800 | struct StructState | |
801 | { | |
802 | Standard_Size StructureState; | |
803 | Standard_Size InstancedState; | |
804 | ||
805 | //! Creates new structure state. | |
806 | StructState (const Standard_Size theStructureState = 0, | |
807 | const Standard_Size theInstancedState = 0) | |
808 | : StructureState (theStructureState), | |
809 | InstancedState (theInstancedState) | |
810 | { | |
811 | // | |
812 | } | |
813 | ||
814 | //! Creates new structure state. | |
815 | StructState (const OpenGl_Structure* theStructure) | |
816 | { | |
817 | StructureState = theStructure->ModificationState(); | |
818 | ||
819 | InstancedState = theStructure->InstancedStructure() != NULL ? | |
820 | theStructure->InstancedStructure()->ModificationState() : 0; | |
821 | } | |
822 | }; | |
823 | ||
91c60b57 | 824 | protected: //! @name methods related to ray-tracing |
825 | ||
826 | //! Updates 3D scene geometry for ray-tracing. | |
827 | Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode theMode, | |
828 | const Standard_Integer theViewId, | |
829 | const Handle(OpenGl_Context)& theGlContext); | |
830 | ||
831 | //! Updates 3D scene light sources for ray-tracing. | |
832 | Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext); | |
833 | ||
834 | //! Updates environment map for ray-tracing. | |
835 | Standard_Boolean updateRaytraceEnvironmentMap (const Handle(OpenGl_Context)& theGlContext); | |
836 | ||
837 | //! Checks to see if the OpenGL structure is modified. | |
838 | Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure); | |
839 | ||
840 | //! Adds OpenGL structure to ray-traced scene geometry. | |
841 | Standard_Boolean addRaytraceStructure (const OpenGl_Structure* theStructure, | |
842 | const Handle(OpenGl_Context)& theGlContext); | |
843 | ||
844 | //! Adds OpenGL groups to ray-traced scene geometry. | |
8c820969 | 845 | Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure, |
846 | const OpenGl_RaytraceMaterial& theStructMat, | |
6bd94e0d | 847 | const Graphic3d_Mat4* theTransform, |
8c820969 | 848 | const Handle(OpenGl_Context)& theGlContext); |
91c60b57 | 849 | |
850 | //! Creates ray-tracing material properties. | |
851 | OpenGl_RaytraceMaterial convertMaterial (const OpenGl_AspectFace* theAspect, | |
852 | const Handle(OpenGl_Context)& theGlContext); | |
853 | ||
854 | //! Adds OpenGL primitive array to ray-traced scene geometry. | |
855 | OpenGl_TriangleSet* addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray, | |
856 | const Standard_Integer theMatID, | |
857 | const OpenGl_Mat4* theTrans); | |
858 | ||
859 | //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry. | |
860 | Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet& theSet, | |
861 | const Standard_Integer theMatID, | |
862 | const Standard_Integer theCount, | |
863 | const Standard_Integer theOffset, | |
864 | const OpenGl_PrimitiveArray& theArray); | |
865 | ||
866 | //! Adds OpenGL triangle array to ray-traced scene geometry. | |
867 | Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet& theSet, | |
868 | const Standard_Integer theMatID, | |
869 | const Standard_Integer theCount, | |
870 | const Standard_Integer theOffset, | |
871 | const Handle(Graphic3d_IndexBuffer)& theIndices); | |
872 | ||
873 | //! Adds OpenGL triangle fan array to ray-traced scene geometry. | |
874 | Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet, | |
875 | const Standard_Integer theMatID, | |
876 | const Standard_Integer theCount, | |
877 | const Standard_Integer theOffset, | |
878 | const Handle(Graphic3d_IndexBuffer)& theIndices); | |
879 | ||
880 | //! Adds OpenGL triangle strip array to ray-traced scene geometry. | |
881 | Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet, | |
882 | const Standard_Integer theMatID, | |
883 | const Standard_Integer theCount, | |
884 | const Standard_Integer theOffset, | |
885 | const Handle(Graphic3d_IndexBuffer)& theIndices); | |
886 | ||
887 | //! Adds OpenGL quadrangle array to ray-traced scene geometry. | |
888 | Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet, | |
889 | const Standard_Integer theMatID, | |
890 | const Standard_Integer theCount, | |
891 | const Standard_Integer theOffset, | |
892 | const Handle(Graphic3d_IndexBuffer)& theIndices); | |
893 | ||
894 | //! Adds OpenGL quadrangle strip array to ray-traced scene geometry. | |
895 | Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet, | |
896 | const Standard_Integer theMatID, | |
897 | const Standard_Integer theCount, | |
898 | const Standard_Integer theOffset, | |
899 | const Handle(Graphic3d_IndexBuffer)& theIndices); | |
900 | ||
901 | //! Adds OpenGL polygon array to ray-traced scene geometry. | |
902 | Standard_Boolean addRaytracePolygonArray (OpenGl_TriangleSet& theSet, | |
903 | const Standard_Integer theMatID, | |
904 | const Standard_Integer theCount, | |
905 | const Standard_Integer theOffset, | |
906 | const Handle(Graphic3d_IndexBuffer)& theIndices); | |
907 | ||
908 | //! Uploads ray-trace data to the GPU. | |
909 | Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext); | |
910 | ||
911 | //! Generates shader prefix based on current ray-tracing options. | |
912 | TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const; | |
913 | ||
914 | //! Performs safe exit when shaders initialization fails. | |
915 | Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage, | |
916 | const Handle(OpenGl_Context)& theGlContext); | |
917 | ||
918 | //! Loads and compiles shader object from specified source. | |
919 | Handle(OpenGl_ShaderObject) initShader (const GLenum theType, | |
920 | const ShaderSource& theSource, | |
921 | const Handle(OpenGl_Context)& theGlContext); | |
922 | ||
189f85a3 | 923 | //! Creates shader program from the given vertex and fragment shaders. |
924 | Handle(OpenGl_ShaderProgram) initProgram (const Handle(OpenGl_Context)& theGlContext, | |
925 | const Handle(OpenGl_ShaderObject)& theVertShader, | |
926 | const Handle(OpenGl_ShaderObject)& theFragShader); | |
927 | ||
91c60b57 | 928 | //! Initializes OpenGL/GLSL shader programs. |
c357e426 | 929 | Standard_Boolean initRaytraceResources (const Handle(OpenGl_Context)& theGlContext); |
91c60b57 | 930 | |
931 | //! Releases OpenGL/GLSL shader programs. | |
932 | void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext); | |
933 | ||
bf02aa7d | 934 | //! Updates auxiliary OpenGL frame buffers. |
935 | Standard_Boolean updateRaytraceBuffers (const Standard_Integer theSizeX, | |
91c60b57 | 936 | const Standard_Integer theSizeY, |
937 | const Handle(OpenGl_Context)& theGlContext); | |
938 | ||
939 | //! Generates viewing rays for corners of screen quad. | |
940 | void updateCamera (const OpenGl_Mat4& theOrientation, | |
941 | const OpenGl_Mat4& theViewMapping, | |
942 | OpenGl_Vec3* theOrigins, | |
943 | OpenGl_Vec3* theDirects, | |
1d865689 | 944 | OpenGl_Mat4& theView, |
91c60b57 | 945 | OpenGl_Mat4& theUnView); |
946 | ||
947 | //! Binds ray-trace textures to corresponding texture units. | |
948 | void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext); | |
949 | ||
950 | //! Unbinds ray-trace textures from corresponding texture unit. | |
951 | void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext); | |
952 | ||
953 | //! Sets uniform state for the given ray-tracing shader program. | |
c357e426 | 954 | Standard_Boolean setUniformState (const OpenGl_Vec3* theOrigins, |
91c60b57 | 955 | const OpenGl_Vec3* theDirects, |
1d865689 | 956 | const OpenGl_Mat4& theViewMat, |
91c60b57 | 957 | const OpenGl_Mat4& theUnviewMat, |
958 | const Standard_Integer theProgramId, | |
959 | const Handle(OpenGl_Context)& theGlContext); | |
960 | ||
961 | //! Runs ray-tracing shader programs. | |
c357e426 | 962 | Standard_Boolean runRaytraceShaders (const Standard_Integer theSizeX, |
91c60b57 | 963 | const Standard_Integer theSizeY, |
964 | const OpenGl_Vec3* theOrigins, | |
965 | const OpenGl_Vec3* theDirects, | |
1d865689 | 966 | const OpenGl_Mat4& theViewMat, |
91c60b57 | 967 | const OpenGl_Mat4& theUnviewMat, |
bf02aa7d | 968 | Graphic3d_Camera::Projection theProjection, |
38a0206f | 969 | OpenGl_FrameBuffer* theReadDrawFbo, |
91c60b57 | 970 | const Handle(OpenGl_Context)& theGlContext); |
971 | ||
972 | //! Redraws the window using OpenGL/GLSL ray-tracing. | |
c357e426 | 973 | Standard_Boolean raytrace (const Standard_Integer theSizeX, |
91c60b57 | 974 | const Standard_Integer theSizeY, |
bf02aa7d | 975 | Graphic3d_Camera::Projection theProjection, |
38a0206f | 976 | OpenGl_FrameBuffer* theReadDrawFbo, |
91c60b57 | 977 | const Handle(OpenGl_Context)& theGlContext); |
978 | ||
979 | protected: //! @name fields related to ray-tracing | |
980 | ||
981 | //! Result of shaders initialization. | |
982 | RaytraceInitStatus myRaytraceInitStatus; | |
983 | ||
984 | //! Is geometry data valid? | |
985 | Standard_Boolean myIsRaytraceDataValid; | |
986 | ||
987 | //! Warning about missing extension GL_ARB_bindless_texture has been displayed? | |
988 | Standard_Boolean myIsRaytraceWarnTextures; | |
989 | ||
990 | //! 3D scene geometry data for ray-tracing. | |
991 | OpenGl_RaytraceGeometry myRaytraceGeometry; | |
992 | ||
993 | //! Compile-time ray-tracing parameters. | |
994 | RaytracingParams myRaytraceParameters; | |
995 | ||
996 | //! Radius of bounding sphere of the scene. | |
997 | Standard_ShortReal myRaytraceSceneRadius; | |
998 | //! Scene epsilon to prevent self-intersections. | |
999 | Standard_ShortReal myRaytraceSceneEpsilon; | |
1000 | ||
1001 | //! OpenGL/GLSL source of ray-tracing fragment shader. | |
1002 | ShaderSource myRaytraceShaderSource; | |
1003 | //! OpenGL/GLSL source of adaptive-AA fragment shader. | |
1004 | ShaderSource myPostFSAAShaderSource; | |
1005 | ||
1006 | //! OpenGL/GLSL ray-tracing fragment shader. | |
1007 | Handle(OpenGl_ShaderObject) myRaytraceShader; | |
1008 | //! OpenGL/GLSL adaptive-AA fragment shader. | |
1009 | Handle(OpenGl_ShaderObject) myPostFSAAShader; | |
1010 | ||
1011 | //! OpenGL/GLSL ray-tracing shader program. | |
1012 | Handle(OpenGl_ShaderProgram) myRaytraceProgram; | |
1013 | //! OpenGL/GLSL adaptive-AA shader program. | |
1014 | Handle(OpenGl_ShaderProgram) myPostFSAAProgram; | |
189f85a3 | 1015 | //! OpenGL/GLSL program for displaying texture. |
1016 | Handle(OpenGl_ShaderProgram) myOutImageProgram; | |
91c60b57 | 1017 | |
1018 | //! Texture buffer of data records of bottom-level BVH nodes. | |
1019 | Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture; | |
1020 | //! Texture buffer of minimum points of bottom-level BVH nodes. | |
1021 | Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture; | |
1022 | //! Texture buffer of maximum points of bottom-level BVH nodes. | |
1023 | Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture; | |
1024 | //! Texture buffer of transformations of high-level BVH nodes. | |
1025 | Handle(OpenGl_TextureBufferArb) mySceneTransformTexture; | |
1026 | ||
1027 | //! Texture buffer of vertex coords. | |
1028 | Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture; | |
1029 | //! Texture buffer of vertex normals. | |
1030 | Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture; | |
1031 | //! Texture buffer of vertex UV coords. | |
1032 | Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture; | |
1033 | //! Texture buffer of triangle indices. | |
1034 | Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture; | |
1035 | ||
1036 | //! Texture buffer of material properties. | |
1037 | Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture; | |
1038 | //! Texture buffer of light source properties. | |
1039 | Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture; | |
1040 | ||
1041 | //! 1st framebuffer (FBO) to perform adaptive FSAA. | |
bf02aa7d | 1042 | Handle(OpenGl_FrameBuffer) myRaytraceFBO1[2]; |
91c60b57 | 1043 | //! 2nd framebuffer (FBO) to perform adaptive FSAA. |
bf02aa7d | 1044 | Handle(OpenGl_FrameBuffer) myRaytraceFBO2[2]; |
91c60b57 | 1045 | //! Framebuffer (FBO) for preliminary OpenGL output. |
1046 | Handle(OpenGl_FrameBuffer) myOpenGlFBO; | |
3c4b62a4 | 1047 | Handle(OpenGl_FrameBuffer) myOpenGlFBO2; |
91c60b57 | 1048 | |
1049 | //! Vertex buffer (VBO) for drawing dummy quad. | |
1050 | OpenGl_VertexBuffer myRaytraceScreenQuad; | |
1051 | ||
1052 | //! Cached locations of frequently used uniform variables. | |
1053 | Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables]; | |
1054 | ||
1055 | //! State of OpenGL structures reflected to ray-tracing. | |
d4aaad5b | 1056 | std::map<const OpenGl_Structure*, StructState> myStructureStates; |
91c60b57 | 1057 | |
1058 | //! PrimitiveArray to TriangleSet map for scene partial update. | |
1059 | std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap; | |
1060 | ||
189f85a3 | 1061 | //! Set of IDs of non-raytracable elements (to detect updates). |
1062 | std::set<Standard_Integer> myNonRaytraceStructureIDs; | |
1063 | ||
1064 | //! Render filter to filter out all raytracable structures. | |
91c60b57 | 1065 | Handle(OpenGl_RaytraceFilter) myRaytraceFilter; |
1066 | ||
1067 | //! Marks if environment map should be updated. | |
1068 | Standard_Boolean myToUpdateEnvironmentMap; | |
1069 | ||
1070 | //! State of OpenGL layer list. | |
189f85a3 | 1071 | Standard_Size myLayerListState; |
1072 | ||
1073 | //! Number of accumulated frames (for progressive rendering). | |
1074 | Standard_Integer myAccumFrames; | |
1075 | ||
1076 | //! Stored ray origins used for detection of camera movements. | |
1077 | OpenGl_Vec3 myPreviousOrigins[3]; | |
1078 | ||
1079 | //! Bullard RNG to produce random sequence. | |
1080 | math_BullardGenerator myRNG; | |
91c60b57 | 1081 | |
679ecdee | 1082 | public: |
1083 | ||
1c35b92f | 1084 | DEFINE_STANDARD_ALLOC |
92efcf78 | 1085 | DEFINE_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView) // Type definition |
679ecdee | 1086 | |
c357e426 | 1087 | friend class OpenGl_GraphicDriver; |
a89742cf | 1088 | friend class OpenGl_Workspace; |
2166f0fa SK |
1089 | }; |
1090 | ||
679ecdee | 1091 | #endif // _OpenGl_View_Header |