-- 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;
// function : GetId
// purpose :
// =======================================================================
-TCollection_AsciiString Graphic3d_TextureRoot::GetId() const
+const TCollection_AsciiString& Graphic3d_TextureRoot::GetId() const
{
return myTexId;
}
};
static TEL_POFFSET_PARAM THE_DEFAULT_POFFSET = { Aspect_POM_Fill, 1.0F, 0.0F };
+ static const TCollection_AsciiString THE_EMPTY_KEY;
};
// 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<Handle(OpenGl_Texture)> (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;
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);
}
// =======================================================================
// =======================================================================
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<Handle(OpenGl_Texture)> (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);
+ }
+ }
+ }
+ }
+}
#include <InterfaceGraphic_telem.hxx>
#include <Aspect_InteriorStyle.hxx>
#include <TCollection_AsciiString.hxx>
-#include <Handle_Graphic3d_TextureParams.hxx>
+
#include <OpenGl_AspectLine.hxx>
#include <OpenGl_Element.hxx>
#include <Handle_OpenGl_Texture.hxx>
+
+#include <Graphic3d_TextureMap.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
+#include <Handle_Graphic3d_TextureParams.hxx>
#define OPENGL_AMBIENT_MASK (1<<0)
#define OPENGL_DIFFUSE_MASK (1<<1)
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:
/*----------------------------------------------------------------------*/
-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;
}
/*----------------------------------------------------------------------*/
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; }
#include <Image_PixMap.hxx>
#include <Graphic3d_MarkerImage.hxx>
#include <NCollection_Vec4.hxx>
+#include <TColStd_HArray1OfByte.hxx>
static const TEL_COLOUR myDefaultColor = {{ 1.0F, 1.0F, 1.0F, 1.0F }};
: 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;
{
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;
{
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<Handle(OpenGl_PointSprite)> (aNewKeyA, mySpriteA) // alpha sprite could be shared
- && theCtx->GetResource<Handle(OpenGl_PointSprite)> (aNewKey, mySprite))
+ && aContext->GetResource<Handle(OpenGl_PointSprite)> (aNewKeyA, mySpriteA) // alpha sprite could be shared
+ && aContext->GetResource<Handle(OpenGl_PointSprite)> (aNewKey, mySprite))
{
// reuse shared resource
if (!mySprite->IsDisplayList())
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
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()
}
if (!anImageA.IsNull())
{
- mySpriteA->Init (theCtx, *anImageA.operator->(), Graphic3d_TOT_2D);
+ mySpriteA->Init (aContext, *anImageA.operator->(), Graphic3d_TOT_2D);
}
}
}
{
// 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
}
}
+// =======================================================================
+// 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 :
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:
}
// =======================================================================
-// 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);
}
// =======================================================================
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
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;
}
if (myAspectMod == myPlaneRoot->MCountAspect())
return; // noting to update
- myAspect->Init (theContext, aCappingAsp);
+ myAspect->SetAspect (aCappingAsp);
myAspectMod = myPlaneRoot->MCountAspect();
return;
}
if (myAspect == NULL && !aCappingAsp.IsNull())
{
myAspect = new OpenGl_AspectFace();
- myAspect->Init (theContext, aCappingAsp);
+ myAspect->SetAspect (aCappingAsp);
myAspectMod = myPlaneRoot->MCountAspect();
}
}
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
// 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
//! 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,
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
-
#include <OpenGl_GlCore11.hxx>
#include <OpenGl_Display.hxx>
+#include <OpenGl_Context.hxx>
+#include <OpenGl_Light.hxx>
#include <OSD_Environment.hxx>
#include <TCollection_AsciiString.hxx>
#include <Aspect_GraphicDeviceDefinitionError.hxx>
-#include <OpenGl_Light.hxx>
-
#if (!defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)))
#include <X11/Xlib.h> // XOpenDisplay()
#endif
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))
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;
}
}
#include <Handle_OpenGl_Display.hxx>
#include <MMgt_TShared.hxx>
-#include <Standard_CString.hxx>
-#include <TColStd_HArray1OfByte.hxx>
-#include <NCollection_DataMap.hxx>
-
#include <Aspect_Display.hxx>
#include <Aspect_DisplayConnection.hxx>
-#include <Aspect_Drawable.hxx>
#include <Aspect_TypeOfLine.hxx>
#include <Aspect_TypeOfMarker.hxx>
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; }
// System attributes
- void InitAttributes ();
+ void InitAttributes();
+ void ReleaseAttributes (const OpenGl_Context* theGlCtx);
void SetTypeOfLine (const Aspect_TypeOfLine AType) const;
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;
Standard_ShortReal myOffsetUnits;
Standard_Integer myAntiAliasingMode;
-#if (defined(_WIN32) || defined(__WIN32__))
- NCollection_DataMap<Aspect_Drawable, Handle(OpenGl_Window)> myMapOfWindows;
-#else
- NCollection_DataMap<Standard_Integer, Handle(OpenGl_Window)> myMapOfWindows;
-#endif
-
unsigned int myLinestyleBase;
unsigned int myPatternBase;
DEFINE_STANDARD_ALLOC
};
-extern Handle(OpenGl_Display) openglDisplay;
-
-#endif //OpenGl_Workspace_Header
+#endif // _OpenGl_Display_Header
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
-
#include <OpenGl_FrameBuffer.hxx>
-#ifdef DEB
- #include <iostream>
-#endif
+#include <Standard_Assert.hxx>
+
+IMPLEMENT_STANDARD_HANDLE (OpenGl_FrameBuffer, OpenGl_Resource)
+IMPLEMENT_STANDARD_RTTIEXT(OpenGl_FrameBuffer, OpenGl_Resource)
static inline bool isOddNumber (const GLsizei theNumber)
{
return !(theNumber & (theNumber - 1));
}
+// =======================================================================
+// function : OpenGl_FrameBuffer
+// purpose :
+// =======================================================================
OpenGl_FrameBuffer::OpenGl_FrameBuffer (GLint theTextureFormat)
: mySizeX (0),
mySizeY (0),
//
}
+// =======================================================================
+// 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)
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;
}
{
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,
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;
// generate new id
glEnable (GL_TEXTURE_2D);
- if (!IsValidTexture())
+ if (!isValidTexture())
{
glGenTextures (1, &myGlTextureId); // Create The Texture
}
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;
}
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
+}
// 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 <OpenGl_Context.hxx>
#include <OpenGl_ExtFBO.hxx>
+#include <OpenGl_Resource.hxx>
#include <Standard_Boolean.hxx>
#include <InterfaceGraphic.hxx>
-class OpenGl_FrameBuffer
+//! Class implements FrameBuffer Object (FBO) resource
+//! intended for off-screen rendering.
+class OpenGl_FrameBuffer : public OpenGl_Resource
{
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
//! 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)
//! 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
#include <Graphic3d_GraphicDriver.hxx>
#include <Handle_OpenGl_GraphicDriver.hxx>
+#include <Handle_OpenGl_Display.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_PrinterContext.hxx>
private:
+ Handle(OpenGl_Display) myGlDisplay;
Handle(OpenGl_Caps) myCaps;
NCollection_DataMap<Standard_Integer, Handle(OpenGl_View)> myMapOfView;
NCollection_DataMap<Standard_Integer, Handle(OpenGl_Workspace)> myMapOfWS;
myDisplayConnection = theDisplayConnection;
try
{
- openglDisplay = new OpenGl_Display (myDisplayConnection);
+ myGlDisplay = new OpenGl_Display (myDisplayConnection);
return Standard_True;
}
catch (Standard_Failure)
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)
Standard_Integer OpenGl_GraphicDriver::InquireViewLimit ()
{
- return (openglDisplay.IsNull()? 0 : openglDisplay->Facilities().MaxViews);
+ return (myGlDisplay.IsNull() ? 0 : myGlDisplay->Facilities().MaxViews);
}
Standard_Integer OpenGl_GraphicDriver::InquirePlaneLimit ()
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)
{
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)
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);
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;
}
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;
}
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.
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)
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;
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);
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;
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)
{
// 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);
}
}
// 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)
{
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);
}
}
// 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)
{
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);
}
}
// 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);
}
}
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 * );
{
if (myBitmapList != 0)
{
- glDeleteLists (myBitmapList, 1);
+ if (theGlCtx->IsValid())
+ {
+ glDeleteLists (myBitmapList, 1);
+ }
myBitmapList = 0;
}
{
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())
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);
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))
{
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();
}
DrawArray (aFrontLightingModel,
- anAspectFace->InteriorStyle,
- anAspectFace->Edge,
+ anAspectFace->InteriorStyle(),
+ anAspectFace->Edge(),
anInteriorColor,
aLineColor,
anEdgeColor,
- &anAspectFace->IntFront,
+ &anAspectFace->IntFront(),
theWorkspace);
}
// 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);
}
// =======================================================================
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);
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);
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;
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;
}
/*----------------------------------------------------------------------*/
//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;
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
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;
#include <OpenGl_Light.hxx>
#include <Handle_OpenGl_Context.hxx>
+#include <Handle_OpenGl_Display.hxx>
#include <Handle_OpenGl_Workspace.hxx>
#include <Handle_OpenGl_View.hxx>
#include <Handle_OpenGl_Texture.hxx>
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);
// =======================================================================
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();
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
}
if (!aViewBuffer)
{
- aFrameBuffer->Release (GetGlContext());
+ aFrameBuffer->Release (GetGlContext().operator->());
aViewBuffer = NULL;
aViewImage = NULL;
}
{
if (hViewBitmap)
DeleteObject (hViewBitmap);
- aFrameBuffer->Release (GetGlContext());
+ aFrameBuffer->Release (GetGlContext().operator->());
hViewBitmap = NULL;
}
else
{
myPrintContext->SetScale ((GLfloat )aFrameWidth /viewWidth,
(GLfloat )aFrameHeight/viewHeight);
- aFrameBuffer->SetupViewport ();
+ aFrameBuffer->SetupViewport (GetGlContext());
Redraw1(ACView, ACUnderLayer, ACOverLayer, 0);
if (!myTransientDrawToFront)
{
aFrameHeight;
// draw to the offscreen buffer and capture the result
- aFrameBuffer->SetupViewport ();
+ aFrameBuffer->SetupViewport (GetGlContext());
Redraw1(ACView, ACUnderLayer, ACOverLayer, 0);
if (!myTransientDrawToFront)
{
}
else
{
- aFrameBuffer->Release (GetGlContext ());
+ aFrameBuffer->Release (GetGlContext().operator->());
delete aFrameBuffer;
}
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;
}
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;
}
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)
{
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:
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);
}
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)
{
}
// 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
{
#include <OpenGl_Display.hxx>
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,
}
/* 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 )
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;
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;
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);
}
-
#define OPENGL_TELEM_VIEW_H
#include <InterfaceGraphic_tgl_all.hxx>
+#include <Handle_OpenGl_Display.hxx>
typedef struct
{
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