From: Laura Ekstrand Date: Mon, 2 Mar 2015 21:41:13 +0000 (-0800) Subject: main: Refactor get_texture_for_framebuffer. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a9f73f7f42081594d0ba9ff6cb7a0a743c3cad93;p=mesa.git main: Refactor get_texture_for_framebuffer. This moves a few blocks around so that the control flow is more obvious. If the texture is 0, just return true at the beginning of the function. Likewise, if the texObj is NULL, return true at the beginning of the function as well. [Fredrik: Fix the texObj NULL check] Reviewed-by: Fredrik Höglund Signed-off-by: Fredrik Höglund --- diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index 553a32b2a4d..f1c0780318c 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -2585,17 +2585,34 @@ get_texture_for_framebuffer(struct gl_context *ctx, struct gl_texture_object **texObj) { GLenum maxLevelsTarget; + GLboolean err = GL_TRUE; *texObj = NULL; /* This will get returned if texture = 0. */ /* The textarget, level, and zoffset parameters are only validated if * texture is non-zero. */ - if (texture) { - GLboolean err = GL_TRUE; + if (!texture) + return true; + + *texObj = _mesa_lookup_texture(ctx, texture); + if (*texObj == NULL || (*texObj)->Target == 0) { + /* Can't render to a non-existent texture object. + * + * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and + * Managing Framebuffer Objects specifies a different error + * depending upon the calling function (PDF pages 325-328). + * *FramebufferTexture (where *layered = GL_TRUE) throws invalid + * value, while the other commands throw invalid operation (where + * *layered = GL_FALSE). + */ + const GLenum error = *layered ? GL_INVALID_VALUE : + GL_INVALID_OPERATION; + _mesa_error(ctx, error, + "%s(non-existent texture %u)", caller, texture); + return false; + } - *texObj = _mesa_lookup_texture(ctx, texture); - if (*texObj != NULL && (*texObj)->Target != 0) { if (textarget == 0) { if (*layered) { /* We're being called by gl*FramebufferTexture() and textarget @@ -2644,23 +2661,6 @@ get_texture_for_framebuffer(struct gl_context *ctx, ? !_mesa_is_cube_face(textarget) : ((*texObj)->Target != textarget); } - } - else { - /* Can't render to a non-existent texture object. - * - * The OpenGL 4.5 core spec (02.02.2015) in Section 9.2 Binding and - * Managing Framebuffer Objects specifies a different error - * depending upon the calling function (PDF pages 325-328). - * *FramebufferTexture (where *layered = GL_TRUE) throws invalid - * value, while the other commands throw invalid operation (where - * *layered = GL_FALSE). - */ - const GLenum error = *layered ? GL_INVALID_VALUE : - GL_INVALID_OPERATION; - _mesa_error(ctx, error, - "%s(non-existent texture %u)", caller, texture); - return false; - } if (err) { _mesa_error(ctx, GL_INVALID_OPERATION, @@ -2707,7 +2707,6 @@ get_texture_for_framebuffer(struct gl_context *ctx, "%s(invalid level %d)", caller, level); return false; } - } return true; }