Adjusting test cases at current state of OCCT master
[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>
29#include <Aspect_TypeOfTriedronPosition.hxx>
2166f0fa
SK
30
31#include <InterfaceGraphic_Graphic3d.hxx>
32#include <InterfaceGraphic_Visual3d.hxx>
33
34#include <Graphic3d_CView.hxx>
a79f67f8 35#include <Graphic3d_GraduatedTrihedron.hxx>
51b10cd4 36#include <Graphic3d_SequenceOfHClipPlane.hxx>
825aa485 37#include <Graphic3d_WorldViewProjState.hxx>
c5751993 38#include <Graphic3d_ZLayerSettings.hxx>
2166f0fa 39#include <Visual3d_TypeOfSurfaceDetail.hxx>
8625ef7e 40#include <Visual3d_TypeOfModel.hxx>
2166f0fa 41
0b0320e7 42#include <OpenGl_AspectFace.hxx>
43#include <OpenGl_BackgroundArray.hxx>
b7cd4ba7 44#include <OpenGl_BVHTreeSelector.hxx>
59f45b7c 45#include <OpenGl_LayerList.hxx>
2166f0fa 46#include <OpenGl_Light.hxx>
73192b37 47#include <OpenGl_LineAttributes.hxx>
536d98e2 48#include <OpenGl_Trihedron.hxx>
49#include <OpenGl_GraduatedTrihedron.hxx>
2166f0fa 50
2166f0fa 51
2166f0fa
SK
52struct OPENGL_ZCLIP
53{
54 struct {
55 Standard_Boolean IsOn;
56 Standard_ShortReal Limit; /* in the range [0., 1.] */
57 } Back;
58 struct {
59 Standard_Boolean IsOn;
60 Standard_ShortReal Limit; /* in the range [0., 1.] */
61 } Front;
62};
63
64struct OPENGL_FOG
65{
66 Standard_Boolean IsOn;
67 Standard_ShortReal Front; /* in the range [0., 1.] */
68 Standard_ShortReal Back; /* in the range [0., 1.] */
69 TEL_COLOUR Color;
70};
71
b5ac8292 72struct OpenGl_Matrix;
2166f0fa 73class OpenGl_Structure;
392ac980 74class OpenGl_StateCounter;
2166f0fa 75
c04c30b3 76class OpenGl_View;
77DEFINE_STANDARD_HANDLE(OpenGl_View,MMgt_TShared)
78
2166f0fa
SK
79class OpenGl_View : public MMgt_TShared
80{
81 public:
62e1beed 82 Standard_EXPORT OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter);
83 Standard_EXPORT virtual ~OpenGl_View ();
2166f0fa 84
62e1beed 85 Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx);
bf75be98 86
87 void SetTextureEnv (const Handle(OpenGl_Context)& theCtx,
88 const Handle(Graphic3d_TextureEnv)& theTexture);
e276548b 89 void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode);
2166f0fa
SK
90 void SetBackfacing (const Standard_Integer AMode);
91 void SetLights (const CALL_DEF_VIEWCONTEXT &AContext);
92 void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; }
51b10cd4 93 void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; }
2166f0fa
SK
94 void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext);
95
c827ea3a 96 const Handle(Graphic3d_Camera)& Camera() { return myCamera; }
b5ac8292 97 void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; }
98
bf75be98 99 void SetClipLimit (const Graphic3d_CView& theCView);
2166f0fa 100
bf75be98 101 void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag);
2166f0fa 102
536d98e2 103 OpenGl_Trihedron& ChangeTrihedron() { return myTrihedron; }
104 void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
a174a3c5 105 const Quantity_NameOfColor theColor,
106 const Standard_Real theScale,
107 const Standard_Boolean theAsWireframe);
108 void TriedronErase (const Handle(OpenGl_Context)& theCtx);
2166f0fa 109
536d98e2 110 OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; }
a174a3c5 111 void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx,
a79f67f8 112 const Graphic3d_GraduatedTrihedron& theCubic);
a174a3c5 113 void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx);
2166f0fa 114
b5ac8292 115 Standard_Real Height () const { return myCamera->ViewDimensions().X(); }
116 Standard_Real Width () const { return myCamera->ViewDimensions().Y(); }
2166f0fa
SK
117
118 Standard_Integer Backfacing () const { return myBackfacing; }
119
59f45b7c 120 //! Add structure to display list with specified priority.
121 //! The structure will be added to associated with it z layer.
122 //! If the z layer is not presented in the view, the structure will
123 //! be displayed in default bottom-level z layer.
a1954302 124 void DisplayStructure (const Handle(Graphic3d_Structure)& theStructure,
125 const Standard_Integer thePriority);
59f45b7c 126
127 //! Erase structure from display list.
a1954302 128 void EraseStructure (const Handle(Graphic3d_Structure)& theStructure);
679ecdee 129
59f45b7c 130 //! Insert a new top-level z layer with ID <theLayerId>
a1954302 131 void AddZLayer (const Graphic3d_ZLayerId theLayerId);
59f45b7c 132
133 //! Remove a z layer with ID <theLayerId>
a1954302 134 void RemoveZLayer (const Graphic3d_ZLayerId theLayerId);
59f45b7c 135
136 //! Display structure in z layer with ID <theNewLayerId>
137 //! If the layer with ID <theNewLayerId> is not presented in the view,
138 //! the structure will be displayed in default bottom-level layer.
a1954302 139 void ChangeZLayer (const OpenGl_Structure* theStructure,
140 const Graphic3d_ZLayerId theNewLayerId);
2166f0fa 141
c5751993 142 //! Sets the settings for a single Z layer of specified view.
a1954302 143 void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
144 const Graphic3d_ZLayerSettings& theSettings);
c5751993 145
b7cd4ba7 146 //! Changes the priority of a structure within its ZLayer
a1954302 147 void ChangePriority (const OpenGl_Structure* theStructure,
148 const Standard_Integer theNewPriority);
b7cd4ba7 149
0b0320e7 150 void CreateBackgroundTexture (const Standard_CString AFileName,
151 const Aspect_FillMethod AFillStyle);
152
2166f0fa
SK
153 void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle);
154 void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType);
155 void SetBackgroundGradientType (const Aspect_GradientFillMethod AType);
156
a174a3c5 157 void Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
158 const Handle(OpenGl_Workspace)& theWorkspace,
38a0206f 159 OpenGl_FrameBuffer* theReadDrawFbo,
160 Graphic3d_Camera::Projection theProjection,
a174a3c5 161 const Graphic3d_CView& theCView,
a1954302 162 const Standard_Boolean theToDrawImmediate);
2166f0fa 163
0b0320e7 164 void DrawBackground (const Handle(OpenGl_Workspace)& theWorkspace);
e276548b 165
166 //! Returns list of OpenGL Z-layers.
167 const OpenGl_LayerList& LayerList() const { return myZLayers; }
168
169 //! Returns list of openGL light sources.
170 const OpenGl_ListOfLight& LightList() const { return myLights; }
171
172 //! Returns OpenGL environment map.
173 const Handle(OpenGl_Texture)& TextureEnv() const { return myTextureEnv; }
174
175 //! Returns visualization mode for objects in the view.
176 Visual3d_TypeOfSurfaceDetail SurfaceDetail() const { return mySurfaceDetail; }
177
b7cd4ba7 178 //! Returns selector for BVH tree, providing a possibility to store information
179 //! about current view volume and to detect which objects are overlapping it.
180 OpenGl_BVHTreeSelector& BVHTreeSelector() { return myBVHSelector; }
181
182 //! Marks BVH tree for given priority list as dirty and
183 //! marks primitive set for rebuild.
184 void InvalidateBVHData (const Standard_Integer theLayerId);
185
a1954302 186 //! Returns true if there are immediate structures to display
187 bool HasImmediateStructures() const
188 {
c3282ec1 189 return myZLayers.NbImmediateStructures() != 0;
a1954302 190 }
191
679ecdee 192protected:
2166f0fa 193
a1954302 194 void RenderStructs (const Handle(OpenGl_Workspace)& theWorkspace,
38a0206f 195 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 196 const Graphic3d_CView& theCView,
a1954302 197 const Standard_Boolean theToDrawImmediate);
91c60b57 198
a89742cf 199 void RedrawTrihedron (const Handle(OpenGl_Workspace) &theWorkspace);
2166f0fa 200
b5ac8292 201 //! Redraw contents of model scene: clipping planes,
202 //! lights, structures. The peculiar properties of "scene" is that
203 //! it requires empty Z-Buffer and uses projection and orientation
204 //! matrices supplied by 3d view.
b5ac8292 205 void RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext,
a1954302 206 const Handle(OpenGl_Workspace)& theWorkspace,
38a0206f 207 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 208 const Graphic3d_CView& theCView,
a1954302 209 const Standard_Boolean theToDrawImmediate);
b5ac8292 210
73192b37 211 Handle(OpenGl_LineAttributes) myLineAttribs;
212 Handle(OpenGl_Texture) myTextureEnv;
213 Visual3d_TypeOfSurfaceDetail mySurfaceDetail;
214 Standard_Integer myBackfacing;
2166f0fa 215
2166f0fa 216 OPENGL_ZCLIP myZClip;
2166f0fa 217
51b10cd4 218 Graphic3d_SequenceOfHClipPlane myClipPlanes;
4269bd1b 219
b5ac8292 220 Handle(Graphic3d_Camera) myCamera;
221
2166f0fa 222 OPENGL_FOG myFog;
536d98e2 223 OpenGl_Trihedron myTrihedron;
224 OpenGl_GraduatedTrihedron myGraduatedTrihedron;
225 bool myToShowTrihedron;
226 bool myToShowGradTrihedron;
2166f0fa
SK
227
228 //View_LABViewContext
229 int myVisualization;
8625ef7e 230 Visual3d_TypeOfModel myShadingModel; //!< lighting shading model
2166f0fa
SK
231
232 //View_LABLight
233 OpenGl_ListOfLight myLights;
234
235 //View_LABPlane
236 //View_LABAliasing
237 Standard_Boolean myAntiAliasing;
238
239 //View_LABDepthCueing - fixed index used
240
9f112210 241 OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
2166f0fa 242
b5ac8292 243 //! Modification state
825aa485 244 Graphic3d_WorldViewProjState myWorldViewProjState;
392ac980 245 OpenGl_StateCounter* myStateCounter;
246
392ac980 247 Standard_Size myCurrLightSourceState;
248
249 typedef std::pair<Standard_Size, Standard_Size> StateInfo;
250
251 StateInfo myLastOrientationState;
252 StateInfo myLastViewMappingState;
253 StateInfo myLastLightSourceState;
30f0ad28 254
b7cd4ba7 255 //! Is needed for selection of overlapping objects and storage of the current view volume
256 OpenGl_BVHTreeSelector myBVHSelector;
257
0b0320e7 258protected: //! @name Background parameters
259
260 OpenGl_AspectFace* myTextureParams; //!< Stores texture and its parameters for textured background
261 OpenGl_BackgroundArray* myBgGradientArray; //!< Primitive array for gradient background
262 OpenGl_BackgroundArray* myBgTextureArray; //!< Primitive array for texture background
263
91c60b57 264protected: //! @name data types related to ray-tracing
265
266 //! Result of OpenGL shaders initialization.
267 enum RaytraceInitStatus
268 {
269 OpenGl_RT_NONE,
270 OpenGl_RT_INIT,
271 OpenGl_RT_FAIL
272 };
273
274 //! Describes update mode (state).
275 enum RaytraceUpdateMode
276 {
277 OpenGl_GUM_CHECK, //!< check geometry state
278 OpenGl_GUM_PREPARE, //!< collect unchanged objects
279 OpenGl_GUM_REBUILD //!< rebuild changed and new objects
280 };
281
282 //! Defines frequently used shader variables.
283 enum ShaderVariableIndex
284 {
285 OpenGl_RT_aPosition,
286
189f85a3 287 // camera position
91c60b57 288 OpenGl_RT_uOriginLT,
289 OpenGl_RT_uOriginLB,
290 OpenGl_RT_uOriginRT,
291 OpenGl_RT_uOriginRB,
292 OpenGl_RT_uDirectLT,
293 OpenGl_RT_uDirectLB,
294 OpenGl_RT_uDirectRT,
295 OpenGl_RT_uDirectRB,
296 OpenGl_RT_uUnviewMat,
297
189f85a3 298 // 3D scene params
91c60b57 299 OpenGl_RT_uSceneRad,
300 OpenGl_RT_uSceneEps,
301 OpenGl_RT_uLightAmbnt,
302 OpenGl_RT_uLightCount,
303
189f85a3 304 // background params
305 OpenGl_RT_uBackColorTop,
306 OpenGl_RT_uBackColorBot,
91c60b57 307
189f85a3 308 // ray-tracing params
309 OpenGl_RT_uShadowsEnabled,
310 OpenGl_RT_uReflectEnabled,
311 OpenGl_RT_uSphereMapEnabled,
312 OpenGl_RT_uSphereMapForBack,
313 OpenGl_RT_uTexSamplersArray,
8c820969 314 OpenGl_RT_uBlockedRngEnabled,
189f85a3 315
316 // sampled frame params
317 OpenGl_RT_uSampleWeight,
318 OpenGl_RT_uFrameRndSeed,
319
320 // adaptive FSAA params
91c60b57 321 OpenGl_RT_uOffsetX,
322 OpenGl_RT_uOffsetY,
323 OpenGl_RT_uSamples,
91c60b57 324
325 OpenGl_RT_NbVariables // special field
326 };
327
328 //! Defines texture samplers.
329 enum ShaderSamplerNames
330 {
331 OpenGl_RT_SceneNodeInfoTexture = 0,
332 OpenGl_RT_SceneMinPointTexture = 1,
333 OpenGl_RT_SceneMaxPointTexture = 2,
334 OpenGl_RT_SceneTransformTexture = 3,
335
336 OpenGl_RT_GeometryVertexTexture = 4,
337 OpenGl_RT_GeometryNormalTexture = 5,
338 OpenGl_RT_GeometryTexCrdTexture = 6,
339 OpenGl_RT_GeometryTriangTexture = 7,
340
341 OpenGl_RT_EnvironmentMapTexture = 8,
342
343 OpenGl_RT_RaytraceMaterialTexture = 9,
344 OpenGl_RT_RaytraceLightSrcTexture = 10,
345
189f85a3 346 OpenGl_RT_FsaaInputTexture = 11,
347 OpenGl_RT_PrevAccumTexture = 12,
91c60b57 348
189f85a3 349 OpenGl_RT_OpenGlColorTexture = 13,
350 OpenGl_RT_OpenGlDepthTexture = 14
91c60b57 351 };
352
353 //! Tool class for management of shader sources.
354 class ShaderSource
355 {
356 public:
357
189f85a3 358 //! Default shader prefix - empty string.
359 static const TCollection_AsciiString EMPTY_PREFIX;
360
91c60b57 361 //! Creates new uninitialized shader source.
362 ShaderSource()
363 {
364 //
365 }
366
73722cc9 367 public:
189f85a3 368
73722cc9 369 //! Returns error description in case of load fail.
370 const TCollection_AsciiString& ErrorDescription() const
371 {
372 return myError;
91c60b57 373 }
374
91c60b57 375 //! Returns prefix to insert before the source.
376 const TCollection_AsciiString& Prefix() const
377 {
378 return myPrefix;
379 }
380
381 //! Sets prefix to insert before the source.
382 void SetPrefix (const TCollection_AsciiString& thePrefix)
383 {
384 myPrefix = thePrefix;
385 }
386
387 //! Returns shader source combined with prefix.
388 TCollection_AsciiString Source() const;
389
390 //! Loads shader source from specified files.
73722cc9 391 Standard_Boolean Load (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);
91c60b57 392
393 private:
394
395 TCollection_AsciiString mySource; //!< Source string of the shader object
396 TCollection_AsciiString myPrefix; //!< Prefix to insert before the source
73722cc9 397 TCollection_AsciiString myError; //!< error state
91c60b57 398
399 };
400
401 //! Default ray-tracing depth.
402 static const Standard_Integer THE_DEFAULT_NB_BOUNCES = 3;
403
404 //! Default size of traversal stack.
405 static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24;
406
407 //! Compile-time ray-tracing parameters.
408 struct RaytracingParams
409 {
410 //! Actual size of traversal stack in shader program.
411 Standard_Integer StackSize;
412
413 //! Actual ray-tracing depth (number of ray bounces).
414 Standard_Integer NbBounces;
415
f483f2ed 416 //! Enables/disables light propagation through transparent media.
91c60b57 417 Standard_Boolean TransparentShadows;
418
189f85a3 419 //! Enables/disables global illumination (GI) effects.
420 Standard_Boolean GlobalIllumination;
421
f483f2ed 422 //! Enables/disables the use of OpenGL bindless textures.
423 Standard_Boolean UseBindlessTextures;
424
91c60b57 425 //! Creates default compile-time ray-tracing parameters.
426 RaytracingParams()
427 : StackSize (THE_DEFAULT_STACK_SIZE),
428 NbBounces (THE_DEFAULT_NB_BOUNCES),
f483f2ed 429 TransparentShadows (Standard_False),
189f85a3 430 GlobalIllumination (Standard_False),
f483f2ed 431 UseBindlessTextures (Standard_False)
91c60b57 432 {
433 //
434 }
435 };
436
d4aaad5b 437 //! Describes state of OpenGL structure.
438 struct StructState
439 {
440 Standard_Size StructureState;
441 Standard_Size InstancedState;
442
443 //! Creates new structure state.
444 StructState (const Standard_Size theStructureState = 0,
445 const Standard_Size theInstancedState = 0)
446 : StructureState (theStructureState),
447 InstancedState (theInstancedState)
448 {
449 //
450 }
451
452 //! Creates new structure state.
453 StructState (const OpenGl_Structure* theStructure)
454 {
455 StructureState = theStructure->ModificationState();
456
457 InstancedState = theStructure->InstancedStructure() != NULL ?
458 theStructure->InstancedStructure()->ModificationState() : 0;
459 }
460 };
461
91c60b57 462protected: //! @name methods related to ray-tracing
463
464 //! Updates 3D scene geometry for ray-tracing.
465 Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode theMode,
466 const Standard_Integer theViewId,
467 const Handle(OpenGl_Context)& theGlContext);
468
469 //! Updates 3D scene light sources for ray-tracing.
470 Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext);
471
472 //! Updates environment map for ray-tracing.
473 Standard_Boolean updateRaytraceEnvironmentMap (const Handle(OpenGl_Context)& theGlContext);
474
475 //! Checks to see if the OpenGL structure is modified.
476 Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure);
477
478 //! Adds OpenGL structure to ray-traced scene geometry.
479 Standard_Boolean addRaytraceStructure (const OpenGl_Structure* theStructure,
480 const Handle(OpenGl_Context)& theGlContext);
481
482 //! Adds OpenGL groups to ray-traced scene geometry.
8c820969 483 Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure,
484 const OpenGl_RaytraceMaterial& theStructMat,
485 const Standard_ShortReal* theTransform,
486 const Handle(OpenGl_Context)& theGlContext);
91c60b57 487
488 //! Creates ray-tracing material properties.
489 OpenGl_RaytraceMaterial convertMaterial (const OpenGl_AspectFace* theAspect,
490 const Handle(OpenGl_Context)& theGlContext);
491
492 //! Adds OpenGL primitive array to ray-traced scene geometry.
493 OpenGl_TriangleSet* addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
494 const Standard_Integer theMatID,
495 const OpenGl_Mat4* theTrans);
496
497 //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
498 Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
499 const Standard_Integer theMatID,
500 const Standard_Integer theCount,
501 const Standard_Integer theOffset,
502 const OpenGl_PrimitiveArray& theArray);
503
504 //! Adds OpenGL triangle array to ray-traced scene geometry.
505 Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
506 const Standard_Integer theMatID,
507 const Standard_Integer theCount,
508 const Standard_Integer theOffset,
509 const Handle(Graphic3d_IndexBuffer)& theIndices);
510
511 //! Adds OpenGL triangle fan array to ray-traced scene geometry.
512 Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
513 const Standard_Integer theMatID,
514 const Standard_Integer theCount,
515 const Standard_Integer theOffset,
516 const Handle(Graphic3d_IndexBuffer)& theIndices);
517
518 //! Adds OpenGL triangle strip array to ray-traced scene geometry.
519 Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
520 const Standard_Integer theMatID,
521 const Standard_Integer theCount,
522 const Standard_Integer theOffset,
523 const Handle(Graphic3d_IndexBuffer)& theIndices);
524
525 //! Adds OpenGL quadrangle array to ray-traced scene geometry.
526 Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
527 const Standard_Integer theMatID,
528 const Standard_Integer theCount,
529 const Standard_Integer theOffset,
530 const Handle(Graphic3d_IndexBuffer)& theIndices);
531
532 //! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
533 Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
534 const Standard_Integer theMatID,
535 const Standard_Integer theCount,
536 const Standard_Integer theOffset,
537 const Handle(Graphic3d_IndexBuffer)& theIndices);
538
539 //! Adds OpenGL polygon array to ray-traced scene geometry.
540 Standard_Boolean addRaytracePolygonArray (OpenGl_TriangleSet& theSet,
541 const Standard_Integer theMatID,
542 const Standard_Integer theCount,
543 const Standard_Integer theOffset,
544 const Handle(Graphic3d_IndexBuffer)& theIndices);
545
546 //! Uploads ray-trace data to the GPU.
547 Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext);
548
549 //! Generates shader prefix based on current ray-tracing options.
550 TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const;
551
552 //! Performs safe exit when shaders initialization fails.
553 Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage,
554 const Handle(OpenGl_Context)& theGlContext);
555
556 //! Loads and compiles shader object from specified source.
557 Handle(OpenGl_ShaderObject) initShader (const GLenum theType,
558 const ShaderSource& theSource,
559 const Handle(OpenGl_Context)& theGlContext);
560
189f85a3 561 //! Creates shader program from the given vertex and fragment shaders.
562 Handle(OpenGl_ShaderProgram) initProgram (const Handle(OpenGl_Context)& theGlContext,
563 const Handle(OpenGl_ShaderObject)& theVertShader,
564 const Handle(OpenGl_ShaderObject)& theFragShader);
565
91c60b57 566 //! Initializes OpenGL/GLSL shader programs.
567 Standard_Boolean initRaytraceResources (const Graphic3d_CView& theCView,
568 const Handle(OpenGl_Context)& theGlContext);
569
570 //! Releases OpenGL/GLSL shader programs.
571 void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
572
573 //! Resizes OpenGL frame buffers.
574 Standard_Boolean resizeRaytraceBuffers (const Standard_Integer theSizeX,
575 const Standard_Integer theSizeY,
576 const Handle(OpenGl_Context)& theGlContext);
577
578 //! Generates viewing rays for corners of screen quad.
579 void updateCamera (const OpenGl_Mat4& theOrientation,
580 const OpenGl_Mat4& theViewMapping,
581 OpenGl_Vec3* theOrigins,
582 OpenGl_Vec3* theDirects,
583 OpenGl_Mat4& theUnView);
584
585 //! Binds ray-trace textures to corresponding texture units.
586 void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
587
588 //! Unbinds ray-trace textures from corresponding texture unit.
589 void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
590
591 //! Sets uniform state for the given ray-tracing shader program.
592 Standard_Boolean setUniformState (const Graphic3d_CView& theCView,
593 const OpenGl_Vec3* theOrigins,
594 const OpenGl_Vec3* theDirects,
595 const OpenGl_Mat4& theUnviewMat,
596 const Standard_Integer theProgramId,
597 const Handle(OpenGl_Context)& theGlContext);
598
599 //! Runs ray-tracing shader programs.
600 Standard_Boolean runRaytraceShaders (const Graphic3d_CView& theCView,
601 const Standard_Integer theSizeX,
602 const Standard_Integer theSizeY,
603 const OpenGl_Vec3* theOrigins,
604 const OpenGl_Vec3* theDirects,
605 const OpenGl_Mat4& theUnviewMat,
38a0206f 606 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 607 const Handle(OpenGl_Context)& theGlContext);
608
609 //! Redraws the window using OpenGL/GLSL ray-tracing.
610 Standard_Boolean raytrace (const Graphic3d_CView& theCView,
611 const Standard_Integer theSizeX,
612 const Standard_Integer theSizeY,
38a0206f 613 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 614 const Handle(OpenGl_Context)& theGlContext);
615
616protected: //! @name fields related to ray-tracing
617
618 //! Result of shaders initialization.
619 RaytraceInitStatus myRaytraceInitStatus;
620
621 //! Is geometry data valid?
622 Standard_Boolean myIsRaytraceDataValid;
623
624 //! Warning about missing extension GL_ARB_bindless_texture has been displayed?
625 Standard_Boolean myIsRaytraceWarnTextures;
626
627 //! 3D scene geometry data for ray-tracing.
628 OpenGl_RaytraceGeometry myRaytraceGeometry;
629
630 //! Compile-time ray-tracing parameters.
631 RaytracingParams myRaytraceParameters;
632
633 //! Radius of bounding sphere of the scene.
634 Standard_ShortReal myRaytraceSceneRadius;
635 //! Scene epsilon to prevent self-intersections.
636 Standard_ShortReal myRaytraceSceneEpsilon;
637
638 //! OpenGL/GLSL source of ray-tracing fragment shader.
639 ShaderSource myRaytraceShaderSource;
640 //! OpenGL/GLSL source of adaptive-AA fragment shader.
641 ShaderSource myPostFSAAShaderSource;
642
643 //! OpenGL/GLSL ray-tracing fragment shader.
644 Handle(OpenGl_ShaderObject) myRaytraceShader;
645 //! OpenGL/GLSL adaptive-AA fragment shader.
646 Handle(OpenGl_ShaderObject) myPostFSAAShader;
647
648 //! OpenGL/GLSL ray-tracing shader program.
649 Handle(OpenGl_ShaderProgram) myRaytraceProgram;
650 //! OpenGL/GLSL adaptive-AA shader program.
651 Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
189f85a3 652 //! OpenGL/GLSL program for displaying texture.
653 Handle(OpenGl_ShaderProgram) myOutImageProgram;
91c60b57 654
655 //! Texture buffer of data records of bottom-level BVH nodes.
656 Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
657 //! Texture buffer of minimum points of bottom-level BVH nodes.
658 Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
659 //! Texture buffer of maximum points of bottom-level BVH nodes.
660 Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
661 //! Texture buffer of transformations of high-level BVH nodes.
662 Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
663
664 //! Texture buffer of vertex coords.
665 Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
666 //! Texture buffer of vertex normals.
667 Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
668 //! Texture buffer of vertex UV coords.
669 Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture;
670 //! Texture buffer of triangle indices.
671 Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
672
673 //! Texture buffer of material properties.
674 Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
675 //! Texture buffer of light source properties.
676 Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
677
678 //! 1st framebuffer (FBO) to perform adaptive FSAA.
679 Handle(OpenGl_FrameBuffer) myRaytraceFBO1;
680 //! 2nd framebuffer (FBO) to perform adaptive FSAA.
681 Handle(OpenGl_FrameBuffer) myRaytraceFBO2;
682 //! Framebuffer (FBO) for preliminary OpenGL output.
683 Handle(OpenGl_FrameBuffer) myOpenGlFBO;
684
685 //! Vertex buffer (VBO) for drawing dummy quad.
686 OpenGl_VertexBuffer myRaytraceScreenQuad;
687
688 //! Cached locations of frequently used uniform variables.
689 Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
690
691 //! State of OpenGL structures reflected to ray-tracing.
d4aaad5b 692 std::map<const OpenGl_Structure*, StructState> myStructureStates;
91c60b57 693
694 //! PrimitiveArray to TriangleSet map for scene partial update.
695 std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
696
189f85a3 697 //! Set of IDs of non-raytracable elements (to detect updates).
698 std::set<Standard_Integer> myNonRaytraceStructureIDs;
699
700 //! Render filter to filter out all raytracable structures.
91c60b57 701 Handle(OpenGl_RaytraceFilter) myRaytraceFilter;
702
703 //! Marks if environment map should be updated.
704 Standard_Boolean myToUpdateEnvironmentMap;
705
706 //! State of OpenGL layer list.
189f85a3 707 Standard_Size myLayerListState;
708
709 //! Number of accumulated frames (for progressive rendering).
710 Standard_Integer myAccumFrames;
711
712 //! Stored ray origins used for detection of camera movements.
713 OpenGl_Vec3 myPreviousOrigins[3];
714
715 //! Bullard RNG to produce random sequence.
716 math_BullardGenerator myRNG;
91c60b57 717
679ecdee 718public:
719
1c35b92f 720 DEFINE_STANDARD_ALLOC
ec357c5c 721 DEFINE_STANDARD_RTTI(OpenGl_View, MMgt_TShared) // Type definition
679ecdee 722
a89742cf 723 friend class OpenGl_Workspace;
724
2166f0fa
SK
725};
726
679ecdee 727#endif // _OpenGl_View_Header