mesa: refactor get_texture_image to remove duplicate code
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Tue, 2 Jul 2019 08:59:21 +0000 (10:59 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Sat, 20 Jul 2019 00:03:40 +0000 (20:03 -0400)
Move shared code in a new function (_get_texture_image) and use it instead
of duplicating the same lines.
Will be also used by the EXT_dsa functions (GetTextureImageEXT and GetMultiTexImageEXT).

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/main/texgetimage.c

index 15c4ce0..395089e 100644 (file)
@@ -1445,23 +1445,28 @@ get_texture_image(struct gl_context *ctx,
    _mesa_unlock_texture(ctx, texObj);
 }
 
-
-void GLAPIENTRY
-_mesa_GetnTexImageARB(GLenum target, GLint level, GLenum format, GLenum type,
-                      GLsizei bufSize, GLvoid *pixels)
+static void
+_get_texture_image(struct gl_context *ctx,
+                  struct gl_texture_object *texObj,
+                  GLenum target, GLint level,
+                  GLenum format, GLenum type,
+                  GLsizei bufSize, GLvoid *pixels,
+                  const char *caller)
 {
-   GET_CURRENT_CONTEXT(ctx);
-   static const char *caller = "glGetnTexImageARB";
    GLsizei width, height, depth;
-   struct gl_texture_object *texObj;
-
-   if (!legal_getteximage_target(ctx, target, false)) {
+   /* EXT/ARB direct_state_access variants don't call _get_texture_image
+    * with a NULL texObj */
+   bool is_dsa = texObj != NULL;
+   if (!legal_getteximage_target(ctx, target, is_dsa)) {
       _mesa_error(ctx, GL_INVALID_ENUM, "%s", caller);
       return;
    }
 
-   texObj = _mesa_get_current_tex_object(ctx, target);
-   assert(texObj);
+   if (!is_dsa) {
+      texObj = _mesa_get_current_tex_object(ctx, target);
+      assert(texObj);
+   }
+
 
    get_texture_image_dims(texObj, target, level, &width, &height, &depth);
 
@@ -1478,33 +1483,26 @@ _mesa_GetnTexImageARB(GLenum target, GLint level, GLenum format, GLenum type,
 
 
 void GLAPIENTRY
-_mesa_GetTexImage(GLenum target, GLint level, GLenum format, GLenum type,
-                  GLvoid *pixels )
+_mesa_GetnTexImageARB(GLenum target, GLint level, GLenum format, GLenum type,
+                      GLsizei bufSize, GLvoid *pixels)
 {
    GET_CURRENT_CONTEXT(ctx);
-   static const char *caller = "glGetTexImage";
-   GLsizei width, height, depth;
-   struct gl_texture_object *texObj;
-
-   if (!legal_getteximage_target(ctx, target, false)) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "%s", caller);
-      return;
-   }
+   static const char *caller = "glGetnTexImageARB";
 
-   texObj = _mesa_get_current_tex_object(ctx, target);
-   assert(texObj);
+   _get_texture_image(ctx, NULL, target, level, format, type,
+                      bufSize, pixels, caller);
+}
 
-   get_texture_image_dims(texObj, target, level, &width, &height, &depth);
 
-   if (getteximage_error_check(ctx, texObj, target, level,
-                               width, height, depth,
-                               format, type, INT_MAX, pixels, caller)) {
-      return;
-   }
+void GLAPIENTRY
+_mesa_GetTexImage(GLenum target, GLint level, GLenum format, GLenum type,
+                  GLvoid *pixels )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   static const char *caller = "glGetTexImage";
 
-   get_texture_image(ctx, texObj, target, level,
-                     0, 0, 0, width, height, depth,
-                     format, type, pixels, caller);
+   _get_texture_image(ctx, NULL, target, level, format, type,
+                      INT_MAX, pixels, caller);
 }
 
 
@@ -1513,7 +1511,6 @@ _mesa_GetTextureImage(GLuint texture, GLint level, GLenum format, GLenum type,
                       GLsizei bufSize, GLvoid *pixels)
 {
    GET_CURRENT_CONTEXT(ctx);
-   GLsizei width, height, depth;
    static const char *caller = "glGetTextureImage";
    struct gl_texture_object *texObj =
       _mesa_lookup_texture_err(ctx, texture, caller);
@@ -1522,23 +1519,8 @@ _mesa_GetTextureImage(GLuint texture, GLint level, GLenum format, GLenum type,
       return;
    }
 
-   if (!legal_getteximage_target(ctx, texObj->Target, true)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
-      return;
-   }
-
-   get_texture_image_dims(texObj, texObj->Target, level,
-                          &width, &height, &depth);
-
-   if (getteximage_error_check(ctx, texObj, texObj->Target, level,
-                               width, height, depth,
-                               format, type, bufSize, pixels, caller)) {
-      return;
-   }
-
-   get_texture_image(ctx, texObj, texObj->Target, level,
-                     0, 0, 0, width, height, depth,
-                     format, type, pixels, caller);
+   _get_texture_image(ctx, texObj, texObj->Target, level, format, type,
+                      bufSize, pixels, caller);
 }