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