#include <OpenGl_Context.hxx>
#include <OpenGl_Sampler.hxx>
-#include <OpenGl_Texture.hxx>
+#include <OpenGl_PointSprite.hxx>
#include <OpenGl_TextureSet.hxx>
#include <Graphic3d_TextureParams.hxx>
// =======================================================================
void OpenGl_AspectsTextureSet::Release (OpenGl_Context* theCtx)
{
- if (myTextures.IsNull())
+ if (myTextures[0].IsNull())
{
return;
}
- for (OpenGl_TextureSet::Iterator aTextureIter (myTextures); aTextureIter.More(); aTextureIter.Next())
+ if (!myTextures[1].IsNull())
+ {
+ // ReleaseResource() will have no effect until nullifying all copies
+ myTextures[1]->InitZero();
+ }
+
+ for (OpenGl_TextureSet::Iterator aTextureIter (myTextures[0]); aTextureIter.More(); aTextureIter.Next())
{
Handle(OpenGl_Texture)& aTextureRes = aTextureIter.ChangeValue();
if (aTextureRes.IsNull())
}
else
{
+ // OpenGl_PointSprite will be actually released later by OpenGl_AspectsSprite,
+ // see order OpenGl_Aspects::Release()
const TCollection_AsciiString aName = aTextureRes->ResourceId();
aTextureRes.Nullify(); // we need nullify all handles before ReleaseResource() call
theCtx->ReleaseResource (aName, Standard_True);
// function : UpdateRediness
// purpose :
// =======================================================================
-void OpenGl_AspectsTextureSet::UpdateRediness (const Handle(Graphic3d_TextureSet)& theTextures)
+void OpenGl_AspectsTextureSet::UpdateRediness (const Handle(Graphic3d_Aspects)& theAspect)
{
- const Standard_Integer aNbTexturesOld = !myTextures.IsNull() ? myTextures->Size() : 0;
- const Standard_Integer aNbTexturesNew = !theTextures.IsNull() ? theTextures->Size() : 0;
+ const Handle(Graphic3d_TextureSet)& aNewTextureSet = theAspect->TextureSet();
+
+ const Standard_Integer aNbTexturesOld = !myTextures[0].IsNull() ? myTextures[0]->Size() : 0;
+ Standard_Integer aNbTexturesNew = !aNewTextureSet.IsNull() && theAspect->ToMapTexture()
+ ? aNewTextureSet->Size()
+ : 0;
+ if (theAspect->IsMarkerSprite())
+ {
+ ++aNbTexturesNew;
+ }
+
if (aNbTexturesOld != aNbTexturesNew)
{
myIsTextureReady = Standard_False;
return;
}
- if (aNbTexturesOld == 0)
+ if (aNbTexturesOld == 0
+ || !theAspect->ToMapTexture())
{
return;
}
- Graphic3d_TextureSet::Iterator aTextureIter (theTextures);
- OpenGl_TextureSet::Iterator aResIter (myTextures);
- for (; aResIter.More(); aResIter.Next(), aTextureIter.Next())
+ Graphic3d_TextureSet::Iterator aTextureIter (aNewTextureSet);
+ OpenGl_TextureSet::Iterator aResIter (myTextures[0]);
+ for (; aTextureIter.More(); aResIter.Next(), aTextureIter.Next())
{
const Handle(OpenGl_Texture)& aResource = aResIter.Value();
const Handle(Graphic3d_TextureMap)& aTexture = aTextureIter.Value();
// purpose :
// =======================================================================
void OpenGl_AspectsTextureSet::build (const Handle(OpenGl_Context)& theCtx,
- const Handle(Graphic3d_TextureSet)& theTextures)
+ const Handle(Graphic3d_Aspects)& theAspect,
+ const Handle(OpenGl_PointSprite)& theSprite,
+ const Handle(OpenGl_PointSprite)& theSpriteA)
{
+ const Handle(Graphic3d_TextureSet)& aNewTextureSet = theAspect->TextureSet();
+
+ const bool hasSprite = theAspect->IsMarkerSprite();
+ const Standard_Integer aNbTexturesOld = !myTextures[0].IsNull() ? myTextures[0]->Size() : 0;
+ Standard_Integer aNbTexturesNew = !aNewTextureSet.IsNull() && theAspect->ToMapTexture()
+ ? aNewTextureSet->Size()
+ : 0;
+ if (hasSprite)
+ {
+ ++aNbTexturesNew;
+ }
+
// release old texture resources
- const Standard_Integer aNbTexturesOld = !myTextures.IsNull() ? myTextures->Size() : 0;
- const Standard_Integer aNbTexturesNew = !theTextures.IsNull() ? theTextures->Size() : 0;
if (aNbTexturesOld != aNbTexturesNew)
{
Release (theCtx.get());
if (aNbTexturesNew > 0)
{
- myTextures = new OpenGl_TextureSet (theTextures->Size());
+ myTextures[0] = new OpenGl_TextureSet (aNbTexturesNew);
}
else
{
- myTextures.Nullify();
+ myTextures[0].Nullify();
+ myTextures[1].Nullify();
}
}
- if (myTextures.IsNull())
+ if (myTextures[0].IsNull())
{
return;
}
- Graphic3d_TextureSet::Iterator aTextureIter (theTextures);
- OpenGl_TextureSet::Iterator aResIter (myTextures);
- for (; aResIter.More(); aResIter.Next(), aTextureIter.Next())
+ if (theSprite == theSpriteA)
+ {
+ myTextures[1].Nullify();
+ }
+ else
{
- Handle(OpenGl_Texture)& aResource = aResIter.ChangeValue();
- const Handle(Graphic3d_TextureMap)& aTexture = aTextureIter.Value();
- if (!aResource.IsNull())
+ if (myTextures[1].IsNull()
+ || myTextures[1]->Size() != myTextures[0]->Size())
{
- if (!aTexture.IsNull()
- && aTexture->GetId() == aResource->ResourceId()
- && aTexture->Revision() != aResource->Revision())
- {
- if (Handle(Image_PixMap) anImage = aTexture->GetImage())
- {
- aResource->Sampler()->SetParameters (aTexture->GetParams());
- aResource->Init (theCtx, *anImage.operator->(), aTexture->Type());
- aResource->SetRevision (aTexture->Revision());
- continue;
- }
- }
-
- if (aResource->ResourceId().IsEmpty())
- {
- theCtx->DelayedRelease (aResource);
- aResource.Nullify();
- }
- else
- {
- const TCollection_AsciiString aTextureKey = aResource->ResourceId();
- aResource.Nullify(); // we need nullify all handles before ReleaseResource() call
- theCtx->ReleaseResource (aTextureKey, Standard_True);
- }
+ myTextures[1] = new OpenGl_TextureSet (aNbTexturesNew);
}
+ else
+ {
+ myTextures[1]->InitZero();
+ }
+ }
- if (!aTexture.IsNull())
+ if (theAspect->ToMapTexture())
+ {
+ Graphic3d_TextureSet::Iterator aTextureIter (aNewTextureSet);
+ OpenGl_TextureSet::Iterator aResIter0 (myTextures[0]);
+ for (; aTextureIter.More(); aResIter0.Next(), aTextureIter.Next())
{
- const TCollection_AsciiString& aTextureKeyNew = aTexture->GetId();
- if (aTextureKeyNew.IsEmpty()
- || !theCtx->GetResource<Handle(OpenGl_Texture)> (aTextureKeyNew, aResource))
+ Handle(OpenGl_Texture)& aResource = aResIter0.ChangeValue();
+ const Handle(Graphic3d_TextureMap)& aTexture = aTextureIter.Value();
+ if (!aResource.IsNull())
{
- aResource = new OpenGl_Texture (aTextureKeyNew, aTexture->GetParams());
- if (Handle(Image_PixMap) anImage = aTexture->GetImage())
+ if (!aTexture.IsNull()
+ && aTexture->GetId() == aResource->ResourceId()
+ && aTexture->Revision() != aResource->Revision())
{
- aResource->Init (theCtx, *anImage.operator->(), aTexture->Type());
- aResource->SetRevision (aTexture->Revision());
+ if (Handle(Image_PixMap) anImage = aTexture->GetImage())
+ {
+ aResource->Sampler()->SetParameters (aTexture->GetParams());
+ aResource->Init (theCtx, *anImage.operator->(), aTexture->Type());
+ aResource->SetRevision (aTexture->Revision());
+ continue;
+ }
+ }
+
+ if (aResource->ResourceId().IsEmpty())
+ {
+ theCtx->DelayedRelease (aResource);
+ aResource.Nullify();
}
- if (!aTextureKeyNew.IsEmpty())
+ else
{
- theCtx->ShareResource (aTextureKeyNew, aResource);
+ const TCollection_AsciiString aTextureKey = aResource->ResourceId();
+ aResource.Nullify(); // we need nullify all handles before ReleaseResource() call
+ theCtx->ReleaseResource (aTextureKey, Standard_True);
}
}
- else
+
+ if (!aTexture.IsNull())
{
- if (aTexture->Revision() != aResource->Revision())
+ const TCollection_AsciiString& aTextureKeyNew = aTexture->GetId();
+ if (aTextureKeyNew.IsEmpty()
+ || !theCtx->GetResource<Handle(OpenGl_Texture)> (aTextureKeyNew, aResource))
{
+ aResource = new OpenGl_Texture (aTextureKeyNew, aTexture->GetParams());
if (Handle(Image_PixMap) anImage = aTexture->GetImage())
{
aResource->Init (theCtx, *anImage.operator->(), aTexture->Type());
aResource->SetRevision (aTexture->Revision());
}
+ if (!aTextureKeyNew.IsEmpty())
+ {
+ theCtx->ShareResource (aTextureKeyNew, aResource);
+ }
+ }
+ else
+ {
+ if (aTexture->Revision() != aResource->Revision())
+ {
+ if (Handle(Image_PixMap) anImage = aTexture->GetImage())
+ {
+ aResource->Init (theCtx, *anImage.operator->(), aTexture->Type());
+ aResource->SetRevision (aTexture->Revision());
+ }
+ }
+ aResource->Sampler()->SetParameters (aTexture->GetParams());
}
- aResource->Sampler()->SetParameters (aTexture->GetParams());
}
}
}
+
+ if (hasSprite)
+ {
+ myTextures[0]->ChangeLast() = theSprite;
+ if (!theSprite.IsNull())
+ {
+ theSprite ->Sampler()->Parameters()->SetTextureUnit (theCtx->SpriteTextureUnit());
+ }
+ if (!theSpriteA.IsNull())
+ {
+ theSpriteA->Sampler()->Parameters()->SetTextureUnit (theCtx->SpriteTextureUnit());
+ }
+ }
+ if (myTextures[1].IsNull())
+ {
+ return;
+ }
+
+ for (OpenGl_TextureSet::Iterator aResIter0 (myTextures[0]), aResIter1 (myTextures[1]); aResIter0.More(); aResIter0.Next(), aResIter1.Next())
+ {
+ aResIter1.ChangeValue() = aResIter0.Value();
+ }
+ if (hasSprite)
+ {
+ myTextures[1]->ChangeLast() = theSpriteA;
+ }
}