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