mesa: refactor get_texture_image to remove duplicate code

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>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2019-07-02 10:59:21 +02:00 committed by Marek Olšák
parent 666ea30017
commit 0d8826f723

View file

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