Commit fa125c9e by Geoff Lang Committed by Commit Bot

Validate GL_COLOR_ATTACHMENT0 separately from the draw buffers attachments.

EXT_draw_buffers may not be enabled but the maxColorAttachments cap is always initialized so make sure to validate for the extension instead of just checking that the attachment is in the valid range. BUG=angleproject:2058 Change-Id: I5b48cb496bf96cbc0911295aa5bf87784ce9241b Reviewed-on: https://chromium-review.googlesource.com/735749Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 70b715c9
......@@ -1170,15 +1170,19 @@ Shader *GetValidShader(ValidationContext *context, GLuint id)
bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment)
{
if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
{
const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers)
{
ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment);
return false;
}
// Color attachment 0 is validated below because it is always valid
const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
if (colorAttachment >= context->getCaps().maxColorAttachments)
{
context->handleError(
InvalidOperation()
<< "attachment index cannot be greater or equal to MAX_COLOR_ATTACHMENTS.");
ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment);
return false;
}
}
......@@ -1186,6 +1190,7 @@ bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment)
{
switch (attachment)
{
case GL_COLOR_ATTACHMENT0:
case GL_DEPTH_ATTACHMENT:
case GL_STENCIL_ATTACHMENT:
break;
......@@ -1194,13 +1199,13 @@ bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment)
if (!context->getExtensions().webglCompatibility &&
context->getClientMajorVersion() < 3)
{
ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported);
ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment);
return false;
}
break;
default:
ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported);
ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment);
return false;
}
}
......@@ -3854,20 +3859,22 @@ bool ValidateGetFramebufferAttachmentParameterivBase(ValidationContext *context,
case GL_DEPTH_STENCIL_ATTACHMENT:
if (clientVersion < 3)
{
context->handleError(InvalidEnum());
ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment);
return false;
}
break;
case GL_COLOR_ATTACHMENT0:
case GL_DEPTH_ATTACHMENT:
case GL_STENCIL_ATTACHMENT:
break;
default:
if (attachment < GL_COLOR_ATTACHMENT0_EXT ||
if ((clientVersion < 3 && !context->getExtensions().drawBuffers) ||
attachment < GL_COLOR_ATTACHMENT0_EXT ||
(attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments)
{
context->handleError(InvalidEnum());
ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment);
return false;
}
break;
......
......@@ -3443,6 +3443,29 @@ TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMismatch)
EXPECT_GL_NO_ERROR();
}
// Test that it's not possible to query the non-zero color attachments without the drawbuffers
// extension in WebGL1
TEST_P(WebGLCompatibilityTest, FramebufferAttachmentQuery)
{
ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
ANGLE_SKIP_TEST_IF(extensionEnabled("GL_EXT_draw_buffers"));
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
EXPECT_GL_NO_ERROR();
GLint result;
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &result);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
GLRenderbuffer renderbuffer;
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, renderbuffer);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
}
// Tests the WebGL removal of undefined behavior when attachments aren't written to.
TEST_P(WebGLCompatibilityTest, DrawBuffers)
{
......
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