Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-20 |
2 | // Created by: Sergey ZERCHANINOV | |
1981cb22 | 3 | // Copyright (c) 2011-2013 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_Workspace_Header |
17 | #define _OpenGl_Workspace_Header | |
18 | ||
fc73a202 | 19 | #include <map> |
20 | #include <set> | |
e276548b | 21 | |
2166f0fa SK |
22 | #include <Handle_OpenGl_Workspace.hxx> |
23 | #include <OpenGl_Window.hxx> | |
24 | ||
25 | #include <TColStd_Array2OfReal.hxx> | |
26 | #include <Quantity_Color.hxx> | |
bf75be98 | 27 | #include <Graphic3d_CView.hxx> |
2166f0fa | 28 | #include <Graphic3d_TypeOfComposition.hxx> |
bf75be98 | 29 | #include <Graphic3d_TypeOfTexture.hxx> |
30 | #include <Graphic3d_PtrFrameBuffer.hxx> | |
31 | #include <Graphic3d_BufferType.hxx> | |
32 | #include <Handle_Graphic3d_TextureParams.hxx> | |
2166f0fa | 33 | |
2166f0fa SK |
34 | #include <Aspect_CLayer2d.hxx> |
35 | #include <Aspect_Handle.hxx> | |
36 | #include <Aspect_PrintAlgo.hxx> | |
550f3b8b | 37 | #include <Aspect_PolygonOffsetMode.hxx> |
2166f0fa SK |
38 | |
39 | #include <InterfaceGraphic_Graphic3d.hxx> | |
40 | #include <InterfaceGraphic_Visual3d.hxx> | |
41 | ||
1981cb22 | 42 | #include <NCollection_Sequence.hxx> |
43 | ||
bf75be98 | 44 | #include <OpenGl_AspectFace.hxx> |
fc73a202 | 45 | #include <OpenGl_FrameBuffer.hxx> |
2166f0fa SK |
46 | #include <OpenGl_Matrix.hxx> |
47 | #include <OpenGl_NamedStatus.hxx> | |
a174a3c5 | 48 | #include <OpenGl_PrinterContext.hxx> |
fc73a202 | 49 | #include <OpenGl_SceneGeometry.hxx> |
2166f0fa | 50 | #include <OpenGl_TextParam.hxx> |
4269bd1b | 51 | #include <OpenGl_RenderFilter.hxx> |
0adbd30f | 52 | #include <OpenGl_Vec.hxx> |
73192b37 | 53 | #include <OpenGl_LineAttributes.hxx> |
2166f0fa SK |
54 | |
55 | #include <Handle_OpenGl_View.hxx> | |
bf75be98 | 56 | #include <Handle_OpenGl_Texture.hxx> |
2166f0fa | 57 | |
fc73a202 | 58 | #include <OpenGl_ShaderObject.hxx> |
59 | #include <OpenGl_ShaderProgram.hxx> | |
60 | #include <OpenGl_TextureBufferArb.hxx> | |
61 | ||
2166f0fa | 62 | class OpenGl_AspectLine; |
2166f0fa SK |
63 | class OpenGl_AspectMarker; |
64 | class OpenGl_AspectText; | |
65 | class OpenGl_FrameBuffer; | |
66 | class OpenGl_Structure; | |
b7cd4ba7 | 67 | class OpenGl_TriangleSet; |
4269bd1b | 68 | class OpenGl_Element; |
692613e5 | 69 | class Image_PixMap; |
2166f0fa | 70 | |
0adbd30f | 71 | //! OpenGL material definition |
72 | struct OpenGl_Material | |
73 | { | |
74 | ||
75 | OpenGl_Vec4 Ambient; //!< ambient reflection coefficient | |
76 | OpenGl_Vec4 Diffuse; //!< diffuse reflection coefficient | |
77 | OpenGl_Vec4 Specular; //!< glossy reflection coefficient | |
78 | OpenGl_Vec4 Emission; //!< material emission | |
79 | OpenGl_Vec4 Params; //!< extra packed parameters | |
80 | ||
81 | Standard_ShortReal Shine() const { return Params.x(); } | |
82 | Standard_ShortReal& ChangeShine() { return Params.x(); } | |
83 | ||
84 | Standard_ShortReal Transparency() const { return Params.y(); } | |
85 | Standard_ShortReal& ChangeTransparency() { return Params.y(); } | |
86 | ||
87 | //! Initialize material | |
88 | void Init (const OPENGL_SURF_PROP& theProps); | |
89 | ||
90 | //! Returns packed (serialized) representation of material properties | |
91 | const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); } | |
92 | static Standard_Integer NbOfVec4() { return 5; } | |
93 | ||
94 | }; | |
95 | ||
e276548b | 96 | //! Represents window with GL context. |
97 | //! Provides methods to render primitives and maintain GL state. | |
2166f0fa SK |
98 | class OpenGl_Workspace : public OpenGl_Window |
99 | { | |
100 | public: | |
101 | ||
102 | //! Main constructor - prepare GL context for specified window. | |
73192b37 | 103 | OpenGl_Workspace (const Handle(Aspect_DisplayConnection)& theDisplayConnection, |
2166f0fa | 104 | const CALL_DEF_WINDOW& theCWindow, |
5e27df78 | 105 | Aspect_RenderingContext theGContext, |
58655684 | 106 | const Handle(OpenGl_Caps)& theCaps, |
5e27df78 | 107 | const Handle(OpenGl_Context)& theShareCtx); |
2166f0fa SK |
108 | |
109 | //! Destructor | |
110 | virtual ~OpenGl_Workspace(); | |
111 | ||
112 | void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; } | |
113 | const Handle(OpenGl_View)& ActiveView () const { return myView; } | |
114 | ||
115 | //! Redraw the window. | |
116 | void Redraw (const Graphic3d_CView& theCView, | |
117 | const Aspect_CLayer2d& theCUnderLayer, | |
118 | const Aspect_CLayer2d& theCOverLayer); | |
119 | ||
679ecdee | 120 | Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer); |
121 | void RedrawImmediate (const Graphic3d_CView& theCView, | |
122 | const Aspect_CLayer2d& theCUnderLayer, | |
123 | const Aspect_CLayer2d& theCOverLayer, | |
124 | const Standard_Boolean theToForce = Standard_False); | |
125 | ||
126 | void Invalidate (const Graphic3d_CView& /*theCView*/) | |
2166f0fa | 127 | { |
679ecdee | 128 | myBackBufferRestored = Standard_False; |
2166f0fa SK |
129 | } |
130 | ||
131 | //! Special method to perform printing. | |
132 | //! System-specific and currently only Win platform implemented. | |
a174a3c5 | 133 | Standard_Boolean Print (const Handle(OpenGl_PrinterContext)& thePrintContext, |
134 | const Graphic3d_CView& theCView, | |
bf75be98 | 135 | const Aspect_CLayer2d& theCUnderLayer, |
2166f0fa SK |
136 | const Aspect_CLayer2d& theCOverLayer, |
137 | const Aspect_Handle theHPrintDC, | |
138 | const Standard_Boolean theToShowBackground, | |
139 | const Standard_CString theFileName, | |
140 | const Aspect_PrintAlgo thePrintAlgorithm, | |
141 | const Standard_Real theScaleFactor); | |
142 | ||
a174a3c5 | 143 | const Handle(OpenGl_PrinterContext)& PrinterContext() const |
144 | { | |
145 | return myPrintContext; | |
146 | } | |
147 | ||
2166f0fa SK |
148 | void DisplayCallback (const Graphic3d_CView& theCView, int theReason); |
149 | ||
2166f0fa SK |
150 | Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight); |
151 | void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr); | |
692613e5 | 152 | Standard_Boolean BufferDump (OpenGl_FrameBuffer* theFBOPtr, |
153 | Image_PixMap& theImage, | |
154 | const Graphic3d_BufferType& theBufferType); | |
2166f0fa | 155 | |
2166f0fa SK |
156 | void UseTransparency (const Standard_Boolean theFlag); |
157 | Standard_Boolean& UseZBuffer() { return myUseZBuffer; } | |
158 | Standard_Boolean& UseDepthTest() { return myUseDepthTest; } | |
159 | Standard_Boolean& UseGLLight() { return myUseGLLight; } | |
160 | ||
73192b37 | 161 | Standard_Integer AntiAliasingMode() const { return myAntiAliasingMode; } |
162 | ||
2166f0fa SK |
163 | //// RELATED TO STATUS //// |
164 | ||
165 | Standard_Integer NamedStatus; | |
166 | ||
2166f0fa SK |
167 | const TEL_COLOUR* HighlightColor; |
168 | ||
169 | const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* ); | |
30f0ad28 | 170 | const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix*, bool aRevert = false); |
2166f0fa | 171 | |
0f8c0fb8 | 172 | //! Updates current model-view matrix |
173 | //! replacing it with StructureMatrixT*ViewMatrix from the workspace. | |
174 | const void UpdateModelViewMatrix(); | |
175 | ||
2166f0fa SK |
176 | const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect); |
177 | const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect); | |
178 | const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect); | |
179 | const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect); | |
180 | ||
181 | void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; } | |
182 | ||
3946774d | 183 | //// THESE METHODS ARE EXPORTED AS THEY PROVIDE STATE INFO TO USERDRAW |
184 | Standard_EXPORT const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply); | |
185 | Standard_EXPORT const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply); | |
186 | Standard_EXPORT const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply); | |
187 | Standard_EXPORT const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply); | |
a174a3c5 | 188 | inline const OpenGl_TextParam* AspectTextParams() const |
189 | { | |
190 | return TextParam_applied; | |
191 | } | |
2166f0fa | 192 | |
34a44cbd | 193 | //! Clear the applied aspect state. |
194 | void ResetAppliedAspect(); | |
195 | ||
bf75be98 | 196 | Standard_EXPORT Handle(OpenGl_Texture) DisableTexture(); |
197 | Standard_EXPORT Handle(OpenGl_Texture) EnableTexture (const Handle(OpenGl_Texture)& theTexture, | |
198 | const Handle(Graphic3d_TextureParams)& theParams = NULL); | |
199 | ||
4269bd1b | 200 | //! Set filter for restricting rendering of particular elements. |
201 | //! Filter can be applied for rendering passes used by recursive | |
202 | //! rendering algorithms for rendering elements of groups. | |
203 | //! @param theFilter [in] the filter instance. | |
204 | inline void SetRenderFilter (const Handle(OpenGl_RenderFilter)& theFilter) | |
205 | { | |
5322131b | 206 | myRenderFilter = theFilter; |
4269bd1b | 207 | } |
208 | ||
209 | //! Get rendering filter. | |
210 | //! @return filter instance. | |
5322131b | 211 | inline const Handle(OpenGl_RenderFilter)& GetRenderFilter() const |
212 | { | |
213 | return myRenderFilter; | |
4269bd1b | 214 | } |
215 | ||
216 | //! @return applied view matrix. | |
217 | inline const OpenGl_Matrix* ViewMatrix() const { return ViewMatrix_applied; } | |
218 | ||
219 | //! @return applied model structure matrix. | |
220 | inline const OpenGl_Matrix* ModelMatrix() const { return StructureMatrix_applied; } | |
221 | ||
550f3b8b | 222 | //! Sets and applies current polygon offset. |
223 | void SetPolygonOffset (int theMode, Standard_ShortReal theFactor, Standard_ShortReal theUnits); | |
224 | ||
225 | //! Returns currently applied polygon offset params. | |
226 | const TEL_POFFSET_PARAM& AppliedPolygonOffset() { return PolygonOffset_applied; } | |
227 | ||
b7cd4ba7 | 228 | //! @return true if clipping algorithm enabled |
229 | inline Standard_Boolean IsCullingEnabled() const { return myIsCullingEnabled; } | |
230 | ||
2166f0fa SK |
231 | protected: |
232 | ||
679ecdee | 233 | //! Copy content of Back buffer to the Front buffer |
234 | void copyBackToFront(); | |
2166f0fa SK |
235 | |
236 | virtual Standard_Boolean Activate(); | |
237 | ||
679ecdee | 238 | void redraw1 (const Graphic3d_CView& theCView, |
bf75be98 | 239 | const Aspect_CLayer2d& theCUnderLayer, |
2166f0fa | 240 | const Aspect_CLayer2d& theCOverLayer, |
679ecdee | 241 | const int theToSwap); |
2166f0fa | 242 | |
0adbd30f | 243 | void updateMaterial (const int theFlag); |
2166f0fa | 244 | |
bf75be98 | 245 | void setTextureParams (Handle(OpenGl_Texture)& theTexture, |
246 | const Handle(Graphic3d_TextureParams)& theParams); | |
2166f0fa | 247 | |
fc73a202 | 248 | protected: |
e276548b | 249 | |
fc73a202 | 250 | //! Result of OpenGL shaders initialization. |
251 | enum RaytraceInitStatus | |
252 | { | |
253 | OpenGl_RT_NONE, | |
254 | OpenGl_RT_INIT, | |
255 | OpenGl_RT_FAIL | |
256 | }; | |
e276548b | 257 | |
84c71f29 | 258 | //! Describes update mode (state). |
259 | enum GeomUpdateMode | |
260 | { | |
261 | OpenGl_GUM_CHECK, //!< check if geometry update is necessary | |
262 | OpenGl_GUM_PREPARE, //!< collect unchanged objects | |
263 | OpenGl_GUM_UPDATE //!< update raytracing data, rebuild changed objects | |
264 | }; | |
265 | ||
fc73a202 | 266 | //! Defines frequently used shader variables. |
267 | enum ShaderVariableIndex | |
268 | { | |
269 | OpenGl_RT_aPosition, | |
270 | ||
271 | OpenGl_RT_uOriginLT, | |
272 | OpenGl_RT_uOriginLB, | |
273 | OpenGl_RT_uOriginRT, | |
274 | OpenGl_RT_uOriginRB, | |
275 | ||
276 | OpenGl_RT_uDirectLT, | |
277 | OpenGl_RT_uDirectLB, | |
278 | OpenGl_RT_uDirectRT, | |
279 | OpenGl_RT_uDirectRB, | |
280 | ||
281 | OpenGl_RT_uSceneRad, | |
282 | OpenGl_RT_uSceneEps, | |
283 | ||
284 | OpenGl_RT_uLightAmbnt, | |
285 | OpenGl_RT_uLightCount, | |
286 | ||
287 | OpenGl_RT_uShadEnabled, | |
288 | OpenGl_RT_uReflEnabled, | |
289 | ||
290 | OpenGl_RT_uInputTexture, | |
291 | ||
292 | OpenGl_RT_uOffsetX, | |
293 | OpenGl_RT_uOffsetY, | |
294 | OpenGl_RT_uSamples, | |
295 | ||
84c71f29 | 296 | OpenGl_RT_uEnvironmentEnable, |
297 | ||
fc73a202 | 298 | OpenGl_RT_NbVariables // special field |
299 | }; | |
e276548b | 300 | |
fc73a202 | 301 | //! Defines texture samplers. |
302 | enum ShaderSamplerNames | |
303 | { | |
304 | OpenGl_RT_SceneNodeInfoTexture = 0, | |
305 | OpenGl_RT_SceneMinPointTexture = 1, | |
306 | OpenGl_RT_SceneMaxPointTexture = 2, | |
307 | ||
308 | OpenGl_RT_ObjectNodeInfoTexture = 3, | |
309 | OpenGl_RT_ObjectMinPointTexture = 4, | |
310 | OpenGl_RT_ObjectMaxPointTexture = 5, | |
311 | ||
312 | OpenGl_RT_GeometryVertexTexture = 6, | |
313 | OpenGl_RT_GeometryNormalTexture = 7, | |
314 | OpenGl_RT_GeometryTriangTexture = 8, | |
e276548b | 315 | |
fc73a202 | 316 | OpenGl_RT_EnvironmentMapTexture = 9, |
317 | ||
318 | OpenGl_RT_RaytraceMaterialTexture = 10, | |
319 | OpenGl_RT_RaytraceLightSrcTexture = 11, | |
320 | ||
84c71f29 | 321 | OpenGl_RT_FSAAInputTexture = 12, |
322 | ||
323 | OpenGl_RT_SceneTransformTexture = 13 | |
fc73a202 | 324 | }; |
325 | ||
326 | //! Tool class for management of shader sources. | |
327 | class ShaderSource | |
e276548b | 328 | { |
fc73a202 | 329 | public: |
330 | ||
331 | //! Creates new uninitialized shader source. | |
332 | ShaderSource() | |
333 | { | |
334 | // | |
335 | } | |
336 | ||
337 | //! Creates new shader source from specified file. | |
338 | ShaderSource (const TCollection_AsciiString& theFileName) | |
339 | { | |
340 | Load (&theFileName, 1); | |
341 | } | |
342 | ||
343 | public: | |
344 | ||
345 | //! Returns prefix to insert before the source. | |
346 | const TCollection_AsciiString& Prefix() const | |
347 | { | |
348 | return myPrefix; | |
349 | } | |
350 | ||
351 | //! Sets prefix to insert before the source. | |
352 | void SetPrefix (const TCollection_AsciiString& thePrefix) | |
353 | { | |
354 | myPrefix = thePrefix; | |
355 | } | |
356 | ||
357 | //! Returns shader source combined with prefix. | |
358 | TCollection_AsciiString Source() const; | |
359 | ||
360 | //! Loads shader source from specified files. | |
361 | void Load (const TCollection_AsciiString* theFileNames, const Standard_Integer theCount); | |
362 | ||
363 | private: | |
364 | ||
365 | TCollection_AsciiString mySource; //!< Source string of the shader object | |
366 | TCollection_AsciiString myPrefix; //!< Prefix to insert before the source | |
367 | ||
e276548b | 368 | }; |
369 | ||
bc8c79bb | 370 | //! Default ray-tracing depth. |
371 | static const Standard_Integer THE_DEFAULT_RAY_DEPTH = 3; | |
372 | ||
fc73a202 | 373 | //! Default size of traversal stack. |
374 | static const Standard_Integer THE_DEFAULT_STACK_SIZE = 24; | |
375 | ||
bc8c79bb | 376 | //! Compile-time ray-tracing parameters. |
377 | struct RaytracingParams | |
378 | { | |
379 | //! Actual size of traversal stack in shader program. | |
380 | Standard_Integer StackSize; | |
381 | ||
382 | //! Actual ray-tracing depth (number of ray bounces). | |
383 | Standard_Integer TraceDepth; | |
384 | ||
385 | //! Sets light propagation through transparent media. | |
386 | Standard_Boolean TransparentShadows; | |
387 | ||
388 | //! Creates default compile-time ray-tracing parameters. | |
389 | RaytracingParams() | |
390 | : StackSize (THE_DEFAULT_STACK_SIZE), | |
391 | TraceDepth (THE_DEFAULT_RAY_DEPTH), | |
392 | TransparentShadows (Standard_False) | |
393 | { | |
394 | // | |
395 | } | |
396 | }; | |
397 | ||
e276548b | 398 | protected: //! @name methods related to ray-tracing |
399 | ||
400 | //! Updates 3D scene geometry for ray-tracing. | |
84c71f29 | 401 | Standard_Boolean UpdateRaytraceGeometry (GeomUpdateMode theMode); |
e276548b | 402 | |
403 | //! Checks to see if the structure is modified. | |
404 | Standard_Boolean CheckRaytraceStructure (const OpenGl_Structure* theStructure); | |
405 | ||
406 | //! Updates 3D scene light sources for ray-tracing. | |
407 | Standard_Boolean UpdateRaytraceLightSources (const GLdouble theInvModelView[16]); | |
408 | ||
409 | //! Updates environment map for ray-tracing. | |
410 | Standard_Boolean UpdateRaytraceEnvironmentMap(); | |
5322131b | 411 | |
e276548b | 412 | //! Adds OpenGL structure to ray-traced scene geometry. |
265d4508 | 413 | Standard_Boolean AddRaytraceStructure (const OpenGl_Structure* theStructure, |
414 | const Standard_ShortReal* theTransform, std::set<const OpenGl_Structure*>& theElements); | |
e276548b | 415 | |
416 | //! Adds OpenGL primitive array to ray-traced scene geometry. | |
265d4508 | 417 | OpenGl_TriangleSet* AddRaytracePrimitiveArray ( |
84c71f29 | 418 | const OpenGl_PrimitiveArray* theArray, int theMatID, const Standard_ShortReal* theTrans); |
e276548b | 419 | |
420 | //! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry. | |
871fa103 | 421 | Standard_Boolean AddRaytraceVertexIndices (OpenGl_TriangleSet& theSet, |
422 | const OpenGl_PrimitiveArray& theArray, | |
423 | Standard_Integer theOffset, | |
424 | Standard_Integer theCount, | |
425 | Standard_Integer theMatID); | |
e276548b | 426 | |
427 | //! Adds OpenGL triangle array to ray-traced scene geometry. | |
871fa103 | 428 | Standard_Boolean AddRaytraceTriangleArray (OpenGl_TriangleSet& theSet, |
429 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
430 | Standard_Integer theOffset, | |
431 | Standard_Integer theCount, | |
432 | Standard_Integer theMatID); | |
e276548b | 433 | |
434 | //! Adds OpenGL triangle fan array to ray-traced scene geometry. | |
871fa103 | 435 | Standard_Boolean AddRaytraceTriangleFanArray (OpenGl_TriangleSet& theSet, |
436 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
437 | Standard_Integer theOffset, | |
438 | Standard_Integer theCount, | |
439 | Standard_Integer theMatID); | |
e276548b | 440 | |
265d4508 | 441 | //! Adds OpenGL triangle strip array to ray-traced scene geometry. |
871fa103 | 442 | Standard_Boolean AddRaytraceTriangleStripArray (OpenGl_TriangleSet& theSet, |
443 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
444 | Standard_Integer theOffset, | |
445 | Standard_Integer theCount, | |
446 | Standard_Integer theMatID); | |
e276548b | 447 | |
448 | //! Adds OpenGL quadrangle array to ray-traced scene geometry. | |
871fa103 | 449 | Standard_Boolean AddRaytraceQuadrangleArray (OpenGl_TriangleSet& theSet, |
450 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
451 | Standard_Integer theOffset, | |
452 | Standard_Integer theCount, | |
453 | Standard_Integer theMatID); | |
e276548b | 454 | |
455 | //! Adds OpenGL quadrangle strip array to ray-traced scene geometry. | |
871fa103 | 456 | Standard_Boolean AddRaytraceQuadrangleStripArray (OpenGl_TriangleSet& theSet, |
457 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
458 | Standard_Integer theOffset, | |
459 | Standard_Integer theCount, | |
460 | Standard_Integer theMatID); | |
e276548b | 461 | |
462 | //! Adds OpenGL polygon array to ray-traced scene geometry. | |
871fa103 | 463 | Standard_Boolean AddRaytracePolygonArray (OpenGl_TriangleSet& theSet, |
464 | const Handle(Graphic3d_IndexBuffer)& theIndices, | |
465 | Standard_Integer theOffset, | |
466 | Standard_Integer theCount, | |
467 | Standard_Integer theMatID); | |
e276548b | 468 | |
fc73a202 | 469 | //! Loads and compiles shader object from specified source. |
470 | Handle(OpenGl_ShaderObject) LoadShader (const ShaderSource& theSource, GLenum theType); | |
471 | ||
472 | //! Performs safe exit when shaders initialization fails. | |
473 | Standard_Boolean SafeFailBack (const TCollection_ExtendedString& theMessage); | |
474 | ||
475 | //! Initializes OpenGL/GLSL shader programs. | |
bc8c79bb | 476 | Standard_Boolean InitRaytraceResources (const Graphic3d_CView& theCView); |
5322131b | 477 | |
fc73a202 | 478 | //! Releases OpenGL/GLSL shader programs. |
479 | void ReleaseRaytraceResources(); | |
e276548b | 480 | |
fc73a202 | 481 | //! Uploads ray-trace data to the GPU. |
482 | Standard_Boolean UploadRaytraceData(); | |
e276548b | 483 | |
fc73a202 | 484 | //! Resizes OpenGL frame buffers. |
485 | Standard_Boolean ResizeRaytraceBuffers (const Standard_Integer theSizeX, | |
486 | const Standard_Integer theSizeY); | |
e276548b | 487 | |
fc73a202 | 488 | //! Generates viewing rays for corners of screen quad. |
489 | void UpdateCamera (const NCollection_Mat4<GLdouble>& theOrientation, | |
490 | const NCollection_Mat4<GLdouble>& theViewMapping, | |
491 | OpenGl_Vec3 theOrigins[4], | |
492 | OpenGl_Vec3 theDirects[4]); | |
e276548b | 493 | |
fc73a202 | 494 | //! Runs ray-tracing shader programs. |
495 | Standard_Boolean RunRaytraceShaders (const Graphic3d_CView& theCView, | |
496 | const Standard_Integer theSizeX, | |
497 | const Standard_Integer theSizeY, | |
498 | const OpenGl_Vec3 theOrigins[4], | |
499 | const OpenGl_Vec3 theDirects[4], | |
500 | OpenGl_FrameBuffer* theFrameBuffer); | |
265d4508 | 501 | |
fc73a202 | 502 | //! Redraws the window using OpenGL/GLSL ray-tracing. |
e276548b | 503 | Standard_Boolean Raytrace (const Graphic3d_CView& theCView, |
fc73a202 | 504 | const Standard_Integer theSizeX, |
505 | const Standard_Integer theSizeY, | |
506 | const Standard_Boolean theToSwap, | |
507 | OpenGl_FrameBuffer* theFrameBuffer); | |
e276548b | 508 | |
509 | protected: //! @name fields related to ray-tracing | |
510 | ||
fc73a202 | 511 | //! Result of shaders initialization. |
512 | RaytraceInitStatus myComputeInitStatus; | |
e276548b | 513 | |
514 | //! Is geometry data valid? | |
515 | Standard_Boolean myIsRaytraceDataValid; | |
5322131b | 516 | |
e276548b | 517 | //! 3D scene geometry data for ray-tracing. |
265d4508 | 518 | OpenGl_RaytraceGeometry myRaytraceGeometry; |
e276548b | 519 | |
520 | //! Radius of bounding sphere of the scene. | |
265d4508 | 521 | Standard_ShortReal myRaytraceSceneRadius; |
e276548b | 522 | //! Scene epsilon to prevent self-intersections. |
265d4508 | 523 | Standard_ShortReal myRaytraceSceneEpsilon; |
e276548b | 524 | |
bc8c79bb | 525 | //! Compile-time ray-tracing parameters. |
526 | RaytracingParams myRaytraceParameters; | |
fc73a202 | 527 | |
528 | //! OpenGL/GLSL source of ray-tracing fragment shader. | |
529 | ShaderSource myRaytraceShaderSource; | |
530 | //! OpenGL/GLSL source of adaptive-AA fragment shader. | |
531 | ShaderSource myPostFSAAShaderSource; | |
532 | ||
533 | //! OpenGL/GLSL ray-tracing fragment shader. | |
534 | Handle(OpenGl_ShaderObject) myRaytraceShader; | |
535 | //! OpenGL/GLSL adaptive-AA fragment shader. | |
536 | Handle(OpenGl_ShaderObject) myPostFSAAShader; | |
537 | ||
538 | //! OpenGL/GLSL ray-tracing shader program. | |
539 | Handle(OpenGl_ShaderProgram) myRaytraceProgram; | |
540 | //! OpenGL/GLSL adaptive-AA shader program. | |
541 | Handle(OpenGl_ShaderProgram) myPostFSAAProgram; | |
542 | ||
543 | //! Texture buffer of data records of high-level BVH nodes. | |
544 | Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture; | |
545 | //! Texture buffer of minimum points of high-level BVH nodes. | |
546 | Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture; | |
547 | //! Texture buffer of maximum points of high-level BVH nodes. | |
548 | Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture; | |
84c71f29 | 549 | //! Texture buffer of transformations of high-level BVH nodes. |
550 | Handle(OpenGl_TextureBufferArb) mySceneTransformTexture; | |
fc73a202 | 551 | |
552 | //! Texture buffer of data records of bottom-level BVH nodes. | |
553 | Handle(OpenGl_TextureBufferArb) myObjectNodeInfoTexture; | |
554 | //! Texture buffer of minimum points of bottom-level BVH nodes. | |
555 | Handle(OpenGl_TextureBufferArb) myObjectMinPointTexture; | |
556 | //! Texture buffer of maximum points of bottom-level BVH nodes. | |
557 | Handle(OpenGl_TextureBufferArb) myObjectMaxPointTexture; | |
558 | ||
559 | //! Texture buffer of vertex coords. | |
560 | Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture; | |
561 | //! Texture buffer of vertex normals. | |
562 | Handle(OpenGl_TextureBufferArb) myGeometryNormalTexture; | |
563 | //! Texture buffer of triangle indices. | |
564 | Handle(OpenGl_TextureBufferArb) myGeometryTriangTexture; | |
565 | ||
566 | //! Texture buffer of material properties. | |
567 | Handle(OpenGl_TextureBufferArb) myRaytraceMaterialTexture; | |
568 | //! Texture buffer of light source properties. | |
569 | Handle(OpenGl_TextureBufferArb) myRaytraceLightSrcTexture; | |
570 | ||
571 | //! Vertex buffer (VBO) for drawing dummy quad. | |
572 | OpenGl_VertexBuffer myRaytraceScreenQuad; | |
573 | ||
574 | //! Framebuffer (FBO) to perform adaptive FSAA. | |
575 | Handle(OpenGl_FrameBuffer) myRaytraceFBO1; | |
576 | //! Framebuffer (FBO) to perform adaptive FSAA. | |
577 | Handle(OpenGl_FrameBuffer) myRaytraceFBO2; | |
265d4508 | 578 | |
e276548b | 579 | //! State of OpenGL view. |
580 | Standard_Size myViewModificationStatus; | |
e276548b | 581 | //! State of OpenGL layer list. |
582 | Standard_Size myLayersModificationStatus; | |
583 | ||
265d4508 | 584 | //! State of OpenGL structures reflected to ray-tracing. |
e276548b | 585 | std::map<const OpenGl_Structure*, Standard_Size> myStructureStates; |
586 | ||
84c71f29 | 587 | //! PrimitiveArray to TriangleSet map for scene partial update. |
588 | std::map<const OpenGl_PrimitiveArray*, OpenGl_TriangleSet*> myArrayToTrianglesMap; | |
589 | ||
fc73a202 | 590 | //! Cached locations of frequently used uniform variables. |
591 | Standard_Integer myUniformLocations[2][OpenGl_RT_NbVariables]; | |
e276548b | 592 | |
bf75be98 | 593 | protected: //! @name protected fields |
2166f0fa | 594 | |
a174a3c5 | 595 | Handle(OpenGl_PrinterContext) myPrintContext; |
73192b37 | 596 | Handle(OpenGl_View) myView; |
597 | Handle(OpenGl_LineAttributes) myLineAttribs; | |
598 | Standard_Integer myAntiAliasingMode; | |
1981cb22 | 599 | Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer) |
679ecdee | 600 | Standard_Boolean myBackBufferRestored; |
601 | Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data | |
bf75be98 | 602 | Standard_Boolean myUseTransparency; |
603 | Standard_Boolean myUseZBuffer; | |
604 | Standard_Boolean myUseDepthTest; | |
605 | Standard_Boolean myUseGLLight; | |
b7cd4ba7 | 606 | Standard_Boolean myIsCullingEnabled; //!< frustum culling flag |
2166f0fa | 607 | |
bf75be98 | 608 | protected: //! @name fields related to status |
609 | ||
4269bd1b | 610 | Handle(OpenGl_RenderFilter) myRenderFilter; |
bf75be98 | 611 | Handle(OpenGl_Texture) myTextureBound; //!< currently bound texture (managed by OpenGl_AspectFace and OpenGl_View environment texture) |
2166f0fa SK |
612 | const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied; |
613 | const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied; | |
614 | const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied; | |
615 | const OpenGl_AspectText *AspectText_set, *AspectText_applied; | |
616 | ||
617 | const OpenGl_TextParam *TextParam_set, *TextParam_applied; | |
618 | ||
619 | const OpenGl_Matrix* ViewMatrix_applied; | |
620 | const OpenGl_Matrix* StructureMatrix_applied; | |
621 | ||
3b1817a9 | 622 | OpenGl_Material myMatFront; //!< current front material state (cached to reduce GL context updates) |
623 | OpenGl_Material myMatBack; //!< current back material state | |
624 | OpenGl_Material myMatTmp; //!< temporary variable | |
625 | TelCullMode myCullingMode; //!< back face culling mode, applied from face aspect | |
0adbd30f | 626 | |
550f3b8b | 627 | OpenGl_Matrix myModelViewMatrix; //!< Model matrix with applied structure transformations |
0f8c0fb8 | 628 | |
550f3b8b | 629 | TEL_POFFSET_PARAM PolygonOffset_applied; //!< Currently applied polygon offset. |
2166f0fa | 630 | |
550f3b8b | 631 | OpenGl_AspectFace myAspectFaceHl; //!< Hiddenline aspect |
bf75be98 | 632 | |
633 | public: //! @name type definition | |
2166f0fa | 634 | |
bf75be98 | 635 | DEFINE_STANDARD_RTTI(OpenGl_Workspace) |
1c35b92f | 636 | DEFINE_STANDARD_ALLOC |
2166f0fa SK |
637 | |
638 | }; | |
639 | ||
bf75be98 | 640 | #endif // _OpenGl_Workspace_Header |