<div dir="ltr"><div>Looks good to me.<br><br></div>Reviewed-by: Laura Ekstrand <<a href="mailto:laura@jlekstrand.net">laura@jlekstrand.net</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 23, 2015 at 4:30 AM, Eduardo Lima Mitev <span dir="ltr"><<a href="mailto:elima@igalia.com" target="_blank">elima@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">glGenerateMipmap() queries the current texture object corresponding to the target<br>
argument before ever validating it. It does so by calling<br>
_mesa_get_current_tex_object() which explicitly states that target must have been<br>
validated before. However, the target validation occurs later on in<br>
_mesa_generate_texture_mipmap().<br>
<br>
This patch takes the target validation from _mesa_generate_texture_mipmap() and<br>
creates a new function generate_mipmap_is_valid_target(), that is called by<br>
both glGenerateMipmap() and glGenerateTextureMipmap().<br>
<br>
This gives the correct GL user error when an invalid target is given to<br>
glGenerateMipmap.<br>
---<br>
src/mesa/main/genmipmap.c | 52 +++++++++++++++++++++++++++++++++--------------<br>
1 file changed, 37 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/src/mesa/main/genmipmap.c b/src/mesa/main/genmipmap.c<br>
index 9aef090..163901f 100644<br>
--- a/src/mesa/main/genmipmap.c<br>
+++ b/src/mesa/main/genmipmap.c<br>
@@ -39,19 +39,16 @@<br>
#include "hash.h"<br>
<br>
/**<br>
- * Implements glGenerateMipmap and glGenerateTextureMipmap.<br>
- * Generates all the mipmap levels below the base level.<br>
+ * Validates the target argument in glGenerateMipmap and<br>
+ * glGenerateTextureMipmap.<br>
+ * Returns true if target is valid, otherwise returns false and sets GL error<br>
+ * accordingly.<br>
*/<br>
-void<br>
-_mesa_generate_texture_mipmap(struct gl_context *ctx,<br>
- struct gl_texture_object *texObj, GLenum target,<br>
- bool dsa)<br>
+static bool<br>
+generate_mipmap_is_valid_target(struct gl_context *ctx, GLenum target,<br>
+ const char *caller)<br>
{<br>
- struct gl_texture_image *srcImage;<br>
- GLboolean error;<br>
- const char *suffix = dsa ? "Texture" : "";<br>
-<br>
- FLUSH_VERTICES(ctx, 0);<br>
+ bool error;<br>
<br>
switch (target) {<br>
case GL_TEXTURE_1D:<br>
@@ -78,15 +75,32 @@ _mesa_generate_texture_mipmap(struct gl_context *ctx,<br>
!ctx->Extensions.ARB_texture_cube_map_array;<br>
break;<br>
default:<br>
- error = GL_TRUE;<br>
+ error = true;<br>
}<br>
<br>
if (error) {<br>
- _mesa_error(ctx, GL_INVALID_ENUM, "glGenerate%sMipmap(target=%s)",<br>
- suffix, _mesa_lookup_enum_by_nr(target));<br>
- return;<br>
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(target=%s)",<br>
+ caller, _mesa_lookup_enum_by_nr(target));<br>
+ return false;<br>
}<br>
<br>
+ return true;<br>
+}<br>
+<br>
+/**<br>
+ * Implements glGenerateMipmap and glGenerateTextureMipmap.<br>
+ * Generates all the mipmap levels below the base level.<br>
+ */<br>
+void<br>
+_mesa_generate_texture_mipmap(struct gl_context *ctx,<br>
+ struct gl_texture_object *texObj, GLenum target,<br>
+ bool dsa)<br>
+{<br>
+ struct gl_texture_image *srcImage;<br>
+ const char *suffix = dsa ? "Texture" : "";<br>
+<br>
+ FLUSH_VERTICES(ctx, 0);<br>
+<br>
if (texObj->BaseLevel >= texObj->MaxLevel) {<br>
/* nothing to do */<br>
return;<br>
@@ -142,6 +156,9 @@ _mesa_GenerateMipmap(GLenum target)<br>
struct gl_texture_object *texObj;<br>
GET_CURRENT_CONTEXT(ctx);<br>
<br>
+ if (!generate_mipmap_is_valid_target(ctx, target, "glGenerateMipmap"))<br>
+ return;<br>
+<br>
texObj = _mesa_get_current_tex_object(ctx, target);<br>
if (!texObj)<br>
return;<br>
@@ -162,5 +179,10 @@ _mesa_GenerateTextureMipmap(GLuint texture)<br>
if (!texObj)<br>
return;<br>
<br>
+ if (!generate_mipmap_is_valid_target(ctx, texObj->Target,<br>
+ "glGenerateTextureMipmap")) {<br>
+ return;<br>
+ }<br>
+<br>
_mesa_generate_texture_mipmap(ctx, texObj, texObj->Target, true);<br>
}<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.1.3<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div>