Refactor Uniform validation to validationES.cpp.
This patch also incidentally fixes some bugged validation in the
new ES3 unsigned int uniform API entry points.
BUG=angle:571
Change-Id: I89bd909467bd9418fe5ce3f246561765cf27a5e9
Reviewed-on: https://chromium-review.googlesource.com/200074
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Shannon Woods <shannonwoods@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libGLESv2/libGLESv2.cpp b/src/libGLESv2/libGLESv2.cpp
index 99a99d0..6ed8bf6 100644
--- a/src/libGLESv2/libGLESv2.cpp
+++ b/src/libGLESv2/libGLESv2.cpp
@@ -5228,26 +5228,16 @@
try
{
- if (count < 0)
- {
- return gl::error(GL_INVALID_VALUE);
- }
-
- if (location == -1)
- {
- return;
- }
-
gl::Context *context = gl::getNonLostContext();
if (context)
{
- gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
+ if (!ValidateUniform(context, GL_FLOAT, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
+ gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform1fv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
@@ -5271,26 +5261,16 @@
try
{
- if (count < 0)
- {
- return gl::error(GL_INVALID_VALUE);
- }
-
- if (location == -1)
- {
- return;
- }
-
gl::Context *context = gl::getNonLostContext();
if (context)
{
- gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
+ if (!ValidateUniform(context, GL_INT, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
+ gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform1iv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
@@ -5316,26 +5296,16 @@
try
{
- if (count < 0)
- {
- return gl::error(GL_INVALID_VALUE);
- }
-
- if (location == -1)
- {
- return;
- }
-
gl::Context *context = gl::getNonLostContext();
if (context)
{
- gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
+ if (!ValidateUniform(context, GL_FLOAT_VEC2, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
+ gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform2fv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
@@ -5361,26 +5331,16 @@
try
{
- if (count < 0)
- {
- return gl::error(GL_INVALID_VALUE);
- }
-
- if (location == -1)
- {
- return;
- }
-
gl::Context *context = gl::getNonLostContext();
if (context)
{
- gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
+ if (!ValidateUniform(context, GL_INT_VEC2, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
+ gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform2iv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
@@ -5406,26 +5366,16 @@
try
{
- if (count < 0)
- {
- return gl::error(GL_INVALID_VALUE);
- }
-
- if (location == -1)
- {
- return;
- }
-
gl::Context *context = gl::getNonLostContext();
if (context)
{
- gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
+ if (!ValidateUniform(context, GL_FLOAT_VEC3, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
+ gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform3fv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
@@ -5451,26 +5401,16 @@
try
{
- if (count < 0)
- {
- return gl::error(GL_INVALID_VALUE);
- }
-
- if (location == -1)
- {
- return;
- }
-
gl::Context *context = gl::getNonLostContext();
if (context)
{
- gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
+ if (!ValidateUniform(context, GL_INT_VEC3, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
+ gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform3iv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
@@ -5496,26 +5436,16 @@
try
{
- if (count < 0)
- {
- return gl::error(GL_INVALID_VALUE);
- }
-
- if (location == -1)
- {
- return;
- }
-
gl::Context *context = gl::getNonLostContext();
if (context)
{
- gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
+ if (!ValidateUniform(context, GL_FLOAT_VEC4, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
+ gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform4fv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
@@ -5541,26 +5471,16 @@
try
{
- if (count < 0)
- {
- return gl::error(GL_INVALID_VALUE);
- }
-
- if (location == -1)
- {
- return;
- }
-
gl::Context *context = gl::getNonLostContext();
if (context)
{
- gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
+ if (!ValidateUniform(context, GL_INT_VEC4, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
+ gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary->setUniform4iv(location, count, v))
{
return gl::error(GL_INVALID_OPERATION);
@@ -7974,17 +7894,12 @@
if (context)
{
- if (context->getClientVersion() < 3)
+ if (!ValidateUniform(context, GL_UNSIGNED_INT, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
- {
- return gl::error(GL_INVALID_OPERATION);
- }
-
if (!programBinary->setUniform1uiv(location, count, value))
{
return gl::error(GL_INVALID_OPERATION);
@@ -8008,17 +7923,12 @@
if (context)
{
- if (context->getClientVersion() < 3)
+ if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC2, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
- {
- return gl::error(GL_INVALID_OPERATION);
- }
-
if (!programBinary->setUniform2uiv(location, count, value))
{
return gl::error(GL_INVALID_OPERATION);
@@ -8042,17 +7952,12 @@
if (context)
{
- if (context->getClientVersion() < 3)
+ if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC3, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
- {
- return gl::error(GL_INVALID_OPERATION);
- }
-
if (!programBinary->setUniform3uiv(location, count, value))
{
return gl::error(GL_INVALID_OPERATION);
@@ -8076,17 +7981,12 @@
if (context)
{
- if (context->getClientVersion() < 3)
+ if (!ValidateUniform(context, GL_UNSIGNED_INT_VEC4, location, count))
{
- return gl::error(GL_INVALID_OPERATION);
+ return;
}
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
- if (!programBinary)
- {
- return gl::error(GL_INVALID_OPERATION);
- }
-
if (!programBinary->setUniform4uiv(location, count, value))
{
return gl::error(GL_INVALID_OPERATION);
diff --git a/src/libGLESv2/validationES.cpp b/src/libGLESv2/validationES.cpp
index 3b649d4..33ed71e 100644
--- a/src/libGLESv2/validationES.cpp
+++ b/src/libGLESv2/validationES.cpp
@@ -946,27 +946,13 @@
return true;
}
-bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
- GLboolean transpose)
+static bool ValidateUniformCommonBase(gl::Context *context, GLint location, GLsizei count)
{
if (count < 0)
{
return gl::error(GL_INVALID_VALUE, false);
}
- // Check for ES3 uniform entry points
- int rows = VariableRowCount(matrixType);
- int cols = VariableColumnCount(matrixType);
- if (rows != cols && context->getClientVersion() < 3)
- {
- return gl::error(GL_INVALID_OPERATION, false);
- }
-
- if (transpose != GL_FALSE && context->getClientVersion() < 3)
- {
- return gl::error(GL_INVALID_VALUE, false);
- }
-
gl::ProgramBinary *programBinary = context->getCurrentProgramBinary();
if (!programBinary)
{
@@ -982,4 +968,34 @@
return true;
}
+bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count)
+{
+ // Check for ES3 uniform entry points
+ if (UniformComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3)
+ {
+ return gl::error(GL_INVALID_OPERATION, false);
+ }
+
+ return ValidateUniformCommonBase(context, location, count);
+}
+
+bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
+ GLboolean transpose)
+{
+ // Check for ES3 uniform entry points
+ int rows = VariableRowCount(matrixType);
+ int cols = VariableColumnCount(matrixType);
+ if (rows != cols && context->getClientVersion() < 3)
+ {
+ return gl::error(GL_INVALID_OPERATION, false);
+ }
+
+ if (transpose != GL_FALSE && context->getClientVersion() < 3)
+ {
+ return gl::error(GL_INVALID_VALUE, false);
+ }
+
+ return ValidateUniformCommonBase(context, location, count);
+}
+
}
diff --git a/src/libGLESv2/validationES.h b/src/libGLESv2/validationES.h
index 6b4f41f..80ec427 100644
--- a/src/libGLESv2/validationES.h
+++ b/src/libGLESv2/validationES.h
@@ -48,6 +48,7 @@
bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id);
bool ValidateEndQuery(gl::Context *context, GLenum target);
+bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count);
bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
GLboolean transpose);