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