Fix a texture state problem that caused clouds to occasionally flash all white.
This commit is contained in:
parent
f08ae9f2ea
commit
1fd63c30e9
@ -320,3 +320,126 @@ SKYRESULT SkyMaterial::Activate()
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Function : SkyMaterial::Force
|
||||
// Description :
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
* @fn SkyMaterial::Force()
|
||||
* @brief @todo <WRITE BRIEF SkyMaterial::SetMaterialPropertiesForDisplay DOCUMENTATION>
|
||||
*
|
||||
* @todo <WRITE EXTENDED SkyMaterial::SetMaterialPropertiesForDisplay FUNCTION DOCUMENTATION>
|
||||
*/
|
||||
SKYRESULT SkyMaterial::Force()
|
||||
{
|
||||
// Update the cached current material, and only pass values that have changed to the GL.
|
||||
|
||||
SkyMaterial *pCurrentMaterial = GraphicsContext::InstancePtr()->GetCurrentMaterial();
|
||||
assert(NULL != pCurrentMaterial);
|
||||
|
||||
// basic material properties
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &(GetDiffuse().x));
|
||||
pCurrentMaterial->SetDiffuse(GetDiffuse());
|
||||
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &(GetSpecular().x));
|
||||
pCurrentMaterial->SetSpecular(GetSpecular());
|
||||
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &(GetAmbient().x));
|
||||
pCurrentMaterial->SetAmbient(GetAmbient());
|
||||
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &(GetEmissive().x));
|
||||
pCurrentMaterial->SetEmissive(GetEmissive());
|
||||
|
||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, GetSpecularPower());
|
||||
pCurrentMaterial->SetSpecularPower(GetSpecularPower());
|
||||
|
||||
// lighting
|
||||
if (IsLightingEnabled())
|
||||
glEnable(GL_LIGHTING);
|
||||
else
|
||||
glDisable(GL_LIGHTING);
|
||||
pCurrentMaterial->EnableLighting(IsLightingEnabled());
|
||||
|
||||
// color material (which material property tracks color calls)
|
||||
glColorMaterial(GetColorMaterialFace(), GetColorMaterialMode());
|
||||
pCurrentMaterial->SetColorMaterialFace(GetColorMaterialFace());
|
||||
pCurrentMaterial->SetColorMaterialMode(GetColorMaterialMode());
|
||||
|
||||
if (IsColorMaterialEnabled())
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
else
|
||||
glDisable(GL_COLOR_MATERIAL);
|
||||
pCurrentMaterial->EnableColorMaterial(IsColorMaterialEnabled());
|
||||
|
||||
// fog
|
||||
glFogf(GL_FOG_MODE, GetFogMode());
|
||||
pCurrentMaterial->SetFogMode(GetFogMode());
|
||||
|
||||
glFogfv(GL_FOG_COLOR, GetFogColor());
|
||||
pCurrentMaterial->SetFogColor(GetFogColor());
|
||||
|
||||
glFogf(GL_FOG_DENSITY, GetFogParameter(GL_FOG_DENSITY));
|
||||
pCurrentMaterial->SetFogParameter(GL_FOG_DENSITY, GetFogParameter(GL_FOG_DENSITY));
|
||||
|
||||
glFogf(GL_FOG_START, GetFogParameter(GL_FOG_START));
|
||||
pCurrentMaterial->SetFogParameter(GL_FOG_START, GetFogParameter(GL_FOG_START));
|
||||
glFogf(GL_FOG_END, GetFogParameter(GL_FOG_END));
|
||||
pCurrentMaterial->SetFogParameter(GL_FOG_END, GetFogParameter(GL_FOG_END));
|
||||
|
||||
if (IsFogEnabled())
|
||||
glEnable(GL_FOG);
|
||||
else
|
||||
glDisable(GL_FOG);
|
||||
pCurrentMaterial->EnableFog(IsFogEnabled());
|
||||
|
||||
// depth test
|
||||
glDepthFunc(GetDepthFunc());
|
||||
pCurrentMaterial->SetDepthFunc(GetDepthFunc());
|
||||
|
||||
glDepthMask(GetDepthMask());
|
||||
pCurrentMaterial->SetDepthMask(GetDepthMask());
|
||||
|
||||
if (IsDepthTestEnabled())
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
else
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
pCurrentMaterial->EnableDepthTest(IsDepthTestEnabled());
|
||||
|
||||
// alpha test
|
||||
glAlphaFunc(GetAlphaFunc(), GetAlphaRef());
|
||||
pCurrentMaterial->SetAlphaFunc(GetAlphaFunc());
|
||||
pCurrentMaterial->SetAlphaRef(GetAlphaRef());
|
||||
|
||||
if (IsAlphaTestEnabled())
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
else
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
|
||||
// blending
|
||||
glBlendFunc(GetBlendingSourceFactor(), GetBlendingDestFactor());
|
||||
pCurrentMaterial->SetBlendFunc(GetBlendingSourceFactor(), GetBlendingDestFactor());
|
||||
|
||||
if (IsBlendingEnabled())
|
||||
glEnable(GL_BLEND);
|
||||
else
|
||||
glDisable(GL_BLEND);
|
||||
pCurrentMaterial->EnableBlending(IsBlendingEnabled());
|
||||
|
||||
glCullFace(GetFaceCullingMode());
|
||||
pCurrentMaterial->SetFaceCullingMode(GetFaceCullingMode());
|
||||
|
||||
if (IsFaceCullingEnabled())
|
||||
glEnable(GL_CULL_FACE);
|
||||
else
|
||||
glDisable(GL_CULL_FACE);
|
||||
pCurrentMaterial->EnableFaceCulling(IsFaceCullingEnabled());
|
||||
|
||||
// texturing
|
||||
FAIL_RETURN(_textureState.Force());
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GetTextureApplicationMode());
|
||||
pCurrentMaterial->SetTextureApplicationMode(GetTextureApplicationMode());
|
||||
|
||||
return SKYRESULT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
~SkyMaterial();
|
||||
|
||||
SKYRESULT Activate();
|
||||
SKYRESULT Force();
|
||||
|
||||
// Getters for basic material properties
|
||||
|
||||
|
@ -239,8 +239,10 @@ SKYRESULT SkyRenderableInstanceCloud::Display(bool bDisplayFrontOfSplit /* = fal
|
||||
}
|
||||
else
|
||||
{//cout << "Using impostor image\n";
|
||||
if (!_pBackTexture || (bDisplayFrontOfSplit && !_pFrontTexture))
|
||||
if (!_pBackTexture || (bDisplayFrontOfSplit && !_pFrontTexture)) {
|
||||
cout << "texture id failure" << endl;
|
||||
FAIL_RETURN_MSG(SKYRESULT_FAIL, "SkyRenderableInstanceCloud::Display(): missing texture!");
|
||||
}
|
||||
|
||||
s_pMaterial->SetTexture(0, GL_TEXTURE_2D, bDisplayFrontOfSplit ? *_pFrontTexture : *_pBackTexture);
|
||||
if (_bScreenImpostor)
|
||||
@ -264,6 +266,7 @@ SKYRESULT SkyRenderableInstanceCloud::Display(bool bDisplayFrontOfSplit /* = fal
|
||||
}
|
||||
|
||||
s_pMaterial->Activate();
|
||||
// s_pMaterial->Force();
|
||||
|
||||
Vec3f x, y, z;
|
||||
|
||||
|
@ -397,6 +397,7 @@ SKYRESULT SkySceneManager::Update(const Camera &cam)
|
||||
SKYRESULT SkySceneManager::Display( const Camera &cam )
|
||||
|
||||
{
|
||||
// _clearMaterial.Force();
|
||||
_clearMaterial.Activate();
|
||||
//glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
@ -106,12 +106,12 @@ SKYRESULT SkyTextureState::Activate()
|
||||
{
|
||||
GLenum eTarget = GetActiveTarget(i);
|
||||
unsigned int iID = GetTextureID(i);
|
||||
if ((pCurrent->GetActiveTarget(i) != eTarget) ||
|
||||
(pCurrent->GetTextureID(i) != iID))
|
||||
{
|
||||
// if ((pCurrent->GetActiveTarget(i) != eTarget) ||
|
||||
// (pCurrent->GetTextureID(i) != iID))
|
||||
// {
|
||||
FAIL_RETURN(pCurrent->SetTexture(i, eTarget, iID));
|
||||
glBindTexture(eTarget, iID);
|
||||
}
|
||||
// }
|
||||
//GLVU::CheckForGLError("SkyTextureState::Activate(5)");
|
||||
GLenum paramValue = GetTextureParameter(i, GL_TEXTURE_WRAP_S);
|
||||
if (pCurrent->GetTextureParameter(i, GL_TEXTURE_WRAP_S) != paramValue)
|
||||
@ -158,6 +158,76 @@ SKYRESULT SkyTextureState::Activate()
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Function : SkyTextureState::Force
|
||||
// Description :
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
* @fn SkyTextureState::Force()
|
||||
* @brief @todo <WRITE BRIEF SkyTextureState::Activate DOCUMENTATION>
|
||||
*
|
||||
* @todo <WRITE EXTENDED SkyTextureState::Activate FUNCTION DOCUMENTATION>
|
||||
*/
|
||||
SKYRESULT SkyTextureState::Force()
|
||||
{
|
||||
SkyTextureState *pCurrent = GraphicsContext::InstancePtr()->GetCurrentTextureState();
|
||||
assert(NULL != pCurrent);
|
||||
//GLVU::CheckForGLError("SkyTextureState::Activate(8)");
|
||||
for (unsigned int i = 0; i < s_iNumTextureUnits; ++i)
|
||||
{
|
||||
#ifdef GL_ARB_multitexture
|
||||
if (s_iNumTextureUnits > 1)
|
||||
glActiveTextureARB(GL_TEXTURE0_ARB + i);
|
||||
#endif
|
||||
bool bEnabled = IsTextureEnabled(i);
|
||||
FAIL_RETURN(pCurrent->EnableTexture(i, bEnabled));
|
||||
//GLVU::CheckForGLError("SkyTextureState::Activate(7)");
|
||||
if (bEnabled)
|
||||
glEnable(GetActiveTarget(i));
|
||||
else
|
||||
glDisable(GetActiveTarget(i));
|
||||
|
||||
//GLVU::CheckForGLError("SkyTextureState::Activate(6)");
|
||||
GLenum eTarget = GetActiveTarget(i);
|
||||
unsigned int iID = GetTextureID(i);
|
||||
|
||||
FAIL_RETURN(pCurrent->SetTexture(i, eTarget, iID));
|
||||
glBindTexture(eTarget, iID);
|
||||
|
||||
//GLVU::CheckForGLError("SkyTextureState::Activate(5)");
|
||||
GLenum paramValue = GetTextureParameter(i, GL_TEXTURE_WRAP_S);
|
||||
FAIL_RETURN(pCurrent->SetTextureParameter(i, GL_TEXTURE_WRAP_S, paramValue));
|
||||
glTexParameteri(eTarget, GL_TEXTURE_WRAP_S, paramValue);
|
||||
|
||||
//GLVU::CheckForGLError("SkyTextureState::Activate(4)");
|
||||
paramValue = GetTextureParameter(i, GL_TEXTURE_WRAP_T);
|
||||
FAIL_RETURN(pCurrent->SetTextureParameter(i, GL_TEXTURE_WRAP_T, paramValue));
|
||||
glTexParameteri(eTarget, GL_TEXTURE_WRAP_T, paramValue);
|
||||
|
||||
//GLVU::CheckForGLError("SkyTextureState::Activate(3)");
|
||||
paramValue = GetTextureParameter(i, GL_TEXTURE_WRAP_R);
|
||||
FAIL_RETURN(pCurrent->SetTextureParameter(i, GL_TEXTURE_WRAP_R, paramValue));
|
||||
glTexParameteri(eTarget, GL_TEXTURE_WRAP_R, paramValue);
|
||||
|
||||
//GLVU::CheckForGLError("SkyTextureState::Activate(2)");
|
||||
paramValue = GetTextureParameter(i, GL_TEXTURE_MIN_FILTER);
|
||||
FAIL_RETURN(pCurrent->SetTextureParameter(i, GL_TEXTURE_MIN_FILTER, paramValue));
|
||||
glTexParameteri(eTarget, GL_TEXTURE_MIN_FILTER, paramValue);
|
||||
|
||||
//GLVU::CheckForGLError("SkyTextureState::Activate(1)");
|
||||
paramValue = GetTextureParameter(i, GL_TEXTURE_MAG_FILTER);
|
||||
FAIL_RETURN(pCurrent->SetTextureParameter(i, GL_TEXTURE_MAG_FILTER, paramValue));
|
||||
glTexParameteri(eTarget, GL_TEXTURE_MIN_FILTER, paramValue);
|
||||
|
||||
#ifdef GL_ARB_multitexture
|
||||
if (s_iNumTextureUnits > 1)
|
||||
glActiveTextureARB(GL_TEXTURE0_ARB);
|
||||
#endif
|
||||
}
|
||||
return SKYRESULT_OK;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Function : SkyTextureState::SetTexture
|
||||
// Description :
|
||||
|
@ -41,6 +41,7 @@ public: // methods
|
||||
SkyTextureState();
|
||||
~SkyTextureState();
|
||||
|
||||
SKYRESULT Force();
|
||||
SKYRESULT Activate();
|
||||
|
||||
SKYRESULT SetTexture(unsigned int iTextureUnit, GLenum eTarget, SkyTexture& texture);
|
||||
|
Loading…
Reference in New Issue
Block a user