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