Adding in checks for program and shader names to return INVALID_OPERATION
When a valid program is given instead of a shader, an INVALID_OPERATION
is returned rather than INVALID_VALUE when a shader related function is
called. The reverse happens when a program related function is called and
a valid shader program is given to it.
This commit also refactors other places that requires a similar check to
use the same validation function and error message.
BUG=angleproject:1029
dEQP-GLES2.functional.negative_api.state.get_shader_info_log
dEQP-GLES2.functional.negative_api.state.get_shader_source
dEQP-GLES2.functional.negative_api.state.get_programiv
dEQP-GLES2.functional.negative_api.state.get_program_info_log
BUG=angleproject:1101
dEQP-GLES3.functional.negative_api.state.get_shader_info_log
dEQP-GLES3.functional.negative_api.state.get_shader_source
dEQP-GLES3.functional.negative_api.state.get_programiv
dEQP-GLES3.functional.negative_api.state.get_program_info_log
Change-Id: I707b6ba10da0288128af185ce8dfb906fca0f766
Reviewed-on: https://chromium-review.googlesource.com/298604
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tryjob-Request: Dian Xiang <dianx@google.com>
Tested-by: Dian Xiang <dianx@google.com>
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 2c58af5..d8e1dd7 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -326,28 +326,50 @@
}
}
-bool ValidProgram(Context *context, GLuint id)
+Program *GetValidProgram(Context *context, GLuint id)
{
// ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the
// error INVALID_VALUE if the provided name is not the name of either a shader or program object and
// INVALID_OPERATION if the provided name identifies an object that is not the expected type."
- if (context->getProgram(id) != NULL)
+ Program *validProgram = context->getProgram(id);
+
+ if (!validProgram)
{
- return true;
+ if (context->getShader(id))
+ {
+ context->recordError(
+ Error(GL_INVALID_OPERATION, "Expected a program name, but found a shader name"));
+ }
+ else
+ {
+ context->recordError(Error(GL_INVALID_VALUE, "Program name is not valid"));
+ }
}
- else if (context->getShader(id) != NULL)
+
+ return validProgram;
+}
+
+Shader *GetValidShader(Context *context, GLuint id)
+{
+ // See ValidProgram for spec details.
+
+ Shader *validShader = context->getShader(id);
+
+ if (!validShader)
{
- // ID is the wrong type
- context->recordError(Error(GL_INVALID_OPERATION));
- return false;
+ if (context->getProgram(id))
+ {
+ context->recordError(
+ Error(GL_INVALID_OPERATION, "Expected a shader name, but found a program name"));
+ }
+ else
+ {
+ context->recordError(Error(GL_INVALID_VALUE, "Shader name is invalid"));
+ }
}
- else
- {
- // No shader/program object has this ID
- context->recordError(Error(GL_INVALID_VALUE));
- return false;
- }
+
+ return validShader;
}
bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment)
@@ -1880,13 +1902,12 @@
return false;
}
- if (!ValidProgram(context, program))
+ gl::Program *programObject = GetValidProgram(context, program);
+ if (!programObject)
{
return false;
}
- gl::Program *programObject = context->getProgram(program);
-
if (!programObject || !programObject->isLinked())
{
context->recordError(Error(GL_INVALID_OPERATION));