diff options
author | Pierre-Eric Pelloux-Prayer <[email protected]> | 2019-07-02 10:59:21 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2019-07-19 20:03:40 -0400 |
commit | 0d8826f723cd8868b5271f17f18a1ab4548a1199 (patch) | |
tree | 220574fd77cf41e2e5597eac5653524ec2b6cdca /src/mesa | |
parent | 666ea30017648197a786dbe26124da791ba6897e (diff) |
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 <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/texgetimage.c | 82 |
1 files changed, 32 insertions, 50 deletions
diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c index 15c4ce00178..395089e6e93 100644 --- a/src/mesa/main/texgetimage.c +++ b/src/mesa/main/texgetimage.c @@ -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); } |