From: apl Date: Thu, 24 Oct 2013 08:53:42 +0000 (+0400) Subject: 0024228: TKOpenGL - destroy GL context at view close X-Git-Tag: V6_7_0_beta~51 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=fd4a696350b967b3b9fa344cc01e7d4e6de1e081 0024228: TKOpenGL - destroy GL context at view close - OpenGl_Display - release GL resources correctly on closing views - OpenGl_AspectFace, OpenGl_AspectText, OpenGl_AspectLine, OpenGl_AspectMarker - initialize OpenGl resources on demand, when context is available. - Graphic3d_TextureRoot - use const modifier for GetId method to avoid asynchronous resource state at OpenGl. - Do not call OpenGL functions if no active GL context has been left - Reset thread's context before deletion for Mesa WNT --- diff --git a/src/Graphic3d/Graphic3d_TextureRoot.cdl b/src/Graphic3d/Graphic3d_TextureRoot.cdl index c43548c39f..b812c4d382 100755 --- a/src/Graphic3d/Graphic3d_TextureRoot.cdl +++ b/src/Graphic3d/Graphic3d_TextureRoot.cdl @@ -82,6 +82,7 @@ is -- for each instance of Graphic3d_AspectFillArea3d where texture will be used. -- . -- @return texture identifier. + ---C++: return const & GetImage (me) returns PixMap_Handle from Image is virtual; diff --git a/src/Graphic3d/Graphic3d_TextureRoot.cxx b/src/Graphic3d/Graphic3d_TextureRoot.cxx index 4f1795ab5f..a599e099e0 100755 --- a/src/Graphic3d/Graphic3d_TextureRoot.cxx +++ b/src/Graphic3d/Graphic3d_TextureRoot.cxx @@ -108,7 +108,7 @@ void Graphic3d_TextureRoot::Destroy() const // function : GetId // purpose : // ======================================================================= -TCollection_AsciiString Graphic3d_TextureRoot::GetId() const +const TCollection_AsciiString& Graphic3d_TextureRoot::GetId() const { return myTexId; } diff --git a/src/OpenGl/OpenGl_AspectFace.cxx b/src/OpenGl/OpenGl_AspectFace.cxx index 428620d182..41f72e217e 100644 --- a/src/OpenGl/OpenGl_AspectFace.cxx +++ b/src/OpenGl/OpenGl_AspectFace.cxx @@ -47,6 +47,7 @@ namespace }; static TEL_POFFSET_PARAM THE_DEFAULT_POFFSET = { Aspect_POM_Fill, 1.0F, 0.0F }; + static const TCollection_AsciiString THE_EMPTY_KEY; }; @@ -121,153 +122,119 @@ void OpenGl_AspectFace::convertMaterial (const CALL_DEF_MATERIAL& theMat, // purpose : // ======================================================================= OpenGl_AspectFace::OpenGl_AspectFace() -: InteriorStyle (Aspect_IS_SOLID), - Edge (Aspect_IS_SOLID), - Hatch (TOn), - DistinguishingMode (TEL_HS_SOLID), - CullingMode (TelCullNone), - doTextureMap (0) -{ - IntFront = THE_DEFAULT_MATERIAL; - IntBack = THE_DEFAULT_MATERIAL; - PolygonOffset = THE_DEFAULT_POFFSET; -} +: myInteriorStyle (Aspect_IS_SOLID), + myEdge (TOff), + myHatch (TEL_HS_SOLID), + myDistinguishingMode (TOff), + myCullingMode (TelCullNone), + myIntFront (THE_DEFAULT_MATERIAL), + myIntBack (THE_DEFAULT_MATERIAL), + myPolygonOffset (THE_DEFAULT_POFFSET), + myDoTextureMap (false), + myTextureMap(), + myIsTextureInit (Standard_False), + myTextureRes(), + myTextureId() +{} // ======================================================================= -// function : Init +// function : SetAspect // purpose : // ======================================================================= -void OpenGl_AspectFace::Init (const Handle(OpenGl_Context)& theContext, - const CALL_DEF_CONTEXTFILLAREA& theAspect) +void OpenGl_AspectFace::SetAspect (const CALL_DEF_CONTEXTFILLAREA& theAspect) { - InteriorStyle = (Aspect_InteriorStyle )theAspect.Style; - Edge = theAspect.Edge ? TOn : TOff; + myInteriorStyle = (Aspect_InteriorStyle )theAspect.Style; + myEdge = theAspect.Edge ? TOn : TOff; //TelInteriorStyleIndex switch (theAspect.Hatch) { case 0: /* Aspect_HS_HORIZONTAL */ - Hatch = TEL_HS_HORIZONTAL; + myHatch = TEL_HS_HORIZONTAL; break; case 1: /* Aspect_HS_HORIZONTAL_WIDE */ - Hatch = TEL_HS_HORIZONTAL_SPARSE; + myHatch = TEL_HS_HORIZONTAL_SPARSE; break; case 2: /* Aspect_HS_VERTICAL */ - Hatch = TEL_HS_VERTICAL; + myHatch = TEL_HS_VERTICAL; break; case 3: /* Aspect_HS_VERTICAL_WIDE */ - Hatch = TEL_HS_VERTICAL_SPARSE; + myHatch = TEL_HS_VERTICAL_SPARSE; break; case 4: /* Aspect_HS_DIAGONAL_45 */ - Hatch = TEL_HS_DIAG_45; + myHatch = TEL_HS_DIAG_45; break; case 5: /* Aspect_HS_DIAGONAL_45_WIDE */ - Hatch = TEL_HS_DIAG_45_SPARSE; + myHatch = TEL_HS_DIAG_45_SPARSE; break; case 6: /* Aspect_HS_DIAGONAL_135 */ - Hatch = TEL_HS_DIAG_135; + myHatch = TEL_HS_DIAG_135; break; case 7: /* Aspect_HS_DIAGONAL_135_WIDE */ - Hatch = TEL_HS_DIAG_135_SPARSE; + myHatch = TEL_HS_DIAG_135_SPARSE; break; case 8: /* Aspect_HS_GRID */ - Hatch = TEL_HS_GRID; + myHatch = TEL_HS_GRID; break; case 9: /* Aspect_HS_GRID_WIDE */ - Hatch = TEL_HS_GRID_SPARSE; + myHatch = TEL_HS_GRID_SPARSE; break; case 10: /* Aspect_HS_GRID_DIAGONAL */ - Hatch = TEL_HS_CROSS; + myHatch = TEL_HS_CROSS; break; case 11: /* Aspect_HS_GRID_DIAGONAL_WIDE */ - Hatch = TEL_HS_CROSS_SPARSE; + myHatch = TEL_HS_CROSS_SPARSE; break; default: - Hatch = 0; + myHatch = 0; break; } - DistinguishingMode = theAspect.Distinguish ? TOn : TOff; - CullingMode = theAspect.BackFace ? TelCullBack : TelCullNone; + myDistinguishingMode = theAspect.Distinguish ? TOn : TOff; + myCullingMode = theAspect.BackFace ? TelCullBack : TelCullNone; - convertMaterial (theAspect.Front, IntFront); - convertMaterial (theAspect.Back, IntBack); + convertMaterial (theAspect.Front, myIntFront); + convertMaterial (theAspect.Back, myIntBack); //TelInteriorColour - IntFront.matcol.rgb[0] = (float )theAspect.IntColor.r; - IntFront.matcol.rgb[1] = (float )theAspect.IntColor.g; - IntFront.matcol.rgb[2] = (float )theAspect.IntColor.b; - IntFront.matcol.rgb[3] = 1.0f; + myIntFront.matcol.rgb[0] = (float )theAspect.IntColor.r; + myIntFront.matcol.rgb[1] = (float )theAspect.IntColor.g; + myIntFront.matcol.rgb[2] = (float )theAspect.IntColor.b; + myIntFront.matcol.rgb[3] = 1.0f; //TelBackInteriorColour - IntBack.matcol.rgb[0] = (float )theAspect.BackIntColor.r; - IntBack.matcol.rgb[1] = (float )theAspect.BackIntColor.g; - IntBack.matcol.rgb[2] = (float )theAspect.BackIntColor.b; - IntBack.matcol.rgb[3] = 1.0f; - - // setup texture - doTextureMap = theAspect.Texture.doTextureMap; - const Handle(Graphic3d_TextureMap)& aNewTexture = theAspect.Texture.TextureMap; - TCollection_AsciiString aNewKey = aNewTexture.IsNull() ? TCollection_AsciiString() : aNewTexture->GetId(); - TextureParams = aNewTexture.IsNull() ? NULL : aNewTexture->GetParams(); - if (aNewKey.IsEmpty() - || myTextureId != aNewKey) - { - if (!TextureRes.IsNull()) - { - if (myTextureId.IsEmpty()) - { - theContext->DelayedRelease (TextureRes); - TextureRes.Nullify(); - } - else - { - TextureRes.Nullify(); // we need nullify all handles before ReleaseResource() call - theContext->ReleaseResource (myTextureId); - } - } - myTextureId = aNewKey; + myIntBack.matcol.rgb[0] = (float )theAspect.BackIntColor.r; + myIntBack.matcol.rgb[1] = (float )theAspect.BackIntColor.g; + myIntBack.matcol.rgb[2] = (float )theAspect.BackIntColor.b; + myIntBack.matcol.rgb[3] = 1.0f; - if (!aNewTexture.IsNull()) - { - if (aNewKey.IsEmpty() || !theContext->GetResource (aNewKey, TextureRes)) - { - TextureRes = new OpenGl_Texture (TextureParams); - Handle(Image_PixMap) anImage = aNewTexture->GetImage(); - if (!anImage.IsNull()) - { - TextureRes->Init (theContext, *anImage.operator->(), aNewTexture->Type()); - } - if (!aNewKey.IsEmpty()) - { - theContext->ShareResource (aNewKey, TextureRes); - } - } - } - } + myDoTextureMap = (theAspect.Texture.doTextureMap != 0); + myTextureMap = theAspect.Texture.TextureMap; + + const TCollection_AsciiString& aNewKey = myTextureMap.IsNull() ? THE_EMPTY_KEY : myTextureMap->GetId(); + myIsTextureInit = (!aNewKey.IsEmpty() && myTextureId == aNewKey); //TelPolygonOffset - PolygonOffset.mode = (Aspect_PolygonOffsetMode )theAspect.PolygonOffsetMode; - PolygonOffset.factor = theAspect.PolygonOffsetFactor; - PolygonOffset.units = theAspect.PolygonOffsetUnits; - - CALL_DEF_CONTEXTLINE anEdgeContext; - anEdgeContext.Color.r = (float )theAspect.EdgeColor.r; - anEdgeContext.Color.g = (float )theAspect.EdgeColor.g; - anEdgeContext.Color.b = (float )theAspect.EdgeColor.b; - anEdgeContext.LineType = (Aspect_TypeOfLine )theAspect.LineType; - anEdgeContext.Width = (float )theAspect.Width; - myAspectEdge.SetContext (anEdgeContext); + myPolygonOffset.mode = (Aspect_PolygonOffsetMode )theAspect.PolygonOffsetMode; + myPolygonOffset.factor = theAspect.PolygonOffsetFactor; + myPolygonOffset.units = theAspect.PolygonOffsetUnits; + + CALL_DEF_CONTEXTLINE anEdgeAspect; + anEdgeAspect.Color.r = (float )theAspect.EdgeColor.r; + anEdgeAspect.Color.g = (float )theAspect.EdgeColor.g; + anEdgeAspect.Color.b = (float )theAspect.EdgeColor.b; + anEdgeAspect.LineType = (Aspect_TypeOfLine )theAspect.LineType; + anEdgeAspect.Width = (float )theAspect.Width; + myAspectEdge.SetAspect (anEdgeAspect); } // ======================================================================= -// function : Init +// function : SetAspect // purpose : // ======================================================================= -void OpenGl_AspectFace::Init (const Handle(OpenGl_Context)& theContext, - const Handle(Graphic3d_AspectFillArea3d)& theAspect) +void OpenGl_AspectFace::SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect) { - CALL_DEF_CONTEXTFILLAREA aCAspect; + CALL_DEF_CONTEXTFILLAREA aFaceContext; Standard_Real aWidth; Quantity_Color aBackIntColor; Quantity_Color aEdgeColor; @@ -279,124 +246,124 @@ void OpenGl_AspectFace::Init (const Handle(OpenGl_Context)& theContext, theAspect->Values (aIntStyle, aIntColor, aBackIntColor, aEdgeColor, aLType, aWidth); aIntColor.Values (aColor.r(), aColor.g(), aColor.b(), Quantity_TOC_RGB); - aCAspect.Style = int (aIntStyle); - aCAspect.IntColor.r = float (aColor.r()); - aCAspect.IntColor.g = float (aColor.g()); - aCAspect.IntColor.b = float (aColor.b()); + aFaceContext.Style = int (aIntStyle); + aFaceContext.IntColor.r = float (aColor.r()); + aFaceContext.IntColor.g = float (aColor.g()); + aFaceContext.IntColor.b = float (aColor.b()); if (theAspect->Distinguish()) { aBackIntColor.Values (aColor.r(), aColor.g(), aColor.b(), Quantity_TOC_RGB); } - aCAspect.BackIntColor.r = float (aColor.r()); - aCAspect.BackIntColor.g = float (aColor.g()); - aCAspect.BackIntColor.b = float (aColor.b()); + aFaceContext.BackIntColor.r = float (aColor.r()); + aFaceContext.BackIntColor.g = float (aColor.g()); + aFaceContext.BackIntColor.b = float (aColor.b()); - aCAspect.Edge = theAspect->Edge () ? 1:0; + aFaceContext.Edge = theAspect->Edge () ? 1:0; aEdgeColor.Values (aColor.r(), aColor.g(), aColor.b(), Quantity_TOC_RGB); - aCAspect.EdgeColor.r = float (aColor.r()); - aCAspect.EdgeColor.g = float (aColor.g()); - aCAspect.EdgeColor.b = float (aColor.b()); - aCAspect.LineType = int (aLType); - aCAspect.Width = float (aWidth); - aCAspect.Hatch = int (theAspect->HatchStyle ()); + aFaceContext.EdgeColor.r = float (aColor.r()); + aFaceContext.EdgeColor.g = float (aColor.g()); + aFaceContext.EdgeColor.b = float (aColor.b()); + aFaceContext.LineType = int (aLType); + aFaceContext.Width = float (aWidth); + aFaceContext.Hatch = int (theAspect->HatchStyle ()); - aCAspect.Distinguish = theAspect->Distinguish () ? 1:0; - aCAspect.BackFace = theAspect->BackFace () ? 1:0; + aFaceContext.Distinguish = theAspect->Distinguish () ? 1:0; + aFaceContext.BackFace = theAspect->BackFace () ? 1:0; - aCAspect.Back.Shininess = float ((theAspect->BackMaterial ()).Shininess ()); - aCAspect.Back.Ambient = float ((theAspect->BackMaterial ()).Ambient ()); - aCAspect.Back.Diffuse = float ((theAspect->BackMaterial ()).Diffuse ()); - aCAspect.Back.Specular = float ((theAspect->BackMaterial ()).Specular ()); - aCAspect.Back.Transparency = float ((theAspect->BackMaterial ()).Transparency ()); - aCAspect.Back.Emission = float ((theAspect->BackMaterial ()).Emissive ()); + aFaceContext.Back.Shininess = float ((theAspect->BackMaterial ()).Shininess ()); + aFaceContext.Back.Ambient = float ((theAspect->BackMaterial ()).Ambient ()); + aFaceContext.Back.Diffuse = float ((theAspect->BackMaterial ()).Diffuse ()); + aFaceContext.Back.Specular = float ((theAspect->BackMaterial ()).Specular ()); + aFaceContext.Back.Transparency = float ((theAspect->BackMaterial ()).Transparency ()); + aFaceContext.Back.Emission = float ((theAspect->BackMaterial ()).Emissive ()); // Reflection mode - aCAspect.Back.IsAmbient = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); - aCAspect.Back.IsDiffuse = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); - aCAspect.Back.IsSpecular = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); - aCAspect.Back.IsEmission = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); + aFaceContext.Back.IsAmbient = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); + aFaceContext.Back.IsDiffuse = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); + aFaceContext.Back.IsSpecular = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); + aFaceContext.Back.IsEmission = ((theAspect->BackMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); // Material type const Graphic3d_MaterialAspect aBackMat = theAspect->BackMaterial (); Standard_Boolean isBackPhys = aBackMat.MaterialType (Graphic3d_MATERIAL_PHYSIC); - aCAspect.Back.IsPhysic = (isBackPhys ? 1 : 0 ); + aFaceContext.Back.IsPhysic = (isBackPhys ? 1 : 0 ); // Specular Color - aCAspect.Back.ColorSpec.r = float (((theAspect->BackMaterial ()).SpecularColor ()).Red ()); - aCAspect.Back.ColorSpec.g = float (((theAspect->BackMaterial ()).SpecularColor ()).Green ()); - aCAspect.Back.ColorSpec.b = float (((theAspect->BackMaterial ()).SpecularColor ()).Blue ()); + aFaceContext.Back.ColorSpec.r = float (((theAspect->BackMaterial ()).SpecularColor ()).Red ()); + aFaceContext.Back.ColorSpec.g = float (((theAspect->BackMaterial ()).SpecularColor ()).Green ()); + aFaceContext.Back.ColorSpec.b = float (((theAspect->BackMaterial ()).SpecularColor ()).Blue ()); // Ambient color - aCAspect.Back.ColorAmb.r = float (((theAspect->BackMaterial ()).AmbientColor ()).Red ()); - aCAspect.Back.ColorAmb.g = float (((theAspect->BackMaterial ()).AmbientColor ()).Green ()); - aCAspect.Back.ColorAmb.b = float (((theAspect->BackMaterial ()).AmbientColor ()).Blue ()); + aFaceContext.Back.ColorAmb.r = float (((theAspect->BackMaterial ()).AmbientColor ()).Red ()); + aFaceContext.Back.ColorAmb.g = float (((theAspect->BackMaterial ()).AmbientColor ()).Green ()); + aFaceContext.Back.ColorAmb.b = float (((theAspect->BackMaterial ()).AmbientColor ()).Blue ()); // Diffuse color - aCAspect.Back.ColorDif.r = float (((theAspect->BackMaterial ()).DiffuseColor ()).Red ()); - aCAspect.Back.ColorDif.g = float (((theAspect->BackMaterial ()).DiffuseColor ()).Green ()); - aCAspect.Back.ColorDif.b = float (((theAspect->BackMaterial ()).DiffuseColor ()).Blue ()); + aFaceContext.Back.ColorDif.r = float (((theAspect->BackMaterial ()).DiffuseColor ()).Red ()); + aFaceContext.Back.ColorDif.g = float (((theAspect->BackMaterial ()).DiffuseColor ()).Green ()); + aFaceContext.Back.ColorDif.b = float (((theAspect->BackMaterial ()).DiffuseColor ()).Blue ()); // Emissive color - aCAspect.Back.ColorEms.r = float (((theAspect->BackMaterial ()).EmissiveColor ()).Red ()); - aCAspect.Back.ColorEms.g = float (((theAspect->BackMaterial ()).EmissiveColor ()).Green ()); - aCAspect.Back.ColorEms.b = float (((theAspect->BackMaterial ()).EmissiveColor ()).Blue ()); + aFaceContext.Back.ColorEms.r = float (((theAspect->BackMaterial ()).EmissiveColor ()).Red ()); + aFaceContext.Back.ColorEms.g = float (((theAspect->BackMaterial ()).EmissiveColor ()).Green ()); + aFaceContext.Back.ColorEms.b = float (((theAspect->BackMaterial ()).EmissiveColor ()).Blue ()); - aCAspect.Back.EnvReflexion = float ((theAspect->BackMaterial ()).EnvReflexion()); + aFaceContext.Back.EnvReflexion = float ((theAspect->BackMaterial ()).EnvReflexion()); - aCAspect.Front.Shininess = float ((theAspect->FrontMaterial ()).Shininess ()); - aCAspect.Front.Ambient = float ((theAspect->FrontMaterial ()).Ambient ()); - aCAspect.Front.Diffuse = float ((theAspect->FrontMaterial ()).Diffuse ()); - aCAspect.Front.Specular = float ((theAspect->FrontMaterial ()).Specular ()); - aCAspect.Front.Transparency = float ((theAspect->FrontMaterial ()).Transparency ()); - aCAspect.Front.Emission = float ((theAspect->FrontMaterial ()).Emissive ()); + aFaceContext.Front.Shininess = float ((theAspect->FrontMaterial ()).Shininess ()); + aFaceContext.Front.Ambient = float ((theAspect->FrontMaterial ()).Ambient ()); + aFaceContext.Front.Diffuse = float ((theAspect->FrontMaterial ()).Diffuse ()); + aFaceContext.Front.Specular = float ((theAspect->FrontMaterial ()).Specular ()); + aFaceContext.Front.Transparency = float ((theAspect->FrontMaterial ()).Transparency ()); + aFaceContext.Front.Emission = float ((theAspect->FrontMaterial ()).Emissive ()); // Reflection mode - aCAspect.Front.IsAmbient = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0); - aCAspect.Front.IsDiffuse = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0); - aCAspect.Front.IsSpecular = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0); - aCAspect.Front.IsEmission = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0); + aFaceContext.Front.IsAmbient = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0); + aFaceContext.Front.IsDiffuse = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0); + aFaceContext.Front.IsSpecular = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0); + aFaceContext.Front.IsEmission = ((theAspect->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0); - // Materail type + // Material type const Graphic3d_MaterialAspect aFrontMat = theAspect->FrontMaterial (); Standard_Boolean isFrontPhys = aFrontMat.MaterialType (Graphic3d_MATERIAL_PHYSIC); - aCAspect.Front.IsPhysic = (isFrontPhys ? 1 : 0 ); + aFaceContext.Front.IsPhysic = (isFrontPhys ? 1 : 0 ); // Specular Color - aCAspect.Front.ColorSpec.r = float (((theAspect->FrontMaterial ()).SpecularColor ()).Red ()); - aCAspect.Front.ColorSpec.g = float (((theAspect->FrontMaterial ()).SpecularColor ()).Green ()); - aCAspect.Front.ColorSpec.b = float (((theAspect->FrontMaterial ()).SpecularColor ()).Blue ()); + aFaceContext.Front.ColorSpec.r = float (((theAspect->FrontMaterial ()).SpecularColor ()).Red ()); + aFaceContext.Front.ColorSpec.g = float (((theAspect->FrontMaterial ()).SpecularColor ()).Green ()); + aFaceContext.Front.ColorSpec.b = float (((theAspect->FrontMaterial ()).SpecularColor ()).Blue ()); // Ambient color - aCAspect.Front.ColorAmb.r = float (((theAspect->FrontMaterial ()).AmbientColor ()).Red ()); - aCAspect.Front.ColorAmb.g = float (((theAspect->FrontMaterial ()).AmbientColor ()).Green ()); - aCAspect.Front.ColorAmb.b = float (((theAspect->FrontMaterial ()).AmbientColor ()).Blue ()); + aFaceContext.Front.ColorAmb.r = float (((theAspect->FrontMaterial ()).AmbientColor ()).Red ()); + aFaceContext.Front.ColorAmb.g = float (((theAspect->FrontMaterial ()).AmbientColor ()).Green ()); + aFaceContext.Front.ColorAmb.b = float (((theAspect->FrontMaterial ()).AmbientColor ()).Blue ()); // Diffuse color - aCAspect.Front.ColorDif.r = float (((theAspect->FrontMaterial ()).DiffuseColor ()).Red ()); - aCAspect.Front.ColorDif.g = float (((theAspect->FrontMaterial ()).DiffuseColor ()).Green ()); - aCAspect.Front.ColorDif.b = float (((theAspect->FrontMaterial ()).DiffuseColor ()).Blue ()); + aFaceContext.Front.ColorDif.r = float (((theAspect->FrontMaterial ()).DiffuseColor ()).Red ()); + aFaceContext.Front.ColorDif.g = float (((theAspect->FrontMaterial ()).DiffuseColor ()).Green ()); + aFaceContext.Front.ColorDif.b = float (((theAspect->FrontMaterial ()).DiffuseColor ()).Blue ()); // Emissive color - aCAspect.Front.ColorEms.r = float (((theAspect->FrontMaterial ()).EmissiveColor ()).Red ()); - aCAspect.Front.ColorEms.g = float (((theAspect->FrontMaterial ()).EmissiveColor ()).Green ()); - aCAspect.Front.ColorEms.b = float (((theAspect->FrontMaterial ()).EmissiveColor ()).Blue ()); + aFaceContext.Front.ColorEms.r = float (((theAspect->FrontMaterial ()).EmissiveColor ()).Red ()); + aFaceContext.Front.ColorEms.g = float (((theAspect->FrontMaterial ()).EmissiveColor ()).Green ()); + aFaceContext.Front.ColorEms.b = float (((theAspect->FrontMaterial ()).EmissiveColor ()).Blue ()); - aCAspect.Front.EnvReflexion = float ((theAspect->FrontMaterial ()).EnvReflexion()); - aCAspect.IsDef = 1; - aCAspect.Texture.TextureMap = theAspect->TextureMap(); - aCAspect.Texture.doTextureMap = theAspect->TextureMapState() ? 1 : 0; + aFaceContext.Front.EnvReflexion = float ((theAspect->FrontMaterial ()).EnvReflexion()); + aFaceContext.IsDef = 1; + aFaceContext.Texture.TextureMap = theAspect->TextureMap(); + aFaceContext.Texture.doTextureMap = theAspect->TextureMapState() ? 1 : 0; Standard_Integer aPolyMode; Standard_ShortReal aPolyFactor, aPolyUnits; theAspect->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits); - aCAspect.PolygonOffsetMode = aPolyMode; - aCAspect.PolygonOffsetFactor = (Standard_ShortReal)aPolyFactor; - aCAspect.PolygonOffsetUnits = (Standard_ShortReal)aPolyUnits; + aFaceContext.PolygonOffsetMode = aPolyMode; + aFaceContext.PolygonOffsetFactor = (Standard_ShortReal)aPolyFactor; + aFaceContext.PolygonOffsetUnits = (Standard_ShortReal)aPolyUnits; - Init (theContext, aCAspect); + SetAspect (aFaceContext); } // ======================================================================= @@ -414,21 +381,66 @@ void OpenGl_AspectFace::Render (const Handle(OpenGl_Workspace)& theWorkspace) co // ======================================================================= void OpenGl_AspectFace::Release (const Handle(OpenGl_Context)& theContext) { - if (!TextureRes.IsNull()) + if (!myTextureRes.IsNull()) { if (!theContext.IsNull()) { if (myTextureId.IsEmpty()) { - theContext->DelayedRelease (TextureRes); + theContext->DelayedRelease (myTextureRes); } else { - TextureRes.Nullify(); // we need nullify all handles before ReleaseResource() call + myTextureRes.Nullify(); // we need nullify all handles before ReleaseResource() call theContext->ReleaseResource (myTextureId); } } - TextureRes.Nullify(); + myTextureRes.Nullify(); } myTextureId.Clear(); } + +// ======================================================================= +// function : buildTexure +// purpose : +// ======================================================================= +void OpenGl_AspectFace::buildTexture (const Handle(OpenGl_Workspace)& theWorkspace) const +{ + const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); + + const TCollection_AsciiString& aNewKey = myTextureMap.IsNull() ? THE_EMPTY_KEY : myTextureMap->GetId(); + if (aNewKey.IsEmpty() || myTextureId != aNewKey) + { + if (!myTextureRes.IsNull()) + { + if (myTextureId.IsEmpty()) + { + aContext->DelayedRelease (myTextureRes); + myTextureRes.Nullify(); + } + else + { + myTextureRes.Nullify(); // we need nullify all handles before ReleaseResource() call + aContext->ReleaseResource (myTextureId); + } + } + myTextureId = aNewKey; + + if (!myTextureMap.IsNull()) + { + if (aNewKey.IsEmpty() || !aContext->GetResource (aNewKey, myTextureRes)) + { + myTextureRes = new OpenGl_Texture (myTextureMap->GetParams()); + Handle(Image_PixMap) anImage = myTextureMap->GetImage(); + if (!anImage.IsNull()) + { + myTextureRes->Init (aContext, *anImage.operator->(), myTextureMap->Type()); + } + if (!aNewKey.IsEmpty()) + { + aContext->ShareResource (aNewKey, myTextureRes); + } + } + } + } +} diff --git a/src/OpenGl/OpenGl_AspectFace.hxx b/src/OpenGl/OpenGl_AspectFace.hxx index 198c08ec91..9174122f46 100644 --- a/src/OpenGl/OpenGl_AspectFace.hxx +++ b/src/OpenGl/OpenGl_AspectFace.hxx @@ -23,11 +23,14 @@ #include #include #include -#include + #include #include #include + +#include #include +#include #define OPENGL_AMBIENT_MASK (1<<0) #define OPENGL_DIFFUSE_MASK (1<<1) @@ -54,43 +57,178 @@ public: OpenGl_AspectFace(); - void Init (const Handle(OpenGl_Context)& theContext, - const CALL_DEF_CONTEXTFILLAREA& theAspect); - - void Init (const Handle(OpenGl_Context)& theContext, - const Handle(Graphic3d_AspectFillArea3d)& theAspect); - - void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge) { myAspectEdge = *theAspectEdge; } - - const OpenGl_AspectLine* AspectEdge() const { return &myAspectEdge; } + //! Copy parameters + void SetAspect (const CALL_DEF_CONTEXTFILLAREA& theAspect); + void SetAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect); + + //! Set edge aspect. + void SetAspectEdge (const OpenGl_AspectLine* theAspectEdge) + { + myAspectEdge = *theAspectEdge; + } + + //! @return edge aspect. + const OpenGl_AspectLine* AspectEdge() const + { + return &myAspectEdge; + } + + //! @return interior style + const Aspect_InteriorStyle InteriorStyle() const + { + return myInteriorStyle; + } + + Aspect_InteriorStyle& ChangeInteriorStyle() + { + return myInteriorStyle; + } + + //! @return edge on flag. + int Edge() const + { + return myEdge; + } + + //! @return edge on flag. + int& ChangeEdge() + { + return myEdge; + } + + //! @return hatch type. + int Hatch() const + { + return myHatch; + } + + //! @return hatch type variable. + int& ChangeHatch() + { + return myHatch; + } + + //! @return distinguishing mode. + int DistinguishingMode() const + { + return myDistinguishingMode; + } + + //! @return distinguishing mode. + int& ChangeDistinguishingMode() + { + return myDistinguishingMode; + } + + //! @return culling mode. + int CullingMode() const + { + return myCullingMode; + } + + //! @return culling mode. + int& ChangeCullingMode() + { + return myCullingMode; + } + + //! @return front material properties. + const OPENGL_SURF_PROP& IntFront() const + { + return myIntFront; + } + + //! @return front material properties. + OPENGL_SURF_PROP& ChangeIntFront() + { + return myIntFront; + } + + //! @return back material properties. + const OPENGL_SURF_PROP& IntBack() const + { + return myIntBack; + } + + //! @return back material properties. + OPENGL_SURF_PROP& ChangeIntBack() + { + return myIntBack; + } + + //! @return polygon offset parameters. + const TEL_POFFSET_PARAM& PolygonOffset() const + { + return myPolygonOffset; + } + + //! @return polygon offset parameters. + TEL_POFFSET_PARAM& ChangePolygonOffset() + { + return myPolygonOffset; + } + + //! @return texture mapping flag. + bool DoTextureMap() const + { + return myDoTextureMap; + } + + //! @return texture mapping flag. + bool& ChangeDoTextureMap() + { + return myDoTextureMap; + } + + //! @return texture map. + const Handle(OpenGl_Texture)& TextureRes (const Handle(OpenGl_Workspace)& theWorkspace) const + { + if (!myIsTextureInit) + { + buildTexture (theWorkspace); + myIsTextureInit = Standard_True; + } + + return myTextureRes; + } + + //! @return texture mapping parameters. + const Handle(Graphic3d_TextureParams)& TextureParams() const + { + return myTextureMap->GetParams(); + } virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; virtual void Release (const Handle(OpenGl_Context)& theContext); -private: +protected: + void buildTexture (const Handle(OpenGl_Workspace)& theWorkspace) const; void convertMaterial (const CALL_DEF_MATERIAL& theMat, OPENGL_SURF_PROP& theSurf); -public: +protected: //! @name ordinary aspect properties + + Aspect_InteriorStyle myInteriorStyle; + int myEdge; + int myHatch; + int myDistinguishingMode; + int myCullingMode; + OPENGL_SURF_PROP myIntFront; + OPENGL_SURF_PROP myIntBack; + TEL_POFFSET_PARAM myPolygonOffset; + bool myDoTextureMap; + Handle(Graphic3d_TextureMap) myTextureMap; - Aspect_InteriorStyle InteriorStyle; - int Edge; - int Hatch; - int DistinguishingMode; - int CullingMode; - OPENGL_SURF_PROP IntFront; - OPENGL_SURF_PROP IntBack; - TEL_POFFSET_PARAM PolygonOffset; +protected: //! @name OpenGl resources - int doTextureMap; - Handle(OpenGl_Texture) TextureRes; - Handle(Graphic3d_TextureParams) TextureParams; + mutable Standard_Boolean myIsTextureInit; + mutable Handle(OpenGl_Texture) myTextureRes; + mutable TCollection_AsciiString myTextureId; protected: - TCollection_AsciiString myTextureId; - OpenGl_AspectLine myAspectEdge; + OpenGl_AspectLine myAspectEdge; public: diff --git a/src/OpenGl/OpenGl_AspectLine.cxx b/src/OpenGl/OpenGl_AspectLine.cxx index 77f7e30366..189c48539b 100644 --- a/src/OpenGl/OpenGl_AspectLine.cxx +++ b/src/OpenGl/OpenGl_AspectLine.cxx @@ -40,14 +40,14 @@ OpenGl_AspectLine::OpenGl_AspectLine (const OpenGl_AspectLine &AnOther) /*----------------------------------------------------------------------*/ -void OpenGl_AspectLine::SetContext (const CALL_DEF_CONTEXTLINE &AContext) +void OpenGl_AspectLine::SetAspect (const CALL_DEF_CONTEXTLINE &theAspect) { - myColor.rgb[0] = (float) AContext.Color.r; - myColor.rgb[1] = (float) AContext.Color.g; - myColor.rgb[2] = (float) AContext.Color.b; + myColor.rgb[0] = (float) theAspect.Color.r; + myColor.rgb[1] = (float) theAspect.Color.g; + myColor.rgb[2] = (float) theAspect.Color.b; myColor.rgb[3] = 1.0f; - myType = (Aspect_TypeOfLine) AContext.LineType; - myWidth = (float) AContext.Width; + myType = (Aspect_TypeOfLine) theAspect.LineType; + myWidth = (float) theAspect.Width; } /*----------------------------------------------------------------------*/ diff --git a/src/OpenGl/OpenGl_AspectLine.hxx b/src/OpenGl/OpenGl_AspectLine.hxx index 17255416ee..3f2d4479a8 100644 --- a/src/OpenGl/OpenGl_AspectLine.hxx +++ b/src/OpenGl/OpenGl_AspectLine.hxx @@ -32,7 +32,7 @@ class OpenGl_AspectLine : public OpenGl_Element OpenGl_AspectLine (); OpenGl_AspectLine (const OpenGl_AspectLine &AnOther); - void SetContext (const CALL_DEF_CONTEXTLINE &AContext); + void SetAspect (const CALL_DEF_CONTEXTLINE &theAspect); const TEL_COLOUR & Color() const { return myColor; } Aspect_TypeOfLine Type() const { return myType; } diff --git a/src/OpenGl/OpenGl_AspectMarker.cxx b/src/OpenGl/OpenGl_AspectMarker.cxx index a261f0f98b..2de0f836e7 100644 --- a/src/OpenGl/OpenGl_AspectMarker.cxx +++ b/src/OpenGl/OpenGl_AspectMarker.cxx @@ -26,6 +26,7 @@ #include #include #include +#include static const TEL_COLOUR myDefaultColor = {{ 1.0F, 1.0F, 1.0F, 1.0F }}; @@ -1447,54 +1448,44 @@ OpenGl_AspectMarker::OpenGl_AspectMarker() : myColor (myDefaultColor), myType (Aspect_TOM_PLUS), myScale (1.0f), + myMarkerImage(), myMarkerSize (1.0f), mySpriteKey (""), - mySpriteAKey ("") + mySpriteAKey (""), + myIsSpriteInit (Standard_False) {} // ======================================================================= -// function : Init +// function : SetAspect // purpose : // ======================================================================= -void OpenGl_AspectMarker::Init (const Handle(OpenGl_Context)& theCtx, - const CALL_DEF_CONTEXTMARKER& theAspect) +void OpenGl_AspectMarker::SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect) { myColor.rgb[0] = (float )theAspect.Color.r; myColor.rgb[1] = (float )theAspect.Color.g; myColor.rgb[2] = (float )theAspect.Color.b; myColor.rgb[3] = 1.0f; - myType = theAspect.MarkerType; + myMarkerImage = theAspect.MarkerImage; + myType = theAspect.MarkerType; myScale = myMarkerSize = theAspect.Scale; - // generate key for shared resource + // check that the resources need to be renewed TCollection_AsciiString aNewKey, aNewKeyA; - if (myType == Aspect_TOM_USERDEFINED) - { - if (!theAspect.MarkerImage.IsNull()) - { - aNewKey = theAspect.MarkerImage->GetImageId(); - aNewKeyA = theAspect.MarkerImage->GetImageAlphaId(); - } - } - else if (myType != Aspect_TOM_POINT) - { - // pre-defined markers - const Standard_Integer aScale = Standard_Integer(myScale + 0.5f); - aNewKey = TCollection_AsciiString ("OpenGl_AspectMarker") + myType + "_" + aScale; - aNewKeyA = aNewKey + "A"; - if (myType == Aspect_TOM_BALL) - { - unsigned int aColor[3] = - { - (unsigned int )(255.0f * myColor.rgb[0]), - (unsigned int )(255.0f * myColor.rgb[1]), - (unsigned int )(255.0f * myColor.rgb[2]) - }; - char aBytes[8]; - sprintf (aBytes, "%02X%02X%02X", aColor[0], aColor[1], aColor[2]); - aNewKey += aBytes; - } - } + resourceKeys (myMarkerImage, myType, myScale, myColor, aNewKey, aNewKeyA); + myIsSpriteInit = !aNewKey.IsEmpty() && mySpriteKey == aNewKey; + myIsSpriteInit &= !aNewKeyA.IsEmpty() && mySpriteAKey == aNewKeyA; +} + +// ======================================================================= +// function : buildSprites +// purpose : +// ======================================================================= +void OpenGl_AspectMarker::buildSprites (const Handle(OpenGl_Workspace)& theWorkspace) const +{ + const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); + + TCollection_AsciiString aNewKey, aNewKeyA; + resourceKeys (myMarkerImage, myType, myMarkerSize, myColor, aNewKey, aNewKeyA); // release old shared resources const Standard_Boolean aNewResource = aNewKey.IsEmpty() || mySpriteKey != aNewKey; @@ -1504,13 +1495,13 @@ void OpenGl_AspectMarker::Init (const Handle(OpenGl_Context)& theCtx, { if (mySpriteKey.IsEmpty()) { - theCtx->DelayedRelease (mySprite); + aContext->DelayedRelease (mySprite); mySprite.Nullify(); } else { mySprite.Nullify(); // we need nullify all handles before ReleaseResource() call - theCtx->ReleaseResource (mySpriteKey); + aContext->ReleaseResource (mySpriteKey); } } mySpriteKey = aNewKey; @@ -1522,28 +1513,28 @@ void OpenGl_AspectMarker::Init (const Handle(OpenGl_Context)& theCtx, { if (mySpriteAKey.IsEmpty()) { - theCtx->DelayedRelease (mySpriteA); + aContext->DelayedRelease (mySpriteA); mySpriteA.Nullify(); } else { mySpriteA.Nullify(); // we need nullify all handles before ReleaseResource() call - theCtx->ReleaseResource (mySpriteKey); + aContext->ReleaseResource (mySpriteKey); } } mySpriteAKey = aNewKeyA; } if (myType == Aspect_TOM_POINT || !aNewResource - || (myType == Aspect_TOM_USERDEFINED && theAspect.MarkerImage.IsNull())) + || (myType == Aspect_TOM_USERDEFINED && myMarkerImage.IsNull())) { // nothing to do - just simple point return; } if (!aNewKey.IsEmpty() - && theCtx->GetResource (aNewKeyA, mySpriteA) // alpha sprite could be shared - && theCtx->GetResource (aNewKey, mySprite)) + && aContext->GetResource (aNewKeyA, mySpriteA) // alpha sprite could be shared + && aContext->GetResource (aNewKey, mySprite)) { // reuse shared resource if (!mySprite->IsDisplayList()) @@ -1561,24 +1552,24 @@ void OpenGl_AspectMarker::Init (const Handle(OpenGl_Context)& theCtx, mySprite = new OpenGl_PointSprite(); if (!aNewKey.IsEmpty()) { - theCtx->ShareResource (aNewKey, mySprite); + aContext->ShareResource (aNewKey, mySprite); if (!hadAlreadyAlpha) { - theCtx->ShareResource (aNewKeyA, mySpriteA); + aContext->ShareResource (aNewKeyA, mySpriteA); } } - if (!theCtx.IsNull() - && theCtx->IsGlGreaterEqual (2, 0) - && !theCtx->caps->pntSpritesDisable) + if (!aContext.IsNull() + && aContext->IsGlGreaterEqual (2, 0) + && !aContext->caps->pntSpritesDisable) { // Creating texture resource for using it with point sprites Handle(Graphic3d_MarkerImage) aNewMarkerImage; Handle(Image_PixMap) anImage, anImageA; - if (myType == Aspect_TOM_USERDEFINED && !theAspect.MarkerImage.IsNull()) + if (myType == Aspect_TOM_USERDEFINED && !myMarkerImage.IsNull()) { - aNewMarkerImage = theAspect.MarkerImage; + aNewMarkerImage = myMarkerImage; anImage = aNewMarkerImage->GetImage(); } else @@ -1697,7 +1688,7 @@ void OpenGl_AspectMarker::Init (const Handle(OpenGl_Context)& theCtx, myMarkerSize = Max ((Standard_ShortReal )anImage->Width(),(Standard_ShortReal )anImage->Height()); - mySprite->Init (theCtx, *anImage.operator->(), Graphic3d_TOT_2D); + mySprite->Init (aContext, *anImage.operator->(), Graphic3d_TOT_2D); if (!hadAlreadyAlpha) { if (anImageA.IsNull() @@ -1708,7 +1699,7 @@ void OpenGl_AspectMarker::Init (const Handle(OpenGl_Context)& theCtx, } if (!anImageA.IsNull()) { - mySpriteA->Init (theCtx, *anImageA.operator->(), Graphic3d_TOT_2D); + mySpriteA->Init (aContext, *anImageA.operator->(), Graphic3d_TOT_2D); } } } @@ -1716,15 +1707,15 @@ void OpenGl_AspectMarker::Init (const Handle(OpenGl_Context)& theCtx, { // Creating list with bitmap for using it in compatibility mode GLuint aBitmapList = glGenLists (1); - mySprite->SetDisplayList (theCtx, aBitmapList); + mySprite->SetDisplayList (aContext, aBitmapList); Standard_Integer aWidth, aHeight, anOffset, aNumOfBytes; - if (myType == Aspect_TOM_USERDEFINED && !theAspect.MarkerImage.IsNull()) + if (myType == Aspect_TOM_USERDEFINED && !myMarkerImage.IsNull()) { - // Reading userdefined marker - Handle(TColStd_HArray1OfByte) aBitMap = theAspect.MarkerImage->GetBitMapArray(); + // Reading user defined marker + Handle(TColStd_HArray1OfByte) aBitMap = myMarkerImage->GetBitMapArray(); Standard_Byte* aBitMapArray = new Standard_Byte[aBitMap->Length()]; - theAspect.MarkerImage->GetTextureSize (aWidth, aHeight); + myMarkerImage->GetTextureSize (aWidth, aHeight); // We should pass bitmap to glBitmap with reversed line order as it draws it from // bottom to top @@ -1825,6 +1816,47 @@ void OpenGl_AspectMarker::Init (const Handle(OpenGl_Context)& theCtx, } } +// ======================================================================= +// function : resourceKeys +// purpose : +// ======================================================================= +void OpenGl_AspectMarker::resourceKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage, + const Aspect_TypeOfMarker theType, + const Standard_ShortReal theScale, + const TEL_COLOUR& theColor, + TCollection_AsciiString& theKey, + TCollection_AsciiString& theKeyA) const +{ + // generate key for shared resource + if (theType == Aspect_TOM_USERDEFINED) + { + if (!theMarkerImage.IsNull()) + { + theKey = theMarkerImage->GetImageId(); + theKeyA = theMarkerImage->GetImageAlphaId(); + } + } + else if (theType != Aspect_TOM_POINT) + { + // predefined markers + const Standard_Integer aScale = Standard_Integer(theScale + 0.5f); + theKey = TCollection_AsciiString ("OpenGl_AspectMarker") + theType + "_" + aScale; + theKeyA = theKey + "A"; + if (theType == Aspect_TOM_BALL) + { + unsigned int aColor[3] = + { + (unsigned int )(255.0f * theColor.rgb[0]), + (unsigned int )(255.0f * theColor.rgb[1]), + (unsigned int )(255.0f * theColor.rgb[2]) + }; + char aBytes[8]; + sprintf (aBytes, "%02X%02X%02X", aColor[0], aColor[1], aColor[2]); + theKey += aBytes; + } + } +} + // ======================================================================= // function : Render // purpose : diff --git a/src/OpenGl/OpenGl_AspectMarker.hxx b/src/OpenGl/OpenGl_AspectMarker.hxx index 4e7fa80122..0a3eb8b8cc 100644 --- a/src/OpenGl/OpenGl_AspectMarker.hxx +++ b/src/OpenGl/OpenGl_AspectMarker.hxx @@ -36,29 +36,87 @@ public: OpenGl_AspectMarker(); - void Init (const Handle(OpenGl_Context)& theContext, - const CALL_DEF_CONTEXTMARKER& theAspect); + //! Copy parameters + void SetAspect (const CALL_DEF_CONTEXTMARKER& theAspect); - const TEL_COLOUR& Color() const { return myColor; } - Aspect_TypeOfMarker Type() const { return myType; } - Standard_ShortReal Scale() const { return myScale; } - Standard_ShortReal MarkerSize() const { return myMarkerSize; } - const Handle(OpenGl_PointSprite)& Sprite() const { return mySprite; } - const Handle(OpenGl_PointSprite)& SpriteHighlight() const { return mySpriteA; } + //! @return marker color + const TEL_COLOUR& Color() const + { + return myColor; + } + + //! @return maker type + Aspect_TypeOfMarker Type() const + { + return myType; + } + + //! @return marker scale + Standard_ShortReal Scale() const + { + return myScale; + } + + //! @return marker size + Standard_ShortReal MarkerSize() const + { + return myMarkerSize; + } + + //! Init and return OpenGl point sprite resource. + //! @return point sprite texture. + const Handle(OpenGl_PointSprite)& Sprite (const Handle(OpenGl_Workspace)& theWorkspace) const + { + if (!myIsSpriteInit) + { + buildSprites (theWorkspace); + myIsSpriteInit = Standard_True; + } + + return mySprite; + } + + //! Init and return OpenGl highlight point sprite resource. + //! @return point sprite texture for highlight. + const Handle(OpenGl_PointSprite)& SpriteHighlight (const Handle(OpenGl_Workspace)& theWorkspace) const + { + if (!myIsSpriteInit) + { + buildSprites (theWorkspace); + myIsSpriteInit = Standard_True; + } + + return mySpriteA; + } virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; virtual void Release (const Handle(OpenGl_Context)& theContext); protected: - TEL_COLOUR myColor; - Aspect_TypeOfMarker myType; - Standard_ShortReal myScale; - Standard_ShortReal myMarkerSize; - TCollection_AsciiString mySpriteKey; //!< shared resource ID - TCollection_AsciiString mySpriteAKey; //!< shared resource ID - Handle(OpenGl_PointSprite) mySprite; //!< normal sprite - Handle(OpenGl_PointSprite) mySpriteA; //!< extra alphs-only sprite for RGB sprites + void buildSprites (const Handle(OpenGl_Workspace)& theWorkspace) const; + void resourceKeys (const Handle(Graphic3d_MarkerImage)& theMarkerImage, + const Aspect_TypeOfMarker theType, + const Standard_ShortReal theScale, + const TEL_COLOUR& theColor, + TCollection_AsciiString& theKey, + TCollection_AsciiString& theKeyA) const; + +protected: //! @name ordinary aspect properties + + TEL_COLOUR myColor; + Aspect_TypeOfMarker myType; + Standard_ShortReal myScale; + Handle(Graphic3d_MarkerImage) myMarkerImage; + +protected: //! @name OpenGl resources + + mutable Standard_ShortReal myMarkerSize; + mutable TCollection_AsciiString mySpriteKey; + mutable TCollection_AsciiString mySpriteAKey; + mutable Standard_Boolean myIsSpriteInit; + mutable Handle(OpenGl_PointSprite) mySprite; //!< normal sprite + mutable Handle(OpenGl_PointSprite) mySpriteA; //!< extra alpha-only sprite for RGB sprites public: diff --git a/src/OpenGl/OpenGl_AspectText.cxx b/src/OpenGl/OpenGl_AspectText.cxx index ea917c39c2..8cf3e6ce8f 100644 --- a/src/OpenGl/OpenGl_AspectText.cxx +++ b/src/OpenGl/OpenGl_AspectText.cxx @@ -52,25 +52,25 @@ OpenGl_AspectText::~OpenGl_AspectText() } // ======================================================================= -// function : SetContext +// function : SetAspect // purpose : // ======================================================================= -void OpenGl_AspectText::SetContext (const CALL_DEF_CONTEXTTEXT& theContext) +void OpenGl_AspectText::SetAspect (const CALL_DEF_CONTEXTTEXT& theAspect) { - myFont = theContext.Font; - myColor.rgb[0] = (float )theContext.Color.r; - myColor.rgb[1] = (float )theContext.Color.g; - myColor.rgb[2] = (float )theContext.Color.b; + myFont = theAspect.Font; + myColor.rgb[0] = (float )theAspect.Color.r; + myColor.rgb[1] = (float )theAspect.Color.g; + myColor.rgb[2] = (float )theAspect.Color.b; myColor.rgb[3] = 1.0f; - mySubtitleColor.rgb[0] = (float )theContext.ColorSubTitle.r; - mySubtitleColor.rgb[1] = (float )theContext.ColorSubTitle.g; - mySubtitleColor.rgb[2] = (float )theContext.ColorSubTitle.b; + mySubtitleColor.rgb[0] = (float )theAspect.ColorSubTitle.r; + mySubtitleColor.rgb[1] = (float )theAspect.ColorSubTitle.g; + mySubtitleColor.rgb[2] = (float )theAspect.ColorSubTitle.b; mySubtitleColor.rgb[3] = 1.0f; - myAngle = (float )theContext.TextAngle; - myStyleType = (Aspect_TypeOfStyleText )theContext.Style; - myDisplayType = (Aspect_TypeOfDisplayText )theContext.DisplayType; - myFontAspect = (Font_FontAspect )theContext.TextFontAspect; - myZoomable = (theContext.TextZoomable != 0); + myAngle = (float )theAspect.TextAngle; + myStyleType = (Aspect_TypeOfStyleText )theAspect.Style; + myDisplayType = (Aspect_TypeOfDisplayText )theAspect.DisplayType; + myFontAspect = (Font_FontAspect )theAspect.TextFontAspect; + myZoomable = (theAspect.TextZoomable != 0); } // ======================================================================= diff --git a/src/OpenGl/OpenGl_AspectText.hxx b/src/OpenGl/OpenGl_AspectText.hxx index 19708068bd..b0f3a7db7d 100644 --- a/src/OpenGl/OpenGl_AspectText.hxx +++ b/src/OpenGl/OpenGl_AspectText.hxx @@ -39,7 +39,7 @@ public: virtual ~OpenGl_AspectText(); //! Copy parameters - void SetContext (const CALL_DEF_CONTEXTTEXT& theContext); + void SetAspect (const CALL_DEF_CONTEXTTEXT& theAspect); //! @return font family name const TCollection_AsciiString& FontName() const diff --git a/src/OpenGl/OpenGl_CappingAlgo.cxx b/src/OpenGl/OpenGl_CappingAlgo.cxx index 482e267436..a24a8796cb 100644 --- a/src/OpenGl/OpenGl_CappingAlgo.cxx +++ b/src/OpenGl/OpenGl_CappingAlgo.cxx @@ -246,11 +246,11 @@ void OpenGl_CappingAlgo::Init() return; myRenderFilter = new OpenGl_CappingAlgoFilter(); - myNoneCulling.CullingMode = TelCullNone; - myNoneCulling.Edge = 0; + myNoneCulling.ChangeCullingMode() = TelCullNone; + myNoneCulling.ChangeEdge() = 0; - myFrontCulling.CullingMode = TelCullBack; - myFrontCulling.Edge = 0; + myFrontCulling.ChangeCullingMode() = TelCullBack; + myFrontCulling.ChangeEdge() = 0; myIsInit = Standard_True; } diff --git a/src/OpenGl/OpenGl_CappingPlaneResource.cxx b/src/OpenGl/OpenGl_CappingPlaneResource.cxx index b7009c2c29..d5b9bce7d8 100644 --- a/src/OpenGl/OpenGl_CappingPlaneResource.cxx +++ b/src/OpenGl/OpenGl_CappingPlaneResource.cxx @@ -79,7 +79,7 @@ void OpenGl_CappingPlaneResource::UpdateAspect (const Handle(OpenGl_Context)& th if (myAspectMod == myPlaneRoot->MCountAspect()) return; // noting to update - myAspect->Init (theContext, aCappingAsp); + myAspect->SetAspect (aCappingAsp); myAspectMod = myPlaneRoot->MCountAspect(); return; } @@ -96,7 +96,7 @@ void OpenGl_CappingPlaneResource::UpdateAspect (const Handle(OpenGl_Context)& th if (myAspect == NULL && !aCappingAsp.IsNull()) { myAspect = new OpenGl_AspectFace(); - myAspect->Init (theContext, aCappingAsp); + myAspect->SetAspect (aCappingAsp); myAspectMod = myPlaneRoot->MCountAspect(); } } diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 6c836fe93b..4862cf325e 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -262,6 +262,7 @@ Standard_Boolean OpenGl_Context::MakeCurrent() LocalFree (aMsgBuff); } PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, (unsigned int )anErrorCode, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg); + myIsInitialized = Standard_False; return Standard_False; } #else @@ -276,6 +277,7 @@ Standard_Boolean OpenGl_Context::MakeCurrent() // if there is no current context it might be impossible to use glGetError() correctly PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB, "glXMakeCurrent() has failed!"); + myIsInitialized = Standard_False; return Standard_False; } #endif diff --git a/src/OpenGl/OpenGl_Context.hxx b/src/OpenGl/OpenGl_Context.hxx index ba7ffcc1f9..4ecd9289f2 100644 --- a/src/OpenGl/OpenGl_Context.hxx +++ b/src/OpenGl/OpenGl_Context.hxx @@ -120,6 +120,12 @@ public: //! GL context should be active! Standard_EXPORT Standard_Boolean Init(); + //! @return true if this context is valid (has been initialized) + inline Standard_Boolean IsValid() const + { + return myIsInitialized; + } + #if defined(_WIN32) Standard_EXPORT Standard_Boolean Init (const Aspect_Handle theWindow, const Aspect_Handle theWindowDC, diff --git a/src/OpenGl/OpenGl_Display.cxx b/src/OpenGl/OpenGl_Display.cxx index a7614a039e..ac25077cf5 100644 --- a/src/OpenGl/OpenGl_Display.cxx +++ b/src/OpenGl/OpenGl_Display.cxx @@ -17,17 +17,16 @@ // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. - #include #include +#include +#include #include #include #include -#include - #if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))) #include // XOpenDisplay() #endif @@ -35,8 +34,6 @@ IMPLEMENT_STANDARD_HANDLE(OpenGl_Display,MMgt_TShared) IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Display,MMgt_TShared) -Handle(OpenGl_Display) openglDisplay; - namespace { #if (defined(_WIN32) || defined(__WIN32__)) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) @@ -78,41 +75,29 @@ OpenGl_Display::OpenGl_Display (const Handle(Aspect_DisplayConnection)& theDispl OpenGl_Display::~OpenGl_Display () { - // Delete line styles - if (myLinestyleBase) - { - glDeleteLists((GLuint)myLinestyleBase,5); - myLinestyleBase = 0; - } - // Delete surface patterns - if (myPatternBase) - { - glDeleteLists((GLuint)myPatternBase,TEL_HS_USER_DEF_START); - myPatternBase = 0; - } - + ReleaseAttributes (NULL); myDisplay = NULL; } -/*----------------------------------------------------------------------*/ - -Handle(OpenGl_Window) OpenGl_Display::GetWindow (const Aspect_Drawable AParent) const +void OpenGl_Display::ReleaseAttributes (const OpenGl_Context* theGlCtx) { - Handle(OpenGl_Window) aWindow; - if ( myMapOfWindows.IsBound( AParent ) ) + // Delete line styles + if (myLinestyleBase != 0) { - aWindow = myMapOfWindows.Find( AParent ); + if (theGlCtx->IsValid()) + { + glDeleteLists ((GLuint )myLinestyleBase, 5); + } + myLinestyleBase = 0; } - return aWindow; -} - -/*----------------------------------------------------------------------*/ - -void OpenGl_Display::SetWindow (const Aspect_Drawable AParent, const Handle(OpenGl_Window) &AWindow) -{ - if ( !myMapOfWindows.IsBound( AParent ) ) + // Delete surface patterns + if (myPatternBase != 0) { - myMapOfWindows.Bind( AParent, AWindow ); + if (theGlCtx->IsValid()) + { + glDeleteLists ((GLuint )myPatternBase, TEL_HS_USER_DEF_START); + } + myPatternBase = 0; } } diff --git a/src/OpenGl/OpenGl_Display.hxx b/src/OpenGl/OpenGl_Display.hxx index 5ba1797044..6c4ad6e0bd 100644 --- a/src/OpenGl/OpenGl_Display.hxx +++ b/src/OpenGl/OpenGl_Display.hxx @@ -23,13 +23,8 @@ #include #include -#include -#include -#include - #include #include -#include #include #include @@ -49,20 +44,17 @@ struct OpenGl_Facilities int MaxViews; }; -class OpenGl_AspectText; -struct OpenGl_TextParam; +class OpenGl_Context; class OpenGl_Display : public MMgt_TShared { - public: +public: + OpenGl_Display (const Handle(Aspect_DisplayConnection)& theDisplayConnection); virtual ~OpenGl_Display (); Aspect_Display GetDisplay () const { return myDisplay; } - Handle(OpenGl_Window) GetWindow (const Aspect_Drawable AParent) const; - void SetWindow (const Aspect_Drawable AParent, const Handle(OpenGl_Window) &AWindow); - const OpenGl_Facilities & Facilities () const { return myFacilities; } Standard_Boolean DBuffer () const { return myDBuffer; } @@ -80,7 +72,8 @@ class OpenGl_Display : public MMgt_TShared // System attributes - void InitAttributes (); + void InitAttributes(); + void ReleaseAttributes (const OpenGl_Context* theGlCtx); void SetTypeOfLine (const Aspect_TypeOfLine AType) const; @@ -96,12 +89,6 @@ class OpenGl_Display : public MMgt_TShared void Init (); - void ExportText (const wchar_t *text, const int is2d, const float x, const float y, const float z, const OpenGl_AspectText *aspect, const OpenGl_TextParam *param, const short height); - -#ifdef HAVE_GL2PS - static void getGL2PSFontName(const char *src_font, char *ps_font); -#endif - Aspect_Display myDisplay; OpenGl_Facilities myFacilities; @@ -114,12 +101,6 @@ class OpenGl_Display : public MMgt_TShared Standard_ShortReal myOffsetUnits; Standard_Integer myAntiAliasingMode; -#if (defined(_WIN32) || defined(__WIN32__)) - NCollection_DataMap myMapOfWindows; -#else - NCollection_DataMap myMapOfWindows; -#endif - unsigned int myLinestyleBase; unsigned int myPatternBase; @@ -127,6 +108,4 @@ class OpenGl_Display : public MMgt_TShared DEFINE_STANDARD_ALLOC }; -extern Handle(OpenGl_Display) openglDisplay; - -#endif //OpenGl_Workspace_Header +#endif // _OpenGl_Display_Header diff --git a/src/OpenGl/OpenGl_FrameBuffer.cxx b/src/OpenGl/OpenGl_FrameBuffer.cxx index ddbc0b54a2..208f1f855d 100644 --- a/src/OpenGl/OpenGl_FrameBuffer.cxx +++ b/src/OpenGl/OpenGl_FrameBuffer.cxx @@ -16,12 +16,12 @@ // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. - #include -#ifdef DEB - #include -#endif +#include + +IMPLEMENT_STANDARD_HANDLE (OpenGl_FrameBuffer, OpenGl_Resource) +IMPLEMENT_STANDARD_RTTIEXT(OpenGl_FrameBuffer, OpenGl_Resource) static inline bool isOddNumber (const GLsizei theNumber) { @@ -39,6 +39,10 @@ static inline bool isPowerOfTwo (const GLsizei theNumber) return !(theNumber & (theNumber - 1)); } +// ======================================================================= +// function : OpenGl_FrameBuffer +// purpose : +// ======================================================================= OpenGl_FrameBuffer::OpenGl_FrameBuffer (GLint theTextureFormat) : mySizeX (0), mySizeY (0), @@ -53,21 +57,31 @@ OpenGl_FrameBuffer::OpenGl_FrameBuffer (GLint theTextureFormat) // } +// ======================================================================= +// function : ~OpenGl_FrameBuffer +// purpose : +// ======================================================================= +OpenGl_FrameBuffer::~OpenGl_FrameBuffer() +{ + Release (NULL); +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlContext, - GLsizei theViewportSizeX, - GLsizei theViewportSizeY, - GLboolean toForcePowerOfTwo) + const GLsizei theViewportSizeX, + const GLsizei theViewportSizeY, + const GLboolean toForcePowerOfTwo) { if (theGlContext->extFBO == NULL) { - #ifdef DEB - std::cerr << "OpenGl_FrameBuffer, FBO extension not supported!\n"; - #endif return Standard_False; } // clean up previous state - Release (theGlContext); + Release (theGlContext.operator->()); // upscale width/height if numbers are odd if (toForcePowerOfTwo) @@ -86,13 +100,13 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo myVPSizeY = theViewportSizeY; // Create the texture (will be used as color buffer) - if (!InitTrashTexture (theGlContext)) + if (!initTrashTexture (theGlContext)) { if (!isPowerOfTwo (mySizeX) || !isPowerOfTwo (mySizeY)) { return Init (theGlContext, theViewportSizeX, theViewportSizeY, GL_TRUE); } - Release (theGlContext); + Release (theGlContext.operator->()); return Standard_False; } @@ -131,68 +145,72 @@ Standard_Boolean OpenGl_FrameBuffer::Init (const Handle(OpenGl_Context)& theGlCo { return Init (theGlContext, theViewportSizeX, theViewportSizeY, GL_TRUE); } - Release (theGlContext); + Release (theGlContext.operator->()); return Standard_False; } - UnbindBuffer (theGlContext); - UnbindTexture(); + UnbindBuffer (theGlContext); + UnbindTexture (theGlContext); theGlContext->extFBO->glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, NO_RENDERBUFFER); - - #ifdef DEB - std::cerr << "OpenGl_FrameBuffer, created FBO " << mySizeX << "x" << mySizeY - << " for viewport " << theViewportSizeX << "x" << theViewportSizeY << "\n"; - #endif return Standard_True; } -void OpenGl_FrameBuffer::Release (const Handle(OpenGl_Context)& theGlContext) +// ======================================================================= +// function : Release +// purpose : +// ======================================================================= +void OpenGl_FrameBuffer::Release (const OpenGl_Context* theGlCtx) { - if (IsValidDepthBuffer()) + if (isValidDepthBuffer() + || isValidStencilBuffer() + || isValidTexture() + || isValidFrameBuffer()) { - if (!theGlContext.IsNull() && theGlContext->extFBO != NULL) - { - theGlContext->extFBO->glDeleteRenderbuffersEXT (1, &myGlDepthRBId); - myGlDepthRBId = NO_RENDERBUFFER; - } - else - { - std::cerr << "OpenGl_FrameBuffer::Release() called with invalid OpenGl_Context!\n"; - } + // application can not handle this case by exception - this is bug in code + Standard_ASSERT_RETURN (theGlCtx != NULL, + "OpenGl_FrameBuffer destroyed without GL context! Possible GPU memory leakage...",); } - if (IsValidStencilBuffer()) + if (isValidStencilBuffer()) { - if (!theGlContext.IsNull() && theGlContext->extFBO != NULL) + if (theGlCtx->IsValid() + && myGlStencilRBId != myGlDepthRBId) { - theGlContext->extFBO->glDeleteRenderbuffersEXT (1, &myGlStencilRBId); - myGlStencilRBId = NO_RENDERBUFFER; + theGlCtx->extFBO->glDeleteRenderbuffersEXT (1, &myGlStencilRBId); } - else + myGlStencilRBId = NO_RENDERBUFFER; + } + if (isValidDepthBuffer()) + { + if (theGlCtx->IsValid()) { - std::cerr << "OpenGl_FrameBuffer::Release() called with invalid OpenGl_Context!\n"; + theGlCtx->extFBO->glDeleteRenderbuffersEXT (1, &myGlDepthRBId); } + myGlDepthRBId = NO_RENDERBUFFER; } - if (IsValidTexture()) + if (isValidTexture()) { - glDeleteTextures (1, &myGlTextureId); + if (theGlCtx->IsValid()) + { + glDeleteTextures (1, &myGlTextureId); + } myGlTextureId = NO_TEXTURE; } mySizeX = mySizeY = myVPSizeX = myVPSizeY = 0; - if (IsValidFrameBuffer()) + if (isValidFrameBuffer()) { - if (!theGlContext.IsNull() && theGlContext->extFBO != NULL) + if (theGlCtx->IsValid()) { - theGlContext->extFBO->glDeleteFramebuffersEXT (1, &myGlFBufferId); - myGlFBufferId = NO_FRAMEBUFFER; - } - else - { - std::cerr << "OpenGl_FrameBuffer::Release() called with invalid OpenGl_Context!\n"; + theGlCtx->extFBO->glDeleteFramebuffersEXT (1, &myGlFBufferId); } + myGlFBufferId = NO_FRAMEBUFFER; } } -Standard_Boolean OpenGl_FrameBuffer::IsProxySuccess() const +// ======================================================================= +// function : isProxySuccess +// purpose : +// ======================================================================= +Standard_Boolean OpenGl_FrameBuffer::isProxySuccess() const { // use proxy to check texture could be created or not glTexImage2D (GL_PROXY_TEXTURE_2D, @@ -206,7 +224,11 @@ Standard_Boolean OpenGl_FrameBuffer::IsProxySuccess() const return aTestParamX != 0 && aTestParamY != 0; } -Standard_Boolean OpenGl_FrameBuffer::InitTrashTexture (const Handle(OpenGl_Context)& theGlContext) +// ======================================================================= +// function : initTrashTexture +// purpose : +// ======================================================================= +Standard_Boolean OpenGl_FrameBuffer::initTrashTexture (const Handle(OpenGl_Context)& theGlContext) { // Check texture size is fit dimension maximum GLint aMaxTexDim = 2048; @@ -218,7 +240,7 @@ Standard_Boolean OpenGl_FrameBuffer::InitTrashTexture (const Handle(OpenGl_Conte // generate new id glEnable (GL_TEXTURE_2D); - if (!IsValidTexture()) + if (!isValidTexture()) { glGenTextures (1, &myGlTextureId); // Create The Texture } @@ -228,9 +250,9 @@ Standard_Boolean OpenGl_FrameBuffer::InitTrashTexture (const Handle(OpenGl_Conte glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - if (!IsProxySuccess()) + if (!isProxySuccess()) { - Release (theGlContext); + Release (theGlContext.operator->()); return Standard_False; } @@ -241,3 +263,61 @@ Standard_Boolean OpenGl_FrameBuffer::InitTrashTexture (const Handle(OpenGl_Conte GL_RGBA, GL_UNSIGNED_BYTE, NULL); // NULL pointer supported from OpenGL 1.1 return Standard_True; } + +// ======================================================================= +// function : SetupViewport +// purpose : +// ======================================================================= +void OpenGl_FrameBuffer::SetupViewport (const Handle(OpenGl_Context)& /*theGlCtx*/) +{ + glViewport (0, 0, myVPSizeX, myVPSizeY); +} + +// ======================================================================= +// function : ChangeViewport +// purpose : +// ======================================================================= +void OpenGl_FrameBuffer::ChangeViewport (const GLsizei theVPSizeX, + const GLsizei theVPSizeY) +{ + myVPSizeX = theVPSizeX; + myVPSizeY = theVPSizeY; +} + +// ======================================================================= +// function : BindBuffer +// purpose : +// ======================================================================= +void OpenGl_FrameBuffer::BindBuffer (const Handle(OpenGl_Context)& theGlCtx) +{ + theGlCtx->extFBO->glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, myGlFBufferId); +} + +// ======================================================================= +// function : UnbindBuffer +// purpose : +// ======================================================================= +void OpenGl_FrameBuffer::UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx) +{ + theGlCtx->extFBO->glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, NO_FRAMEBUFFER); +} + +// ======================================================================= +// function : BindTexture +// purpose : +// ======================================================================= +void OpenGl_FrameBuffer::BindTexture (const Handle(OpenGl_Context)& /*theGlCtx*/) +{ + glEnable (GL_TEXTURE_2D); // needed only for fixed pipeline rendering + glBindTexture (GL_TEXTURE_2D, myGlTextureId); +} + +// ======================================================================= +// function : UnbindTexture +// purpose : +// ======================================================================= +void OpenGl_FrameBuffer::UnbindTexture (const Handle(OpenGl_Context)& /*theGlCtx*/) +{ + glBindTexture (GL_TEXTURE_2D, NO_TEXTURE); + glDisable (GL_TEXTURE_2D); // needed only for fixed pipeline rendering +} diff --git a/src/OpenGl/OpenGl_FrameBuffer.hxx b/src/OpenGl/OpenGl_FrameBuffer.hxx index 20ba7f05ae..117b94b242 100644 --- a/src/OpenGl/OpenGl_FrameBuffer.hxx +++ b/src/OpenGl/OpenGl_FrameBuffer.hxx @@ -16,17 +16,19 @@ // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. - #ifndef OPENGL_FRAME_BUFFER_H #define OPENGL_FRAME_BUFFER_H #include #include +#include #include #include -class OpenGl_FrameBuffer +//! Class implements FrameBuffer Object (FBO) resource +//! intended for off-screen rendering. +class OpenGl_FrameBuffer : public OpenGl_Resource { public: @@ -38,12 +40,14 @@ public: public: - OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8); + //! Empty constructor + Standard_EXPORT OpenGl_FrameBuffer (GLint theTextureFormat = GL_RGBA8); - virtual ~OpenGl_FrameBuffer() - { - Release (Handle(OpenGl_Context)()); - } + //! Destructor + Standard_EXPORT virtual ~OpenGl_FrameBuffer(); + + //! Destroy object - will release GPU memory if any. + Standard_EXPORT virtual void Release (const OpenGl_Context* theGlCtx); //! Texture width. GLsizei GetSizeX() const @@ -72,7 +76,7 @@ public: //! Returns true if current object was initialized Standard_Boolean IsValid() const { - return IsValidFrameBuffer() && IsValidTexture() && IsValidDepthBuffer() && IsValidStencilBuffer(); + return isValidFrameBuffer() && isValidTexture() && isValidDepthBuffer() && isValidStencilBuffer(); } //! Notice! Obsolete hardware (GeForce FX etc) @@ -83,94 +87,76 @@ public: //! current implementation will try to generate compatible FBO; //! 2) FBO rendering will be done in software mode (ForceWare 'hack'); //! 3) FBO rendering will be incorrect (some obsolete Catalyst drivers). - Standard_Boolean Init (const Handle(OpenGl_Context)& theGlContext, - GLsizei theViewportSizeX, - GLsizei theViewportSizeY, - GLboolean toForcePowerOfTwo = GL_FALSE); - - //! Release GL objects - void Release (const Handle(OpenGl_Context)& theGlContext); + Standard_EXPORT Standard_Boolean Init (const Handle(OpenGl_Context)& theGlCtx, + const GLsizei theViewportSizeX, + const GLsizei theViewportSizeY, + const GLboolean toForcePowerOfTwo = GL_FALSE); //! Setup viewport to render into FBO - void SetupViewport() - { - glViewport (0, 0, myVPSizeX, myVPSizeY); - } + Standard_EXPORT void SetupViewport (const Handle(OpenGl_Context)& theGlCtx); //! Override viewport settings - void ChangeViewport (const GLsizei theVPSizeX, - const GLsizei theVPSizeY) - { - myVPSizeX = theVPSizeX; - myVPSizeY = theVPSizeY; - } + Standard_EXPORT void ChangeViewport (const GLsizei theVPSizeX, + const GLsizei theVPSizeY); //! Bind frame buffer (to render into the texture). - void BindBuffer (const Handle(OpenGl_Context)& theGlContext) - { - theGlContext->extFBO->glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, myGlFBufferId); - } + Standard_EXPORT void BindBuffer (const Handle(OpenGl_Context)& theGlCtx); //! Unbind frame buffer. - void UnbindBuffer (const Handle(OpenGl_Context)& theGlContext) - { - theGlContext->extFBO->glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, NO_FRAMEBUFFER); - } + Standard_EXPORT void UnbindBuffer (const Handle(OpenGl_Context)& theGlCtx); //! Bind the texture. - void BindTexture () - { - glEnable (GL_TEXTURE_2D); // needed only for fixed pipeline rendering - glBindTexture (GL_TEXTURE_2D, myGlTextureId); - } + Standard_EXPORT void BindTexture (const Handle(OpenGl_Context)& theGlCtx); //! Unbind the texture. - void UnbindTexture() - { - glBindTexture (GL_TEXTURE_2D, NO_TEXTURE); - glDisable (GL_TEXTURE_2D); // needed only for fixed pipeline rendering - } + Standard_EXPORT void UnbindTexture (const Handle(OpenGl_Context)& theGlCtx); private: //! Check texture could be created - Standard_Boolean IsProxySuccess() const; + Standard_Boolean isProxySuccess() const; //! Generate texture with undefined data - Standard_Boolean InitTrashTexture (const Handle(OpenGl_Context)& theGlContext); + Standard_Boolean initTrashTexture (const Handle(OpenGl_Context)& theGlContext); - Standard_Boolean IsValidTexture() const + Standard_Boolean isValidTexture() const { return myGlTextureId != NO_TEXTURE; } - Standard_Boolean IsValidFrameBuffer() const + Standard_Boolean isValidFrameBuffer() const { return myGlFBufferId != NO_FRAMEBUFFER; } - Standard_Boolean IsValidDepthBuffer() const + Standard_Boolean isValidDepthBuffer() const { return myGlDepthRBId != NO_RENDERBUFFER; } - Standard_Boolean IsValidStencilBuffer() const + Standard_Boolean isValidStencilBuffer() const { return myGlStencilRBId != NO_RENDERBUFFER; } private: - GLsizei mySizeX; // texture width - GLsizei mySizeY; // texture height - GLsizei myVPSizeX; // viewport width (should be <= texture width) - GLsizei myVPSizeY; // viewport height (should be <= texture height) - GLint myTextFormat; // GL_RGB, GL_RGBA,... - GLuint myGlTextureId; // GL texture ID - GLuint myGlFBufferId; // FBO object ID - GLuint myGlDepthRBId; // RenderBuffer object for depth ID - GLuint myGlStencilRBId; // RenderBuffer object for stencil ID + GLsizei mySizeX; //!< texture width + GLsizei mySizeY; //!< texture height + GLsizei myVPSizeX; //!< viewport width (should be <= texture width) + GLsizei myVPSizeY; //!< viewport height (should be <= texture height) + GLint myTextFormat; //!< GL_RGB, GL_RGBA,... + GLuint myGlTextureId; //!< GL texture ID + GLuint myGlFBufferId; //!< FBO object ID + GLuint myGlDepthRBId; //!< RenderBuffer object for depth ID + GLuint myGlStencilRBId; //!< RenderBuffer object for stencil ID + +public: + + DEFINE_STANDARD_RTTI(OpenGl_FrameBuffer) // Type definition }; -#endif //OPENGL_FRAME_BUFFER_H +DEFINE_STANDARD_HANDLE(OpenGl_FrameBuffer, OpenGl_Resource) + +#endif // OPENGL_FRAME_BUFFER_H diff --git a/src/OpenGl/OpenGl_GraphicDriver.hxx b/src/OpenGl/OpenGl_GraphicDriver.hxx index f5af18f665..39415f6c5f 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.hxx +++ b/src/OpenGl/OpenGl_GraphicDriver.hxx @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -330,6 +331,7 @@ public: private: + Handle(OpenGl_Display) myGlDisplay; Handle(OpenGl_Caps) myCaps; NCollection_DataMap myMapOfView; NCollection_DataMap myMapOfWS; diff --git a/src/OpenGl/OpenGl_GraphicDriver_1.cxx b/src/OpenGl/OpenGl_GraphicDriver_1.cxx index abcf5b7156..a1982b5b2a 100755 --- a/src/OpenGl/OpenGl_GraphicDriver_1.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver_1.cxx @@ -36,7 +36,7 @@ Standard_Boolean OpenGl_GraphicDriver::Begin (const Handle(Aspect_DisplayConnect myDisplayConnection = theDisplayConnection; try { - openglDisplay = new OpenGl_Display (myDisplayConnection); + myGlDisplay = new OpenGl_Display (myDisplayConnection); return Standard_True; } catch (Standard_Failure) diff --git a/src/OpenGl/OpenGl_GraphicDriver_2.cxx b/src/OpenGl/OpenGl_GraphicDriver_2.cxx index e62f1d2f8e..05ca5c0b79 100755 --- a/src/OpenGl/OpenGl_GraphicDriver_2.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver_2.cxx @@ -27,7 +27,7 @@ Standard_Integer OpenGl_GraphicDriver::InquireLightLimit () { - return (openglDisplay.IsNull()? 0 : openglDisplay->Facilities().MaxLights); + return (myGlDisplay.IsNull() ? 0 : myGlDisplay->Facilities().MaxLights); } void OpenGl_GraphicDriver::InquireMat (const Graphic3d_CView& ACView, TColStd_Array2OfReal& AMatO, TColStd_Array2OfReal& AMatM) @@ -39,7 +39,7 @@ void OpenGl_GraphicDriver::InquireMat (const Graphic3d_CView& ACView, TColStd_Ar Standard_Integer OpenGl_GraphicDriver::InquireViewLimit () { - return (openglDisplay.IsNull()? 0 : openglDisplay->Facilities().MaxViews); + return (myGlDisplay.IsNull() ? 0 : myGlDisplay->Facilities().MaxViews); } Standard_Integer OpenGl_GraphicDriver::InquirePlaneLimit () diff --git a/src/OpenGl/OpenGl_GraphicDriver_3.cxx b/src/OpenGl/OpenGl_GraphicDriver_3.cxx index f51a56baaa..8f278b4c4e 100755 --- a/src/OpenGl/OpenGl_GraphicDriver_3.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver_3.cxx @@ -39,7 +39,7 @@ void OpenGl_GraphicDriver::FaceContextGroup (const Graphic3d_CGroup& theCGroup, if (!theCGroup.ContextFillArea.IsDef || theCGroup.ptrGroup == NULL) return; - ((OpenGl_Group* )theCGroup.ptrGroup)->SetAspectFace (GetSharedContext(), theCGroup.ContextFillArea, theNoInsert); + ((OpenGl_Group* )theCGroup.ptrGroup)->SetAspectFace (theCGroup.ContextFillArea, theNoInsert); } void OpenGl_GraphicDriver::Group (Graphic3d_CGroup& theCGroup) @@ -64,7 +64,7 @@ void OpenGl_GraphicDriver::MarkerContextGroup (const Graphic3d_CGroup& theCGroup { if (!theCGroup.ContextMarker.IsDef || theCGroup.ptrGroup == NULL) return; - ((OpenGl_Group* )theCGroup.ptrGroup)->SetAspectMarker (GetSharedContext(), theCGroup.ContextMarker, theNoInsert); + ((OpenGl_Group* )theCGroup.ptrGroup)->SetAspectMarker (theCGroup.ContextMarker, theNoInsert); } void OpenGl_GraphicDriver::RemoveGroup (const Graphic3d_CGroup& theCGroup) diff --git a/src/OpenGl/OpenGl_GraphicDriver_4.cxx b/src/OpenGl/OpenGl_GraphicDriver_4.cxx index 8449479169..1b883c6a64 100755 --- a/src/OpenGl/OpenGl_GraphicDriver_4.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver_4.cxx @@ -45,10 +45,10 @@ void OpenGl_GraphicDriver::ContextStructure (const Graphic3d_CStructure& theCStr aStructure->SetAspectLine (theCStructure.ContextLine); if (theCStructure.ContextFillArea.IsDef) - aStructure->SetAspectFace (GetSharedContext(), theCStructure.ContextFillArea); + aStructure->SetAspectFace (theCStructure.ContextFillArea); if (theCStructure.ContextMarker.IsDef) - aStructure->SetAspectMarker (GetSharedContext(), theCStructure.ContextMarker); + aStructure->SetAspectMarker (theCStructure.ContextMarker); if (theCStructure.ContextText.IsDef) aStructure->SetAspectText (theCStructure.ContextText); diff --git a/src/OpenGl/OpenGl_GraphicDriver_7.cxx b/src/OpenGl/OpenGl_GraphicDriver_7.cxx index 84f522cf93..c1d9f57469 100755 --- a/src/OpenGl/OpenGl_GraphicDriver_7.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver_7.cxx @@ -223,16 +223,19 @@ Graphic3d_PtrFrameBuffer OpenGl_GraphicDriver::FBOCreate (const Graphic3d_CView& return (Graphic3d_PtrFrameBuffer)NULL; } -Graphic3d_PtrFrameBuffer OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight) +Graphic3d_PtrFrameBuffer OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth, + const Standard_Integer theHeight) { // activate OpenGL context if (!Activate()) return NULL; // create the FBO + const Handle(OpenGl_Context)& aCtx = GetGlContext(); OpenGl_FrameBuffer* aFrameBuffer = new OpenGl_FrameBuffer(); - if (!aFrameBuffer->Init (GetGlContext(), theWidth, theHeight)) + if (!aFrameBuffer->Init (aCtx, theWidth, theHeight)) { + aFrameBuffer->Release (aCtx.operator->()); delete aFrameBuffer; return NULL; } @@ -254,12 +257,18 @@ void OpenGl_GraphicDriver::FBORelease (const Graphic3d_CView& ACView, Graphic3d_ void OpenGl_Workspace::FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr) { // activate OpenGL context - if (!Activate()) + if (!Activate() + || theFBOPtr == NULL) + { return; + } // release the object OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer*)theFBOPtr; - aFrameBuffer->Release (GetGlContext()); + if (aFrameBuffer != NULL) + { + aFrameBuffer->Release (GetGlContext().operator->()); + } delete aFrameBuffer; } @@ -417,14 +426,38 @@ Standard_Boolean OpenGl_Workspace::BufferDump (OpenGl_FrameBuffer* theFB void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& theCView) { - Handle(OpenGl_Context) aShareCtx = GetSharedContext(); - if (myMapOfView.IsBound (theCView.ViewId)) - myMapOfView.UnBind (theCView.ViewId); - - if (myMapOfWS.IsBound (theCView.WsId)) + Handle(OpenGl_Context) aCtx = GetSharedContext(); + Handle(OpenGl_View) aView; + Handle(OpenGl_Workspace) aWindow; + if (myMapOfWS.Find (theCView.WsId, aWindow)) + { myMapOfWS.UnBind (theCView.WsId); + } + if (!aWindow.IsNull()) + { + if (aWindow->GetGlContext()->MakeCurrent()) + { + aCtx = aWindow->GetGlContext(); + } + else + { + // try to hijack another context if any + const Handle(OpenGl_Context)& anOtherCtx = GetSharedContext(); + if (!anOtherCtx.IsNull() + && anOtherCtx != aWindow->GetGlContext()) + { + aCtx = anOtherCtx; + aCtx->MakeCurrent(); + } + } + } + if (myMapOfView.Find (theCView.ViewId, aView)) + { + aView->ReleaseGlResources (aCtx); + myMapOfView.UnBind (theCView.ViewId); + } - if (myMapOfWS.IsEmpty() && !myMapOfStructure.IsEmpty()) + if (myMapOfWS.IsEmpty()) { // The last view removed but some objects still present. // Release GL resources now without object destruction. @@ -432,16 +465,20 @@ void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& theCView) aStructIt.More (); aStructIt.Next()) { OpenGl_Structure* aStruct = aStructIt.ChangeValue(); - aStruct->ReleaseGlResources (aShareCtx); + aStruct->ReleaseGlResources (aCtx); } - myTempText->Release (aShareCtx); - myDeviceLostFlag = Standard_True; + myTempText->Release (aCtx); + myGlDisplay->ReleaseAttributes (aCtx.operator->()); + myDeviceLostFlag = !myMapOfStructure.IsEmpty(); } OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView; - aCView->View->ReleaseGlResources (aShareCtx); delete aCView; ((Graphic3d_CView *)&theCView)->ptrView = NULL; + + aCtx.Nullify(); + aView.Nullify(); + aWindow.Nullify(); } void OpenGl_GraphicDriver::SetLight (const Graphic3d_CView& ACView) @@ -502,31 +539,22 @@ void OpenGl_GraphicDriver::Update (const Graphic3d_CView& ACView, const Aspect_C Standard_Boolean OpenGl_GraphicDriver::View (Graphic3d_CView& theCView) { - if (openglDisplay.IsNull()) - return Standard_False; - - if (myMapOfView.IsBound (theCView.ViewId)) - myMapOfView.UnBind (theCView.ViewId); - - if (myMapOfWS.IsBound (theCView.WsId)) - myMapOfWS.UnBind (theCView.WsId); - - Handle(OpenGl_Workspace) aWS = Handle(OpenGl_Workspace)::DownCast(openglDisplay->GetWindow (theCView.DefWindow.XWindow)); - if (aWS.IsNull()) + if (myGlDisplay.IsNull() + || myMapOfView.IsBound (theCView.ViewId) + || myMapOfWS .IsBound (theCView.WsId)) { - Handle(OpenGl_Context) aShareCtx = GetSharedContext(); - aWS = new OpenGl_Workspace (openglDisplay, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx); - openglDisplay->SetWindow (theCView.DefWindow.XWindow, aWS); + return Standard_False; } - myMapOfWS.Bind (theCView.WsId, aWS); - - Handle(OpenGl_View) aView = new OpenGl_View (theCView.Context); + Handle(OpenGl_Context) aShareCtx = GetSharedContext(); + Handle(OpenGl_Workspace) aWS = new OpenGl_Workspace (myGlDisplay, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx); + Handle(OpenGl_View) aView = new OpenGl_View (theCView.Context); + myMapOfWS .Bind (theCView.WsId, aWS); myMapOfView.Bind (theCView.ViewId, aView); OpenGl_CView* aCView = new OpenGl_CView(); aCView->View = aView; - aCView->WS = aWS; + aCView->WS = aWS; theCView.ptrView = aCView; return Standard_True; @@ -537,7 +565,7 @@ void OpenGl_GraphicDriver::ViewMapping (const Graphic3d_CView& ACView, const Sta const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; if (aCView) { - aCView->View->SetMapping(ACView); + aCView->View->SetMapping (myGlDisplay, ACView); if (!AWait) { aCView->WS->Resize(ACView.DefWindow); diff --git a/src/OpenGl/OpenGl_GraphicDriver_Layer.cxx b/src/OpenGl/OpenGl_GraphicDriver_Layer.cxx index c8f244645c..33b977e282 100755 --- a/src/OpenGl/OpenGl_GraphicDriver_Layer.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver_Layer.cxx @@ -78,7 +78,7 @@ void InitLayerProp (const int AListId) TheLayerProp.LineType = -1; TheLayerProp.LineWidth = -1.F; - TheLayerProp.AspectText.SetContext(myDefaultContextText); + TheLayerProp.AspectText.SetAspect (myDefaultContextText); TheLayerProp.TextParam.HAlign = Graphic3d_HTA_LEFT; TheLayerProp.TextParam.VAlign = Graphic3d_VTA_BOTTOM; @@ -230,12 +230,12 @@ void OpenGl_GraphicDriver::UnsetTransparency () void OpenGl_GraphicDriver::SetLineAttributes (const Standard_Integer Type, const Standard_ShortReal Width) { - if (!TheLayerProp.ListId || openglDisplay.IsNull()) return; + if (!TheLayerProp.ListId || myGlDisplay.IsNull()) return; if (TheLayerProp.LineType != Type) { TheLayerProp.LineType = Type; - openglDisplay->SetTypeOfLine((Aspect_TypeOfLine) Type); + myGlDisplay->SetTypeOfLine((Aspect_TypeOfLine) Type); } if (TheLayerProp.LineWidth != Width) { diff --git a/src/OpenGl/OpenGl_Group.cxx b/src/OpenGl/OpenGl_Group.cxx index a6471518b2..38d2d8332c 100644 --- a/src/OpenGl/OpenGl_Group.cxx +++ b/src/OpenGl/OpenGl_Group.cxx @@ -48,19 +48,21 @@ OpenGl_Group::~OpenGl_Group() // function : SetAspectLine // purpose : // ======================================================================= -void OpenGl_Group::SetAspectLine (const CALL_DEF_CONTEXTLINE& theContext, +void OpenGl_Group::SetAspectLine (const CALL_DEF_CONTEXTLINE& theAspect, const Standard_Boolean theIsGlobal) { if (theIsGlobal || myFirst == NULL) { if (myAspectLine == NULL) + { myAspectLine = new OpenGl_AspectLine(); - myAspectLine->SetContext (theContext); + } + myAspectLine->SetAspect (theAspect); } else { OpenGl_AspectLine* anAspectLine = new OpenGl_AspectLine(); - anAspectLine->SetContext (theContext); + anAspectLine->SetAspect (theAspect); AddElement (TelNil/*TelAspectLine*/, anAspectLine); } } @@ -69,8 +71,7 @@ void OpenGl_Group::SetAspectLine (const CALL_DEF_CONTEXTLINE& theContext, // function : SetAspectFace // purpose : // ======================================================================= -void OpenGl_Group::SetAspectFace (const Handle(OpenGl_Context)& theCtx, - const CALL_DEF_CONTEXTFILLAREA& theAspect, +void OpenGl_Group::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect, const Standard_Boolean theIsGlobal) { if (theIsGlobal || myFirst == NULL) @@ -79,12 +80,12 @@ void OpenGl_Group::SetAspectFace (const Handle(OpenGl_Context)& theCtx, { myAspectFace = new OpenGl_AspectFace(); } - myAspectFace->Init (theCtx, theAspect); + myAspectFace->SetAspect (theAspect); } else { OpenGl_AspectFace* anAspectFace = new OpenGl_AspectFace(); - anAspectFace->Init (theCtx, theAspect); + anAspectFace->SetAspect (theAspect); AddElement (TelNil/*TelAspectFace*/, anAspectFace); } } @@ -93,8 +94,7 @@ void OpenGl_Group::SetAspectFace (const Handle(OpenGl_Context)& theCtx, // function : SetAspectMarker // purpose : // ======================================================================= -void OpenGl_Group::SetAspectMarker (const Handle(OpenGl_Context)& theCtx, - const CALL_DEF_CONTEXTMARKER& theAspect, +void OpenGl_Group::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect, const Standard_Boolean theIsGlobal) { if (theIsGlobal || myFirst == NULL) @@ -103,12 +103,12 @@ void OpenGl_Group::SetAspectMarker (const Handle(OpenGl_Context)& theCtx, { myAspectMarker = new OpenGl_AspectMarker(); } - myAspectMarker->Init (theCtx, theAspect); + myAspectMarker->SetAspect (theAspect); } else { OpenGl_AspectMarker* anAspectMarker = new OpenGl_AspectMarker(); - anAspectMarker->Init (theCtx, theAspect); + anAspectMarker->SetAspect (theAspect); AddElement (TelNil/*TelAspectMarker*/, anAspectMarker); } } @@ -117,19 +117,21 @@ void OpenGl_Group::SetAspectMarker (const Handle(OpenGl_Context)& theCtx, // function : SetAspectText // purpose : // ======================================================================= -void OpenGl_Group::SetAspectText (const CALL_DEF_CONTEXTTEXT& theContext, +void OpenGl_Group::SetAspectText (const CALL_DEF_CONTEXTTEXT& theAspect, const Standard_Boolean theIsGlobal) { if (theIsGlobal || myFirst == NULL) { if (myAspectText == NULL) + { myAspectText = new OpenGl_AspectText(); - myAspectText->SetContext (theContext); + } + myAspectText->SetAspect (theAspect); } else { OpenGl_AspectText* anAspectText = new OpenGl_AspectText(); - anAspectText->SetContext (theContext); + anAspectText->SetAspect (theAspect); AddElement ( TelNil/*TelAspectText*/, anAspectText); } } diff --git a/src/OpenGl/OpenGl_Group.hxx b/src/OpenGl/OpenGl_Group.hxx index 47ca2da4e8..6ed3e996de 100644 --- a/src/OpenGl/OpenGl_Group.hxx +++ b/src/OpenGl/OpenGl_Group.hxx @@ -51,14 +51,10 @@ public: OpenGl_Group(); - void SetAspectLine (const CALL_DEF_CONTEXTLINE &AContext, const Standard_Boolean IsGlobal = Standard_True); - void SetAspectFace (const Handle(OpenGl_Context)& theCtx, - const CALL_DEF_CONTEXTFILLAREA& theAspect, - const Standard_Boolean IsGlobal = Standard_True); - void SetAspectMarker (const Handle(OpenGl_Context)& theCtx, - const CALL_DEF_CONTEXTMARKER& theAspect, - const Standard_Boolean IsGlobal = Standard_True); - void SetAspectText (const CALL_DEF_CONTEXTTEXT &AContext, const Standard_Boolean IsGlobal = Standard_True); + void SetAspectLine (const CALL_DEF_CONTEXTLINE& theAspect, const Standard_Boolean IsGlobal = Standard_True); + void SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect, const Standard_Boolean IsGlobal = Standard_True); + void SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect, const Standard_Boolean IsGlobal = Standard_True); + void SetAspectText (const CALL_DEF_CONTEXTTEXT& theAspect, const Standard_Boolean IsGlobal = Standard_True); void AddElement (const TelType, OpenGl_Element * ); diff --git a/src/OpenGl/OpenGl_PointSprite.cxx b/src/OpenGl/OpenGl_PointSprite.cxx index f733595c55..458bc7b89d 100644 --- a/src/OpenGl/OpenGl_PointSprite.cxx +++ b/src/OpenGl/OpenGl_PointSprite.cxx @@ -57,7 +57,10 @@ void OpenGl_PointSprite::Release (const OpenGl_Context* theGlCtx) { if (myBitmapList != 0) { - glDeleteLists (myBitmapList, 1); + if (theGlCtx->IsValid()) + { + glDeleteLists (myBitmapList, 1); + } myBitmapList = 0; } diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 415f02a6d0..f806cc7754 100755 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -539,7 +539,7 @@ void OpenGl_PrimitiveArray::DrawMarkers (const Handle(OpenGl_Workspace)& theWork { const OpenGl_AspectMarker* anAspectMarker = theWorkspace->AspectMarker (Standard_True); const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); - const Handle(OpenGl_PointSprite)& aSpriteNorm = anAspectMarker->Sprite(); + const Handle(OpenGl_PointSprite)& aSpriteNorm = anAspectMarker->Sprite(theWorkspace); const Standard_Boolean isHilight = (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT); if (aCtx->IsGlGreaterEqual (2, 0) && !aSpriteNorm.IsNull() && !aSpriteNorm->IsDisplayList()) @@ -550,8 +550,8 @@ void OpenGl_PrimitiveArray::DrawMarkers (const Handle(OpenGl_Workspace)& theWork Handle(OpenGl_Texture) aTextureBack; if (anAspectMarker->Type() != Aspect_TOM_POINT) { - const Handle(OpenGl_PointSprite)& aSprite = (isHilight && anAspectMarker->SpriteHighlight()->IsValid()) - ? anAspectMarker->SpriteHighlight() + const Handle(OpenGl_PointSprite)& aSprite = (isHilight && anAspectMarker->SpriteHighlight(theWorkspace)->IsValid()) + ? anAspectMarker->SpriteHighlight(theWorkspace) : aSpriteNorm; aTextureBack = theWorkspace->EnableTexture (aSprite); @@ -704,7 +704,7 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace if (!myIsVboInit && !aCtx->caps->vboDisable && aCtx->core15 != NULL - && (myDrawMode != GL_POINTS || anAspectMarker->Sprite().IsNull() || !anAspectMarker->Sprite()->IsDisplayList())) + && (myDrawMode != GL_POINTS || anAspectMarker->Sprite(theWorkspace).IsNull() || !anAspectMarker->Sprite(theWorkspace)->IsDisplayList())) { if (!BuildVBO (theWorkspace)) { @@ -730,8 +730,8 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace break; } - Tint aFrontLightingModel = anAspectFace->IntFront.color_mask; - const TEL_COLOUR* anInteriorColor = &anAspectFace->IntFront.matcol; + Tint aFrontLightingModel = anAspectFace->IntFront().color_mask; + const TEL_COLOUR* anInteriorColor = &anAspectFace->IntFront().matcol; const TEL_COLOUR* anEdgeColor = &anAspectFace->AspectEdge()->Color(); const TEL_COLOUR* aLineColor = (myPArray->type == TelPointsArrayType) ? &anAspectMarker->Color() : &anAspectLine->Color(); @@ -743,11 +743,11 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace } DrawArray (aFrontLightingModel, - anAspectFace->InteriorStyle, - anAspectFace->Edge, + anAspectFace->InteriorStyle(), + anAspectFace->Edge(), anInteriorColor, aLineColor, anEdgeColor, - &anAspectFace->IntFront, + &anAspectFace->IntFront(), theWorkspace); } diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index c7c3f49b16..6bcd5bb52f 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -187,50 +187,52 @@ void OpenGl_Structure::SetTransformPersistence(const CALL_DEF_TRANSFORM_PERSISTE // function : SetAspectLine // purpose : // ======================================================================= -void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &AContext) +void OpenGl_Structure::SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect) { if (!myAspectLine) + { myAspectLine = new OpenGl_AspectLine(); - myAspectLine->SetContext( AContext ); + } + myAspectLine->SetAspect (theAspect); } // ======================================================================= // function : SetAspectFace // purpose : // ======================================================================= -void OpenGl_Structure::SetAspectFace (const Handle(OpenGl_Context)& theCtx, - const CALL_DEF_CONTEXTFILLAREA& theAspect) +void OpenGl_Structure::SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect) { if (!myAspectFace) { myAspectFace = new OpenGl_AspectFace(); } - myAspectFace->Init (theCtx, theAspect); + myAspectFace->SetAspect (theAspect); } // ======================================================================= // function : SetAspectMarker // purpose : // ======================================================================= -void OpenGl_Structure::SetAspectMarker (const Handle(OpenGl_Context)& theCtx, - const CALL_DEF_CONTEXTMARKER& theAspect) +void OpenGl_Structure::SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect) { if (!myAspectMarker) { myAspectMarker = new OpenGl_AspectMarker(); } - myAspectMarker->Init (theCtx, theAspect); + myAspectMarker->SetAspect (theAspect); } // ======================================================================= // function : SetAspectText // purpose : // ======================================================================= -void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &AContext) +void OpenGl_Structure::SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect) { if (!myAspectText) + { myAspectText = new OpenGl_AspectText(); - myAspectText->SetContext( AContext ); + } + myAspectText->SetAspect (theAspect); } // ======================================================================= diff --git a/src/OpenGl/OpenGl_Structure.hxx b/src/OpenGl/OpenGl_Structure.hxx index 6a22a118d8..47862bb233 100644 --- a/src/OpenGl/OpenGl_Structure.hxx +++ b/src/OpenGl/OpenGl_Structure.hxx @@ -48,12 +48,10 @@ public: void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers); - void SetAspectLine (const CALL_DEF_CONTEXTLINE &AContext); - void SetAspectFace (const Handle(OpenGl_Context)& theCtx, - const CALL_DEF_CONTEXTFILLAREA& theAspect); - void SetAspectMarker (const Handle(OpenGl_Context)& theCtx, - const CALL_DEF_CONTEXTMARKER& theAspect); - void SetAspectText (const CALL_DEF_CONTEXTTEXT &AContext); + void SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect); + void SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect); + void SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect); + void SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect); void SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx, const CALL_DEF_BOUNDBOX& theBoundBox); diff --git a/src/OpenGl/OpenGl_TextureBufferArb.cxx b/src/OpenGl/OpenGl_TextureBufferArb.cxx index 405b6fdc9a..5f1dfda770 100644 --- a/src/OpenGl/OpenGl_TextureBufferArb.cxx +++ b/src/OpenGl/OpenGl_TextureBufferArb.cxx @@ -66,7 +66,10 @@ void OpenGl_TextureBufferArb::Release (const OpenGl_Context* theGlCtx) Standard_ASSERT_RETURN (theGlCtx != NULL, "OpenGl_TextureBufferExt destroyed without GL context! Possible GPU memory leakage...",); - glDeleteTextures (1, &myTextureId); + if (theGlCtx->IsValid()) + { + glDeleteTextures (1, &myTextureId); + } myTextureId = NO_TEXTURE; } OpenGl_VertexBuffer::Release (theGlCtx); diff --git a/src/OpenGl/OpenGl_Trihedron.cxx b/src/OpenGl/OpenGl_Trihedron.cxx index 6bc7d53262..e3498f95fd 100644 --- a/src/OpenGl/OpenGl_Trihedron.cxx +++ b/src/OpenGl/OpenGl_Trihedron.cxx @@ -576,17 +576,17 @@ OpenGl_Trihedron::OpenGl_Trihedron (const Aspect_TypeOfTriedronPosition thePosit Quantity_Color aColor (theColor); aColor.Values (R, G, B, Quantity_TOC_RGB); - CALL_DEF_CONTEXTLINE aContextLine = myDefaultContextLine; - aContextLine.Color.r = (float)R; - aContextLine.Color.g = (float)G; - aContextLine.Color.b = (float)B; - myAspectLine.SetContext(aContextLine); - - CALL_DEF_CONTEXTTEXT aContextText = myDefaultContextText; - aContextText.Color.r = (float)R; - aContextText.Color.g = (float)G; - aContextText.Color.b = (float)B; - myAspectText.SetContext(aContextText); + CALL_DEF_CONTEXTLINE aLineAspect = myDefaultContextLine; + aLineAspect.Color.r = (float)R; + aLineAspect.Color.g = (float)G; + aLineAspect.Color.b = (float)B; + myAspectLine.SetAspect (aLineAspect); + + CALL_DEF_CONTEXTTEXT aTextAspect = myDefaultContextText; + aTextAspect.Color.r = (float)R; + aTextAspect.Color.g = (float)G; + aTextAspect.Color.b = (float)B; + myAspectText.SetAspect (aTextAspect); myXColor = theXColor; myYColor = theYColor; diff --git a/src/OpenGl/OpenGl_VertexBuffer.cxx b/src/OpenGl/OpenGl_VertexBuffer.cxx index 1a9878ca4b..b1c9b3d863 100644 --- a/src/OpenGl/OpenGl_VertexBuffer.cxx +++ b/src/OpenGl/OpenGl_VertexBuffer.cxx @@ -84,7 +84,10 @@ void OpenGl_VertexBuffer::Release (const OpenGl_Context* theGlCtx) Standard_ASSERT_RETURN (theGlCtx != NULL, "OpenGl_VertexBuffer destroyed without GL context! Possible GPU memory leakage...",); - theGlCtx->core15->glDeleteBuffers (1, &myBufferId); + if (theGlCtx->IsValid()) + { + theGlCtx->core15->glDeleteBuffers (1, &myBufferId); + } myBufferId = NO_BUFFER; } diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index 77df670eee..cb53c9046a 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -291,7 +291,8 @@ void OpenGl_View::SetClipLimit (const Graphic3d_CView& theCView) /*----------------------------------------------------------------------*/ //call_togl_viewmapping -void OpenGl_View::SetMapping (const Graphic3d_CView& theCView) +void OpenGl_View::SetMapping (const Handle(OpenGl_Display)& theGlDisplay, + const Graphic3d_CView& theCView) { const float ratio = theCView.DefWindow.dy / theCView.DefWindow.dx; const float r_ratio = theCView.DefWindow.dx / theCView.DefWindow.dy; @@ -325,7 +326,7 @@ void OpenGl_View::SetMapping (const Graphic3d_CView& theCView) Map.prp[0] = theCView.Mapping.ProjectionReferencePoint.x; Map.prp[1] = theCView.Mapping.ProjectionReferencePoint.y; Map.prp[2] = theCView.Mapping.ProjectionReferencePoint.z; - if (!openglDisplay.IsNull() && !openglDisplay->Walkthrough()) + if (!theGlDisplay.IsNull() && !theGlDisplay->Walkthrough()) Map.prp[2] += theCView.Mapping.FrontPlaneDistance; // view plane distance @@ -348,7 +349,7 @@ void OpenGl_View::SetMapping (const Graphic3d_CView& theCView) myMappingMatrix[i][j] = theCView.Mapping.ProjectionMatrix[i][j]; } else - TelEvalViewMappingMatrix( &Map, &err_ind, myMappingMatrix ); + TelEvalViewMappingMatrix (theGlDisplay, &Map, &err_ind, myMappingMatrix); if (!err_ind) myExtra.map = Map; diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index 15593c7bb8..43d3a6bc6f 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -45,6 +45,7 @@ #include #include +#include #include #include #include @@ -116,7 +117,7 @@ class OpenGl_View : public MMgt_TShared void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext); void SetClipLimit (const Graphic3d_CView& theCView); - void SetMapping (const Graphic3d_CView& theCView); + void SetMapping (const Handle(OpenGl_Display)& theGlDisplay, const Graphic3d_CView& theCView); void SetOrientation (const Graphic3d_CView& theCView); void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag); diff --git a/src/OpenGl/OpenGl_Window.cxx b/src/OpenGl/OpenGl_Window.cxx index 0a7f7f18c9..eaea9aeef2 100644 --- a/src/OpenGl/OpenGl_Window.cxx +++ b/src/OpenGl/OpenGl_Window.cxx @@ -547,26 +547,39 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_Display)& theDisplay, // ======================================================================= OpenGl_Window::~OpenGl_Window() { + if (!myOwnGContext) + { + myGlContext.Nullify(); + return; + } + + // release "GL" context if it is owned by window #if defined(_WIN32) - HWND aWindow = (HWND )myGlContext->myWindow; - HDC aWindowDC = (HDC )myGlContext->myWindowDC; - HGLRC aGContext = (HGLRC )myGlContext->myGContext; + HWND aWindow = (HWND )myGlContext->myWindow; + HDC aWindowDC = (HDC )myGlContext->myWindowDC; + HGLRC aWindowGContext = (HGLRC )myGlContext->myGContext; + HGLRC aThreadGlContext = wglGetCurrentContext(); myGlContext.Nullify(); - if (myOwnGContext) + if (aThreadGlContext != NULL) { - if (wglGetCurrentContext() != NULL) + // Mesa implementation can fail to reset this thread's context if wglDeleteContext() + // called without this step. This might lead to crash when using newly created + // context if wglMakeCurrent() is not forced right after the wglCreateContext(). + if (aThreadGlContext == aWindowGContext) { - wglDeleteContext (aGContext); + wglMakeCurrent (NULL, NULL); } - ReleaseDC (aWindow, aWindowDC); + + wglDeleteContext (aWindowGContext); } + ReleaseDC (aWindow, aWindowDC); #else Display* aDisplay = (Display* )myGlContext->myDisplay; GLXContext aGContext = (GLXContext )myGlContext->myGContext; myGlContext.Nullify(); - if (aDisplay != NULL && myOwnGContext) + if (aDisplay != NULL) { // FSXXX sync necessary if non-direct rendering glXWaitGL(); diff --git a/src/OpenGl/OpenGl_Workspace.cxx b/src/OpenGl/OpenGl_Workspace.cxx index 5045cae263..e7562f94b9 100644 --- a/src/OpenGl/OpenGl_Workspace.cxx +++ b/src/OpenGl/OpenGl_Workspace.cxx @@ -478,8 +478,8 @@ void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView, if (aFrameBuffer != NULL) { glGetIntegerv (GL_VIEWPORT, aViewPortBack); - aFrameBuffer->SetupViewport(); - aFrameBuffer->BindBuffer (aGlCtx); + aFrameBuffer->SetupViewport (aGlCtx); + aFrameBuffer->BindBuffer (aGlCtx); toSwap = 0; // no need to swap buffers } diff --git a/src/OpenGl/OpenGl_Workspace_2.cxx b/src/OpenGl/OpenGl_Workspace_2.cxx index 24d2e90425..f1afc27cb6 100644 --- a/src/OpenGl/OpenGl_Workspace_2.cxx +++ b/src/OpenGl/OpenGl_Workspace_2.cxx @@ -489,7 +489,7 @@ Standard_Boolean OpenGl_Workspace::Print if (!aViewBuffer) { - aFrameBuffer->Release (GetGlContext()); + aFrameBuffer->Release (GetGlContext().operator->()); aViewBuffer = NULL; aViewImage = NULL; } @@ -503,7 +503,7 @@ Standard_Boolean OpenGl_Workspace::Print { if (hViewBitmap) DeleteObject (hViewBitmap); - aFrameBuffer->Release (GetGlContext()); + aFrameBuffer->Release (GetGlContext().operator->()); hViewBitmap = NULL; } else @@ -593,7 +593,7 @@ Standard_Boolean OpenGl_Workspace::Print { myPrintContext->SetScale ((GLfloat )aFrameWidth /viewWidth, (GLfloat )aFrameHeight/viewHeight); - aFrameBuffer->SetupViewport (); + aFrameBuffer->SetupViewport (GetGlContext()); Redraw1(ACView, ACUnderLayer, ACOverLayer, 0); if (!myTransientDrawToFront) { @@ -704,7 +704,7 @@ Standard_Boolean OpenGl_Workspace::Print aFrameHeight; // draw to the offscreen buffer and capture the result - aFrameBuffer->SetupViewport (); + aFrameBuffer->SetupViewport (GetGlContext()); Redraw1(ACView, ACUnderLayer, ACOverLayer, 0); if (!myTransientDrawToFront) { @@ -766,7 +766,7 @@ Standard_Boolean OpenGl_Workspace::Print } else { - aFrameBuffer->Release (GetGlContext ()); + aFrameBuffer->Release (GetGlContext().operator->()); delete aFrameBuffer; } diff --git a/src/OpenGl/OpenGl_Workspace_5.cxx b/src/OpenGl/OpenGl_Workspace_5.cxx index 5f8d740f30..c537078e5d 100644 --- a/src/OpenGl/OpenGl_Workspace_5.cxx +++ b/src/OpenGl/OpenGl_Workspace_5.cxx @@ -70,15 +70,15 @@ static void TelUpdatePolygonOffsets( const TEL_POFFSET_PARAM *pdata ) void OpenGl_Workspace::UpdateMaterial( const int flag ) { - // Case of Hiddenline - if (AspectFace_set->InteriorStyle == Aspect_IS_HIDDENLINE) + // Case of hidden line + if (AspectFace_set->InteriorStyle() == Aspect_IS_HIDDENLINE) { - myAspectFaceHl = *AspectFace_set; // copy all values including line edge aspect - myAspectFaceHl.IntFront.matcol = BackgroundColor(); - myAspectFaceHl.IntFront.color_mask = 0; - myAspectFaceHl.IntBack.color_mask = 0; + myAspectFaceHl = *AspectFace_set; // copy all values including line edge aspect + myAspectFaceHl.ChangeIntFront().matcol = BackgroundColor(); + myAspectFaceHl.ChangeIntFront().color_mask = 0; + myAspectFaceHl.ChangeIntFront().color_mask = 0; - AspectFace_set = &myAspectFaceHl; + AspectFace_set = &myAspectFaceHl; return; } @@ -86,12 +86,12 @@ void OpenGl_Workspace::UpdateMaterial( const int flag ) GLenum face = 0; if ( flag == TEL_FRONT_MATERIAL ) { - prop = &AspectFace_set->IntFront; + prop = &AspectFace_set->IntFront(); face = GL_FRONT_AND_BACK; } else { - prop = &AspectFace_set->IntBack; + prop = &AspectFace_set->IntBack(); face = GL_BACK; } @@ -492,8 +492,8 @@ const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean th return AspectFace_set; } - const Aspect_InteriorStyle anIntstyle = AspectFace_set->InteriorStyle; - if (AspectFace_applied == NULL || AspectFace_applied->InteriorStyle != anIntstyle) + const Aspect_InteriorStyle anIntstyle = AspectFace_set->InteriorStyle(); + if (AspectFace_applied == NULL || AspectFace_applied->InteriorStyle() != anIntstyle) { switch (anIntstyle) { @@ -506,7 +506,7 @@ const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean th case Aspect_IS_HATCH: { glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); - myDisplay->SetTypeOfHatch (AspectFace_applied != NULL ? AspectFace_applied->Hatch : TEL_HS_SOLID); + myDisplay->SetTypeOfHatch (AspectFace_applied != NULL ? AspectFace_applied->Hatch() : TEL_HS_SOLID); break; } case Aspect_IS_SOLID: @@ -526,8 +526,8 @@ const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean th if (anIntstyle == Aspect_IS_HATCH) { - const Tint hatchstyle = AspectFace_set->Hatch; - if (AspectFace_applied == NULL || AspectFace_applied->Hatch != hatchstyle) + const Tint hatchstyle = AspectFace_set->Hatch(); + if (AspectFace_applied == NULL || AspectFace_applied->Hatch() != hatchstyle) { myDisplay->SetTypeOfHatch(hatchstyle); } @@ -535,8 +535,8 @@ const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean th if (!ActiveView()->Backfacing()) { - const Tint aCullingMode = AspectFace_set->CullingMode; - if (AspectFace_applied == NULL || AspectFace_applied->CullingMode != aCullingMode) + const Tint aCullingMode = AspectFace_set->CullingMode(); + if (AspectFace_applied == NULL || AspectFace_applied->CullingMode() != aCullingMode) { switch ((TelCullMode )aCullingMode) { @@ -562,30 +562,30 @@ const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean th } // Aspect_POM_None means: do not change current settings - if ((AspectFace_set->PolygonOffset.mode & Aspect_POM_None) != Aspect_POM_None) + if ((AspectFace_set->PolygonOffset().mode & Aspect_POM_None) != Aspect_POM_None) { if (PolygonOffset_applied == NULL - || PolygonOffset_applied->mode != AspectFace_set->PolygonOffset.mode - || PolygonOffset_applied->factor != AspectFace_set->PolygonOffset.factor - || PolygonOffset_applied->units != AspectFace_set->PolygonOffset.units) + || PolygonOffset_applied->mode != AspectFace_set->PolygonOffset().mode + || PolygonOffset_applied->factor != AspectFace_set->PolygonOffset().factor + || PolygonOffset_applied->units != AspectFace_set->PolygonOffset().units) { - PolygonOffset_applied = &AspectFace_set->PolygonOffset; + PolygonOffset_applied = &AspectFace_set->PolygonOffset(); TelUpdatePolygonOffsets (PolygonOffset_applied); } } UpdateMaterial (TEL_FRONT_MATERIAL); - if (AspectFace_set->DistinguishingMode == TOn) + if (AspectFace_set->DistinguishingMode() == TOn) { UpdateMaterial (TEL_BACK_MATERIAL); } if ((NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0) { - if (AspectFace_set->doTextureMap) + if (AspectFace_set->DoTextureMap()) { - EnableTexture (AspectFace_set->TextureRes, - AspectFace_set->TextureParams); + EnableTexture (AspectFace_set->TextureRes (this), + AspectFace_set->TextureParams()); } else { diff --git a/src/OpenGl/OpenGl_telem_view.cxx b/src/OpenGl/OpenGl_telem_view.cxx index 3a061344ba..73bdaa4a9c 100644 --- a/src/OpenGl/OpenGl_telem_view.cxx +++ b/src/OpenGl/OpenGl_telem_view.cxx @@ -29,7 +29,8 @@ File OpenGl_telem_view : #include static void -EvalViewMappingMatrix( tel_view_mapping mapping /* View Mapping */, +EvalViewMappingMatrix (const Handle(OpenGl_Display)& theGlDisplay, + tel_view_mapping mapping /* View Mapping */, Tint* error_ind /* Out: Error Indicator */, Tmatrix3 mat /* Out: Mapping Matrix * */, Tint flag, @@ -85,7 +86,7 @@ EvalViewMappingMatrix( tel_view_mapping mapping /* View Mapping */, } /* prp between front and back planes */ - if (openglDisplay.IsNull() || !openglDisplay->Walkthrough()) + if (theGlDisplay.IsNull() || !theGlDisplay->Walkthrough()) { if( mapping->prp[2] < mapping->fpd && mapping->prp[2] > mapping->bpd ) @@ -142,7 +143,7 @@ EvalViewMappingMatrix( tel_view_mapping mapping /* View Mapping */, pmat[2][0] = -gx; pmat[3][0] = mapping->vpd*gx; pmat[2][1] = -gy; pmat[3][1] = mapping->vpd*gy; } - else if (!openglDisplay.IsNull() && !openglDisplay->SymPerspective())/* TelPerspective */ + else if (!theGlDisplay.IsNull() && !theGlDisplay->SymPerspective())/* TelPerspective */ { pmat[0][0] = pmat[1][1] = mapping->prp[2] - mapping->vpd; pmat[2][0] = -gx; @@ -153,7 +154,7 @@ EvalViewMappingMatrix( tel_view_mapping mapping /* View Mapping */, pmat[3][3] = mapping->prp[2]; /* modify the next two cells to change clipping policy */ - if (!openglDisplay.IsNull() && !openglDisplay->Walkthrough()) + if (!theGlDisplay.IsNull() && !theGlDisplay->Walkthrough()) { pmat[2][2] = mapping->prp[2] - ( fpd + bpd ); pmat[3][2] = fpd * bpd; @@ -336,12 +337,11 @@ TelEvalViewOrientationMatrix( Tfloat *vrp /* View Reference Point */, return; } -void -TelEvalViewMappingMatrix( tel_view_mapping mapping /* View Mapping */, - Tint *error_ind /* Out: Error Indicator */, - Tmatrix3 mat /* Out: Mapping Matrix */ - ) +void TelEvalViewMappingMatrix (const Handle(OpenGl_Display)& theGlDisplay, + tel_view_mapping mapping /* View Mapping */, + Tint *error_ind /* Out: Error Indicator */, + Tmatrix3 mat /* Out: Mapping Matrix */ + ) { - EvalViewMappingMatrix( mapping, error_ind, mat, 0, ( float )0.0, ( float )0.0, 0, 0 ); + EvalViewMappingMatrix (theGlDisplay, mapping, error_ind, mat, 0, ( float )0.0, ( float )0.0, 0, 0); } - diff --git a/src/OpenGl/OpenGl_telem_view.hxx b/src/OpenGl/OpenGl_telem_view.hxx index 7bc96f58b7..ca140ad69d 100755 --- a/src/OpenGl/OpenGl_telem_view.hxx +++ b/src/OpenGl/OpenGl_telem_view.hxx @@ -43,6 +43,7 @@ Suppression de TelPrintAllViews() #define OPENGL_TELEM_VIEW_H #include +#include typedef struct { @@ -82,6 +83,6 @@ extern void /* vrp, vpn, vup, error_ind, mat */ TelEvalViewOrientationMatrix(Tfloat*, Tfloat*, Tfloat*, Tfloat*, Tint*, Tmatrix3); extern void /* mapping, error_ind, mat */ -TelEvalViewMappingMatrix( tel_view_mapping, Tint*, Tmatrix3 ); +TelEvalViewMappingMatrix (const Handle(OpenGl_Display)& theGlDisplay, tel_view_mapping theMapping, Tint* theError, Tmatrix3 theMat); #endif