<div dir="ltr"><div>Reviewed-by: Marek Olšák <<a href="mailto:marek.olsak@amd.com">marek.olsak@amd.com</a>></div><div><br></div><div>Marek<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 29, 2018 at 7:24 AM, Tapani Pälli <span dir="ltr"><<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Patch skips useless and possibly dangerous calls down to the driver<br>
in case invalid arguments were given. I noticed this would be happening<br>
with demo of Darwinia game. AFAIK this does not fix anything but makes<br>
this path safer and more like how other API functions are implemented.<br>
<br>
Signed-off-by: Tapani Pälli <<a href="mailto:tapani.palli@intel.com">tapani.palli@intel.com</a>><br>
---<br>
src/mesa/main/texenv.c | 54 ++++++++++++++++++++++++++++++<wbr>+-------------------<br>
1 file changed, 34 insertions(+), 20 deletions(-)<br>
<br>
diff --git a/src/mesa/main/texenv.c b/src/mesa/main/texenv.c<br>
index 22fc8da1ca..a69c8dd743 100644<br>
--- a/src/mesa/main/texenv.c<br>
+++ b/src/mesa/main/texenv.c<br>
@@ -103,7 +103,7 @@ set_env_color(struct gl_context *ctx,<br>
<br>
<br>
/** Set an RGB or A combiner mode/function */<br>
-static void<br>
+static bool<br>
set_combiner_mode(struct gl_context *ctx,<br>
struct gl_fixedfunc_texture_unit *texUnit,<br>
GLenum pname, GLenum mode)<br>
@@ -144,32 +144,35 @@ set_combiner_mode(struct gl_context *ctx,<br>
<br>
if (!legal) {<br>
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);<br>
- return;<br>
+ return false;<br>
}<br>
<br>
switch (pname) {<br>
case GL_COMBINE_RGB:<br>
if (texUnit->Combine.ModeRGB == mode)<br>
- return;<br>
+ return true;<br>
FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);<br>
texUnit->Combine.ModeRGB = mode;<br>
break;<br>
<br>
case GL_COMBINE_ALPHA:<br>
if (texUnit->Combine.ModeA == mode)<br>
- return;<br>
+ return true;<br>
FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);<br>
texUnit->Combine.ModeA = mode;<br>
break;<br>
default:<br>
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);<br>
+ return false;<br>
}<br>
+<br>
+ return true;<br>
}<br>
<br>
<br>
<br>
/** Set an RGB or A combiner source term */<br>
-static void<br>
+static bool<br>
set_combiner_source(struct gl_context *ctx,<br>
struct gl_fixedfunc_texture_unit *texUnit,<br>
GLenum pname, GLenum param)<br>
@@ -199,13 +202,13 @@ set_combiner_source(struct gl_context *ctx,<br>
break;<br>
default:<br>
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);<br>
- return;<br>
+ return false;<br>
}<br>
<br>
if ((term == 3) && (ctx->API != API_OPENGL_COMPAT<br>
|| !ctx->Extensions.NV_texture_<wbr>env_combine4)) {<br>
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);<br>
- return;<br>
+ return false;<br>
}<br>
<br>
assert(term < MAX_COMBINER_TERMS);<br>
@@ -246,7 +249,7 @@ set_combiner_source(struct gl_context *ctx,<br>
<br>
if (!legal) {<br>
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", param);<br>
- return;<br>
+ return false;<br>
}<br>
<br>
FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);<br>
@@ -255,11 +258,13 @@ set_combiner_source(struct gl_context *ctx,<br>
texUnit->Combine.SourceA[term] = param;<br>
else<br>
texUnit->Combine.SourceRGB[<wbr>term] = param;<br>
+<br>
+ return true;<br>
}<br>
<br>
<br>
/** Set an RGB or A combiner operand term */<br>
-static void<br>
+static bool<br>
set_combiner_operand(struct gl_context *ctx,<br>
struct gl_fixedfunc_texture_unit *texUnit,<br>
GLenum pname, GLenum param)<br>
@@ -286,13 +291,13 @@ set_combiner_operand(struct gl_context *ctx,<br>
break;<br>
default:<br>
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);<br>
- return;<br>
+ return false;<br>
}<br>
<br>
if ((term == 3) && (ctx->API != API_OPENGL_COMPAT<br>
|| !ctx->Extensions.NV_texture_<wbr>env_combine4)) {<br>
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);<br>
- return;<br>
+ return false;<br>
}<br>
<br>
assert(term < MAX_COMBINER_TERMS);<br>
@@ -328,7 +333,7 @@ set_combiner_operand(struct gl_context *ctx,<br>
<br>
if (!legal) {<br>
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", param);<br>
- return;<br>
+ return false;<br>
}<br>
<br>
FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);<br>
@@ -337,10 +342,12 @@ set_combiner_operand(struct gl_context *ctx,<br>
texUnit->Combine.OperandA[<wbr>term] = param;<br>
else<br>
texUnit->Combine.OperandRGB[<wbr>term] = param;<br>
+<br>
+ return true;<br>
}<br>
<br>
<br>
-static void<br>
+static bool<br>
set_combiner_scale(struct gl_context *ctx,<br>
struct gl_fixedfunc_texture_unit *texUnit,<br>
GLenum pname, GLfloat scale)<br>
@@ -359,25 +366,28 @@ set_combiner_scale(struct gl_context *ctx,<br>
else {<br>
_mesa_error( ctx, GL_INVALID_VALUE,<br>
"glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );<br>
- return;<br>
+ return false;<br>
}<br>
<br>
switch (pname) {<br>
case GL_RGB_SCALE:<br>
if (texUnit->Combine.<wbr>ScaleShiftRGB == shift)<br>
- return;<br>
+ return true;<br>
FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);<br>
texUnit->Combine.ScaleShiftRGB = shift;<br>
break;<br>
case GL_ALPHA_SCALE:<br>
if (texUnit->Combine.ScaleShiftA == shift)<br>
- return;<br>
+ return true;<br>
FLUSH_VERTICES(ctx, _NEW_TEXTURE_STATE);<br>
texUnit->Combine.ScaleShiftA = shift;<br>
break;<br>
default:<br>
TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);<br>
+ return false;<br>
}<br>
+<br>
+ return true;<br>
}<br>
<br>
<br>
@@ -418,7 +428,8 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )<br>
break;<br>
case GL_COMBINE_RGB:<br>
case GL_COMBINE_ALPHA:<br>
- set_combiner_mode(ctx, texUnit, pname, (GLenum) iparam0);<br>
+ if (!set_combiner_mode(ctx, texUnit, pname, (GLenum) iparam0))<br>
+ return;<br>
break;<br>
case GL_SOURCE0_RGB:<br>
case GL_SOURCE1_RGB:<br>
@@ -428,7 +439,8 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )<br>
case GL_SOURCE1_ALPHA:<br>
case GL_SOURCE2_ALPHA:<br>
case GL_SOURCE3_ALPHA_NV:<br>
- set_combiner_source(ctx, texUnit, pname, (GLenum) iparam0);<br>
+ if (!set_combiner_source(ctx, texUnit, pname, (GLenum) iparam0))<br>
+ return;<br>
break;<br>
case GL_OPERAND0_RGB:<br>
case GL_OPERAND1_RGB:<br>
@@ -438,11 +450,13 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )<br>
case GL_OPERAND1_ALPHA:<br>
case GL_OPERAND2_ALPHA:<br>
case GL_OPERAND3_ALPHA_NV:<br>
- set_combiner_operand(ctx, texUnit, pname, (GLenum) iparam0);<br>
+ if (!set_combiner_operand(ctx, texUnit, pname, (GLenum) iparam0))<br>
+ return;<br>
break;<br>
case GL_RGB_SCALE:<br>
case GL_ALPHA_SCALE:<br>
- set_combiner_scale(ctx, texUnit, pname, param[0]);<br>
+ if (!set_combiner_scale(ctx, texUnit, pname, param[0]))<br>
+ return;<br>
break;<br>
default:<br>
_mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );<br>
<span class="HOEnZb"><font color="#888888">-- <br>
2.14.3<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div>