Commit 893ab087 by Jamie Madill

Move state query validation out of Context.

Generate all GL errors in the validation helper functions, instead of within the state manipulation logic and internals of Context. BUG=angle:571 Change-Id: I7a3f540e2ae0f5f8c7126e2593717cc3200dd7e5 Reviewed-on: https://chromium-review.googlesource.com/200551Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 5df9f523
......@@ -225,6 +225,7 @@ class Context
GLuint getRenderbufferHandle() const;
GLuint getVertexArrayHandle() const;
GLuint getSamplerHandle(GLuint textureUnit) const;
unsigned int getActiveSampler() const;
GLuint getArrayBufferHandle() const;
......@@ -368,10 +369,10 @@ class Context
bool isSampler(GLuint samplerName) const;
bool getBooleanv(GLenum pname, GLboolean *params);
bool getFloatv(GLenum pname, GLfloat *params);
bool getIntegerv(GLenum pname, GLint *params);
bool getInteger64v(GLenum pname, GLint64 *params);
void getBooleanv(GLenum pname, GLboolean *params);
void getFloatv(GLenum pname, GLfloat *params);
void getIntegerv(GLenum pname, GLint *params);
void getInteger64v(GLenum pname, GLint64 *params);
bool getIndexedIntegerv(GLenum target, GLuint index, GLint *data);
bool getIndexedInteger64v(GLenum target, GLuint index, GLint64 *data);
......@@ -448,7 +449,7 @@ class Context
bool supportsTextureFilterAnisotropy() const;
bool supportsPBOs() const;
bool getCurrentReadFormatType(GLenum *internalFormat, GLenum *format, GLenum *type);
void getCurrentReadFormatType(GLenum *internalFormat, GLenum *format, GLenum *type);
float getTextureMaxAnisotropy() const;
......
......@@ -2450,12 +2450,10 @@ void __stdcall glGetBooleanv(GLenum pname, GLboolean* params)
{
GLenum nativeType;
unsigned int numParams = 0;
if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
return gl::error(GL_INVALID_ENUM);
// pname is valid, but there are no parameters to return
if (numParams == 0)
if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
{
return;
}
if (nativeType == GL_BOOL)
{
......@@ -2598,12 +2596,10 @@ void __stdcall glGetFloatv(GLenum pname, GLfloat* params)
{
GLenum nativeType;
unsigned int numParams = 0;
if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
return gl::error(GL_INVALID_ENUM);
// pname is valid, but that there are no parameters to return.
if (numParams == 0)
if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
{
return;
}
if (nativeType == GL_FLOAT)
{
......@@ -2957,12 +2953,11 @@ void __stdcall glGetIntegerv(GLenum pname, GLint* params)
{
GLenum nativeType;
unsigned int numParams = 0;
if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
return gl::error(GL_INVALID_ENUM);
// pname is valid, but there are no parameters to return
if (numParams == 0)
if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
{
return;
}
if (nativeType == GL_INT)
{
......@@ -8779,12 +8774,10 @@ void __stdcall glGetInteger64v(GLenum pname, GLint64* params)
GLenum nativeType;
unsigned int numParams = 0;
if (!context->getQueryParameterInfo(pname, &nativeType, &numParams))
return gl::error(GL_INVALID_ENUM);
// pname is valid, but that there are no parameters to return.
if (numParams == 0)
if (!ValidateStateQuery(context, pname, &nativeType, &numParams))
{
return;
}
if (nativeType == GL_INT_64_ANGLEX)
{
......
......@@ -829,6 +829,7 @@ bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsize
GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels)
{
gl::Framebuffer *framebuffer = context->getReadFramebuffer();
ASSERT(framebuffer);
if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
{
......@@ -840,16 +841,15 @@ bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsize
return gl::error(GL_INVALID_OPERATION, false);
}
if (!framebuffer->getReadColorbuffer())
{
return gl::error(GL_INVALID_OPERATION, false);
}
GLenum currentInternalFormat, currentFormat, currentType;
int clientVersion = context->getClientVersion();
// Failure in getCurrentReadFormatType indicates that no color attachment is currently bound,
// and attempting to read back if that's the case is an error. The error will be registered
// by getCurrentReadFormat.
// Note: we need to explicitly check for framebuffer completeness here, before we call
// getCurrentReadFormatType, because it generates a different (wrong) error for incomplete FBOs
if (!context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType))
return false;
context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType);
bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) :
ValidES3ReadFormatType(context, currentInternalFormat, format, type);
......@@ -1038,4 +1038,64 @@ bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint locati
return true;
}
bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams)
{
if (!context->getQueryParameterInfo(pname, nativeType, numParams))
{
return gl::error(GL_INVALID_ENUM, false);
}
if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15)
{
unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0);
if (colorAttachment >= context->getMaximumRenderTargets())
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
switch (pname)
{
case GL_TEXTURE_BINDING_2D:
case GL_TEXTURE_BINDING_CUBE_MAP:
case GL_TEXTURE_BINDING_3D:
case GL_TEXTURE_BINDING_2D_ARRAY:
if (context->getActiveSampler() >= context->getMaximumCombinedTextureImageUnits())
{
return gl::error(GL_INVALID_OPERATION, false);
}
break;
case GL_IMPLEMENTATION_COLOR_READ_TYPE:
case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
{
Framebuffer *framebuffer = context->getReadFramebuffer();
ASSERT(framebuffer);
if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
{
return gl::error(GL_INVALID_OPERATION, false);
}
Renderbuffer *renderbuffer = framebuffer->getReadColorbuffer();
if (!renderbuffer)
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
break;
default:
break;
}
// pname is valid, but there are no parameters to return
if (numParams == 0)
{
return false;
}
return true;
}
}
......@@ -52,6 +52,8 @@ bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, G
bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
GLboolean transpose);
bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams);
}
#endif // LIBGLESV2_VALIDATION_ES_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment