st/mesa: don't allocate mipmapped texture for NEAREST_MIPMAP_LINEAR
authorMarek Olšák <marek.olsak@amd.com>
Fri, 2 Aug 2019 23:11:53 +0000 (19:11 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 12 Aug 2019 18:52:17 +0000 (14:52 -0400)
Reviewed-by: Brian Paul <brianp@vmware.com>
src/mesa/state_tracker/st_cb_texture.c

index 0edb3ea5c7e391f8a3ffbf9286402030fa068901..1ace61863ff2796754d0760acf4363519adcfcb3 100644 (file)
@@ -523,6 +523,18 @@ allocate_full_mipmap(const struct st_texture_object *stObj,
       /* not a mipmap minification filter */
       return FALSE;
 
+   /* If the following sequence of GL calls is used:
+    *   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, ...
+    *   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    *
+    * we would needlessly allocate a mipmapped texture, because the initial
+    * MinFilter is GL_NEAREST_MIPMAP_LINEAR. Catch this case and don't
+    * allocate a mipmapped texture by default. This may cause texture
+    * reallocation later, but GL_NEAREST_MIPMAP_LINEAR is pretty rare.
+    */
+   if (stObj->base.Sampler.MinFilter == GL_NEAREST_MIPMAP_LINEAR)
+      return FALSE;
+
    if (stObj->base.Target == GL_TEXTURE_3D)
       /* 3D textures are seldom mipmapped */
       return FALSE;