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 | |
c357e426 | 16 | #include <OpenGl_Workspace.hxx> |
5f8b738e | 17 | |
bf5f0ca2 | 18 | #include <OpenGl_Aspects.hxx> |
bf75be98 | 19 | #include <OpenGl_Context.hxx> |
679ecdee | 20 | #include <OpenGl_Element.hxx> |
a174a3c5 | 21 | #include <OpenGl_FrameBuffer.hxx> |
c357e426 | 22 | #include <OpenGl_GlCore15.hxx> |
23 | #include <OpenGl_SceneGeometry.hxx> | |
679ecdee | 24 | #include <OpenGl_Structure.hxx> |
25ef750e | 25 | #include <OpenGl_Sampler.hxx> |
8613985b | 26 | #include <OpenGl_ShaderManager.hxx> |
bf75be98 | 27 | #include <OpenGl_Texture.hxx> |
e276548b | 28 | #include <OpenGl_View.hxx> |
c357e426 | 29 | #include <OpenGl_Window.hxx> |
2166f0fa | 30 | |
bf75be98 | 31 | #include <Graphic3d_TextureParams.hxx> |
825aa485 | 32 | #include <Graphic3d_TransformUtils.hxx> |
2166f0fa | 33 | |
92efcf78 | 34 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient) |
92efcf78 | 35 | |
0adbd30f | 36 | // ======================================================================= |
37 | // function : Init | |
38 | // purpose : | |
39 | // ======================================================================= | |
ba00aab7 | 40 | void OpenGl_Material::Init (const OpenGl_Context& theCtx, |
941f6cae | 41 | const Graphic3d_MaterialAspect& theFront, |
42 | const Quantity_Color& theFrontColor, | |
43 | const Graphic3d_MaterialAspect& theBack, | |
44 | const Quantity_Color& theBackColor) | |
0adbd30f | 45 | { |
941f6cae | 46 | init (theCtx, theFront, theFrontColor, 0); |
47 | if (&theFront != &theBack) | |
48 | { | |
49 | init (theCtx, theBack, theBackColor, 1); | |
50 | } | |
51 | else | |
52 | { | |
53 | Common[1] = Common[0]; | |
54 | Pbr[1] = Pbr[0]; | |
55 | } | |
56 | } | |
67312b79 | 57 | |
941f6cae | 58 | // ======================================================================= |
59 | // function : init | |
60 | // purpose : | |
61 | // ======================================================================= | |
62 | void OpenGl_Material::init (const OpenGl_Context& theCtx, | |
63 | const Graphic3d_MaterialAspect& theMat, | |
64 | const Quantity_Color& theInteriorColor, | |
65 | const Standard_Integer theIndex) | |
66 | { | |
67 | OpenGl_MaterialCommon& aCommon = Common[theIndex]; | |
68 | OpenGl_MaterialPBR& aPbr = Pbr[theIndex]; | |
69 | aPbr.ChangeMetallic() = theMat.PBRMaterial().Metallic(); | |
70 | aPbr.ChangeRoughness() = theMat.PBRMaterial().NormalizedRoughness(); | |
71 | aPbr.EmissionIOR = Graphic3d_Vec4 (theMat.PBRMaterial().Emission(), theMat.PBRMaterial().IOR()); | |
b6472664 | 72 | |
61168418 | 73 | const OpenGl_Vec3& aSrcAmb = theMat.AmbientColor(); |
74 | const OpenGl_Vec3& aSrcDif = theMat.DiffuseColor(); | |
75 | const OpenGl_Vec3& aSrcSpe = theMat.SpecularColor(); | |
76 | const OpenGl_Vec3& aSrcEms = theMat.EmissiveColor(); | |
941f6cae | 77 | aCommon.SpecularShininess.SetValues (aSrcSpe,128.0f * theMat.Shininess()); // interior color is ignored for Specular |
61168418 | 78 | switch (theMat.MaterialType()) |
0adbd30f | 79 | { |
61168418 | 80 | case Graphic3d_MATERIAL_ASPECT: |
81 | { | |
941f6cae | 82 | aCommon.Diffuse .SetValues (aSrcDif * theInteriorColor, theMat.Alpha()); |
83 | aCommon.Ambient .SetValues (aSrcAmb * theInteriorColor, 1.0f); | |
84 | aCommon.Emission.SetValues (aSrcEms * theInteriorColor, 1.0f); | |
85 | aPbr .BaseColor.SetValues (theInteriorColor, theMat.Alpha()); | |
61168418 | 86 | break; |
87 | } | |
88 | case Graphic3d_MATERIAL_PHYSIC: | |
89 | { | |
941f6cae | 90 | aCommon.Diffuse .SetValues (aSrcDif, theMat.Alpha()); |
91 | aCommon.Ambient .SetValues (aSrcAmb, 1.0f); | |
92 | aCommon.Emission.SetValues (aSrcEms, 1.0f); | |
93 | aPbr.BaseColor = theMat.PBRMaterial().Color(); | |
61168418 | 94 | break; |
95 | } | |
0adbd30f | 96 | } |
ba00aab7 | 97 | |
941f6cae | 98 | aCommon.Diffuse = theCtx.Vec4FromQuantityColor (aCommon.Diffuse); |
99 | aCommon.Ambient = theCtx.Vec4FromQuantityColor (aCommon.Ambient); | |
100 | aCommon.SpecularShininess = theCtx.Vec4FromQuantityColor (aCommon.SpecularShininess); | |
101 | aCommon.Emission = theCtx.Vec4FromQuantityColor (aCommon.Emission); | |
0adbd30f | 102 | } |
103 | ||
2166f0fa SK |
104 | // ======================================================================= |
105 | // function : OpenGl_Workspace | |
106 | // purpose : | |
107 | // ======================================================================= | |
c357e426 | 108 | OpenGl_Workspace::OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow) |
1a0dfc1b | 109 | : myView (theView), |
c357e426 | 110 | myWindow (theWindow), |
111 | myGlContext (!theWindow.IsNull() ? theWindow->GetGlContext() : NULL), | |
eae454e3 | 112 | myUseZBuffer (Standard_True), |
113 | myUseDepthWrite (Standard_True), | |
2166f0fa | 114 | // |
1b661a81 | 115 | myNbSkippedTranspElems (0), |
116 | myRenderFilter (OpenGl_RenderFilter_Empty), | |
117 | // | |
bf5f0ca2 | 118 | myAspectsSet (&myDefaultAspects), |
f9ba5c4d | 119 | // |
a2af24d1 | 120 | myToAllowFaceCulling (false) |
2166f0fa | 121 | { |
c357e426 | 122 | if (!myGlContext.IsNull() && myGlContext->MakeCurrent()) |
73192b37 | 123 | { |
c357e426 | 124 | myGlContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1); |
2166f0fa | 125 | |
c357e426 | 126 | // General initialization of the context |
c357e426 | 127 | #if !defined(GL_ES_VERSION_2_0) |
43eddb47 | 128 | if (myGlContext->core11ffp != NULL) |
c357e426 | 129 | { |
dd1ae9df | 130 | // enable two-side lighting by default |
43eddb47 | 131 | myGlContext->core11ffp->glLightModeli ((GLenum )GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); |
132 | myGlContext->core11fwd->glHint (GL_POINT_SMOOTH_HINT, GL_FASTEST); | |
dd1ae9df | 133 | if (myGlContext->caps->ffpEnable) |
134 | { | |
43eddb47 | 135 | myGlContext->core11fwd->glHint (GL_FOG_HINT, GL_FASTEST); |
dd1ae9df | 136 | } |
c357e426 | 137 | } |
2166f0fa | 138 | |
43eddb47 | 139 | myGlContext->core11fwd->glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST); |
140 | myGlContext->core11fwd->glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST); | |
1202160b | 141 | if (myGlContext->Vendor() == "microsoft corporation" |
142 | && !myGlContext->IsGlGreaterEqual (1, 2)) | |
143 | { | |
144 | // this software implementation causes too slow rendering into GL_FRONT on modern Windows | |
145 | theView->SetImmediateModeDrawToFront (false); | |
146 | } | |
c357e426 | 147 | #endif |
73192b37 | 148 | } |
f8ae3605 | 149 | |
7fd4958d | 150 | myNoneCulling .Aspect()->SetFaceCulling (Graphic3d_TypeOfBackfacingModel_DoubleSided); |
b6472664 | 151 | myNoneCulling .Aspect()->SetDrawEdges (false); |
c40eb6b9 | 152 | myNoneCulling .Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque); |
153 | ||
7fd4958d | 154 | myFrontCulling.Aspect()->SetFaceCulling (Graphic3d_TypeOfBackfacingModel_BackCulled); |
b6472664 | 155 | myFrontCulling.Aspect()->SetDrawEdges (false); |
c40eb6b9 | 156 | myFrontCulling.Aspect()->SetAlphaMode (Graphic3d_AlphaMode_Opaque); |
2166f0fa SK |
157 | } |
158 | ||
2166f0fa SK |
159 | // ======================================================================= |
160 | // function : Activate | |
161 | // purpose : | |
162 | // ======================================================================= | |
163 | Standard_Boolean OpenGl_Workspace::Activate() | |
164 | { | |
c357e426 | 165 | if (myWindow.IsNull() || !myWindow->Activate()) |
166 | { | |
2166f0fa | 167 | return Standard_False; |
c357e426 | 168 | } |
2166f0fa | 169 | |
43eddb47 | 170 | if (myGlContext->core11ffp == NULL) |
92996979 | 171 | { |
172 | if (myGlContext->caps->ffpEnable) | |
173 | { | |
174 | #if defined(GL_ES_VERSION_2_0) | |
175 | Message::SendWarning ("Warning: FFP is unsupported by OpenGL ES"); | |
176 | #else | |
177 | Message::SendWarning ("Warning: FFP is unsupported by OpenGL Core Profile"); | |
178 | #endif | |
179 | myGlContext->caps->ffpEnable = false; | |
180 | } | |
181 | } | |
182 | ||
e70625d6 | 183 | if (myGlContext->caps->useZeroToOneDepth |
184 | && !myGlContext->arbClipControl) | |
185 | { | |
186 | Message::SendWarning ("Warning: glClipControl() requires OpenGL 4.5 or GL_ARB_clip_control extension"); | |
187 | myGlContext->caps->useZeroToOneDepth = false; | |
188 | } | |
189 | myView->Camera()->SetZeroToOneDepth (myGlContext->caps->useZeroToOneDepth); | |
190 | #if !defined(GL_ES_VERSION_2_0) | |
191 | if (myGlContext->arbClipControl) | |
192 | { | |
193 | myGlContext->Functions()->glClipControl (GL_LOWER_LEFT, myGlContext->caps->useZeroToOneDepth ? GL_ZERO_TO_ONE : GL_NEGATIVE_ONE_TO_ONE); | |
194 | } | |
195 | #endif | |
196 | ||
26395493 | 197 | ResetAppliedAspect(); |
198 | ||
8613985b | 199 | // reset state for safety |
200 | myGlContext->BindProgram (Handle(OpenGl_ShaderProgram)()); | |
201 | if (myGlContext->core20fwd != NULL) | |
202 | { | |
203 | myGlContext->core20fwd->glUseProgram (OpenGl_ShaderProgram::NO_PROGRAM); | |
204 | } | |
dd1ae9df | 205 | if (myGlContext->caps->ffpEnable) |
206 | { | |
207 | myGlContext->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)()); | |
208 | } | |
26395493 | 209 | return Standard_True; |
2166f0fa SK |
210 | } |
211 | ||
26395493 | 212 | //======================================================================= |
213 | //function : ResetAppliedAspect | |
214 | //purpose : Sets default values of GL parameters in accordance with default aspects | |
215 | //======================================================================= | |
216 | void OpenGl_Workspace::ResetAppliedAspect() | |
217 | { | |
4e1523ef | 218 | myGlContext->BindDefaultVao(); |
219 | ||
f838dac4 | 220 | myHighlightStyle.Nullify(); |
b6472664 | 221 | myToAllowFaceCulling = false; |
bf5f0ca2 | 222 | myAspectsSet = &myDefaultAspects; |
223 | myAspectsApplied.Nullify(); | |
8d1a539c | 224 | myGlContext->SetPolygonOffset (Graphic3d_PolygonOffset()); |
26395493 | 225 | |
bf5f0ca2 | 226 | ApplyAspects(); |
3f1675c9 | 227 | myGlContext->SetLineStipple(myDefaultAspects.Aspect()->LinePattern()); |
bf5f0ca2 | 228 | myGlContext->SetLineWidth (myDefaultAspects.Aspect()->LineWidth()); |
0c33a0bf | 229 | if (myGlContext->core15fwd != NULL) |
230 | { | |
231 | myGlContext->core15fwd->glActiveTexture (GL_TEXTURE0); | |
232 | } | |
26395493 | 233 | } |
bf75be98 | 234 | |
a6df1715 | 235 | // ======================================================================= |
236 | // function : SetDefaultPolygonOffset | |
237 | // purpose : | |
238 | // ======================================================================= | |
239 | Graphic3d_PolygonOffset OpenGl_Workspace::SetDefaultPolygonOffset (const Graphic3d_PolygonOffset& theOffset) | |
240 | { | |
bf5f0ca2 | 241 | Graphic3d_PolygonOffset aPrev = myDefaultAspects.Aspect()->PolygonOffset(); |
242 | myDefaultAspects.Aspect()->SetPolygonOffset (theOffset); | |
243 | if (myAspectsApplied == myDefaultAspects.Aspect() | |
244 | || myAspectsApplied.IsNull() | |
245 | || (myAspectsApplied->PolygonOffset().Mode & Aspect_POM_None) == Aspect_POM_None) | |
a6df1715 | 246 | { |
247 | myGlContext->SetPolygonOffset (theOffset); | |
248 | } | |
249 | return aPrev; | |
250 | } | |
251 | ||
38a0206f | 252 | // ======================================================================= |
bf5f0ca2 | 253 | // function : SetAspects |
c357e426 | 254 | // purpose : |
255 | // ======================================================================= | |
bf5f0ca2 | 256 | const OpenGl_Aspects* OpenGl_Workspace::SetAspects (const OpenGl_Aspects* theAspect) |
c357e426 | 257 | { |
bf5f0ca2 | 258 | const OpenGl_Aspects* aPrevAspects = myAspectsSet; |
259 | myAspectsSet = theAspect; | |
260 | return aPrevAspects; | |
c357e426 | 261 | } |
f978241f | 262 | |
c357e426 | 263 | // ======================================================================= |
bf5f0ca2 | 264 | // function : ApplyAspects |
c357e426 | 265 | // purpose : |
266 | // ======================================================================= | |
72f6dc61 | 267 | const OpenGl_Aspects* OpenGl_Workspace::ApplyAspects (bool theToBindTextures) |
c357e426 | 268 | { |
7fd4958d | 269 | bool toSuppressBackFaces = myView->BackfacingModel() == Graphic3d_TypeOfBackfacingModel_BackCulled; |
270 | if (myView->BackfacingModel() == Graphic3d_TypeOfBackfacingModel_Auto) | |
38a0206f | 271 | { |
7fd4958d | 272 | toSuppressBackFaces = myAspectsSet->Aspect()->FaceCulling() == Graphic3d_TypeOfBackfacingModel_BackCulled; |
273 | if (myAspectsSet->Aspect()->FaceCulling() == Graphic3d_TypeOfBackfacingModel_Auto | |
274 | && myToAllowFaceCulling) | |
f978241f | 275 | { |
7fd4958d | 276 | toSuppressBackFaces = true; |
bf5f0ca2 | 277 | if (myAspectsSet->Aspect()->InteriorStyle() == Aspect_IS_HATCH |
278 | || myAspectsSet->Aspect()->AlphaMode() == Graphic3d_AlphaMode_Blend | |
279 | || myAspectsSet->Aspect()->AlphaMode() == Graphic3d_AlphaMode_Mask | |
33425a46 | 280 | || myAspectsSet->Aspect()->AlphaMode() == Graphic3d_AlphaMode_MaskBlend |
bf5f0ca2 | 281 | || (myAspectsSet->Aspect()->AlphaMode() == Graphic3d_AlphaMode_BlendAuto |
282 | && myAspectsSet->Aspect()->FrontMaterial().Transparency() != 0.0f)) | |
c357e426 | 283 | { |
b6472664 | 284 | // disable culling in case of translucent shading aspect |
285 | toSuppressBackFaces = false; | |
f978241f | 286 | } |
f978241f | 287 | } |
f978241f | 288 | } |
7fd4958d | 289 | myGlContext->SetCullBackFaces (toSuppressBackFaces); |
f978241f | 290 | |
bf5f0ca2 | 291 | if (myAspectsSet->Aspect() == myAspectsApplied |
8613985b | 292 | && myHighlightStyle == myAspectFaceAppliedWithHL) |
a2e4f780 | 293 | { |
bf5f0ca2 | 294 | return myAspectsSet; |
a2e4f780 | 295 | } |
8613985b | 296 | myAspectFaceAppliedWithHL = myHighlightStyle; |
a2e4f780 | 297 | |
2a332745 | 298 | // Aspect_POM_None means: do not change current settings |
bf5f0ca2 | 299 | if ((myAspectsSet->Aspect()->PolygonOffset().Mode & Aspect_POM_None) != Aspect_POM_None) |
2a332745 | 300 | { |
bf5f0ca2 | 301 | myGlContext->SetPolygonOffset (myAspectsSet->Aspect()->PolygonOffset()); |
2a332745 | 302 | } |
303 | ||
bf5f0ca2 | 304 | const Aspect_InteriorStyle anIntstyle = myAspectsSet->Aspect()->InteriorStyle(); |
305 | if (myAspectsApplied.IsNull() | |
306 | || myAspectsApplied->InteriorStyle() != anIntstyle) | |
b86bb3df | 307 | { |
2a332745 | 308 | #if !defined(GL_ES_VERSION_2_0) |
309 | myGlContext->SetPolygonMode (anIntstyle == Aspect_IS_POINT ? GL_POINT : GL_FILL); | |
310 | myGlContext->SetPolygonHatchEnabled (anIntstyle == Aspect_IS_HATCH); | |
311 | #endif | |
91c60b57 | 312 | } |
e276548b | 313 | |
2a332745 | 314 | #if !defined(GL_ES_VERSION_2_0) |
c357e426 | 315 | if (anIntstyle == Aspect_IS_HATCH) |
91c60b57 | 316 | { |
bf5f0ca2 | 317 | myGlContext->SetPolygonHatchStyle (myAspectsSet->Aspect()->HatchStyle()); |
c357e426 | 318 | } |
319 | #endif | |
38a0206f | 320 | |
8613985b | 321 | // Case of hidden line |
2a332745 | 322 | if (anIntstyle == Aspect_IS_HIDDENLINE) |
8613985b | 323 | { |
324 | // copy all values including line edge aspect | |
bf5f0ca2 | 325 | *myAspectFaceHl.Aspect() = *myAspectsSet->Aspect(); |
dc89236f | 326 | myAspectFaceHl.Aspect()->SetShadingModel (Graphic3d_TOSM_UNLIT); |
8613985b | 327 | myAspectFaceHl.Aspect()->SetInteriorColor (myView->BackgroundColor().GetRGB()); |
2a332745 | 328 | myAspectFaceHl.Aspect()->SetDistinguish (false); |
dc89236f | 329 | myAspectFaceHl.SetNoLighting(); |
bf5f0ca2 | 330 | myAspectsSet = &myAspectFaceHl; |
8613985b | 331 | } |
332 | else | |
a174a3c5 | 333 | { |
bf5f0ca2 | 334 | myGlContext->SetShadingMaterial (myAspectsSet, myHighlightStyle); |
c357e426 | 335 | } |
62e1beed | 336 | |
72f6dc61 | 337 | if (theToBindTextures) |
c357e426 | 338 | { |
72f6dc61 | 339 | const Handle(OpenGl_TextureSet)& aTextureSet = TextureSet(); |
340 | myGlContext->BindTextures (aTextureSet, Handle(OpenGl_ShaderProgram)()); | |
a174a3c5 | 341 | } |
342 | ||
114db5a5 | 343 | if ((myView->ShadingModel() == Graphic3d_TOSM_PBR |
344 | || myView->ShadingModel() == Graphic3d_TOSM_PBR_FACET) | |
67312b79 | 345 | && !myView->myPBREnvironment.IsNull() |
346 | && myView->myPBREnvironment->IsNeededToBeBound()) | |
347 | { | |
348 | myView->myPBREnvironment->Bind (myGlContext); | |
349 | } | |
350 | ||
bf5f0ca2 | 351 | myAspectsApplied = myAspectsSet->Aspect(); |
352 | return myAspectsSet; | |
679ecdee | 353 | } |
354 | ||
355 | // ======================================================================= | |
c357e426 | 356 | // function : Width |
679ecdee | 357 | // purpose : |
358 | // ======================================================================= | |
c357e426 | 359 | Standard_Integer OpenGl_Workspace::Width() const |
679ecdee | 360 | { |
c357e426 | 361 | return !myView->GlWindow().IsNull() ? myView->GlWindow()->Width() : 0; |
362 | } | |
679ecdee | 363 | |
c357e426 | 364 | // ======================================================================= |
365 | // function : Height | |
366 | // purpose : | |
367 | // ======================================================================= | |
368 | Standard_Integer OpenGl_Workspace::Height() const | |
369 | { | |
370 | return !myView->GlWindow().IsNull() ? myView->GlWindow()->Height() : 0; | |
371 | } | |
679ecdee | 372 | |
679ecdee | 373 | // ======================================================================= |
c357e426 | 374 | // function : FBOCreate |
679ecdee | 375 | // purpose : |
376 | // ======================================================================= | |
b128c892 | 377 | Handle(OpenGl_FrameBuffer) OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth, |
378 | const Standard_Integer theHeight) | |
679ecdee | 379 | { |
c357e426 | 380 | // activate OpenGL context |
381 | if (!Activate()) | |
b128c892 | 382 | return Handle(OpenGl_FrameBuffer)(); |
c357e426 | 383 | |
384 | // create the FBO | |
385 | const Handle(OpenGl_Context)& aCtx = GetGlContext(); | |
72f6dc61 | 386 | aCtx->BindTextures (Handle(OpenGl_TextureSet)(), Handle(OpenGl_ShaderProgram)()); |
b128c892 | 387 | Handle(OpenGl_FrameBuffer) aFrameBuffer = new OpenGl_FrameBuffer(); |
1220d98e | 388 | if (!aFrameBuffer->Init (aCtx, Graphic3d_Vec2i (theWidth, theHeight), GL_SRGB8_ALPHA8, GL_DEPTH24_STENCIL8, 0)) |
679ecdee | 389 | { |
c357e426 | 390 | aFrameBuffer->Release (aCtx.operator->()); |
b128c892 | 391 | return Handle(OpenGl_FrameBuffer)(); |
679ecdee | 392 | } |
b128c892 | 393 | return aFrameBuffer; |
679ecdee | 394 | } |
395 | ||
396 | // ======================================================================= | |
c357e426 | 397 | // function : FBORelease |
679ecdee | 398 | // purpose : |
399 | // ======================================================================= | |
b128c892 | 400 | void OpenGl_Workspace::FBORelease (Handle(OpenGl_FrameBuffer)& theFbo) |
679ecdee | 401 | { |
c357e426 | 402 | // activate OpenGL context |
403 | if (!Activate() | |
b128c892 | 404 | || theFbo.IsNull()) |
62e1beed | 405 | { |
62e1beed | 406 | return; |
407 | } | |
c357e426 | 408 | |
b128c892 | 409 | theFbo->Release (GetGlContext().operator->()); |
410 | theFbo.Nullify(); | |
c357e426 | 411 | } |
62e1beed | 412 | |
f9f740d6 | 413 | // ======================================================================= |
414 | // function : BufferDump | |
415 | // purpose : | |
416 | // ======================================================================= | |
417 | Standard_Boolean OpenGl_Workspace::BufferDump (const Handle(OpenGl_FrameBuffer)& theFbo, | |
418 | Image_PixMap& theImage, | |
419 | const Graphic3d_BufferType& theBufferType) | |
c357e426 | 420 | { |
6cde53c4 | 421 | return !theImage.IsEmpty() |
422 | && Activate() | |
423 | && OpenGl_FrameBuffer::BufferDump (GetGlContext(), theFbo, theImage, theBufferType); | |
679ecdee | 424 | } |
91c60b57 | 425 | |
91c60b57 | 426 | // ======================================================================= |
a1073ae2 | 427 | // function : ShouldRender |
91c60b57 | 428 | // purpose : |
429 | // ======================================================================= | |
4552cb85 | 430 | bool OpenGl_Workspace::ShouldRender (const OpenGl_Element* theElement, |
431 | const OpenGl_Group* theGroup) | |
91c60b57 | 432 | { |
1b661a81 | 433 | // render only non-raytracable elements when RayTracing is enabled |
434 | if ((myRenderFilter & OpenGl_RenderFilter_NonRaytraceableOnly) != 0) | |
435 | { | |
4552cb85 | 436 | if (!theGroup->HasPersistence() && OpenGl_Raytrace::IsRaytracedElement (theElement)) |
1b661a81 | 437 | { |
438 | return false; | |
439 | } | |
440 | } | |
441 | else if ((myRenderFilter & OpenGl_RenderFilter_FillModeOnly) != 0) | |
442 | { | |
443 | if (!theElement->IsFillDrawMode()) | |
444 | { | |
445 | return false; | |
446 | } | |
447 | } | |
448 | ||
449 | // handle opaque/transparency render passes | |
450 | if ((myRenderFilter & OpenGl_RenderFilter_OpaqueOnly) != 0) | |
451 | { | |
452 | if (!theElement->IsFillDrawMode()) | |
453 | { | |
454 | return true; | |
455 | } | |
456 | ||
bf5f0ca2 | 457 | if (OpenGl_Context::CheckIsTransparent (myAspectsSet, myHighlightStyle)) |
1b661a81 | 458 | { |
459 | ++myNbSkippedTranspElems; | |
460 | return false; | |
461 | } | |
462 | } | |
463 | else if ((myRenderFilter & OpenGl_RenderFilter_TransparentOnly) != 0) | |
91c60b57 | 464 | { |
1b661a81 | 465 | if (!theElement->IsFillDrawMode()) |
466 | { | |
bf5f0ca2 | 467 | if (dynamic_cast<const OpenGl_Aspects*> (theElement) == NULL) |
1b661a81 | 468 | { |
469 | return false; | |
470 | } | |
471 | } | |
bf5f0ca2 | 472 | else if (!OpenGl_Context::CheckIsTransparent (myAspectsSet, myHighlightStyle)) |
1b661a81 | 473 | { |
474 | return false; | |
475 | } | |
91c60b57 | 476 | } |
1b661a81 | 477 | return true; |
91c60b57 | 478 | } |
bc73b006 | 479 | |
480 | // ======================================================================= | |
481 | // function : DumpJson | |
482 | // purpose : | |
483 | // ======================================================================= | |
484 | void OpenGl_Workspace::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const | |
485 | { | |
486 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) | |
487 | ||
488 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUseZBuffer) | |
489 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUseDepthWrite) | |
490 | ||
491 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myNoneCulling) | |
492 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myFrontCulling) | |
493 | ||
494 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myNbSkippedTranspElems) | |
495 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myRenderFilter) | |
496 | ||
497 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myDefaultAspects) | |
498 | ||
499 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myAspectsSet) | |
500 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myAspectsApplied.get()) | |
501 | ||
502 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToAllowFaceCulling) | |
503 | ||
504 | OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myAspectFaceHl) | |
505 | } |