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