]> git.mxchange.org Git - simgear.git/commitdiff
Fix a texture state problem that caused clouds to occasionally flash all white.
authorcurt <curt>
Thu, 3 Oct 2002 18:44:34 +0000 (18:44 +0000)
committercurt <curt>
Thu, 3 Oct 2002 18:44:34 +0000 (18:44 +0000)
simgear/scene/sky/clouds3d/SkyMaterial.cpp
simgear/scene/sky/clouds3d/SkyMaterial.hpp
simgear/scene/sky/clouds3d/SkyRenderableInstanceCloud.cpp
simgear/scene/sky/clouds3d/SkySceneManager.cpp
simgear/scene/sky/clouds3d/SkyTextureState.cpp
simgear/scene/sky/clouds3d/SkyTextureState.hpp

index 7b6aaa7a5f4f50c9bb1a727bfd83ca1e405764b2..30e95a86aef9ed03f4601433596fd6c5c82bf189 100644 (file)
@@ -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;
+}
+
+
index 27f570e218389b94149642d2dadf3168828dcf19..feae9e3700b93c6d4336702b45a924996c1c330d 100644 (file)
@@ -51,6 +51,7 @@ public:
   ~SkyMaterial();
   
   SKYRESULT     Activate();
+  SKYRESULT     Force();
 
   // Getters for basic material properties
 
index df4650e1c022cb9f97c9dab6dee0e58f7a083f5e..6abe46506f6d4cfade0e756025610d3bfbdd152f 100644 (file)
@@ -239,8 +239,10 @@ SKYRESULT SkyRenderableInstanceCloud::Display(bool bDisplayFrontOfSplit /* = fal
   }
   else
   {//cout << "Using impostor image\n";
-    if (!_pBackTexture || (bDisplayFrontOfSplit && !_pFrontTexture))
-      FAIL_RETURN_MSG(SKYRESULT_FAIL, "SkyRenderableInstanceCloud::Display(): missing texture!");
+      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;
     
index 722a0eda2a7eee5b92cb0db56141da2b1ca99317..9569f952224122b68aaf3e647b22b2cb829e03ae 100644 (file)
@@ -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);
 
index 5844ff7d823b0d92f1f2e707a8e1d5b47dd37686..16d33704540385810cb2c0c492f2d88c53dc3fd7 100644 (file)
@@ -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     : 
index 24312919315c381de6e40efe38acd0c59e0da6ff..91c7de26044e1bac5dca748e4f65eea67328adf8 100644 (file)
@@ -41,6 +41,7 @@ public: // methods
        SkyTextureState();
        ~SkyTextureState();
 
+  SKYRESULT Force();
   SKYRESULT Activate();
 
   SKYRESULT SetTexture(unsigned int iTextureUnit, GLenum eTarget, SkyTexture& texture);