Commit 146e8a1c by Frank Henigman Committed by Commit Bot

WebGL validation of constant color & alpha blend.

In WebGL, generate INVALID_OPERATION if constant color and constant alpha are used together as source and destination blend functions. BUG=angleproject:1817 Change-Id: I9b2d05ab5017c013bb89c13256efbd80198de91b Reviewed-on: https://chromium-review.googlesource.com/448940Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Frank Henigman <fjhenigman@chromium.org>
parent d61396b4
...@@ -3848,7 +3848,8 @@ bool ValidateBlendFuncSeparate(ValidationContext *context, ...@@ -3848,7 +3848,8 @@ bool ValidateBlendFuncSeparate(ValidationContext *context,
return false; return false;
} }
if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc) if (context->getLimitations().noSimultaneousConstantColorAndAlphaBlendFunc ||
context->getExtensions().webglCompatibility)
{ {
bool constantColorUsed = bool constantColorUsed =
(srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR || (srcRGB == GL_CONSTANT_COLOR || srcRGB == GL_ONE_MINUS_CONSTANT_COLOR ||
...@@ -3860,14 +3861,22 @@ bool ValidateBlendFuncSeparate(ValidationContext *context, ...@@ -3860,14 +3861,22 @@ bool ValidateBlendFuncSeparate(ValidationContext *context,
if (constantColorUsed && constantAlphaUsed) if (constantColorUsed && constantAlphaUsed)
{ {
ERR() << "Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and " const char *msg;
"GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR not supported by this " if (context->getExtensions().webglCompatibility)
"implementation."; {
context->handleError(Error(GL_INVALID_OPERATION, msg =
"Simultaneous use of " "Invalid simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and "
"GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and " "GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR.";
"GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR not " }
"supported by this implementation.")); else
{
msg =
"Simultaneous use of GL_CONSTANT_ALPHA/GL_ONE_MINUS_CONSTANT_ALPHA and "
"GL_CONSTANT_COLOR/GL_ONE_MINUS_CONSTANT_COLOR not supported by this "
"implementation.";
ERR() << msg;
}
context->handleError(Error(GL_INVALID_OPERATION, msg));
return false; return false;
} }
} }
......
...@@ -10,6 +10,30 @@ ...@@ -10,6 +10,30 @@
#include "test_utils/gl_raii.h" #include "test_utils/gl_raii.h"
namespace
{
bool ConstantColorAndAlphaBlendFunctions(GLenum first, GLenum second)
{
return (first == GL_CONSTANT_COLOR || first == GL_ONE_MINUS_CONSTANT_COLOR) &&
(second == GL_CONSTANT_ALPHA || second == GL_ONE_MINUS_CONSTANT_ALPHA);
}
void CheckBlendFunctions(GLenum src, GLenum dst)
{
if (ConstantColorAndAlphaBlendFunctions(src, dst) ||
ConstantColorAndAlphaBlendFunctions(dst, src))
{
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
else
{
ASSERT_GL_NO_ERROR();
}
}
} // namespace
namespace angle namespace angle
{ {
...@@ -436,6 +460,50 @@ TEST_P(WebGLCompatibilityTest, DepthRange) ...@@ -436,6 +460,50 @@ TEST_P(WebGLCompatibilityTest, DepthRange)
EXPECT_GL_ERROR(GL_INVALID_OPERATION); EXPECT_GL_ERROR(GL_INVALID_OPERATION);
} }
// Test all blend function combinations.
// In WebGL it is invalid to combine constant color with constant alpha.
TEST_P(WebGLCompatibilityTest, BlendWithConstantColor)
{
constexpr GLenum srcFunc[] = {
GL_ZERO,
GL_ONE,
GL_SRC_COLOR,
GL_ONE_MINUS_SRC_COLOR,
GL_DST_COLOR,
GL_ONE_MINUS_DST_COLOR,
GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA,
GL_DST_ALPHA,
GL_ONE_MINUS_DST_ALPHA,
GL_CONSTANT_COLOR,
GL_ONE_MINUS_CONSTANT_COLOR,
GL_CONSTANT_ALPHA,
GL_ONE_MINUS_CONSTANT_ALPHA,
GL_SRC_ALPHA_SATURATE,
};
constexpr GLenum dstFunc[] = {
GL_ZERO, GL_ONE,
GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
};
for (GLenum src : srcFunc)
{
for (GLenum dst : dstFunc)
{
glBlendFunc(src, dst);
CheckBlendFunctions(src, dst);
glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE);
CheckBlendFunctions(src, dst);
}
}
}
// Test the checks for OOB reads in the vertex buffers, instanced version // Test the checks for OOB reads in the vertex buffers, instanced version
TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced) TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
{ {
......
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