myGlContext->SetLineWidth (myDefaultAspectLine.Aspect()->Width());
}
-// =======================================================================
-// function : DisableTexture
-// purpose :
-// =======================================================================
-Handle(OpenGl_Texture) OpenGl_Workspace::DisableTexture()
-{
- if (myTextureBound.IsNull())
- {
- return myTextureBound;
- }
-
- const Handle(OpenGl_Sampler)& aSampler = myGlContext->TextureSampler();
- if (!aSampler.IsNull())
- {
- aSampler->Unbind (*myGlContext);
- }
-
-#if !defined(GL_ES_VERSION_2_0)
- // reset texture matrix because some code may expect it is identity
- if (myGlContext->core11 != NULL)
- {
- GLint aMatrixMode = GL_TEXTURE;
- glGetIntegerv (GL_MATRIX_MODE, &aMatrixMode);
- glMatrixMode (GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode (aMatrixMode);
- }
-#endif
-
- myTextureBound->Unbind (myGlContext);
- switch (myTextureBound->GetTarget())
- {
- #if !defined(GL_ES_VERSION_2_0)
- case GL_TEXTURE_1D:
- {
- if (myGlContext->core11 != NULL)
- {
- if (myTextureBound->GetParams()->GenMode() != GL_NONE)
- {
- glDisable (GL_TEXTURE_GEN_S);
- }
- glDisable (GL_TEXTURE_1D);
- }
- break;
- }
- #endif
- case GL_TEXTURE_2D:
- {
- #if !defined(GL_ES_VERSION_2_0)
- if (myGlContext->core11 != NULL)
- {
- if (myTextureBound->GetParams()->GenMode() != GL_NONE)
- {
- glDisable (GL_TEXTURE_GEN_S);
- glDisable (GL_TEXTURE_GEN_T);
- if (myTextureBound->GetParams()->GenMode() == Graphic3d_TOTM_SPRITE)
- {
- glDisable (GL_POINT_SPRITE);
- }
- }
- glDisable (GL_TEXTURE_2D);
- }
- #endif
- break;
- }
- default: break;
- }
-
- Handle(OpenGl_Texture) aPrevTexture = myTextureBound;
- myTextureBound.Nullify();
- return aPrevTexture;
-}
-
-// =======================================================================
-// function : setTextureParams
-// purpose :
-// =======================================================================
-void OpenGl_Workspace::setTextureParams (Handle(OpenGl_Texture)& theTexture,
- const Handle(Graphic3d_TextureParams)& theParams)
-{
- const Handle(Graphic3d_TextureParams)& aParams = theParams.IsNull() ? theTexture->GetParams() : theParams;
- if (aParams.IsNull())
- {
- return;
- }
-
-#if !defined(GL_ES_VERSION_2_0)
- if (myGlContext->core11 != NULL)
- {
- GLint anEnvMode = GL_MODULATE; // lighting mode
- if (!aParams->IsModulate())
- {
- anEnvMode = GL_DECAL;
- if (theTexture->GetFormat() == GL_ALPHA
- || theTexture->GetFormat() == GL_LUMINANCE)
- {
- anEnvMode = GL_REPLACE;
- }
- }
-
- // setup generation of texture coordinates
- switch (aParams->GenMode())
- {
- case Graphic3d_TOTM_OBJECT:
- {
- glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
- glTexGenfv (GL_S, GL_OBJECT_PLANE, aParams->GenPlaneS().GetData());
- if (theTexture->GetTarget() != GL_TEXTURE_1D)
- {
- glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
- glTexGenfv (GL_T, GL_OBJECT_PLANE, aParams->GenPlaneT().GetData());
- }
- break;
- }
- case Graphic3d_TOTM_SPHERE:
- {
- glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
- if (theTexture->GetTarget() != GL_TEXTURE_1D)
- {
- glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
- }
- break;
- }
- case Graphic3d_TOTM_EYE:
- {
- myGlContext->WorldViewState.Push();
-
- myGlContext->WorldViewState.SetIdentity();
- myGlContext->ApplyWorldViewMatrix();
-
- glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
- glTexGenfv (GL_S, GL_EYE_PLANE, aParams->GenPlaneS().GetData());
-
- if (theTexture->GetTarget() != GL_TEXTURE_1D)
- {
- glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
- glTexGenfv (GL_T, GL_EYE_PLANE, aParams->GenPlaneT().GetData());
- }
-
- myGlContext->WorldViewState.Pop();
-
- break;
- }
- case Graphic3d_TOTM_SPRITE:
- {
- if (myGlContext->core20fwd != NULL)
- {
- glEnable (GL_POINT_SPRITE);
- glTexEnvi (GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
- anEnvMode = GL_REPLACE;
- }
- break;
- }
- case Graphic3d_TOTM_MANUAL:
- default: break;
- }
-
- // setup lighting
- glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, anEnvMode);
- }
-#endif
-
- // get active sampler object to override default texture parameters
- const Handle(OpenGl_Sampler)& aSampler = myGlContext->TextureSampler();
-
- // setup texture filtering and wrapping
- //if (theTexture->GetParams() != theParams)
- const GLenum aFilter = (aParams->Filter() == Graphic3d_TOTF_NEAREST) ? GL_NEAREST : GL_LINEAR;
- const GLenum aWrapMode = aParams->IsRepeat() ? GL_REPEAT : myGlContext->TextureWrapClamp();
- switch (theTexture->GetTarget())
- {
- #if !defined(GL_ES_VERSION_2_0)
- case GL_TEXTURE_1D:
- {
- if (aSampler.IsNull() || !aSampler->IsValid())
- {
- glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, aFilter);
- glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, aFilter);
- glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, aWrapMode);
- }
- else
- {
- aSampler->SetParameter (*myGlContext, GL_TEXTURE_MAG_FILTER, aFilter);
- aSampler->SetParameter (*myGlContext, GL_TEXTURE_MIN_FILTER, aFilter);
- aSampler->SetParameter (*myGlContext, GL_TEXTURE_WRAP_S, aWrapMode);
- }
-
- break;
- }
- #endif
- case GL_TEXTURE_2D:
- {
- GLenum aFilterMin = aFilter;
- if (theTexture->HasMipmaps())
- {
- aFilterMin = GL_NEAREST_MIPMAP_NEAREST;
- if (aParams->Filter() == Graphic3d_TOTF_BILINEAR)
- {
- aFilterMin = GL_LINEAR_MIPMAP_NEAREST;
- }
- else if (aParams->Filter() == Graphic3d_TOTF_TRILINEAR)
- {
- aFilterMin = GL_LINEAR_MIPMAP_LINEAR;
- }
-
- if (myGlContext->extAnis)
- {
- // setup degree of anisotropy filter
- const GLint aMaxDegree = myGlContext->MaxDegreeOfAnisotropy();
- GLint aDegree;
- switch (aParams->AnisoFilter())
- {
- case Graphic3d_LOTA_QUALITY:
- {
- aDegree = aMaxDegree;
- break;
- }
- case Graphic3d_LOTA_MIDDLE:
- {
- aDegree = (aMaxDegree <= 4) ? 2 : (aMaxDegree / 2);
- break;
- }
- case Graphic3d_LOTA_FAST:
- {
- aDegree = 2;
- break;
- }
- case Graphic3d_LOTA_OFF:
- default:
- {
- aDegree = 1;
- break;
- }
- }
-
- if (aSampler.IsNull() || !aSampler->IsValid())
- {
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aDegree);
- }
- else
- {
- aSampler->SetParameter (*myGlContext, GL_TEXTURE_MAX_ANISOTROPY_EXT, aDegree);
- }
- }
- }
-
- if (aSampler.IsNull() || !aSampler->IsValid())
- {
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, aFilterMin);
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, aFilter);
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, aWrapMode);
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, aWrapMode);
- }
- else
- {
- aSampler->SetParameter (*myGlContext, GL_TEXTURE_MIN_FILTER, aFilterMin);
- aSampler->SetParameter (*myGlContext, GL_TEXTURE_MAG_FILTER, aFilter);
- aSampler->SetParameter (*myGlContext, GL_TEXTURE_WRAP_S, aWrapMode);
- aSampler->SetParameter (*myGlContext, GL_TEXTURE_WRAP_T, aWrapMode);
- }
-
- break;
- }
- default: break;
- }
-
- switch (theTexture->GetTarget())
- {
- #if !defined(GL_ES_VERSION_2_0)
- case GL_TEXTURE_1D:
- {
- if (myGlContext->core11 != NULL)
- {
- if (aParams->GenMode() != Graphic3d_TOTM_MANUAL)
- {
- glEnable (GL_TEXTURE_GEN_S);
- }
- glEnable (GL_TEXTURE_1D);
- }
- break;
- }
- #endif
- case GL_TEXTURE_2D:
- {
- #if !defined(GL_ES_VERSION_2_0)
- if (myGlContext->core11 != NULL)
- {
- if (aParams->GenMode() != Graphic3d_TOTM_MANUAL)
- {
- glEnable (GL_TEXTURE_GEN_S);
- glEnable (GL_TEXTURE_GEN_T);
- }
- glEnable (GL_TEXTURE_2D);
- }
- #endif
- break;
- }
- default: break;
- }
-
- theTexture->SetParams (aParams);
-}
-
-// =======================================================================
-// function : EnableTexture
-// purpose :
-// =======================================================================
-Handle(OpenGl_Texture) OpenGl_Workspace::EnableTexture (const Handle(OpenGl_Texture)& theTexture,
- const Handle(Graphic3d_TextureParams)& theParams)
-{
- if (theTexture.IsNull() || !theTexture->IsValid())
- {
- return DisableTexture();
- }
-
- if (myTextureBound == theTexture
- && (theParams.IsNull() || theParams == theTexture->GetParams()))
- {
- // already bound
- return myTextureBound;
- }
-
- Handle(OpenGl_Texture) aPrevTexture = DisableTexture();
- myTextureBound = theTexture;
- myTextureBound->Bind (myGlContext);
- setTextureParams (myTextureBound, theParams);
-
- // If custom sampler object is available it will be
- // used for overriding default texture parameters
- const Handle(OpenGl_Sampler)& aSampler = myGlContext->TextureSampler();
-
- if (!aSampler.IsNull() && aSampler->IsValid())
- {
- aSampler->Bind (*myGlContext);
- }
-
- return aPrevTexture;
-}
-
// =======================================================================
// function : SetAspectLine
// purpose :
if (myAspectFaceSet->Aspect()->ToMapTexture())
{
- EnableTexture (myAspectFaceSet->TextureRes (myGlContext),
- myAspectFaceSet->TextureParams());
+ myGlContext->BindTextures (myAspectFaceSet->TextureSet (myGlContext));
}
else
{
- if (!myEnvironmentTexture.IsNull())
- {
- EnableTexture (myEnvironmentTexture,
- myEnvironmentTexture->GetParams());
- }
- else
- {
- DisableTexture();
- }
+ myGlContext->BindTextures (myEnvironmentTexture);
}
myAspectFaceApplied = myAspectFaceSet->Aspect();
if (!Activate())
return Handle(OpenGl_FrameBuffer)();
- DisableTexture();
-
// create the FBO
const Handle(OpenGl_Context)& aCtx = GetGlContext();
+ aCtx->BindTextures (Handle(OpenGl_TextureSet)());
Handle(OpenGl_FrameBuffer) aFrameBuffer = new OpenGl_FrameBuffer();
if (!aFrameBuffer->Init (aCtx, theWidth, theHeight, GL_RGBA8, GL_DEPTH24_STENCIL8, 0))
{