[Mesa-dev] [PATCH 3/3] mesa: fix issues with glTexStorage() and proxy textures

Brian Paul brianp at vmware.com
Wed Jul 13 21:57:57 UTC 2016


When we call ctx->Driver.TestProxyTexImage() we want to have the
texture object's Immutable and NumLevels fields initialized so that
the function doesn't have to guess about the number of mipmap levels.

But since the proxy textures are shared by the old glTexImage() and
new glTexStorage(), we can't just set these fields and forget them.
We have to save/restore them.

This allows glTexStorage(GL_PROXY_TEXTURE_x) calls to produce a more
accurate result.

An alternative would be to change the ctx->Driver.TestProxyTexImage()
function to take extra immutable, numLevels arguments.
---
 src/mesa/main/texstorage.c | 41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/texstorage.c b/src/mesa/main/texstorage.c
index 72ed869..ea23876 100644
--- a/src/mesa/main/texstorage.c
+++ b/src/mesa/main/texstorage.c
@@ -367,6 +367,42 @@ tex_storage_error_check(struct gl_context *ctx,
 
 
 /**
+ * Wrapper for ctx->Driver.TestProxyTexImage() which sets/restores
+ * immutable texture state.
+ * We do this so that the TestProxyTexImage() function can know that
+ * we're testing with an immutable texture and we know the number of
+ * mipmap levels.
+ */
+static GLboolean
+test_proxy_tex_image(struct gl_context *ctx,
+                     struct gl_texture_object *texObj, GLenum target,
+                     mesa_format texFormat, GLsizei levels,
+                     GLsizei width, GLsizei height, GLsizei depth)
+{
+   GLboolean immutableSave;
+   GLuint numLevelsSave;
+   GLboolean sizeOK;
+
+   /* save current vals */
+   immutableSave = texObj->Immutable;
+   numLevelsSave = texObj->NumLevels;
+
+   /* set immutable fields */
+   texObj->Immutable = GL_TRUE;
+   texObj->NumLevels = levels;
+
+   sizeOK = ctx->Driver.TestProxyTexImage(ctx, target, 0, texFormat,
+                                          width, height, depth, 0);
+
+   /* restore */
+   texObj->Immutable = immutableSave;
+   texObj->NumLevels = numLevelsSave;
+
+   return sizeOK;
+}
+
+
+/**
  * Helper that does the storage allocation for _mesa_TexStorage1/2/3D()
  * and _mesa_TextureStorage1/2/3D().
  */
@@ -396,8 +432,8 @@ _mesa_texture_storage(struct gl_context *ctx, GLuint dims,
    dimensionsOK = _mesa_legal_texture_dimensions(ctx, target, 0,
                                                   width, height, depth, 0);
 
-   sizeOK = ctx->Driver.TestProxyTexImage(ctx, target, 0, texFormat,
-                                          width, height, depth, 0);
+   sizeOK = test_proxy_tex_image(ctx, texObj, target, texFormat, levels,
+                                 width, height, depth);
 
    if (_mesa_is_proxy_texture(target)) {
       if (dimensionsOK && sizeOK) {
@@ -447,6 +483,7 @@ _mesa_texture_storage(struct gl_context *ctx, GLuint dims,
          return;
       }
 
+      /* This will set the gl_texture_object->Immutable flag to true */
       _mesa_set_texture_view_state(ctx, texObj, target, levels);
 
       update_fbo_texture(ctx, texObj);
-- 
1.9.1



More information about the mesa-dev mailing list