Update of unstable Boolean test cases
[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
204 const OpenGl_SequenceOfStructure& ImmediateStructures() const
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
679ecdee 270 OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
271 OpenGl_SequenceOfStructure 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
451protected: //! @name methods related to ray-tracing
452
453 //! Updates 3D scene geometry for ray-tracing.
454 Standard_Boolean updateRaytraceGeometry (const RaytraceUpdateMode theMode,
455 const Standard_Integer theViewId,
456 const Handle(OpenGl_Context)& theGlContext);
457
458 //! Updates 3D scene light sources for ray-tracing.
459 Standard_Boolean updateRaytraceLightSources (const OpenGl_Mat4& theInvModelView, const Handle(OpenGl_Context)& theGlContext);
460
461 //! Updates environment map for ray-tracing.
462 Standard_Boolean updateRaytraceEnvironmentMap (const Handle(OpenGl_Context)& theGlContext);
463
464 //! Checks to see if the OpenGL structure is modified.
465 Standard_Boolean toUpdateStructure (const OpenGl_Structure* theStructure);
466
467 //! Adds OpenGL structure to ray-traced scene geometry.
468 Standard_Boolean addRaytraceStructure (const OpenGl_Structure* theStructure,
469 const Handle(OpenGl_Context)& theGlContext);
470
471 //! Adds OpenGL groups to ray-traced scene geometry.
472 Standard_Boolean addRaytraceGroups (const OpenGl_Structure* theStructure,
473 const Standard_Integer theStructMat,
474 const Standard_ShortReal* theTransform,
475 const Handle(OpenGl_Context)& theGlContext);
476
477 //! Creates ray-tracing material properties.
478 OpenGl_RaytraceMaterial convertMaterial (const OpenGl_AspectFace* theAspect,
479 const Handle(OpenGl_Context)& theGlContext);
480
481 //! Adds OpenGL primitive array to ray-traced scene geometry.
482 OpenGl_TriangleSet* addRaytracePrimitiveArray (const OpenGl_PrimitiveArray* theArray,
483 const Standard_Integer theMatID,
484 const OpenGl_Mat4* theTrans);
485
486 //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
487 Standard_Boolean addRaytraceVertexIndices (OpenGl_TriangleSet& theSet,
488 const Standard_Integer theMatID,
489 const Standard_Integer theCount,
490 const Standard_Integer theOffset,
491 const OpenGl_PrimitiveArray& theArray);
492
493 //! Adds OpenGL triangle array to ray-traced scene geometry.
494 Standard_Boolean addRaytraceTriangleArray (OpenGl_TriangleSet& theSet,
495 const Standard_Integer theMatID,
496 const Standard_Integer theCount,
497 const Standard_Integer theOffset,
498 const Handle(Graphic3d_IndexBuffer)& theIndices);
499
500 //! Adds OpenGL triangle fan array to ray-traced scene geometry.
501 Standard_Boolean addRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet,
502 const Standard_Integer theMatID,
503 const Standard_Integer theCount,
504 const Standard_Integer theOffset,
505 const Handle(Graphic3d_IndexBuffer)& theIndices);
506
507 //! Adds OpenGL triangle strip array to ray-traced scene geometry.
508 Standard_Boolean addRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet,
509 const Standard_Integer theMatID,
510 const Standard_Integer theCount,
511 const Standard_Integer theOffset,
512 const Handle(Graphic3d_IndexBuffer)& theIndices);
513
514 //! Adds OpenGL quadrangle array to ray-traced scene geometry.
515 Standard_Boolean addRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet,
516 const Standard_Integer theMatID,
517 const Standard_Integer theCount,
518 const Standard_Integer theOffset,
519 const Handle(Graphic3d_IndexBuffer)& theIndices);
520
521 //! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
522 Standard_Boolean addRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet,
523 const Standard_Integer theMatID,
524 const Standard_Integer theCount,
525 const Standard_Integer theOffset,
526 const Handle(Graphic3d_IndexBuffer)& theIndices);
527
528 //! Adds OpenGL polygon array to ray-traced scene geometry.
529 Standard_Boolean addRaytracePolygonArray (OpenGl_TriangleSet& theSet,
530 const Standard_Integer theMatID,
531 const Standard_Integer theCount,
532 const Standard_Integer theOffset,
533 const Handle(Graphic3d_IndexBuffer)& theIndices);
534
535 //! Uploads ray-trace data to the GPU.
536 Standard_Boolean uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext);
537
538 //! Generates shader prefix based on current ray-tracing options.
539 TCollection_AsciiString generateShaderPrefix (const Handle(OpenGl_Context)& theGlContext) const;
540
541 //! Performs safe exit when shaders initialization fails.
542 Standard_Boolean safeFailBack (const TCollection_ExtendedString& theMessage,
543 const Handle(OpenGl_Context)& theGlContext);
544
545 //! Loads and compiles shader object from specified source.
546 Handle(OpenGl_ShaderObject) initShader (const GLenum theType,
547 const ShaderSource& theSource,
548 const Handle(OpenGl_Context)& theGlContext);
549
550 //! Initializes OpenGL/GLSL shader programs.
551 Standard_Boolean initRaytraceResources (const Graphic3d_CView& theCView,
552 const Handle(OpenGl_Context)& theGlContext);
553
554 //! Releases OpenGL/GLSL shader programs.
555 void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext);
556
557 //! Resizes OpenGL frame buffers.
558 Standard_Boolean resizeRaytraceBuffers (const Standard_Integer theSizeX,
559 const Standard_Integer theSizeY,
560 const Handle(OpenGl_Context)& theGlContext);
561
562 //! Generates viewing rays for corners of screen quad.
563 void updateCamera (const OpenGl_Mat4& theOrientation,
564 const OpenGl_Mat4& theViewMapping,
565 OpenGl_Vec3* theOrigins,
566 OpenGl_Vec3* theDirects,
567 OpenGl_Mat4& theUnView);
568
569 //! Binds ray-trace textures to corresponding texture units.
570 void bindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
571
572 //! Unbinds ray-trace textures from corresponding texture unit.
573 void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext);
574
575 //! Sets uniform state for the given ray-tracing shader program.
576 Standard_Boolean setUniformState (const Graphic3d_CView& theCView,
577 const OpenGl_Vec3* theOrigins,
578 const OpenGl_Vec3* theDirects,
579 const OpenGl_Mat4& theUnviewMat,
580 const Standard_Integer theProgramId,
581 const Handle(OpenGl_Context)& theGlContext);
582
583 //! Runs ray-tracing shader programs.
584 Standard_Boolean runRaytraceShaders (const Graphic3d_CView& theCView,
585 const Standard_Integer theSizeX,
586 const Standard_Integer theSizeY,
587 const OpenGl_Vec3* theOrigins,
588 const OpenGl_Vec3* theDirects,
589 const OpenGl_Mat4& theUnviewMat,
38a0206f 590 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 591 const Handle(OpenGl_Context)& theGlContext);
592
593 //! Redraws the window using OpenGL/GLSL ray-tracing.
594 Standard_Boolean raytrace (const Graphic3d_CView& theCView,
595 const Standard_Integer theSizeX,
596 const Standard_Integer theSizeY,
38a0206f 597 OpenGl_FrameBuffer* theReadDrawFbo,
91c60b57 598 const Handle(OpenGl_Context)& theGlContext);
599
600protected: //! @name fields related to ray-tracing
601
602 //! Result of shaders initialization.
603 RaytraceInitStatus myRaytraceInitStatus;
604
605 //! Is geometry data valid?
606 Standard_Boolean myIsRaytraceDataValid;
607
608 //! Warning about missing extension GL_ARB_bindless_texture has been displayed?
609 Standard_Boolean myIsRaytraceWarnTextures;
610
611 //! 3D scene geometry data for ray-tracing.
612 OpenGl_RaytraceGeometry myRaytraceGeometry;
613
614 //! Compile-time ray-tracing parameters.
615 RaytracingParams myRaytraceParameters;
616
617 //! Radius of bounding sphere of the scene.
618 Standard_ShortReal myRaytraceSceneRadius;
619 //! Scene epsilon to prevent self-intersections.
620 Standard_ShortReal myRaytraceSceneEpsilon;
621
622 //! OpenGL/GLSL source of ray-tracing fragment shader.
623 ShaderSource myRaytraceShaderSource;
624 //! OpenGL/GLSL source of adaptive-AA fragment shader.
625 ShaderSource myPostFSAAShaderSource;
626
627 //! OpenGL/GLSL ray-tracing fragment shader.
628 Handle(OpenGl_ShaderObject) myRaytraceShader;
629 //! OpenGL/GLSL adaptive-AA fragment shader.
630 Handle(OpenGl_ShaderObject) myPostFSAAShader;
631
632 //! OpenGL/GLSL ray-tracing shader program.
633 Handle(OpenGl_ShaderProgram) myRaytraceProgram;
634 //! OpenGL/GLSL adaptive-AA shader program.
635 Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
636
637 //! Texture buffer of data records of bottom-level BVH nodes.
638 Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
639 //! Texture buffer of minimum points of bottom-level BVH nodes.
640 Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
641 //! Texture buffer of maximum points of bottom-level BVH nodes.
642 Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
643 //! Texture buffer of transformations of high-level BVH nodes.
644 Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
645
646 //! Texture buffer of vertex coords.
647 Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
648 //! Texture buffer of vertex normals.
649 Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture;
650 //! Texture buffer of vertex UV coords.
651 Handle(OpenGl_TextureBufferArb) myGeometryTexCrdTexture;
652 //! Texture buffer of triangle indices.
653 Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture;
654
655 //! Texture buffer of material properties.
656 Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture;
657 //! Texture buffer of light source properties.
658 Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture;
659
660 //! 1st framebuffer (FBO) to perform adaptive FSAA.
661 Handle(OpenGl_FrameBuffer) myRaytraceFBO1;
662 //! 2nd framebuffer (FBO) to perform adaptive FSAA.
663 Handle(OpenGl_FrameBuffer) myRaytraceFBO2;
664 //! Framebuffer (FBO) for preliminary OpenGL output.
665 Handle(OpenGl_FrameBuffer) myOpenGlFBO;
666
667 //! Vertex buffer (VBO) for drawing dummy quad.
668 OpenGl_VertexBuffer myRaytraceScreenQuad;
669
670 //! Cached locations of frequently used uniform variables.
671 Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables];
672
673 //! State of OpenGL structures reflected to ray-tracing.
674 std::map<const OpenGl_Structure*, Standard_Size> myStructureStates;
675
676 //! PrimitiveArray to TriangleSet map for scene partial update.
677 std::map<Standard_Size, OpenGl_TriangleSet*> myArrayToTrianglesMap;
678
679 //! Graphical ray-tracing filter to filter out all raytracable structures.
680 Handle(OpenGl_RaytraceFilter) myRaytraceFilter;
681
682 //! Marks if environment map should be updated.
683 Standard_Boolean myToUpdateEnvironmentMap;
684
685 //! State of OpenGL layer list.
686 Standard_Size myLayersModificationStatus;
687
679ecdee 688public:
689
1c35b92f 690 DEFINE_STANDARD_ALLOC
679ecdee 691 DEFINE_STANDARD_RTTI(OpenGl_View) // Type definition
692
a89742cf 693 friend class OpenGl_Workspace;
694
2166f0fa
SK
695};
696
679ecdee 697#endif // _OpenGl_View_Header