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