0031478: Visualization, TKOpenGl - allow uploading Cubemap in compressed DDS format...
[occt.git] / src / OpenGl / OpenGl_Sampler.cxx
index 6e7bb10..3ec1e07 100644 (file)
@@ -105,7 +105,7 @@ Standard_Boolean OpenGl_Sampler::Init (const Handle(OpenGl_Context)& theCtx,
     }
     else if (!myIsImmutable)
     {
-      applySamplerParams (theCtx, myParams, this, theTexture.GetTarget(), theTexture.HasMipmaps());
+      applySamplerParams (theCtx, myParams, this, theTexture.GetTarget(), theTexture.MaxMipmapLevel());
       return Standard_True;
     }
     Release (theCtx.get());
@@ -116,7 +116,7 @@ Standard_Boolean OpenGl_Sampler::Init (const Handle(OpenGl_Context)& theCtx,
     return Standard_False;
   }
 
-  applySamplerParams (theCtx, myParams, this, theTexture.GetTarget(), theTexture.HasMipmaps());
+  applySamplerParams (theCtx, myParams, this, theTexture.GetTarget(), theTexture.MaxMipmapLevel());
   return Standard_True;
 }
 
@@ -187,7 +187,7 @@ void OpenGl_Sampler::applySamplerParams (const Handle(OpenGl_Context)& theCtx,
                                          const Handle(Graphic3d_TextureParams)& theParams,
                                          OpenGl_Sampler* theSampler,
                                          const GLenum theTarget,
-                                         const bool theHasMipMaps)
+                                         const Standard_Integer theMaxMipLevels)
 {
   if (theSampler != NULL && theSampler->Parameters() == theParams)
   {
@@ -197,7 +197,7 @@ void OpenGl_Sampler::applySamplerParams (const Handle(OpenGl_Context)& theCtx,
   // setup texture filtering
   const GLenum aFilter = (theParams->Filter() == Graphic3d_TOTF_NEAREST) ? GL_NEAREST : GL_LINEAR;
   GLenum aFilterMin = aFilter;
-  if (theHasMipMaps)
+  if (theMaxMipLevels > 0)
   {
     aFilterMin = GL_NEAREST_MIPMAP_NEAREST;
     if (theParams->Filter() == Graphic3d_TOTF_BILINEAR)
@@ -266,8 +266,9 @@ void OpenGl_Sampler::applySamplerParams (const Handle(OpenGl_Context)& theCtx,
   if (theCtx->HasTextureBaseLevel()
    && (theSampler == NULL || !theSampler->isValidSampler()))
   {
+    const Standard_Integer aMaxLevel = Min (theMaxMipLevels, theParams->MaxLevel());
     setParameter (theCtx, theSampler, theTarget, GL_TEXTURE_BASE_LEVEL, theParams->BaseLevel());
-    setParameter (theCtx, theSampler, theTarget, GL_TEXTURE_MAX_LEVEL,  theParams->MaxLevel());
+    setParameter (theCtx, theSampler, theTarget, GL_TEXTURE_MAX_LEVEL,  aMaxLevel);
   }
 }