Commit 672f7f3f by Corentin Wallez Committed by Commit Bot

WebGL Compat: forbid client side arrays, even unused

BUG=angleproject:2064 Change-Id: I9a9c2df9a158799dbdc490446352cdf30fb87ca6 Reviewed-on: https://chromium-review.googlesource.com/537812 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 6260b7aa
...@@ -51,15 +51,17 @@ bool ValidateDrawAttribs(ValidationContext *context, ...@@ -51,15 +51,17 @@ bool ValidateDrawAttribs(ValidationContext *context,
for (size_t attributeIndex = 0; attributeIndex < maxEnabledAttrib; ++attributeIndex) for (size_t attributeIndex = 0; attributeIndex < maxEnabledAttrib; ++attributeIndex)
{ {
const VertexAttribute &attrib = vertexAttribs[attributeIndex]; const VertexAttribute &attrib = vertexAttribs[attributeIndex];
if (!program->isAttribLocationActive(attributeIndex) || !attrib.enabled)
// No need to range check for disabled attribs.
if (!attrib.enabled)
{ {
continue; continue;
} }
const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
// If we have no buffer, then we either get an error, or there are no more checks to be // If we have no buffer, then we either get an error, or there are no more checks to be
// done. // done.
gl::Buffer *buffer = binding.getBuffer().get(); const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
gl::Buffer *buffer = binding.getBuffer().get();
if (!buffer) if (!buffer)
{ {
if (webglCompatibility || !state.areClientArraysEnabled()) if (webglCompatibility || !state.areClientArraysEnabled())
...@@ -84,6 +86,13 @@ bool ValidateDrawAttribs(ValidationContext *context, ...@@ -84,6 +86,13 @@ bool ValidateDrawAttribs(ValidationContext *context,
continue; continue;
} }
// This needs to come after the check for client arrays as even unused attributes cannot use
// client-side arrays
if (!program->isAttribLocationActive(attributeIndex))
{
continue;
}
// If we're drawing zero vertices, we have enough data. // If we're drawing zero vertices, we have enough data.
if (vertexCount <= 0 || primcount <= 0) if (vertexCount <= 0 || primcount <= 0)
{ {
......
...@@ -573,6 +573,35 @@ TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer) ...@@ -573,6 +573,35 @@ TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer)
EXPECT_GL_ERROR(GL_INVALID_OPERATION); EXPECT_GL_ERROR(GL_INVALID_OPERATION);
} }
// Test that client-side array buffers are forbidden even if the program doesn't use the attribute
TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBufferEvenNotUsedOnes)
{
const std::string &vert =
"void main()\n"
"{\n"
" gl_Position = vec4(1.0);\n"
"}\n";
const std::string &frag =
"precision highp float;\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(1.0);\n"
"}\n";
ANGLE_GL_PROGRAM(program, vert, frag);
glUseProgram(program.get());
const auto &vertices = GetQuadVertices();
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
glEnableVertexAttribArray(0);
ASSERT_GL_NO_ERROR();
glDrawArrays(GL_TRIANGLES, 0, 6);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back // Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back
TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef) TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef)
{ {
......
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