0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[occt.git] / src / OpenGl / OpenGl_View.hxx
CommitLineData
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
25e59720 19#include <Standard_Transient.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>
2166f0fa 29
2166f0fa 30#include <Graphic3d_CView.hxx>
d325cb7f 31#include <Graphic3d_CullingTool.hxx>
a79f67f8 32#include <Graphic3d_GraduatedTrihedron.hxx>
51b10cd4 33#include <Graphic3d_SequenceOfHClipPlane.hxx>
eb85ed36 34#include <Graphic3d_ToneMappingMethod.hxx>
c357e426 35#include <Graphic3d_TypeOfShadingModel.hxx>
825aa485 36#include <Graphic3d_WorldViewProjState.hxx>
c5751993 37#include <Graphic3d_ZLayerSettings.hxx>
2166f0fa 38
bf5f0ca2 39#include <OpenGl_Aspects.hxx>
0b0320e7 40#include <OpenGl_BackgroundArray.hxx>
c357e426 41#include <OpenGl_Context.hxx>
42#include <OpenGl_FrameBuffer.hxx>
15669413 43#include <OpenGl_FrameStatsPrs.hxx>
c357e426 44#include <OpenGl_GraduatedTrihedron.hxx>
59f45b7c 45#include <OpenGl_LayerList.hxx>
73192b37 46#include <OpenGl_LineAttributes.hxx>
c357e426 47#include <OpenGl_SceneGeometry.hxx>
48#include <OpenGl_Structure.hxx>
c357e426 49#include <OpenGl_Window.hxx>
50#include <OpenGl_Workspace.hxx>
3a9b5dc8 51#include <OpenGl_TileSampler.hxx>
2166f0fa 52
c357e426 53#include <map>
54#include <set>
2166f0fa 55
b5ac8292 56struct OpenGl_Matrix;
2166f0fa 57
c357e426 58class Graphic3d_StructureManager;
59class OpenGl_GraphicDriver;
60class OpenGl_StateCounter;
61class OpenGl_RaytraceMaterial;
62class OpenGl_TriangleSet;
63class OpenGl_Workspace;
c04c30b3 64class OpenGl_View;
c357e426 65DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView)
c04c30b3 66
c357e426 67//! Implementation of OpenGl view.
68class OpenGl_View : public Graphic3d_CView
2166f0fa 69{
c357e426 70
71public:
72
73 //! Constructor.
74 Standard_EXPORT OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
75 const Handle(OpenGl_GraphicDriver)& theDriver,
76 const Handle(OpenGl_Caps)& theCaps,
c357e426 77 OpenGl_StateCounter* theCounter);
78
79 //! Default destructor.
80 Standard_EXPORT virtual ~OpenGl_View();
2166f0fa 81
62e1beed 82 Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
bf75be98 83
c357e426 84 //! Deletes and erases the view.
85 Standard_EXPORT virtual void Remove() Standard_OVERRIDE;
86
87 //! @param theDrawToFrontBuffer Advanced option to modify rendering mode:
88 //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image.
89 //! Fast, so preferred for interactive work (used by default).
90 //! However these extra drawings will be missed in image dump since it is performed from back buffer.
91 //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen
92 //! in run-time (in case of slow hardware) and/or tearing may appear.
93 //! So this is strongly recommended to draw only simple (fast) structures.
94 //! 2. FALSE. Drawing immediate mode structures to the back buffer.
95 //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync
96 //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read
97 //! from the back buffer.
98 //! @return previous mode.
99 Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) Standard_OVERRIDE;
100
101 //! Creates and maps rendering window to the view.
c357e426 102 //! @param theWindow [in] the window.
103 //! @param theContext [in] the rendering context. If NULL the context will be created internally.
a521d90d 104 Standard_EXPORT virtual void SetWindow (const Handle(Aspect_Window)& theWindow,
105 const Aspect_RenderingContext theContext) Standard_OVERRIDE;
c357e426 106
107 //! Returns window associated with the view.
79104795 108 virtual Handle(Aspect_Window) Window() const Standard_OVERRIDE
109 { return myWindow->PlatformWindow(); }
c357e426 110
111 //! Returns True if the window associated to the view is defined.
79104795 112 virtual Standard_Boolean IsDefined() const Standard_OVERRIDE
113 { return !myWindow.IsNull(); }
c357e426 114
115 //! Handle changing size of the rendering window.
116 Standard_EXPORT virtual void Resized() Standard_OVERRIDE;
117
118 //! Redraw content of the view.
119 Standard_EXPORT virtual void Redraw() Standard_OVERRIDE;
120
121 //! Redraw immediate content of the view.
122 Standard_EXPORT virtual void RedrawImmediate() Standard_OVERRIDE;
123
124 //! Marks BVH tree for given priority list as dirty and marks primitive set for rebuild.
125 Standard_EXPORT virtual void Invalidate() Standard_OVERRIDE;
126
127 //! Return true if view content cache has been invalidated.
d2eddacc 128 virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return !myBackBufferRestored; }
c357e426 129
c357e426 130 //! Dump active rendering buffer into specified memory buffer.
38d90bb3 131 //! In Ray-Tracing allow to get a raw HDR buffer using Graphic3d_BT_RGB_RayTraceHdrLeft buffer type,
132 //! only Left view will be dumped ignoring stereoscopic parameter.
c357e426 133 Standard_EXPORT virtual Standard_Boolean BufferDump (Image_PixMap& theImage,
134 const Graphic3d_BufferType& theBufferType) Standard_OVERRIDE;
135
c357e426 136 //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated.
8f138407 137 Standard_EXPORT virtual void InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
c357e426 138
139 //! Insert a new top-level z layer with the given ID.
140 Standard_EXPORT virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
141
142 //! Remove a z layer with the given ID.
143 Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
2166f0fa 144
c357e426 145 //! Sets the settings for a single Z layer of specified view.
146 Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
147 const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE;
b5ac8292 148
50d06d8f 149 //! Returns the maximum Z layer ID.
150 //! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
151 Standard_EXPORT virtual Standard_Integer ZLayerMax() const Standard_OVERRIDE;
152
153 //! Returns the bounding box of all structures displayed in the Z layer.
154 //! Never fails. If Z layer does not exist nothing happens.
155 Standard_EXPORT virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const Standard_OVERRIDE;
156
157 //! Returns the bounding box of all structures displayed in the Z layer.
3fe9ce0e 158 //! If Z layer does not exist the empty box is returned.
159 //! @param theLayerId layer identifier
160 //! @param theCamera camera definition
161 //! @param theWindowWidth viewport width (for applying transformation-persistence)
162 //! @param theWindowHeight viewport height (for applying transformation-persistence)
163 //! @param theToIncludeAuxiliary consider also auxiliary presentations (with infinite flag or with trihedron transformation persistence)
164 //! @return computed bounding box
7c3ef2f7 165 Standard_EXPORT virtual Bnd_Box ZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId,
166 const Handle(Graphic3d_Camera)& theCamera,
167 const Standard_Integer theWindowWidth,
168 const Standard_Integer theWindowHeight,
169 const Standard_Boolean theToIncludeAuxiliary) const Standard_OVERRIDE;
50d06d8f 170
c357e426 171 //! Returns pointer to an assigned framebuffer object.
b128c892 172 Standard_EXPORT virtual Handle(Standard_Transient) FBO() const Standard_OVERRIDE;
2166f0fa 173
c357e426 174 //! Sets framebuffer object for offscreen rendering.
b128c892 175 Standard_EXPORT virtual void SetFBO (const Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
2166f0fa 176
c357e426 177 //! Generate offscreen FBO in the graphic library.
178 //! If not supported on hardware returns NULL.
b128c892 179 Standard_EXPORT virtual Handle(Standard_Transient) FBOCreate (const Standard_Integer theWidth,
180 const Standard_Integer theHeight) Standard_OVERRIDE;
2166f0fa 181
c357e426 182 //! Remove offscreen FBO from the graphic library
b128c892 183 Standard_EXPORT virtual void FBORelease (Handle(Standard_Transient)& theFbo) Standard_OVERRIDE;
2166f0fa 184
c357e426 185 //! Read offscreen FBO configuration.
b128c892 186 Standard_EXPORT virtual void FBOGetDimensions (const Handle(Standard_Transient)& theFbo,
c357e426 187 Standard_Integer& theWidth,
188 Standard_Integer& theHeight,
189 Standard_Integer& theWidthMax,
190 Standard_Integer& theHeightMax) Standard_OVERRIDE;
191
192 //! Change offscreen FBO viewport.
b128c892 193 Standard_EXPORT virtual void FBOChangeViewport (const Handle(Standard_Transient)& theFbo,
c357e426 194 const Standard_Integer theWidth,
195 const Standard_Integer theHeight) Standard_OVERRIDE;
2166f0fa 196
c357e426 197public:
2166f0fa 198
c357e426 199 //! Returns gradient background fill colors.
200 Standard_EXPORT virtual Aspect_GradientBackground GradientBackground() const Standard_OVERRIDE;
2166f0fa 201
c357e426 202 //! Sets gradient background fill colors.
203 Standard_EXPORT virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) Standard_OVERRIDE;
204
205 //! Returns background image texture file path.
0f57ab75 206 virtual TCollection_AsciiString BackgroundImage() Standard_OVERRIDE { return myBackgroundImagePath; }
c357e426 207
208 //! Sets background image texture file path.
209 Standard_EXPORT virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) Standard_OVERRIDE;
210
211 //! Returns background image fill style.
212 Standard_EXPORT virtual Aspect_FillMethod BackgroundImageStyle() const Standard_OVERRIDE;
213
214 //! Sets background image fill style.
215 Standard_EXPORT virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) Standard_OVERRIDE;
216
217 //! Returns environment texture set for the view.
0f57ab75 218 virtual Handle(Graphic3d_TextureEnv) TextureEnv() const Standard_OVERRIDE { return myTextureEnvData; }
c357e426 219
220 //! Sets environment texture for the view.
221 Standard_EXPORT virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) Standard_OVERRIDE;
222
c357e426 223 //! Return backfacing model used for the view.
224 virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const Standard_OVERRIDE { return myBackfacing; }
225
226 //! Sets backfacing model for the view.
227 virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) Standard_OVERRIDE { myBackfacing = theModel; }
228
7c3ef2f7 229 //! Returns local camera origin currently set for rendering, might be modified during rendering.
230 const gp_XYZ& LocalOrigin() const { return myLocalOrigin; }
231
232 //! Setup local camera origin currently set for rendering.
233 Standard_EXPORT void SetLocalOrigin (const gp_XYZ& theOrigin);
234
c357e426 235 //! Returns list of lights of the view.
992ed6b3 236 virtual const Handle(Graphic3d_LightSet)& Lights() const Standard_OVERRIDE { return myLights; }
c357e426 237
238 //! Sets list of lights for the view.
992ed6b3 239 virtual void SetLights (const Handle(Graphic3d_LightSet)& theLights) Standard_OVERRIDE
c357e426 240 {
241 myLights = theLights;
242 myCurrLightSourceState = myStateCounter->Increment();
243 }
244
245 //! Returns list of clip planes set for the view.
3202bf1e 246 virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const Standard_OVERRIDE { return myClipPlanes; }
c357e426 247
248 //! Sets list of clip planes for the view.
3202bf1e 249 virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) Standard_OVERRIDE { myClipPlanes = thePlanes; }
c357e426 250
26d9c835 251 //! Fill in the dictionary with diagnostic info.
252 //! Should be called within rendering thread.
253 //!
254 //! This API should be used only for user output or for creating automated reports.
255 //! The format of returned information (e.g. key-value layout)
256 //! is NOT part of this API and can be changed at any time.
257 //! Thus application should not parse returned information to weed out specific parameters.
258 Standard_EXPORT virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
259 Graphic3d_DiagnosticInfo theFlags) const Standard_OVERRIDE;
260
79b544e6 261 //! Returns string with statistic performance info.
262 Standard_EXPORT virtual TCollection_AsciiString StatisticInformation() const Standard_OVERRIDE;
263
264 //! Fills in the dictionary with statistic performance info.
265 Standard_EXPORT virtual void StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const Standard_OVERRIDE;
266
c357e426 267public:
268
269 //! Returns background color.
b6472664 270 const Quantity_ColorRGBA& BackgroundColor() const { return myBgColor; }
c357e426 271
c357e426 272 //! Change graduated trihedron.
273 OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
274
275 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
276 const Handle(Graphic3d_TextureEnv)& theTexture);
277
2166f0fa 278 void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
c357e426 279
2166f0fa 280 void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
2166f0fa 281
c357e426 282 void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
2166f0fa 283
e276548b 284 //! Returns list of OpenGL Z-layers.
285 const OpenGl_LayerList& LayerList() const { return myZLayers; }
286
c357e426 287 //! Returns OpenGL window implementation.
5e30547b 288 const Handle(OpenGl_Window)& GlWindow() const { return myWindow; }
e276548b 289
c357e426 290 //! Returns OpenGL environment map.
cc8cbabe 291 const Handle(OpenGl_TextureSet)& GlTextureEnv() const { return myTextureEnv; }
e276548b 292
b7cd4ba7 293 //! Returns selector for BVH tree, providing a possibility to store information
294 //! about current view volume and to detect which objects are overlapping it.
d325cb7f 295 const Graphic3d_CullingTool& BVHTreeSelector() const { return myBVHSelector; }
b7cd4ba7 296
a1954302 297 //! Returns true if there are immediate structures to display
298 bool HasImmediateStructures() const
299 {
c3282ec1 300 return myZLayers.NbImmediateStructures() != 0;
a1954302 301 }
302
d325cb7f 303public: //! @name obsolete Graduated Trihedron functionality
304
305 //! Displays Graduated Trihedron.
306 Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) Standard_OVERRIDE;
307
308 //! Erases Graduated Trihedron.
309 Standard_EXPORT virtual void GraduatedTrihedronErase() Standard_OVERRIDE;
310
311 //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object.
312 //! @param theMin [in] the minimum point of scene.
313 //! @param theMax [in] the maximum point of scene.
314 Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE;
315
c357e426 316protected: //! @name Internal methods for managing GL resources
317
318 //! Initializes OpenGl resource for environment texture.
319 void initTextureEnv (const Handle(OpenGl_Context)& theContext);
320
a521d90d 321protected: //! @name low-level redrawing sub-routines
c357e426 322
323 //! Redraws view for the given monographic camera projection, or left/right eye.
a521d90d 324 Standard_EXPORT virtual void redraw (const Graphic3d_Camera::Projection theProjection,
a1073ae2 325 OpenGl_FrameBuffer* theReadDrawFbo,
326 OpenGl_FrameBuffer* theOitAccumFbo);
2166f0fa 327
c357e426 328 //! Redraws view for the given monographic camera projection, or left/right eye.
329 //!
330 //! Method will blit snapshot containing main scene (myMainSceneFbos or BackBuffer)
331 //! into presentation buffer (myMainSceneFbos -> offscreen FBO or
332 //! myMainSceneFbos -> BackBuffer or BackBuffer -> FrontBuffer),
333 //! and redraw immediate structures on top.
334 //!
335 //! When scene caching is disabled (myTransientDrawToFront, no double buffer in window, etc.),
336 //! the first step (blitting) will be skipped.
337 //!
338 //! @return false if immediate structures has been rendered directly into FrontBuffer
339 //! and Buffer Swap should not be called.
a521d90d 340 Standard_EXPORT virtual bool redrawImmediate (const Graphic3d_Camera::Projection theProjection,
341 OpenGl_FrameBuffer* theReadFbo,
342 OpenGl_FrameBuffer* theDrawFbo,
a1073ae2 343 OpenGl_FrameBuffer* theOitAccumFbo,
a521d90d 344 const Standard_Boolean theIsPartialUpdate = Standard_False);
b5ac8292 345
c357e426 346 //! Blit image from/to specified buffers.
a521d90d 347 Standard_EXPORT bool blitBuffers (OpenGl_FrameBuffer* theReadFbo,
348 OpenGl_FrameBuffer* theDrawFbo,
349 const Standard_Boolean theToFlip = Standard_False);
2166f0fa 350
c357e426 351 //! Setup default FBO.
a521d90d 352 Standard_EXPORT void bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo = NULL);
2166f0fa 353
c357e426 354protected: //! @name Rendering of GL graphics (with prepared drawing buffer).
2166f0fa 355
c357e426 356 //! Renders the graphical contents of the view into the preprepared window or framebuffer.
357 //! @param theProjection [in] the projection that should be used for rendering.
358 //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
a1073ae2 359 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
c357e426 360 //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
a521d90d 361 Standard_EXPORT virtual void render (Graphic3d_Camera::Projection theProjection,
362 OpenGl_FrameBuffer* theReadDrawFbo,
a1073ae2 363 OpenGl_FrameBuffer* theOitAccumFbo,
a521d90d 364 const Standard_Boolean theToDrawImmediate);
2166f0fa 365
c357e426 366 //! Renders the graphical scene.
bf02aa7d 367 //! @param theProjection [in] the projection that is used for rendering.
c357e426 368 //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
a1073ae2 369 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
c357e426 370 //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
bf02aa7d 371 Standard_EXPORT virtual void renderScene (Graphic3d_Camera::Projection theProjection,
372 OpenGl_FrameBuffer* theReadDrawFbo,
a1073ae2 373 OpenGl_FrameBuffer* theOitAccumFbo,
a521d90d 374 const Standard_Boolean theToDrawImmediate);
375
376 //! Draw background (gradient / image)
377 Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace);
2166f0fa 378
c357e426 379 //! Render set of structures presented in the view.
bf02aa7d 380 //! @param theProjection [in] the projection that is used for rendering.
c357e426 381 //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
a1073ae2 382 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
c357e426 383 //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
bf02aa7d 384 Standard_EXPORT virtual void renderStructs (Graphic3d_Camera::Projection theProjection,
385 OpenGl_FrameBuffer* theReadDrawFbo,
a1073ae2 386 OpenGl_FrameBuffer* theOitAccumFbo,
a521d90d 387 const Standard_Boolean theToDrawImmediate);
2166f0fa 388
c357e426 389 //! Renders trihedron.
390 void renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
2166f0fa 391
15669413 392 //! Renders frame statistics.
393 void renderFrameStats();
394
c357e426 395private:
392ac980 396
c357e426 397 //! Adds the structure to display lists of the view.
398 Standard_EXPORT virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
399 const Standard_Integer thePriority) Standard_OVERRIDE;
400
401 //! Erases the structure from display lists of the view.
402 Standard_EXPORT virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) Standard_OVERRIDE;
403
404 //! Change Z layer of a structure already presented in view.
405 Standard_EXPORT virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
406 const Graphic3d_ZLayerId theNewLayerId) Standard_OVERRIDE;
407
408 //! Changes the priority of a structure within its Z layer in the specified view.
409 Standard_EXPORT virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
410 const Standard_Integer theNewPriority) Standard_OVERRIDE;
411
50d06d8f 412 //! Returns zoom-scale factor.
413 Standard_EXPORT virtual Standard_Real considerZoomPersistenceObjects (const Graphic3d_ZLayerId theLayerId,
414 const Handle(Graphic3d_Camera)& theCamera,
415 const Standard_Integer theWindowWidth,
3fe9ce0e 416 const Standard_Integer theWindowHeight) const Standard_OVERRIDE;
50d06d8f 417
a521d90d 418private:
419
420 //! Copy content of Back buffer to the Front buffer.
a0b49de4 421 bool copyBackToFront();
a521d90d 422
423 //! Initialize blit quad.
424 OpenGl_VertexBuffer* initBlitQuad (const Standard_Boolean theToFlip);
425
426 //! Blend together views pair into stereo image.
3c4b62a4 427 void drawStereoPair (OpenGl_FrameBuffer* theDrawFbo);
a521d90d 428
a1073ae2 429 //! Check and update OIT compatibility with current OpenGL context's state.
430 bool checkOitCompatibility (const Handle(OpenGl_Context)& theGlContext,
431 const Standard_Boolean theMSAA);
432
433 //! Chooses compatible internal color format for OIT frame buffer.
434 bool chooseOitColorConfiguration (const Handle(OpenGl_Context)& theGlContext,
435 const Standard_Integer theConfigIndex,
436 OpenGl_ColorFormats& theFormats);
437
c357e426 438protected:
439
440 OpenGl_GraphicDriver* myDriver;
441 Handle(OpenGl_Window) myWindow;
442 Handle(OpenGl_Workspace) myWorkspace;
443 Handle(OpenGl_Caps) myCaps;
c357e426 444 Standard_Boolean myWasRedrawnGL;
445
c357e426 446 Graphic3d_TypeOfBackfacingModel myBackfacing;
3202bf1e 447 Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
7c3ef2f7 448 gp_XYZ myLocalOrigin;
b128c892 449 Handle(OpenGl_FrameBuffer) myFBO;
c357e426 450 Standard_Boolean myToShowGradTrihedron;
451 TCollection_AsciiString myBackgroundImagePath;
452 Handle(Graphic3d_TextureEnv) myTextureEnvData;
453 Graphic3d_GraduatedTrihedron myGTrihedronData;
454
992ed6b3 455 Handle(Graphic3d_LightSet) myNoShadingLight;
456 Handle(Graphic3d_LightSet) myLights;
c357e426 457 OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
458
459 Graphic3d_WorldViewProjState myWorldViewProjState; //!< camera modification state
460 OpenGl_StateCounter* myStateCounter;
461 Standard_Size myCurrLightSourceState;
992ed6b3 462 Standard_Size myLightsRevision;
392ac980 463
464 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
465
466 StateInfo myLastOrientationState;
467 StateInfo myLastViewMappingState;
468 StateInfo myLastLightSourceState;
30f0ad28 469
b7cd4ba7 470 //! Is needed for selection of overlapping objects and storage of the current view volume
d325cb7f 471 Graphic3d_CullingTool myBVHSelector;
b7cd4ba7 472
c357e426 473 OpenGl_GraduatedTrihedron myGraduatedTrihedron;
15669413 474 OpenGl_FrameStatsPrs myFrameStatsPrs;
c357e426 475
cc8cbabe 476 Handle(OpenGl_TextureSet) myTextureEnv;
c357e426 477
3a9b5dc8 478 //! Framebuffers for OpenGL output.
479 Handle(OpenGl_FrameBuffer) myOpenGlFBO;
480 Handle(OpenGl_FrameBuffer) myOpenGlFBO2;
481
c357e426 482protected: //! @name Rendering properties
483
484 //! Two framebuffers (left and right views) store cached main presentation
485 //! of the view (without presentation of immediate layers).
3c4b62a4 486 GLint myFboColorFormat; //!< sized format for color attachments
487 GLint myFboDepthFormat; //!< sized format for depth-stencil attachments
a1073ae2 488 OpenGl_ColorFormats myFboOitColorConfig; //!< selected color format configuration for OIT color attachments
c357e426 489 Handle(OpenGl_FrameBuffer) myMainSceneFbos[2];
a1073ae2 490 Handle(OpenGl_FrameBuffer) myMainSceneFbosOit[2]; //!< Additional buffers for transparent draw of main layer.
491 Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2]; //!< Additional buffers for immediate layer in stereo mode.
492 Handle(OpenGl_FrameBuffer) myImmediateSceneFbosOit[2]; //!< Additional buffers for transparency draw of immediate layer.
c357e426 493 OpenGl_VertexBuffer myFullScreenQuad; //!< Vertices for full-screen quad rendering.
494 OpenGl_VertexBuffer myFullScreenQuadFlip;
495 Standard_Boolean myToFlipOutput; //!< Flag to draw result image upside-down
496 unsigned int myFrameCounter; //!< redraw counter, for debugging
7ccf8676 497 Standard_Boolean myHasFboBlit; //!< disable FBOs on failure
a1073ae2 498 Standard_Boolean myToDisableOIT; //!< disable OIT on failure
499 Standard_Boolean myToDisableOITMSAA; //!< disable OIT with MSAA on failure
7ccf8676 500 Standard_Boolean myToDisableMSAA; //!< disable MSAA after failure
c357e426 501 Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
502 Standard_Boolean myBackBufferRestored;
503 Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data
504
0b0320e7 505protected: //! @name Background parameters
506
bf5f0ca2 507 OpenGl_Aspects* myTextureParams; //!< Stores texture and its parameters for textured background
0b0320e7 508 OpenGl_BackgroundArray* myBgGradientArray; //!< Primitive array for gradient background
509 OpenGl_BackgroundArray* myBgTextureArray; //!< Primitive array for texture background
510
91c60b57 511protected: //! @name data types related to ray-tracing
512
513 //! Result of OpenGL shaders initialization.
514 enum RaytraceInitStatus
515 {
516 OpenGl_RT_NONE,
517 OpenGl_RT_INIT,
518 OpenGl_RT_FAIL
519 };
520
521 //! Describes update mode (state).
522 enum RaytraceUpdateMode
523 {
524 OpenGl_GUM_CHECK, //!< check geometry state
525 OpenGl_GUM_PREPARE, //!< collect unchanged objects
526 OpenGl_GUM_REBUILD //!< rebuild changed and new objects
527 };
528
529 //! Defines frequently used shader variables.
530 enum ShaderVariableIndex
531 {
532 OpenGl_RT_aPosition,
533
189f85a3 534 // camera position
91c60b57 535 OpenGl_RT_uOriginLT,
536 OpenGl_RT_uOriginLB,
537 OpenGl_RT_uOriginRT,
538 OpenGl_RT_uOriginRB,
539 OpenGl_RT_uDirectLT,
540 OpenGl_RT_uDirectLB,
541 OpenGl_RT_uDirectRT,
542 OpenGl_RT_uDirectRB,
3a9b5dc8 543 OpenGl_RT_uViewPrMat,
91c60b57 544 OpenGl_RT_uUnviewMat,
545
189f85a3 546 // 3D scene params
91c60b57 547 OpenGl_RT_uSceneRad,
548 OpenGl_RT_uSceneEps,
549 OpenGl_RT_uLightAmbnt,
550 OpenGl_RT_uLightCount,
551
189f85a3 552 // background params
553 OpenGl_RT_uBackColorTop,
554 OpenGl_RT_uBackColorBot,
91c60b57 555
189f85a3 556 // ray-tracing params
557 OpenGl_RT_uShadowsEnabled,
558 OpenGl_RT_uReflectEnabled,
559 OpenGl_RT_uSphereMapEnabled,
560 OpenGl_RT_uSphereMapForBack,
561 OpenGl_RT_uTexSamplersArray,
8c820969 562 OpenGl_RT_uBlockedRngEnabled,
189f85a3 563
3a9b5dc8 564 // size of render window
565 OpenGl_RT_uWinSizeX,
566 OpenGl_RT_uWinSizeY,
567
189f85a3 568 // sampled frame params
383c6c9f 569 OpenGl_RT_uAccumSamples,
189f85a3 570 OpenGl_RT_uFrameRndSeed,
571
572 // adaptive FSAA params
91c60b57 573 OpenGl_RT_uOffsetX,
574 OpenGl_RT_uOffsetY,
575 OpenGl_RT_uSamples,
91c60b57 576
b09447ed 577 // images used by ISS mode
3a9b5dc8 578 OpenGl_RT_uRenderImage,
e084dbbc 579 OpenGl_RT_uTilesImage,
3a9b5dc8 580 OpenGl_RT_uOffsetImage,
66d1cdc6 581 OpenGl_RT_uTileSize,
582 OpenGl_RT_uVarianceScaleFactor,
3a9b5dc8 583
b09447ed 584 // maximum radiance value
585 OpenGl_RT_uMaxRadiance,
586
91c60b57 587 OpenGl_RT_NbVariables // special field
588 };
589
3a9b5dc8 590 //! Defines OpenGL image samplers.
591 enum ShaderImageNames
592 {
66d1cdc6 593 OpenGl_RT_OutputImage = 0,
594 OpenGl_RT_VisualErrorImage = 1,
595 OpenGl_RT_TileOffsetsImage = 2,
e084dbbc 596 OpenGl_RT_TileSamplesImage = 3
91c60b57 597 };
598
599 //! Tool class for management of shader sources.
600 class ShaderSource
601 {
602 public:
603
189f85a3 604 //! Default shader prefix - empty string.
605 static const TCollection_AsciiString EMPTY_PREFIX;
606
91c60b57 607 //! Creates new uninitialized shader source.
608 ShaderSource()
609 {
610 //
611 }
612
73722cc9 613 public:
189f85a3 614
73722cc9 615 //! Returns error description in case of load fail.
616 const TCollection_AsciiString& ErrorDescription() const
617 {
618 return myError;
91c60b57 619 }
620
91c60b57 621 //! Returns prefix to insert before the source.
622 const TCollection_AsciiString& Prefix() const
623 {
624 return myPrefix;
625 }
626
627 //! Sets prefix to insert before the source.
628 void SetPrefix (const TCollection_AsciiString& thePrefix)
629 {
630 myPrefix = thePrefix;
631 }
632
633 //! Returns shader source combined with prefix.
634 TCollection_AsciiString Source() const;
635
636 //! Loads shader source from specified files.
ee5befae 637 Standard_Boolean LoadFromFiles (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
638
639 //! Loads shader source from specified strings.
640 Standard_Boolean LoadFromStrings (const TCollection_AsciiString* theStrings, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
91c60b57 641
642 private:
643
644 TCollection_AsciiString mySource; //!< Source string of the shader object
645 TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
73722cc9 646 TCollection_AsciiString myError; //!< error state
91c60b57 647
648 };
649
650 //! Default ray-tracing depth.
651 static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
652
653 //! Default size of traversal stack.
f2474958 654 static const Standard_Integer THE_DEFAULT_STACK_SIZE = 10;
91c60b57 655
656 //! Compile-time ray-tracing parameters.
657 struct RaytracingParams
658 {
659 //! Actual size of traversal stack in shader program.
660 Standard_Integer StackSize;
661
662 //! Actual ray-tracing depth (number of ray bounces).
663 Standard_Integer NbBounces;
664
f483f2ed 665 //! Enables/disables light propagation through transparent media.
91c60b57 666 Standard_Boolean TransparentShadows;
667
189f85a3 668 //! Enables/disables global illumination (GI) effects.
669 Standard_Boolean GlobalIllumination;
670
f483f2ed 671 //! Enables/disables the use of OpenGL bindless textures.
672 Standard_Boolean UseBindlessTextures;
673
b4327ba8 674 //! Enables/disables two-sided BSDF models instead of one-sided.
675 Standard_Boolean TwoSidedBsdfModels;
676
3a9b5dc8 677 //! Enables/disables adaptive screen sampling for path tracing.
678 Standard_Boolean AdaptiveScreenSampling;
679
e084dbbc 680 //! Enables/disables 1-pass atomic mode for AdaptiveScreenSampling.
681 Standard_Boolean AdaptiveScreenSamplingAtomic;
682
b09447ed 683 //! Enables/disables environment map for background.
684 Standard_Boolean UseEnvMapForBackground;
685
686 //! Maximum radiance value used for clamping radiance estimation.
687 Standard_ShortReal RadianceClampingValue;
eb85ed36 688
b27ab03d 689 //! Enables/disables depth-of-field effect (path tracing, perspective camera).
690 Standard_Boolean DepthOfField;
691
eb85ed36 692 //! Tone mapping method for path tracing.
693 Graphic3d_ToneMappingMethod ToneMappingMethod;
4eaaf9d8 694
91c60b57 695 //! Creates default compile-time ray-tracing parameters.
696 RaytracingParams()
b09447ed 697 : StackSize (THE_DEFAULT_STACK_SIZE),
698 NbBounces (THE_DEFAULT_NB_BOUNCES),
b4327ba8 699 TransparentShadows (Standard_False),
700 GlobalIllumination (Standard_False),
701 UseBindlessTextures (Standard_False),
702 TwoSidedBsdfModels (Standard_False),
b09447ed 703 AdaptiveScreenSampling (Standard_False),
e084dbbc 704 AdaptiveScreenSamplingAtomic (Standard_False),
b09447ed 705 UseEnvMapForBackground (Standard_False),
4eaaf9d8 706 RadianceClampingValue (30.0),
b27ab03d 707 DepthOfField (Standard_False),
eb85ed36 708 ToneMappingMethod (Graphic3d_ToneMappingMethod_Disabled) { }
91c60b57 709 };
710
d4aaad5b 711 //! Describes state of OpenGL structure.
712 struct StructState
713 {
714 Standard_Size StructureState;
715 Standard_Size InstancedState;
716
717 //! Creates new structure state.
718 StructState (const Standard_Size theStructureState = 0,
719 const Standard_Size theInstancedState = 0)
720 : StructureState (theStructureState),
721 InstancedState (theInstancedState)
722 {
723 //
724 }
725
726 //! Creates new structure state.
727 StructState (const OpenGl_Structure* theStructure)
728 {
729 StructureState = theStructure->ModificationState();
730
731 InstancedState = theStructure->InstancedStructure() != NULL ?
732 theStructure->InstancedStructure()->ModificationState() : 0;
733 }
734 };
735
91c60b57 736protected: //! @name methods related to ray-tracing
737
738 //! Updates 3D scene geometry for ray-tracing.
739 Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode theMode,
740 const Standard_Integer theViewId,
741 const Handle(OpenGl_Context)& theGlContext);
742
743 //! Updates 3D scene light sources for ray-tracing.
744 Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext);
745
91c60b57 746 //! Checks to see if the OpenGL structure is modified.
747 Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure);
748
749 //! Adds OpenGL structure to ray-traced scene geometry.
750 Standard_Boolean addRaytraceStructure (const OpenGl_Structure* theStructure,
751 const Handle(OpenGl_Context)& theGlContext);
752
753 //! Adds OpenGL groups to ray-traced scene geometry.
8c820969 754 Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure,
755 const OpenGl_RaytraceMaterial& theStructMat,
1f7f5a90 756 const Handle(Geom_Transformation)& theTrsf,
8c820969 757 const Handle(OpenGl_Context)& theGlContext);
91c60b57 758
759 //! Creates ray-tracing material properties.
bf5f0ca2 760 OpenGl_RaytraceMaterial convertMaterial (const OpenGl_Aspects* theAspect,
91c60b57 761 const Handle(OpenGl_Context)& theGlContext);
762
763 //! Adds OpenGL primitive array to ray-traced scene geometry.
f5b72419 764 Handle(OpenGl_TriangleSet) addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
765 const Standard_Integer theMatID,
766 const OpenGl_Mat4* theTrans);
91c60b57 767
768 //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
769 Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
770 const Standard_Integer theMatID,
771 const Standard_Integer theCount,
772 const Standard_Integer theOffset,
773 const OpenGl_PrimitiveArray& theArray);
774
775 //! Adds OpenGL triangle array to ray-traced scene geometry.
776 Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
777 const Standard_Integer theMatID,
778 const Standard_Integer theCount,
779 const Standard_Integer theOffset,
780 const Handle(Graphic3d_IndexBuffer)& theIndices);
781
782 //! Adds OpenGL triangle fan array to ray-traced scene geometry.
783 Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
784 const Standard_Integer theMatID,
785 const Standard_Integer theCount,
786 const Standard_Integer theOffset,
787 const Handle(Graphic3d_IndexBuffer)& theIndices);
788
789 //! Adds OpenGL triangle strip array to ray-traced scene geometry.
790 Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
791 const Standard_Integer theMatID,
792 const Standard_Integer theCount,
793 const Standard_Integer theOffset,
794 const Handle(Graphic3d_IndexBuffer)& theIndices);
795
796 //! Adds OpenGL quadrangle array to ray-traced scene geometry.
797 Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
798 const Standard_Integer theMatID,
799 const Standard_Integer theCount,
800 const Standard_Integer theOffset,
801 const Handle(Graphic3d_IndexBuffer)& theIndices);
802
803 //! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
804 Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
805 const Standard_Integer theMatID,
806 const Standard_Integer theCount,
807 const Standard_Integer theOffset,
808 const Handle(Graphic3d_IndexBuffer)& theIndices);
809
810 //! Adds OpenGL polygon array to ray-traced scene geometry.
811 Standard_Boolean addRaytracePolygonArray (OpenGl_TriangleSet& theSet,
812 const Standard_Integer theMatID,
813 const Standard_Integer theCount,
814 const Standard_Integer theOffset,
815 const Handle(Graphic3d_IndexBuffer)& theIndices);
816
817 //! Uploads ray-trace data to the GPU.
818 Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext);
819
820 //! Generates shader prefix based on current ray-tracing options.
821 TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const;
822
823 //! Performs safe exit when shaders initialization fails.
824 Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage,
825 const Handle(OpenGl_Context)& theGlContext);
826
827 //! Loads and compiles shader object from specified source.
828 Handle(OpenGl_ShaderObject) initShader (const GLenum theType,
829 const ShaderSource& theSource,
830 const Handle(OpenGl_Context)& theGlContext);
831
189f85a3 832 //! Creates shader program from the given vertex and fragment shaders.
833 Handle(OpenGl_ShaderProgram) initProgram (const Handle(OpenGl_Context)& theGlContext,
834 const Handle(OpenGl_ShaderObject)& theVertShader,
d95f5ce1 835 const Handle(OpenGl_ShaderObject)& theFragShader,
836 const TCollection_AsciiString& theName);
189f85a3 837
91c60b57 838 //! Initializes OpenGL/GLSL shader programs.
66d1cdc6 839 Standard_Boolean initRaytraceResources (const Standard_Integer theSizeX,
840 const Standard_Integer theSizeY,
841 const Handle(OpenGl_Context)& theGlContext);
91c60b57 842
843 //! Releases OpenGL/GLSL shader programs.
d877e610 844 void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext,
845 const Standard_Boolean theToRebuild = Standard_False);
91c60b57 846
bf02aa7d 847 //! Updates auxiliary OpenGL frame buffers.
848 Standard_Boolean updateRaytraceBuffers (const Standard_Integer theSizeX,
91c60b57 849 const Standard_Integer theSizeY,
850 const Handle(OpenGl_Context)& theGlContext);
851
852 //! Generates viewing rays for corners of screen quad.
b27ab03d 853 //! (ray tracing; path tracing for orthographic camera)
91c60b57 854 void updateCamera (const OpenGl_Mat4& theOrientation,
855 const OpenGl_Mat4& theViewMapping,
856 OpenGl_Vec3* theOrigins,
857 OpenGl_Vec3* theDirects,
1d865689 858 OpenGl_Mat4& theView,
91c60b57 859 OpenGl_Mat4& theUnView);
860
b27ab03d 861 //! Generate viewing rays (path tracing, perspective camera).
862 void updatePerspCameraPT(const OpenGl_Mat4& theOrientation,
863 const OpenGl_Mat4& theViewMapping,
864 Graphic3d_Camera::Projection theProjection,
865 OpenGl_Mat4& theViewPr,
866 OpenGl_Mat4& theUnview,
867 const int theWinSizeX,
868 const int theWinSizeY);
869
91c60b57 870 //! Binds ray-trace textures to corresponding texture units.
66d1cdc6 871 void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext,
872 int theStereoView);
91c60b57 873
874 //! Unbinds ray-trace textures from corresponding texture unit.
875 void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
876
877 //! Sets uniform state for the given ray-tracing shader program.
3a9b5dc8 878 Standard_Boolean setUniformState (const Standard_Integer theProgramId,
879 const Standard_Integer theSizeX,
880 const Standard_Integer theSizeY,
b27ab03d 881 Graphic3d_Camera::Projection theProjection,
91c60b57 882 const Handle(OpenGl_Context)& theGlContext);
883
884 //! Runs ray-tracing shader programs.
c357e426 885 Standard_Boolean runRaytraceShaders (const Standard_Integer theSizeX,
91c60b57 886 const Standard_Integer theSizeY,
bf02aa7d 887 Graphic3d_Camera::Projection theProjection,
38a0206f 888 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 889 const Handle(OpenGl_Context)& theGlContext);
890
3a9b5dc8 891 //! Runs classical (Whitted-style) ray-tracing kernel.
892 Standard_Boolean runRaytrace (const Standard_Integer theSizeX,
893 const Standard_Integer theSizeY,
894 Graphic3d_Camera::Projection theProjection,
895 OpenGl_FrameBuffer* theReadDrawFbo,
896 const Handle(OpenGl_Context)& theGlContext);
897
898 //! Runs path tracing (global illumination) kernel.
4eaaf9d8 899 Standard_Boolean runPathtrace (const Standard_Integer theSizeX,
900 const Standard_Integer theSizeY,
901 Graphic3d_Camera::Projection theProjection,
4eaaf9d8 902 const Handle(OpenGl_Context)& theGlContext);
3a9b5dc8 903
66d1cdc6 904 //! Runs path tracing (global illumination) kernel.
905 Standard_Boolean runPathtraceOut (Graphic3d_Camera::Projection theProjection,
906 OpenGl_FrameBuffer* theReadDrawFbo,
907 const Handle(OpenGl_Context)& theGlContext);
908
3a9b5dc8 909 //! Redraws the window using OpenGL/GLSL ray-tracing or path tracing.
c357e426 910 Standard_Boolean raytrace (const Standard_Integer theSizeX,
91c60b57 911 const Standard_Integer theSizeY,
bf02aa7d 912 Graphic3d_Camera::Projection theProjection,
38a0206f 913 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 914 const Handle(OpenGl_Context)& theGlContext);
915
916protected: //! @name fields related to ray-tracing
917
3a9b5dc8 918 //! Result of RT/PT shaders initialization.
91c60b57 919 RaytraceInitStatus myRaytraceInitStatus;
920
3a9b5dc8 921 //! Is ray-tracing geometry data valid?
91c60b57 922 Standard_Boolean myIsRaytraceDataValid;
923
3a9b5dc8 924 //! True if warning about missing extension GL_ARB_bindless_texture has been displayed.
91c60b57 925 Standard_Boolean myIsRaytraceWarnTextures;
926
927 //! 3D scene geometry data for ray-tracing.
928 OpenGl_RaytraceGeometry myRaytraceGeometry;
929
f5b72419 930 //! Builder for triangle set.
931 opencascade::handle<BVH_Builder<Standard_ShortReal, 3> > myRaytraceBVHBuilder;
932
91c60b57 933 //! Compile-time ray-tracing parameters.
934 RaytracingParams myRaytraceParameters;
935
936 //! Radius of bounding sphere of the scene.
937 Standard_ShortReal myRaytraceSceneRadius;
938 //! Scene epsilon to prevent self-intersections.
939 Standard_ShortReal myRaytraceSceneEpsilon;
940
941 //! OpenGL/GLSL source of ray-tracing fragment shader.
942 ShaderSource myRaytraceShaderSource;
943 //! OpenGL/GLSL source of adaptive-AA fragment shader.
944 ShaderSource myPostFSAAShaderSource;
3a9b5dc8 945 //! OpenGL/GLSL source of RT/PT display fragment shader.
946 ShaderSource myOutImageShaderSource;
91c60b57 947
948 //! OpenGL/GLSL ray-tracing fragment shader.
949 Handle(OpenGl_ShaderObject) myRaytraceShader;
950 //! OpenGL/GLSL adaptive-AA fragment shader.
951 Handle(OpenGl_ShaderObject) myPostFSAAShader;
3a9b5dc8 952 //! OpenGL/GLSL ray-tracing display fragment shader.
953 Handle(OpenGl_ShaderObject) myOutImageShader;
91c60b57 954
955 //! OpenGL/GLSL ray-tracing shader program.
956 Handle(OpenGl_ShaderProgram) myRaytraceProgram;
957 //! OpenGL/GLSL adaptive-AA shader program.
958 Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
189f85a3 959 //! OpenGL/GLSL program for displaying texture.
960 Handle(OpenGl_ShaderProgram) myOutImageProgram;
91c60b57 961
962 //! Texture buffer of data records of bottom-level BVH nodes.
963 Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
964 //! Texture buffer of minimum points of bottom-level BVH nodes.
965 Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
966 //! Texture buffer of maximum points of bottom-level BVH nodes.
967 Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
968 //! Texture buffer of transformations of high-level BVH nodes.
969 Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
970
971 //! Texture buffer of vertex coords.
972 Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
973 //! Texture buffer of vertex normals.
974 Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
975 //! Texture buffer of vertex UV coords.
976 Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture;
977 //! Texture buffer of triangle indices.
978 Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
979
980 //! Texture buffer of material properties.
981 Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
982 //! Texture buffer of light source properties.
983 Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
984
985 //! 1st framebuffer (FBO) to perform adaptive FSAA.
3a9b5dc8 986 //! Used in compatibility mode (no adaptive sampling).
bf02aa7d 987 Handle(OpenGl_FrameBuffer) myRaytraceFBO1[2];
91c60b57 988 //! 2nd framebuffer (FBO) to perform adaptive FSAA.
3a9b5dc8 989 //! Used in compatibility mode (no adaptive sampling).
bf02aa7d 990 Handle(OpenGl_FrameBuffer) myRaytraceFBO2[2];
3a9b5dc8 991
992 //! Output textures (2 textures are used in stereo mode).
993 //! Used if adaptive screen sampling is activated.
994 Handle(OpenGl_Texture) myRaytraceOutputTexture[2];
995
b27ab03d 996 //! Texture containing per-tile visual error estimation (2 textures are used in stereo mode).
3a9b5dc8 997 //! Used if adaptive screen sampling is activated.
b27ab03d 998 Handle(OpenGl_Texture) myRaytraceVisualErrorTexture[2];
999 //! Texture containing offsets of sampled screen tiles (2 textures are used in stereo mode).
3a9b5dc8 1000 //! Used if adaptive screen sampling is activated.
b27ab03d 1001 Handle(OpenGl_Texture) myRaytraceTileOffsetsTexture[2];
e084dbbc 1002 //! Texture containing amount of extra per-tile samples (2 textures are used in stereo mode).
1003 //! Used if adaptive screen sampling is activated.
1004 Handle(OpenGl_Texture) myRaytraceTileSamplesTexture[2];
91c60b57 1005
1006 //! Vertex buffer (VBO) for drawing dummy quad.
1007 OpenGl_VertexBuffer myRaytraceScreenQuad;
1008
1009 //! Cached locations of frequently used uniform variables.
1010 Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
1011
1012 //! State of OpenGL structures reflected to ray-tracing.
d4aaad5b 1013 std::map<const OpenGl_Structure*, StructState> myStructureStates;
91c60b57 1014
1015 //! PrimitiveArray to TriangleSet map for scene partial update.
1016 std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
1017
189f85a3 1018 //! Set of IDs of non-raytracable elements (to detect updates).
1019 std::set<Standard_Integer> myNonRaytraceStructureIDs;
1020
91c60b57 1021 //! Marks if environment map should be updated.
1022 Standard_Boolean myToUpdateEnvironmentMap;
1023
1024 //! State of OpenGL layer list.
bd6a8454 1025 Standard_Size myRaytraceLayerListState;
189f85a3 1026
1027 //! Number of accumulated frames (for progressive rendering).
1028 Standard_Integer myAccumFrames;
1029
1030 //! Stored ray origins used for detection of camera movements.
1031 OpenGl_Vec3 myPreviousOrigins[3];
1032
1033 //! Bullard RNG to produce random sequence.
1034 math_BullardGenerator myRNG;
91c60b57 1035
3a9b5dc8 1036 //! Tool object for sampling screen tiles in PT mode.
1037 OpenGl_TileSampler myTileSampler;
1038
b27ab03d 1039 //! Camera position used for projective mode
1040 OpenGl_Vec3 myEyeOrig;
1041
1042 //! Camera view direction used for projective mode
1043 OpenGl_Vec3 myEyeView;
1044
1045 //! Camera's screen vertical direction used for projective mode
1046 OpenGl_Vec3 myEyeVert;
1047
1048 //! Camera's screen horizontal direction used for projective mode
1049 OpenGl_Vec3 myEyeSide;
1050
1051 //! Camera's screen size used for projective mode
1052 OpenGl_Vec2 myEyeSize;
1053
1054 //! Aperture radius of camera on previous frame used for depth-of-field (path tracing)
1055 float myPrevCameraApertureRadius;
1056
1057 //! Focal distance of camera on previous frame used for depth-of-field (path tracing)
1058 float myPrevCameraFocalPlaneDist;
1059
679ecdee 1060public:
1061
1c35b92f 1062 DEFINE_STANDARD_ALLOC
92efcf78 1063 DEFINE_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView) // Type definition
679ecdee 1064
c357e426 1065 friend class OpenGl_GraphicDriver;
a89742cf 1066 friend class OpenGl_Workspace;
a1073ae2 1067 friend class OpenGl_LayerList;
15669413 1068 friend class OpenGl_FrameStats;
2166f0fa
SK
1069};
1070
679ecdee 1071#endif // _OpenGl_View_Header