0028654: Existed tool (gendoc) for generation documentation does not take into accoun...
[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
19#include <MMgt_TShared.hxx>
ec357c5c 20#include <Standard_Type.hxx>
2166f0fa
SK
21
22#include <TColStd_Array2OfReal.hxx>
23#include <NCollection_List.hxx>
189f85a3 24#include <math_BullardGenerator.hxx>
2166f0fa
SK
25
26#include <Quantity_NameOfColor.hxx>
27#include <Aspect_FillMethod.hxx>
28#include <Aspect_GradientFillMethod.hxx>
2166f0fa 29
2166f0fa 30#include <Graphic3d_CView.hxx>
a79f67f8 31#include <Graphic3d_GraduatedTrihedron.hxx>
51b10cd4 32#include <Graphic3d_SequenceOfHClipPlane.hxx>
c357e426 33#include <Graphic3d_TypeOfShadingModel.hxx>
825aa485 34#include <Graphic3d_WorldViewProjState.hxx>
c5751993 35#include <Graphic3d_ZLayerSettings.hxx>
2166f0fa 36
0b0320e7 37#include <OpenGl_AspectFace.hxx>
38#include <OpenGl_BackgroundArray.hxx>
b7cd4ba7 39#include <OpenGl_BVHTreeSelector.hxx>
c357e426 40#include <OpenGl_Context.hxx>
41#include <OpenGl_FrameBuffer.hxx>
42#include <OpenGl_GraduatedTrihedron.hxx>
59f45b7c 43#include <OpenGl_LayerList.hxx>
2166f0fa 44#include <OpenGl_Light.hxx>
73192b37 45#include <OpenGl_LineAttributes.hxx>
c357e426 46#include <OpenGl_SceneGeometry.hxx>
47#include <OpenGl_Structure.hxx>
c357e426 48#include <OpenGl_Window.hxx>
49#include <OpenGl_Workspace.hxx>
3a9b5dc8 50#include <OpenGl_TileSampler.hxx>
2166f0fa 51
c357e426 52#include <map>
53#include <set>
2166f0fa 54
b5ac8292 55struct OpenGl_Matrix;
2166f0fa 56
c357e426 57class Graphic3d_StructureManager;
58class OpenGl_GraphicDriver;
59class OpenGl_StateCounter;
60class OpenGl_RaytraceMaterial;
61class OpenGl_TriangleSet;
62class OpenGl_Workspace;
c04c30b3 63class OpenGl_View;
c357e426 64DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView)
c04c30b3 65
c357e426 66//! Implementation of OpenGl view.
67class OpenGl_View : public Graphic3d_CView
2166f0fa 68{
c357e426 69
70public:
71
72 //! Constructor.
73 Standard_EXPORT OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
74 const Handle(OpenGl_GraphicDriver)& theDriver,
75 const Handle(OpenGl_Caps)& theCaps,
76 Standard_Boolean& theDeviceLostFlag,
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
258 //! Returns shading model of the view.
259 virtual Graphic3d_TypeOfShadingModel ShadingModel() const Standard_OVERRIDE { return myShadingModel; }
260
261 //! Sets shading model of the view.
262 virtual void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel) Standard_OVERRIDE { myShadingModel = theModel; }
263
c357e426 264 //! Return backfacing model used for the view.
265 virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const Standard_OVERRIDE { return myBackfacing; }
266
267 //! Sets backfacing model for the view.
268 virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) Standard_OVERRIDE { myBackfacing = theModel; }
269
270 //! Returns camera object of the view.
271 virtual const Handle(Graphic3d_Camera)& Camera() const Standard_OVERRIDE { return myCamera; }
272
7c3ef2f7 273 //! Returns local camera origin currently set for rendering, might be modified during rendering.
274 const gp_XYZ& LocalOrigin() const { return myLocalOrigin; }
275
276 //! Setup local camera origin currently set for rendering.
277 Standard_EXPORT void SetLocalOrigin (const gp_XYZ& theOrigin);
278
c357e426 279 //! Sets camera used by the view.
7c3ef2f7 280 Standard_EXPORT virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) Standard_OVERRIDE;
c357e426 281
c357e426 282 //! Returns list of lights of the view.
283 virtual const Graphic3d_ListOfCLight& Lights() const Standard_OVERRIDE { return myLights; }
284
285 //! Sets list of lights for the view.
286 virtual void SetLights (const Graphic3d_ListOfCLight& theLights) Standard_OVERRIDE
287 {
288 myLights = theLights;
289 myCurrLightSourceState = myStateCounter->Increment();
290 }
291
292 //! Returns list of clip planes set for the view.
3202bf1e 293 virtual const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const Standard_OVERRIDE { return myClipPlanes; }
c357e426 294
295 //! Sets list of clip planes for the view.
3202bf1e 296 virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) Standard_OVERRIDE { myClipPlanes = thePlanes; }
c357e426 297
26d9c835 298 //! Fill in the dictionary with diagnostic info.
299 //! Should be called within rendering thread.
300 //!
301 //! This API should be used only for user output or for creating automated reports.
302 //! The format of returned information (e.g. key-value layout)
303 //! is NOT part of this API and can be changed at any time.
304 //! Thus application should not parse returned information to weed out specific parameters.
305 Standard_EXPORT virtual void DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
306 Graphic3d_DiagnosticInfo theFlags) const Standard_OVERRIDE;
307
c357e426 308public:
309
310 //! Returns background color.
b6472664 311 const Quantity_ColorRGBA& BackgroundColor() const { return myBgColor; }
c357e426 312
c357e426 313 //! Change graduated trihedron.
314 OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
315
316 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
317 const Handle(Graphic3d_TextureEnv)& theTexture);
318
2166f0fa 319 void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
c357e426 320
2166f0fa 321 void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
2166f0fa 322
c357e426 323 void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
2166f0fa 324
e276548b 325 //! Returns list of OpenGL Z-layers.
326 const OpenGl_LayerList& LayerList() const { return myZLayers; }
327
328 //! Returns list of openGL light sources.
329 const OpenGl_ListOfLight& LightList() const { return myLights; }
330
c357e426 331 //! Returns OpenGL window implementation.
332 const Handle(OpenGl_Window) GlWindow() const { return myWindow; }
e276548b 333
c357e426 334 //! Returns OpenGL environment map.
335 const Handle(OpenGl_Texture)& GlTextureEnv() const { return myTextureEnv; }
e276548b 336
b7cd4ba7 337 //! Returns selector for BVH tree, providing a possibility to store information
338 //! about current view volume and to detect which objects are overlapping it.
339 OpenGl_BVHTreeSelector& BVHTreeSelector() { return myBVHSelector; }
340
a1954302 341 //! Returns true if there are immediate structures to display
342 bool HasImmediateStructures() const
343 {
c3282ec1 344 return myZLayers.NbImmediateStructures() != 0;
a1954302 345 }
346
c357e426 347protected: //! @name Internal methods for managing GL resources
348
349 //! Initializes OpenGl resource for environment texture.
350 void initTextureEnv (const Handle(OpenGl_Context)& theContext);
351
a521d90d 352protected: //! @name low-level redrawing sub-routines
c357e426 353
354 //! Redraws view for the given monographic camera projection, or left/right eye.
a521d90d 355 Standard_EXPORT virtual void redraw (const Graphic3d_Camera::Projection theProjection,
a1073ae2 356 OpenGl_FrameBuffer* theReadDrawFbo,
357 OpenGl_FrameBuffer* theOitAccumFbo);
2166f0fa 358
c357e426 359 //! Redraws view for the given monographic camera projection, or left/right eye.
360 //!
361 //! Method will blit snapshot containing main scene (myMainSceneFbos or BackBuffer)
362 //! into presentation buffer (myMainSceneFbos -> offscreen FBO or
363 //! myMainSceneFbos -> BackBuffer or BackBuffer -> FrontBuffer),
364 //! and redraw immediate structures on top.
365 //!
366 //! When scene caching is disabled (myTransientDrawToFront, no double buffer in window, etc.),
367 //! the first step (blitting) will be skipped.
368 //!
369 //! @return false if immediate structures has been rendered directly into FrontBuffer
370 //! and Buffer Swap should not be called.
a521d90d 371 Standard_EXPORT virtual bool redrawImmediate (const Graphic3d_Camera::Projection theProjection,
372 OpenGl_FrameBuffer* theReadFbo,
373 OpenGl_FrameBuffer* theDrawFbo,
a1073ae2 374 OpenGl_FrameBuffer* theOitAccumFbo,
a521d90d 375 const Standard_Boolean theIsPartialUpdate = Standard_False);
b5ac8292 376
c357e426 377 //! Blit image from/to specified buffers.
a521d90d 378 Standard_EXPORT bool blitBuffers (OpenGl_FrameBuffer* theReadFbo,
379 OpenGl_FrameBuffer* theDrawFbo,
380 const Standard_Boolean theToFlip = Standard_False);
2166f0fa 381
c357e426 382 //! Setup default FBO.
a521d90d 383 Standard_EXPORT void bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo = NULL);
2166f0fa 384
c357e426 385protected: //! @name Rendering of GL graphics (with prepared drawing buffer).
2166f0fa 386
c357e426 387 //! Renders the graphical contents of the view into the preprepared window or framebuffer.
388 //! @param theProjection [in] the projection that should be used for rendering.
389 //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
a1073ae2 390 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
c357e426 391 //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
a521d90d 392 Standard_EXPORT virtual void render (Graphic3d_Camera::Projection theProjection,
393 OpenGl_FrameBuffer* theReadDrawFbo,
a1073ae2 394 OpenGl_FrameBuffer* theOitAccumFbo,
a521d90d 395 const Standard_Boolean theToDrawImmediate);
2166f0fa 396
c357e426 397 //! Renders the graphical scene.
bf02aa7d 398 //! @param theProjection [in] the projection that is used for rendering.
c357e426 399 //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
a1073ae2 400 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
c357e426 401 //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
bf02aa7d 402 Standard_EXPORT virtual void renderScene (Graphic3d_Camera::Projection theProjection,
403 OpenGl_FrameBuffer* theReadDrawFbo,
a1073ae2 404 OpenGl_FrameBuffer* theOitAccumFbo,
a521d90d 405 const Standard_Boolean theToDrawImmediate);
406
407 //! Draw background (gradient / image)
408 Standard_EXPORT virtual void drawBackground (const Handle(OpenGl_Workspace)& theWorkspace);
2166f0fa 409
c357e426 410 //! Render set of structures presented in the view.
bf02aa7d 411 //! @param theProjection [in] the projection that is used for rendering.
c357e426 412 //! @param theReadDrawFbo [in] the framebuffer for rendering graphics.
a1073ae2 413 //! @param theOitAccumFbo [in] the framebuffer for accumulating color and coverage for OIT process.
c357e426 414 //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode.
bf02aa7d 415 Standard_EXPORT virtual void renderStructs (Graphic3d_Camera::Projection theProjection,
416 OpenGl_FrameBuffer* theReadDrawFbo,
a1073ae2 417 OpenGl_FrameBuffer* theOitAccumFbo,
a521d90d 418 const Standard_Boolean theToDrawImmediate);
2166f0fa 419
c357e426 420 //! Renders trihedron.
421 void renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
2166f0fa 422
c357e426 423private:
392ac980 424
c357e426 425 //! Adds the structure to display lists of the view.
426 Standard_EXPORT virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure,
427 const Standard_Integer thePriority) Standard_OVERRIDE;
428
429 //! Erases the structure from display lists of the view.
430 Standard_EXPORT virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) Standard_OVERRIDE;
431
432 //! Change Z layer of a structure already presented in view.
433 Standard_EXPORT virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure,
434 const Graphic3d_ZLayerId theNewLayerId) Standard_OVERRIDE;
435
436 //! Changes the priority of a structure within its Z layer in the specified view.
437 Standard_EXPORT virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
438 const Standard_Integer theNewPriority) Standard_OVERRIDE;
439
50d06d8f 440 //! Returns zoom-scale factor.
441 Standard_EXPORT virtual Standard_Real considerZoomPersistenceObjects (const Graphic3d_ZLayerId theLayerId,
442 const Handle(Graphic3d_Camera)& theCamera,
443 const Standard_Integer theWindowWidth,
3fe9ce0e 444 const Standard_Integer theWindowHeight) const Standard_OVERRIDE;
50d06d8f 445
a521d90d 446private:
447
448 //! Copy content of Back buffer to the Front buffer.
a0b49de4 449 bool copyBackToFront();
a521d90d 450
451 //! Initialize blit quad.
452 OpenGl_VertexBuffer* initBlitQuad (const Standard_Boolean theToFlip);
453
454 //! Blend together views pair into stereo image.
3c4b62a4 455 void drawStereoPair (OpenGl_FrameBuffer* theDrawFbo);
a521d90d 456
a1073ae2 457 //! Check and update OIT compatibility with current OpenGL context's state.
458 bool checkOitCompatibility (const Handle(OpenGl_Context)& theGlContext,
459 const Standard_Boolean theMSAA);
460
461 //! Chooses compatible internal color format for OIT frame buffer.
462 bool chooseOitColorConfiguration (const Handle(OpenGl_Context)& theGlContext,
463 const Standard_Integer theConfigIndex,
464 OpenGl_ColorFormats& theFormats);
465
c357e426 466protected:
467
468 OpenGl_GraphicDriver* myDriver;
469 Handle(OpenGl_Window) myWindow;
470 Handle(OpenGl_Workspace) myWorkspace;
471 Handle(OpenGl_Caps) myCaps;
472 Standard_Boolean& myDeviceLostFlag;
473 Standard_Boolean myWasRedrawnGL;
474
c357e426 475 Standard_Boolean myCulling;
476 Graphic3d_TypeOfShadingModel myShadingModel;
c357e426 477 Graphic3d_TypeOfBackfacingModel myBackfacing;
b6472664 478 Quantity_ColorRGBA myBgColor;
3202bf1e 479 Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
c357e426 480 Handle(Graphic3d_Camera) myCamera;
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
016e5959 488 OpenGl_ListOfLight myNoShadingLight;
c357e426 489 OpenGl_ListOfLight myLights;
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;
392ac980 495
496 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
497
498 StateInfo myLastOrientationState;
499 StateInfo myLastViewMappingState;
500 StateInfo myLastLightSourceState;
30f0ad28 501
b7cd4ba7 502 //! Is needed for selection of overlapping objects and storage of the current view volume
503 OpenGl_BVHTreeSelector myBVHSelector;
504
c357e426 505 OpenGl_GraduatedTrihedron myGraduatedTrihedron;
506
507 Handle(OpenGl_Texture) myTextureEnv;
508
3a9b5dc8 509 //! Framebuffers for OpenGL output.
510 Handle(OpenGl_FrameBuffer) myOpenGlFBO;
511 Handle(OpenGl_FrameBuffer) myOpenGlFBO2;
512
c357e426 513protected: //! @name Rendering properties
514
515 //! Two framebuffers (left and right views) store cached main presentation
516 //! of the view (without presentation of immediate layers).
3c4b62a4 517 GLint myFboColorFormat; //!< sized format for color attachments
518 GLint myFboDepthFormat; //!< sized format for depth-stencil attachments
a1073ae2 519 OpenGl_ColorFormats myFboOitColorConfig; //!< selected color format configuration for OIT color attachments
c357e426 520 Handle(OpenGl_FrameBuffer) myMainSceneFbos[2];
a1073ae2 521 Handle(OpenGl_FrameBuffer) myMainSceneFbosOit[2]; //!< Additional buffers for transparent draw of main layer.
522 Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2]; //!< Additional buffers for immediate layer in stereo mode.
523 Handle(OpenGl_FrameBuffer) myImmediateSceneFbosOit[2]; //!< Additional buffers for transparency draw of immediate layer.
c357e426 524 OpenGl_VertexBuffer myFullScreenQuad; //!< Vertices for full-screen quad rendering.
525 OpenGl_VertexBuffer myFullScreenQuadFlip;
526 Standard_Boolean myToFlipOutput; //!< Flag to draw result image upside-down
527 unsigned int myFrameCounter; //!< redraw counter, for debugging
7ccf8676 528 Standard_Boolean myHasFboBlit; //!< disable FBOs on failure
a1073ae2 529 Standard_Boolean myToDisableOIT; //!< disable OIT on failure
530 Standard_Boolean myToDisableOITMSAA; //!< disable OIT with MSAA on failure
7ccf8676 531 Standard_Boolean myToDisableMSAA; //!< disable MSAA after failure
c357e426 532 Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer)
533 Standard_Boolean myBackBufferRestored;
534 Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data
535
0b0320e7 536protected: //! @name Background parameters
537
538 OpenGl_AspectFace* myTextureParams; //!< Stores texture and its parameters for textured background
539 OpenGl_BackgroundArray* myBgGradientArray; //!< Primitive array for gradient background
540 OpenGl_BackgroundArray* myBgTextureArray; //!< Primitive array for texture background
541
91c60b57 542protected: //! @name data types related to ray-tracing
543
544 //! Result of OpenGL shaders initialization.
545 enum RaytraceInitStatus
546 {
547 OpenGl_RT_NONE,
548 OpenGl_RT_INIT,
549 OpenGl_RT_FAIL
550 };
551
552 //! Describes update mode (state).
553 enum RaytraceUpdateMode
554 {
555 OpenGl_GUM_CHECK, //!< check geometry state
556 OpenGl_GUM_PREPARE, //!< collect unchanged objects
557 OpenGl_GUM_REBUILD //!< rebuild changed and new objects
558 };
559
560 //! Defines frequently used shader variables.
561 enum ShaderVariableIndex
562 {
563 OpenGl_RT_aPosition,
564
189f85a3 565 // camera position
91c60b57 566 OpenGl_RT_uOriginLT,
567 OpenGl_RT_uOriginLB,
568 OpenGl_RT_uOriginRT,
569 OpenGl_RT_uOriginRB,
570 OpenGl_RT_uDirectLT,
571 OpenGl_RT_uDirectLB,
572 OpenGl_RT_uDirectRT,
573 OpenGl_RT_uDirectRB,
3a9b5dc8 574 OpenGl_RT_uViewPrMat,
91c60b57 575 OpenGl_RT_uUnviewMat,
576
189f85a3 577 // 3D scene params
91c60b57 578 OpenGl_RT_uSceneRad,
579 OpenGl_RT_uSceneEps,
580 OpenGl_RT_uLightAmbnt,
581 OpenGl_RT_uLightCount,
582
189f85a3 583 // background params
584 OpenGl_RT_uBackColorTop,
585 OpenGl_RT_uBackColorBot,
91c60b57 586
189f85a3 587 // ray-tracing params
588 OpenGl_RT_uShadowsEnabled,
589 OpenGl_RT_uReflectEnabled,
590 OpenGl_RT_uSphereMapEnabled,
591 OpenGl_RT_uSphereMapForBack,
592 OpenGl_RT_uTexSamplersArray,
8c820969 593 OpenGl_RT_uBlockedRngEnabled,
189f85a3 594
3a9b5dc8 595 // size of render window
596 OpenGl_RT_uWinSizeX,
597 OpenGl_RT_uWinSizeY,
598
189f85a3 599 // sampled frame params
383c6c9f 600 OpenGl_RT_uAccumSamples,
189f85a3 601 OpenGl_RT_uFrameRndSeed,
602
603 // adaptive FSAA params
91c60b57 604 OpenGl_RT_uOffsetX,
605 OpenGl_RT_uOffsetY,
606 OpenGl_RT_uSamples,
91c60b57 607
b09447ed 608 // images used by ISS mode
3a9b5dc8 609 OpenGl_RT_uRenderImage,
610 OpenGl_RT_uOffsetImage,
611
b09447ed 612 // maximum radiance value
613 OpenGl_RT_uMaxRadiance,
614
91c60b57 615 OpenGl_RT_NbVariables // special field
616 };
617
3a9b5dc8 618 //! Defines OpenGL texture samplers.
91c60b57 619 enum ShaderSamplerNames
620 {
6e728f3b 621 OpenGl_RT_EnvironmentMapTexture = 0,
91c60b57 622
6e728f3b 623 OpenGl_RT_SceneNodeInfoTexture = 1,
624 OpenGl_RT_SceneMinPointTexture = 2,
625 OpenGl_RT_SceneMaxPointTexture = 3,
626 OpenGl_RT_SceneTransformTexture = 4,
91c60b57 627
6e728f3b 628 OpenGl_RT_GeometryVertexTexture = 5,
629 OpenGl_RT_GeometryNormalTexture = 6,
630 OpenGl_RT_GeometryTexCrdTexture = 7,
631 OpenGl_RT_GeometryTriangTexture = 8,
91c60b57 632
633 OpenGl_RT_RaytraceMaterialTexture = 9,
634 OpenGl_RT_RaytraceLightSrcTexture = 10,
635
189f85a3 636 OpenGl_RT_FsaaInputTexture = 11,
637 OpenGl_RT_PrevAccumTexture = 12,
91c60b57 638
3a9b5dc8 639 OpenGl_RT_RaytraceDepthTexture = 13
640 };
641
642 //! Defines OpenGL image samplers.
643 enum ShaderImageNames
644 {
645 OpenGl_RT_OutputImageLft = 0,
646 OpenGl_RT_OutputImageRgh = 1,
647 OpenGl_RT_VisualErrorImage = 2,
648 OpenGl_RT_TileOffsetsImage = 3
91c60b57 649 };
650
651 //! Tool class for management of shader sources.
652 class ShaderSource
653 {
654 public:
655
189f85a3 656 //! Default shader prefix - empty string.
657 static const TCollection_AsciiString EMPTY_PREFIX;
658
91c60b57 659 //! Creates new uninitialized shader source.
660 ShaderSource()
661 {
662 //
663 }
664
73722cc9 665 public:
189f85a3 666
73722cc9 667 //! Returns error description in case of load fail.
668 const TCollection_AsciiString& ErrorDescription() const
669 {
670 return myError;
91c60b57 671 }
672
91c60b57 673 //! Returns prefix to insert before the source.
674 const TCollection_AsciiString& Prefix() const
675 {
676 return myPrefix;
677 }
678
679 //! Sets prefix to insert before the source.
680 void SetPrefix (const TCollection_AsciiString& thePrefix)
681 {
682 myPrefix = thePrefix;
683 }
684
685 //! Returns shader source combined with prefix.
686 TCollection_AsciiString Source() const;
687
688 //! Loads shader source from specified files.
ee5befae 689 Standard_Boolean LoadFromFiles (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
690
691 //! Loads shader source from specified strings.
692 Standard_Boolean LoadFromStrings (const TCollection_AsciiString* theStrings, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
91c60b57 693
694 private:
695
696 TCollection_AsciiString mySource; //!< Source string of the shader object
697 TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
73722cc9 698 TCollection_AsciiString myError; //!< error state
91c60b57 699
700 };
701
702 //! Default ray-tracing depth.
703 static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
704
705 //! Default size of traversal stack.
f2474958 706 static const Standard_Integer THE_DEFAULT_STACK_SIZE = 10;
91c60b57 707
708 //! Compile-time ray-tracing parameters.
709 struct RaytracingParams
710 {
711 //! Actual size of traversal stack in shader program.
712 Standard_Integer StackSize;
713
714 //! Actual ray-tracing depth (number of ray bounces).
715 Standard_Integer NbBounces;
716
f483f2ed 717 //! Enables/disables light propagation through transparent media.
91c60b57 718 Standard_Boolean TransparentShadows;
719
189f85a3 720 //! Enables/disables global illumination (GI) effects.
721 Standard_Boolean GlobalIllumination;
722
f483f2ed 723 //! Enables/disables the use of OpenGL bindless textures.
724 Standard_Boolean UseBindlessTextures;
725
b4327ba8 726 //! Enables/disables two-sided BSDF models instead of one-sided.
727 Standard_Boolean TwoSidedBsdfModels;
728
3a9b5dc8 729 //! Enables/disables adaptive screen sampling for path tracing.
730 Standard_Boolean AdaptiveScreenSampling;
731
b09447ed 732 //! Enables/disables environment map for background.
733 Standard_Boolean UseEnvMapForBackground;
734
735 //! Maximum radiance value used for clamping radiance estimation.
736 Standard_ShortReal RadianceClampingValue;
737
4eaaf9d8 738 //! Number of tiles in X dimension (in adaptive sampling mode).
739 Standard_Integer NbTilesX;
740
741 //! Number of tiles in Y dimension (in adaptive sampling mode).
742 Standard_Integer NbTilesY;
743
91c60b57 744 //! Creates default compile-time ray-tracing parameters.
745 RaytracingParams()
b09447ed 746 : StackSize (THE_DEFAULT_STACK_SIZE),
747 NbBounces (THE_DEFAULT_NB_BOUNCES),
b4327ba8 748 TransparentShadows (Standard_False),
749 GlobalIllumination (Standard_False),
750 UseBindlessTextures (Standard_False),
751 TwoSidedBsdfModels (Standard_False),
b09447ed 752 AdaptiveScreenSampling (Standard_False),
753 UseEnvMapForBackground (Standard_False),
4eaaf9d8 754 RadianceClampingValue (30.0),
755 NbTilesX (16),
756 NbTilesY (16) { }
91c60b57 757 };
758
d4aaad5b 759 //! Describes state of OpenGL structure.
760 struct StructState
761 {
762 Standard_Size StructureState;
763 Standard_Size InstancedState;
764
765 //! Creates new structure state.
766 StructState (const Standard_Size theStructureState = 0,
767 const Standard_Size theInstancedState = 0)
768 : StructureState (theStructureState),
769 InstancedState (theInstancedState)
770 {
771 //
772 }
773
774 //! Creates new structure state.
775 StructState (const OpenGl_Structure* theStructure)
776 {
777 StructureState = theStructure->ModificationState();
778
779 InstancedState = theStructure->InstancedStructure() != NULL ?
780 theStructure->InstancedStructure()->ModificationState() : 0;
781 }
782 };
783
91c60b57 784protected: //! @name methods related to ray-tracing
785
786 //! Updates 3D scene geometry for ray-tracing.
787 Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode theMode,
788 const Standard_Integer theViewId,
789 const Handle(OpenGl_Context)& theGlContext);
790
791 //! Updates 3D scene light sources for ray-tracing.
792 Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext);
793
91c60b57 794 //! Checks to see if the OpenGL structure is modified.
795 Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure);
796
797 //! Adds OpenGL structure to ray-traced scene geometry.
798 Standard_Boolean addRaytraceStructure (const OpenGl_Structure* theStructure,
799 const Handle(OpenGl_Context)& theGlContext);
800
801 //! Adds OpenGL groups to ray-traced scene geometry.
8c820969 802 Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure,
803 const OpenGl_RaytraceMaterial& theStructMat,
1f7f5a90 804 const Handle(Geom_Transformation)& theTrsf,
8c820969 805 const Handle(OpenGl_Context)& theGlContext);
91c60b57 806
807 //! Creates ray-tracing material properties.
808 OpenGl_RaytraceMaterial convertMaterial (const OpenGl_AspectFace* theAspect,
809 const Handle(OpenGl_Context)& theGlContext);
810
811 //! Adds OpenGL primitive array to ray-traced scene geometry.
812 OpenGl_TriangleSet* addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
813 const Standard_Integer theMatID,
814 const OpenGl_Mat4* theTrans);
815
816 //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
817 Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
818 const Standard_Integer theMatID,
819 const Standard_Integer theCount,
820 const Standard_Integer theOffset,
821 const OpenGl_PrimitiveArray& theArray);
822
823 //! Adds OpenGL triangle array to ray-traced scene geometry.
824 Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
825 const Standard_Integer theMatID,
826 const Standard_Integer theCount,
827 const Standard_Integer theOffset,
828 const Handle(Graphic3d_IndexBuffer)& theIndices);
829
830 //! Adds OpenGL triangle fan array to ray-traced scene geometry.
831 Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
832 const Standard_Integer theMatID,
833 const Standard_Integer theCount,
834 const Standard_Integer theOffset,
835 const Handle(Graphic3d_IndexBuffer)& theIndices);
836
837 //! Adds OpenGL triangle strip array to ray-traced scene geometry.
838 Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
839 const Standard_Integer theMatID,
840 const Standard_Integer theCount,
841 const Standard_Integer theOffset,
842 const Handle(Graphic3d_IndexBuffer)& theIndices);
843
844 //! Adds OpenGL quadrangle array to ray-traced scene geometry.
845 Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
846 const Standard_Integer theMatID,
847 const Standard_Integer theCount,
848 const Standard_Integer theOffset,
849 const Handle(Graphic3d_IndexBuffer)& theIndices);
850
851 //! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
852 Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
853 const Standard_Integer theMatID,
854 const Standard_Integer theCount,
855 const Standard_Integer theOffset,
856 const Handle(Graphic3d_IndexBuffer)& theIndices);
857
858 //! Adds OpenGL polygon array to ray-traced scene geometry.
859 Standard_Boolean addRaytracePolygonArray (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 //! Uploads ray-trace data to the GPU.
866 Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext);
867
868 //! Generates shader prefix based on current ray-tracing options.
869 TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const;
870
871 //! Performs safe exit when shaders initialization fails.
872 Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage,
873 const Handle(OpenGl_Context)& theGlContext);
874
875 //! Loads and compiles shader object from specified source.
876 Handle(OpenGl_ShaderObject) initShader (const GLenum theType,
877 const ShaderSource& theSource,
878 const Handle(OpenGl_Context)& theGlContext);
879
189f85a3 880 //! Creates shader program from the given vertex and fragment shaders.
881 Handle(OpenGl_ShaderProgram) initProgram (const Handle(OpenGl_Context)& theGlContext,
882 const Handle(OpenGl_ShaderObject)& theVertShader,
883 const Handle(OpenGl_ShaderObject)& theFragShader);
884
91c60b57 885 //! Initializes OpenGL/GLSL shader programs.
c357e426 886 Standard_Boolean initRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
91c60b57 887
888 //! Releases OpenGL/GLSL shader programs.
d877e610 889 void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext,
890 const Standard_Boolean theToRebuild = Standard_False);
91c60b57 891
bf02aa7d 892 //! Updates auxiliary OpenGL frame buffers.
893 Standard_Boolean updateRaytraceBuffers (const Standard_Integer theSizeX,
91c60b57 894 const Standard_Integer theSizeY,
895 const Handle(OpenGl_Context)& theGlContext);
896
897 //! Generates viewing rays for corners of screen quad.
898 void updateCamera (const OpenGl_Mat4& theOrientation,
899 const OpenGl_Mat4& theViewMapping,
900 OpenGl_Vec3* theOrigins,
901 OpenGl_Vec3* theDirects,
1d865689 902 OpenGl_Mat4& theView,
91c60b57 903 OpenGl_Mat4& theUnView);
904
905 //! Binds ray-trace textures to corresponding texture units.
906 void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
907
908 //! Unbinds ray-trace textures from corresponding texture unit.
909 void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
910
911 //! Sets uniform state for the given ray-tracing shader program.
3a9b5dc8 912 Standard_Boolean setUniformState (const Standard_Integer theProgramId,
913 const Standard_Integer theSizeX,
914 const Standard_Integer theSizeY,
91c60b57 915 const Handle(OpenGl_Context)& theGlContext);
916
917 //! Runs ray-tracing shader programs.
c357e426 918 Standard_Boolean runRaytraceShaders (const Standard_Integer theSizeX,
91c60b57 919 const Standard_Integer theSizeY,
bf02aa7d 920 Graphic3d_Camera::Projection theProjection,
38a0206f 921 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 922 const Handle(OpenGl_Context)& theGlContext);
923
3a9b5dc8 924 //! Runs classical (Whitted-style) ray-tracing kernel.
925 Standard_Boolean runRaytrace (const Standard_Integer theSizeX,
926 const Standard_Integer theSizeY,
927 Graphic3d_Camera::Projection theProjection,
928 OpenGl_FrameBuffer* theReadDrawFbo,
929 const Handle(OpenGl_Context)& theGlContext);
930
931 //! Runs path tracing (global illumination) kernel.
4eaaf9d8 932 Standard_Boolean runPathtrace (const Standard_Integer theSizeX,
933 const Standard_Integer theSizeY,
934 Graphic3d_Camera::Projection theProjection,
935 OpenGl_FrameBuffer* theReadDrawFbo,
936 const Handle(OpenGl_Context)& theGlContext);
3a9b5dc8 937
938 //! Redraws the window using OpenGL/GLSL ray-tracing or path tracing.
c357e426 939 Standard_Boolean raytrace (const Standard_Integer theSizeX,
91c60b57 940 const Standard_Integer theSizeY,
bf02aa7d 941 Graphic3d_Camera::Projection theProjection,
38a0206f 942 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 943 const Handle(OpenGl_Context)& theGlContext);
944
945protected: //! @name fields related to ray-tracing
946
3a9b5dc8 947 //! Result of RT/PT shaders initialization.
91c60b57 948 RaytraceInitStatus myRaytraceInitStatus;
949
3a9b5dc8 950 //! Is ray-tracing geometry data valid?
91c60b57 951 Standard_Boolean myIsRaytraceDataValid;
952
3a9b5dc8 953 //! True if warning about missing extension GL_ARB_bindless_texture has been displayed.
91c60b57 954 Standard_Boolean myIsRaytraceWarnTextures;
955
956 //! 3D scene geometry data for ray-tracing.
957 OpenGl_RaytraceGeometry myRaytraceGeometry;
958
959 //! Compile-time ray-tracing parameters.
960 RaytracingParams myRaytraceParameters;
961
962 //! Radius of bounding sphere of the scene.
963 Standard_ShortReal myRaytraceSceneRadius;
964 //! Scene epsilon to prevent self-intersections.
965 Standard_ShortReal myRaytraceSceneEpsilon;
966
967 //! OpenGL/GLSL source of ray-tracing fragment shader.
968 ShaderSource myRaytraceShaderSource;
969 //! OpenGL/GLSL source of adaptive-AA fragment shader.
970 ShaderSource myPostFSAAShaderSource;
3a9b5dc8 971 //! OpenGL/GLSL source of RT/PT display fragment shader.
972 ShaderSource myOutImageShaderSource;
91c60b57 973
974 //! OpenGL/GLSL ray-tracing fragment shader.
975 Handle(OpenGl_ShaderObject) myRaytraceShader;
976 //! OpenGL/GLSL adaptive-AA fragment shader.
977 Handle(OpenGl_ShaderObject) myPostFSAAShader;
3a9b5dc8 978 //! OpenGL/GLSL ray-tracing display fragment shader.
979 Handle(OpenGl_ShaderObject) myOutImageShader;
91c60b57 980
981 //! OpenGL/GLSL ray-tracing shader program.
982 Handle(OpenGl_ShaderProgram) myRaytraceProgram;
983 //! OpenGL/GLSL adaptive-AA shader program.
984 Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
189f85a3 985 //! OpenGL/GLSL program for displaying texture.
986 Handle(OpenGl_ShaderProgram) myOutImageProgram;
91c60b57 987
988 //! Texture buffer of data records of bottom-level BVH nodes.
989 Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
990 //! Texture buffer of minimum points of bottom-level BVH nodes.
991 Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
992 //! Texture buffer of maximum points of bottom-level BVH nodes.
993 Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
994 //! Texture buffer of transformations of high-level BVH nodes.
995 Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
996
997 //! Texture buffer of vertex coords.
998 Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
999 //! Texture buffer of vertex normals.
1000 Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
1001 //! Texture buffer of vertex UV coords.
1002 Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture;
1003 //! Texture buffer of triangle indices.
1004 Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
1005
1006 //! Texture buffer of material properties.
1007 Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
1008 //! Texture buffer of light source properties.
1009 Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
1010
1011 //! 1st framebuffer (FBO) to perform adaptive FSAA.
3a9b5dc8 1012 //! Used in compatibility mode (no adaptive sampling).
bf02aa7d 1013 Handle(OpenGl_FrameBuffer) myRaytraceFBO1[2];
91c60b57 1014 //! 2nd framebuffer (FBO) to perform adaptive FSAA.
3a9b5dc8 1015 //! Used in compatibility mode (no adaptive sampling).
bf02aa7d 1016 Handle(OpenGl_FrameBuffer) myRaytraceFBO2[2];
3a9b5dc8 1017
1018 //! Output textures (2 textures are used in stereo mode).
1019 //! Used if adaptive screen sampling is activated.
1020 Handle(OpenGl_Texture) myRaytraceOutputTexture[2];
1021
1022 //! Texture containing per-tile visual error estimation.
1023 //! Used if adaptive screen sampling is activated.
1024 Handle(OpenGl_Texture) myRaytraceVisualErrorTexture;
1025 //! Texture containing offsets of sampled screen tiles.
1026 //! Used if adaptive screen sampling is activated.
1027 Handle(OpenGl_Texture) myRaytraceTileOffsetsTexture;
91c60b57 1028
1029 //! Vertex buffer (VBO) for drawing dummy quad.
1030 OpenGl_VertexBuffer myRaytraceScreenQuad;
1031
1032 //! Cached locations of frequently used uniform variables.
1033 Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
1034
1035 //! State of OpenGL structures reflected to ray-tracing.
d4aaad5b 1036 std::map<const OpenGl_Structure*, StructState> myStructureStates;
91c60b57 1037
1038 //! PrimitiveArray to TriangleSet map for scene partial update.
1039 std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
1040
189f85a3 1041 //! Set of IDs of non-raytracable elements (to detect updates).
1042 std::set<Standard_Integer> myNonRaytraceStructureIDs;
1043
1044 //! Render filter to filter out all raytracable structures.
91c60b57 1045 Handle(OpenGl_RaytraceFilter) myRaytraceFilter;
1046
1047 //! Marks if environment map should be updated.
1048 Standard_Boolean myToUpdateEnvironmentMap;
1049
1050 //! State of OpenGL layer list.
bd6a8454 1051 Standard_Size myRaytraceLayerListState;
189f85a3 1052
1053 //! Number of accumulated frames (for progressive rendering).
1054 Standard_Integer myAccumFrames;
1055
1056 //! Stored ray origins used for detection of camera movements.
1057 OpenGl_Vec3 myPreviousOrigins[3];
1058
1059 //! Bullard RNG to produce random sequence.
1060 math_BullardGenerator myRNG;
91c60b57 1061
3a9b5dc8 1062 //! Tool object for sampling screen tiles in PT mode.
1063 OpenGl_TileSampler myTileSampler;
1064
679ecdee 1065public:
1066
1c35b92f 1067 DEFINE_STANDARD_ALLOC
92efcf78 1068 DEFINE_STANDARD_RTTIEXT(OpenGl_View,Graphic3d_CView) // Type definition
679ecdee 1069
c357e426 1070 friend class OpenGl_GraphicDriver;
a89742cf 1071 friend class OpenGl_Workspace;
a1073ae2 1072 friend class OpenGl_LayerList;
2166f0fa
SK
1073};
1074
679ecdee 1075#endif // _OpenGl_View_Header