Commit db975cd1 authored by qiankun.miao's avatar qiankun.miao Committed by Commit bot

Attaching an image to many color attachment points is unsupported

See Section 5.34 Framebuffer color attachments in WebGL 2.0 spec.

BUG=628861
TEST=gpu_unittests conformance2/rendering/framebuffer-unsupported.html
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2159183002
Cr-Commit-Position: refs/heads/master@{#406613}
parent 378e044a
......@@ -211,6 +211,10 @@ bool FeatureInfo::InitializeForTesting() {
return Initialize(CONTEXT_TYPE_OPENGLES2, DisallowedFeatures());
}
bool FeatureInfo::InitializeForTesting(ContextType context_type) {
return Initialize(context_type, DisallowedFeatures());
}
bool IsGL_REDSupportedOnFBOs() {
// Skia uses GL_RED with frame buffers, unfortunately, Mesa claims to support
// GL_EXT_texture_rg, but it doesn't support it on frame buffers. To fix
......
......@@ -110,6 +110,8 @@ class GPU_EXPORT FeatureInfo : public base::RefCounted<FeatureInfo> {
// Helper that defaults to no disallowed features and a GLES2 context.
bool InitializeForTesting();
// Helper that defaults to no disallowed Features.
bool InitializeForTesting(ContextType context_type);
// Helper that defaults to a GLES2 context.
bool InitializeForTesting(const DisallowedFeatures& disallowed_features);
......
......@@ -89,6 +89,15 @@ class RenderbufferAttachment
return renderbuffer_.get() == renderbuffer;
}
bool IsSameAttachment(const Attachment* attachment) const override {
if (attachment->IsRenderbufferAttachment()) {
const RenderbufferAttachment* other =
reinterpret_cast<const RenderbufferAttachment*>(attachment);
return IsRenderbuffer(other->renderbuffer());
}
return false;
}
bool Is3D() const override { return false; }
bool CanRenderTo(const FeatureInfo*) const override { return true; }
......@@ -220,6 +229,18 @@ class TextureAttachment
return texture == texture_ref_.get();
}
bool IsSameAttachment(const Attachment* attachment) const override {
if (attachment->IsTextureAttachment()) {
const TextureAttachment* other =
reinterpret_cast<const TextureAttachment*>(attachment);
return IsTexture(other->texture()) &&
layer_ == other->layer() &&
target_ == other->target() &&
level_ == other->level();
}
return false;
}
bool IsRenderbuffer(Renderbuffer* /* renderbuffer */) const override {
return false;
}
......@@ -711,6 +732,19 @@ GLenum Framebuffer::IsPossiblyComplete(const FeatureInfo* feature_info) const {
if (!attachment->CanRenderTo(feature_info)) {
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
// Attaching an image to more than one color attachment point should return
// FRAMEBUFFER_UNSUPPORTED.
if (it->first >= GL_COLOR_ATTACHMENT0 &&
it->first < GL_COLOR_ATTACHMENT0 + manager_->max_color_attachments_) {
for (GLenum i = it->first + 1;
i < GL_COLOR_ATTACHMENT0 + manager_->max_color_attachments_; i++) {
const Attachment* other = GetAttachment(i);
if (other && attachment->IsSameAttachment(other)) {
return GL_FRAMEBUFFER_UNSUPPORTED;
}
}
}
}
// This does not mean the framebuffer is actually complete. It just means our
......
......@@ -51,8 +51,8 @@ class GPU_EXPORT Framebuffer : public base::RefCounted<Framebuffer> {
virtual bool IsTextureAttachment() const = 0;
virtual bool IsRenderbufferAttachment() const = 0;
virtual bool IsTexture(TextureRef* texture) const = 0;
virtual bool IsRenderbuffer(
Renderbuffer* renderbuffer) const = 0;
virtual bool IsRenderbuffer(Renderbuffer* renderbuffer) const = 0;
virtual bool IsSameAttachment(const Attachment* attachment) const = 0;
virtual bool Is3D() const = 0;
// If it's a 3D texture attachment, return true if
......
......@@ -1494,6 +1494,23 @@ TEST_F(FramebufferInfoTest, GetStatus) {
class FramebufferInfoES3Test : public FramebufferInfoTestBase {
public:
FramebufferInfoES3Test() : FramebufferInfoTestBase(CONTEXT_TYPE_WEBGL2) {}
protected:
void SetUp() override {
InitializeContext("OpenGL ES 3.0", "");
}
void InitializeContext(const char* gl_version, const char* extensions) {
GpuServiceTest::SetUpWithGLVersion(gl_version, extensions);
TestHelper::SetupFeatureInfoInitExpectationsWithGLVersion(gl_.get(),
extensions, "", gl_version);
feature_info_->InitializeForTesting(CONTEXT_TYPE_OPENGLES3);
decoder_.reset(new MockGLES2Decoder());
manager_.CreateFramebuffer(kClient1Id, kService1Id);
error_state_.reset(new ::testing::StrictMock<gles2::MockErrorState>());
framebuffer_ = manager_.GetFramebuffer(kClient1Id);
ASSERT_TRUE(framebuffer_ != NULL);
}
};
TEST_F(FramebufferInfoES3Test, DifferentDimensions) {
......@@ -1538,6 +1555,38 @@ TEST_F(FramebufferInfoES3Test, DifferentDimensions) {
framebuffer_->IsPossiblyComplete(feature_info_.get()));
}
TEST_F(FramebufferInfoES3Test, DuplicatedAttachments) {
const GLuint kTextureClientId = 33;
const GLuint kTextureServiceId = 333;
const GLenum kTarget = GL_TEXTURE_2D;
const GLint kLevel = 0;
const GLenum kFormat = GL_RGBA;
const GLenum kType = GL_UNSIGNED_BYTE;
const GLint kWidth = 16;
const GLint kHeight = 32;
const GLint kDepth = 1;
const GLint kBorder = 0;
const GLint kSamples = 0;
texture_manager_->CreateTexture(kTextureClientId, kTextureServiceId);
scoped_refptr<TextureRef> texture(
texture_manager_->GetTexture(kTextureClientId));
ASSERT_TRUE(texture.get() != nullptr);
texture_manager_->SetTarget(texture.get(), GL_TEXTURE_2D);
texture_manager_->SetLevelInfo(texture.get(), GL_TEXTURE_2D, kLevel,
kFormat, kWidth, kHeight, kDepth, kBorder,
kFormat, kType, gfx::Rect());
// Check an image is attached to more than one color attachment point
// in a framebuffer.
framebuffer_->AttachTexture(
GL_COLOR_ATTACHMENT0, texture.get(), kTarget, kLevel, kSamples);
framebuffer_->AttachTexture(
GL_COLOR_ATTACHMENT1, texture.get(), kTarget, kLevel, kSamples);
EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_UNSUPPORTED),
framebuffer_->IsPossiblyComplete(feature_info_.get()));
}
TEST_F(FramebufferInfoES3Test, ReadBuffer) {
const GLuint kRenderbufferClientId = 33;
const GLuint kRenderbufferServiceId = 333;
......
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