WebGL compatibility: remove UB for draw buffers in the GL backend.
WebGL adds two rules:
- Fragment outputs declared but not written to should default to black.
- FBO attachments for outputs not declared in the shader should not be
written to (it is UB in OpenGL ES).
Fix the first one by using the SH_INIT_OUTPUT_VARIABLES compiler
options, and the second one by messing with glDrawBuffers so that the
enabled draw buffers are always a subset of the ones declared by the
shader.
BUG=angleproject:2048
Change-Id: I1d851c190959c1acfc3e41d837e6990aec1d4086
Reviewed-on: https://chromium-review.googlesource.com/521682
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/Framebuffer.cpp b/src/libANGLE/Framebuffer.cpp
index a2aac1d..2952201 100644
--- a/src/libANGLE/Framebuffer.cpp
+++ b/src/libANGLE/Framebuffer.cpp
@@ -176,7 +176,7 @@
FramebufferState::FramebufferState()
: mLabel(),
mColorAttachments(1),
- mDrawBufferStates(IMPLEMENTATION_MAX_DRAW_BUFFERS, GL_NONE),
+ mDrawBufferStates(1, GL_BACK),
mReadBufferState(GL_BACK),
mDefaultWidth(0),
mDefaultHeight(0),
@@ -185,7 +185,6 @@
mWebGLDepthStencilConsistent(true)
{
ASSERT(mDrawBufferStates.size() > 0);
- mDrawBufferStates[0] = GL_BACK;
mEnabledDrawBuffers.set(0);
}
@@ -202,6 +201,7 @@
{
ASSERT(mDrawBufferStates.size() > 0);
mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT;
+ mEnabledDrawBuffers.set(0);
}
FramebufferState::~FramebufferState()
@@ -1243,6 +1243,8 @@
&mDirtyColorAttachmentBindings[colorIndex], type, binding,
textureIndex, resource);
+ // TODO(jmadill): ASSERT instead of checking the attachment exists in
+ // formsRenderingFeedbackLoopWith
bool enabled = (type != GL_NONE && getDrawBufferState(colorIndex) != GL_NONE);
mState.mEnabledDrawBuffers.set(colorIndex, enabled);
}