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