Commit a02315b0 by Jamie Madill Committed by Commit Bot

WebGL Compat: Add DEPTH_STENCIL attachments.

This is a special WebGL 1 binding point, that does not correspond to any native functionality. Due to particularities in validation we need to represent this with additional state in the Framebuffer. WebGL 2 fixes this oddity by resolving to the GLES 3 native spec. In order to pass the WebGL framebuffer objects test, we will also need a chromium-side CL to work with the additional state tracking it does in the blink layer, and an additional patch to ANGLE to clear the depth buffer before the first use (robust resource init). BUG=angleproject:1708 Change-Id: I111f8f5a451cce7de6cf281a6bc335b92dd2daf2 Reviewed-on: https://chromium-review.googlesource.com/444095 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 89fcb8e8
...@@ -2123,7 +2123,7 @@ void Context::detachTexture(GLuint texture) ...@@ -2123,7 +2123,7 @@ void Context::detachTexture(GLuint texture)
// allocation map management either here or in the resource manager at detach time. // allocation map management either here or in the resource manager at detach time.
// Zero textures are held by the Context, and we don't attempt to request them from // Zero textures are held by the Context, and we don't attempt to request them from
// the State. // the State.
mGLState.detachTexture(mZeroTextures, texture); mGLState.detachTexture(this, mZeroTextures, texture);
} }
void Context::detachBuffer(GLuint buffer) void Context::detachBuffer(GLuint buffer)
...@@ -2162,7 +2162,7 @@ void Context::detachFramebuffer(GLuint framebuffer) ...@@ -2162,7 +2162,7 @@ void Context::detachFramebuffer(GLuint framebuffer)
void Context::detachRenderbuffer(GLuint renderbuffer) void Context::detachRenderbuffer(GLuint renderbuffer)
{ {
mGLState.detachRenderbuffer(renderbuffer); mGLState.detachRenderbuffer(this, renderbuffer);
} }
void Context::detachVertexArray(GLuint vertexArray) void Context::detachVertexArray(GLuint vertexArray)
...@@ -2738,11 +2738,11 @@ void Context::framebufferTexture2D(GLenum target, ...@@ -2738,11 +2738,11 @@ void Context::framebufferTexture2D(GLenum target,
index = ImageIndex::MakeCube(textarget, level); index = ImageIndex::MakeCube(textarget, level);
} }
framebuffer->setAttachment(GL_TEXTURE, attachment, index, textureObj); framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
} }
else else
{ {
framebuffer->resetAttachment(attachment); framebuffer->resetAttachment(this, attachment);
} }
mGLState.setObjectDirty(target); mGLState.setObjectDirty(target);
...@@ -2759,12 +2759,13 @@ void Context::framebufferRenderbuffer(GLenum target, ...@@ -2759,12 +2759,13 @@ void Context::framebufferRenderbuffer(GLenum target,
if (renderbuffer != 0) if (renderbuffer != 0)
{ {
Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer); Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
framebuffer->setAttachment(GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
renderbufferObject); renderbufferObject);
} }
else else
{ {
framebuffer->resetAttachment(attachment); framebuffer->resetAttachment(this, attachment);
} }
mGLState.setObjectDirty(target); mGLState.setObjectDirty(target);
...@@ -2795,11 +2796,11 @@ void Context::framebufferTextureLayer(GLenum target, ...@@ -2795,11 +2796,11 @@ void Context::framebufferTextureLayer(GLenum target,
index = ImageIndex::Make2DArray(level, layer); index = ImageIndex::Make2DArray(level, layer);
} }
framebuffer->setAttachment(GL_TEXTURE, attachment, index, textureObject); framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
} }
else else
{ {
framebuffer->resetAttachment(attachment); framebuffer->resetAttachment(this, attachment);
} }
mGLState.setObjectDirty(target); mGLState.setObjectDirty(target);
......
...@@ -98,6 +98,11 @@ ContextState::~ContextState() ...@@ -98,6 +98,11 @@ ContextState::~ContextState()
// Handles are released by the Context. // Handles are released by the Context.
} }
bool ContextState::isWebGL1() const
{
return (mExtensions.webglCompatibility && mClientVersion.major == 2);
}
const TextureCaps &ContextState::getTextureCap(GLenum internalFormat) const const TextureCaps &ContextState::getTextureCap(GLenum internalFormat) const
{ {
return mTextureCaps.get(internalFormat); return mTextureCaps.get(internalFormat);
......
...@@ -58,6 +58,8 @@ class ContextState final : public angle::NonCopyable ...@@ -58,6 +58,8 @@ class ContextState final : public angle::NonCopyable
bool usingDisplayTextureShareGroup() const; bool usingDisplayTextureShareGroup() const;
bool isWebGL1() const;
private: private:
friend class Context; friend class Context;
friend class ValidationContext; friend class ValidationContext;
...@@ -124,6 +126,8 @@ class ValidationContext : angle::NonCopyable ...@@ -124,6 +126,8 @@ class ValidationContext : angle::NonCopyable
// Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
GLenum getConvertedRenderbufferFormat(GLenum internalformat) const; GLenum getConvertedRenderbufferFormat(GLenum internalformat) const;
bool isWebGL1() const { return mState.isWebGL1(); }
protected: protected:
ContextState mState; ContextState mState;
bool mSkipValidation; bool mSkipValidation;
......
...@@ -50,7 +50,8 @@ FramebufferState::FramebufferState() ...@@ -50,7 +50,8 @@ FramebufferState::FramebufferState()
mDefaultWidth(0), mDefaultWidth(0),
mDefaultHeight(0), mDefaultHeight(0),
mDefaultSamples(0), mDefaultSamples(0),
mDefaultFixedSampleLocations(GL_FALSE) mDefaultFixedSampleLocations(GL_FALSE),
mWebGLDepthStencilConsistent(true)
{ {
mEnabledDrawBuffers.set(0); mEnabledDrawBuffers.set(0);
} }
...@@ -63,7 +64,8 @@ FramebufferState::FramebufferState(const Caps &caps) ...@@ -63,7 +64,8 @@ FramebufferState::FramebufferState(const Caps &caps)
mDefaultWidth(0), mDefaultWidth(0),
mDefaultHeight(0), mDefaultHeight(0),
mDefaultSamples(0), mDefaultSamples(0),
mDefaultFixedSampleLocations(GL_FALSE) mDefaultFixedSampleLocations(GL_FALSE),
mWebGLDepthStencilConsistent(true)
{ {
ASSERT(mDrawBufferStates.size() > 0); ASSERT(mDrawBufferStates.size() > 0);
mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT; mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT;
...@@ -313,16 +315,17 @@ Framebuffer::Framebuffer(egl::Surface *surface) ...@@ -313,16 +315,17 @@ Framebuffer::Framebuffer(egl::Surface *surface)
mDirtyColorAttachmentBindings.push_back( mDirtyColorAttachmentBindings.push_back(
ChannelBinding(this, static_cast<SignalToken>(DIRTY_BIT_COLOR_ATTACHMENT_0))); ChannelBinding(this, static_cast<SignalToken>(DIRTY_BIT_COLOR_ATTACHMENT_0)));
setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_BACK, gl::ImageIndex::MakeInvalid(), surface); setAttachmentImpl(GL_FRAMEBUFFER_DEFAULT, GL_BACK, gl::ImageIndex::MakeInvalid(), surface);
if (surface->getConfig()->depthSize > 0) if (surface->getConfig()->depthSize > 0)
{ {
setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_DEPTH, gl::ImageIndex::MakeInvalid(), surface); setAttachmentImpl(GL_FRAMEBUFFER_DEFAULT, GL_DEPTH, gl::ImageIndex::MakeInvalid(), surface);
} }
if (surface->getConfig()->stencilSize > 0) if (surface->getConfig()->stencilSize > 0)
{ {
setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_STENCIL, gl::ImageIndex::MakeInvalid(), surface); setAttachmentImpl(GL_FRAMEBUFFER_DEFAULT, GL_STENCIL, gl::ImageIndex::MakeInvalid(),
surface);
} }
} }
...@@ -363,17 +366,17 @@ const std::string &Framebuffer::getLabel() const ...@@ -363,17 +366,17 @@ const std::string &Framebuffer::getLabel() const
return mState.mLabel; return mState.mLabel;
} }
void Framebuffer::detachTexture(GLuint textureId) void Framebuffer::detachTexture(const Context *context, GLuint textureId)
{ {
detachResourceById(GL_TEXTURE, textureId); detachResourceById(context, GL_TEXTURE, textureId);
} }
void Framebuffer::detachRenderbuffer(GLuint renderbufferId) void Framebuffer::detachRenderbuffer(const Context *context, GLuint renderbufferId)
{ {
detachResourceById(GL_RENDERBUFFER, renderbufferId); detachResourceById(context, GL_RENDERBUFFER, renderbufferId);
} }
void Framebuffer::detachResourceById(GLenum resourceType, GLuint resourceId) void Framebuffer::detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId)
{ {
for (size_t colorIndex = 0; colorIndex < mState.mColorAttachments.size(); ++colorIndex) for (size_t colorIndex = 0; colorIndex < mState.mColorAttachments.size(); ++colorIndex)
{ {
...@@ -381,10 +384,27 @@ void Framebuffer::detachResourceById(GLenum resourceType, GLuint resourceId) ...@@ -381,10 +384,27 @@ void Framebuffer::detachResourceById(GLenum resourceType, GLuint resourceId)
DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex); DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex);
} }
if (context->isWebGL1())
{
const std::array<FramebufferAttachment *, 3> attachments = {
{&mState.mWebGLDepthStencilAttachment, &mState.mWebGLDepthAttachment,
&mState.mWebGLStencilAttachment}};
for (FramebufferAttachment *attachment : attachments)
{
if (attachment->isAttached() && attachment->type() == resourceType &&
attachment->id() == resourceId)
{
resetAttachment(context, attachment->getBinding());
}
}
}
else
{
detachMatchingAttachment(&mState.mDepthAttachment, resourceType, resourceId, detachMatchingAttachment(&mState.mDepthAttachment, resourceType, resourceId,
DIRTY_BIT_DEPTH_ATTACHMENT); DIRTY_BIT_DEPTH_ATTACHMENT);
detachMatchingAttachment(&mState.mStencilAttachment, resourceType, resourceId, detachMatchingAttachment(&mState.mStencilAttachment, resourceType, resourceId,
DIRTY_BIT_STENCIL_ATTACHMENT); DIRTY_BIT_STENCIL_ATTACHMENT);
}
} }
void Framebuffer::detachMatchingAttachment(FramebufferAttachment *attachment, void Framebuffer::detachMatchingAttachment(FramebufferAttachment *attachment,
...@@ -763,6 +783,34 @@ GLenum Framebuffer::checkStatusImpl(const ContextState &state) ...@@ -763,6 +783,34 @@ GLenum Framebuffer::checkStatusImpl(const ContextState &state)
} }
} }
// Special additional validation for WebGL 1 DEPTH/STENCIL/DEPTH_STENCIL.
if (state.isWebGL1())
{
if (!mState.mWebGLDepthStencilConsistent)
{
return GL_FRAMEBUFFER_UNSUPPORTED;
}
if (mState.mWebGLDepthStencilAttachment.isAttached())
{
if (mState.mWebGLDepthStencilAttachment.getDepthSize() == 0 ||
mState.mWebGLDepthStencilAttachment.getStencilSize() == 0)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
else if (mState.mStencilAttachment.isAttached() &&
mState.mStencilAttachment.getDepthSize() > 0)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
else if (mState.mDepthAttachment.isAttached() &&
mState.mDepthAttachment.getStencilSize() > 0)
{
return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
}
}
// we need to have at least one attachment to be complete // we need to have at least one attachment to be complete
if (missingAttachment) if (missingAttachment)
{ {
...@@ -951,7 +999,93 @@ bool Framebuffer::hasValidDepthStencil() const ...@@ -951,7 +999,93 @@ bool Framebuffer::hasValidDepthStencil() const
return mState.getDepthStencilAttachment() != nullptr; return mState.getDepthStencilAttachment() != nullptr;
} }
void Framebuffer::setAttachment(GLenum type, void Framebuffer::setAttachment(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource)
{
// Context may be null in unit tests.
if (!context || !context->isWebGL1())
{
setAttachmentImpl(type, binding, textureIndex, resource);
return;
}
switch (binding)
{
case GL_DEPTH_STENCIL:
case GL_DEPTH_STENCIL_ATTACHMENT:
mState.mWebGLDepthStencilAttachment.attach(type, binding, textureIndex, resource);
break;
case GL_DEPTH:
case GL_DEPTH_ATTACHMENT:
mState.mWebGLDepthAttachment.attach(type, binding, textureIndex, resource);
break;
case GL_STENCIL:
case GL_STENCIL_ATTACHMENT:
mState.mWebGLStencilAttachment.attach(type, binding, textureIndex, resource);
break;
default:
setAttachmentImpl(type, binding, textureIndex, resource);
return;
}
commitWebGL1DepthStencilIfConsistent();
}
void Framebuffer::commitWebGL1DepthStencilIfConsistent()
{
int count = 0;
std::array<FramebufferAttachment *, 3> attachments = {{&mState.mWebGLDepthStencilAttachment,
&mState.mWebGLDepthAttachment,
&mState.mWebGLStencilAttachment}};
for (FramebufferAttachment *attachment : attachments)
{
if (attachment->isAttached())
{
count++;
}
}
mState.mWebGLDepthStencilConsistent = (count <= 1);
if (!mState.mWebGLDepthStencilConsistent)
{
// Inconsistent.
return;
}
if (mState.mWebGLDepthAttachment.isAttached())
{
const auto &depth = mState.mWebGLDepthAttachment;
setAttachmentImpl(depth.type(), GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(),
depth.getResource());
setAttachmentImpl(GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(), nullptr);
}
else if (mState.mWebGLStencilAttachment.isAttached())
{
const auto &stencil = mState.mWebGLStencilAttachment;
setAttachmentImpl(GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(), nullptr);
setAttachmentImpl(stencil.type(), GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(),
stencil.getResource());
}
else if (mState.mWebGLDepthStencilAttachment.isAttached())
{
const auto &depthStencil = mState.mWebGLDepthStencilAttachment;
setAttachmentImpl(depthStencil.type(), GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(),
depthStencil.getResource());
setAttachmentImpl(depthStencil.type(), GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(),
depthStencil.getResource());
}
else
{
setAttachmentImpl(GL_NONE, GL_DEPTH_ATTACHMENT, ImageIndex::MakeInvalid(), nullptr);
setAttachmentImpl(GL_NONE, GL_STENCIL_ATTACHMENT, ImageIndex::MakeInvalid(), nullptr);
}
}
void Framebuffer::setAttachmentImpl(GLenum type,
GLenum binding, GLenum binding,
const ImageIndex &textureIndex, const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource) FramebufferAttachmentObject *resource)
...@@ -977,9 +1111,9 @@ void Framebuffer::setAttachment(GLenum type, ...@@ -977,9 +1111,9 @@ void Framebuffer::setAttachment(GLenum type,
mDirtyBits.set(DIRTY_BIT_STENCIL_ATTACHMENT); mDirtyBits.set(DIRTY_BIT_STENCIL_ATTACHMENT);
BindResourceChannel(&mDirtyDepthAttachmentBinding, resource); BindResourceChannel(&mDirtyDepthAttachmentBinding, resource);
BindResourceChannel(&mDirtyStencilAttachmentBinding, resource); BindResourceChannel(&mDirtyStencilAttachmentBinding, resource);
return;
} }
else
{
switch (binding) switch (binding)
{ {
case GL_DEPTH: case GL_DEPTH:
...@@ -1012,12 +1146,11 @@ void Framebuffer::setAttachment(GLenum type, ...@@ -1012,12 +1146,11 @@ void Framebuffer::setAttachment(GLenum type,
} }
break; break;
} }
}
} }
void Framebuffer::resetAttachment(GLenum binding) void Framebuffer::resetAttachment(const Context *context, GLenum binding)
{ {
setAttachment(GL_NONE, binding, ImageIndex::MakeInvalid(), nullptr); setAttachment(context, GL_NONE, binding, ImageIndex::MakeInvalid(), nullptr);
} }
void Framebuffer::syncState() void Framebuffer::syncState()
......
...@@ -105,6 +105,13 @@ class FramebufferState final : angle::NonCopyable ...@@ -105,6 +105,13 @@ class FramebufferState final : angle::NonCopyable
GLint mDefaultHeight; GLint mDefaultHeight;
GLint mDefaultSamples; GLint mDefaultSamples;
GLboolean mDefaultFixedSampleLocations; GLboolean mDefaultFixedSampleLocations;
// It's necessary to store all this extra state so we can restore attachments
// when DEPTH_STENCIL/DEPTH/STENCIL is unbound in WebGL 1.
FramebufferAttachment mWebGLDepthStencilAttachment;
FramebufferAttachment mWebGLDepthAttachment;
FramebufferAttachment mWebGLStencilAttachment;
bool mWebGLDepthStencilConsistent;
}; };
class Framebuffer final : public LabeledObject, public angle::SignalReceiver class Framebuffer final : public LabeledObject, public angle::SignalReceiver
...@@ -128,14 +135,15 @@ class Framebuffer final : public LabeledObject, public angle::SignalReceiver ...@@ -128,14 +135,15 @@ class Framebuffer final : public LabeledObject, public angle::SignalReceiver
GLuint id() const { return mId; } GLuint id() const { return mId; }
void setAttachment(GLenum type, void setAttachment(const Context *context,
GLenum type,
GLenum binding, GLenum binding,
const ImageIndex &textureIndex, const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource); FramebufferAttachmentObject *resource);
void resetAttachment(GLenum binding); void resetAttachment(const Context *context, GLenum binding);
void detachTexture(GLuint texture); void detachTexture(const Context *context, GLuint texture);
void detachRenderbuffer(GLuint renderbuffer); void detachRenderbuffer(const Context *context, GLuint renderbuffer);
const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const; const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
const FramebufferAttachment *getDepthbuffer() const; const FramebufferAttachment *getDepthbuffer() const;
...@@ -254,12 +262,18 @@ class Framebuffer final : public LabeledObject, public angle::SignalReceiver ...@@ -254,12 +262,18 @@ class Framebuffer final : public LabeledObject, public angle::SignalReceiver
GLint copyTextureLayer) const; GLint copyTextureLayer) const;
private: private:
void detachResourceById(GLenum resourceType, GLuint resourceId); void detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId);
void detachMatchingAttachment(FramebufferAttachment *attachment, void detachMatchingAttachment(FramebufferAttachment *attachment,
GLenum matchType, GLenum matchType,
GLuint matchId, GLuint matchId,
size_t dirtyBit); size_t dirtyBit);
GLenum checkStatusImpl(const ContextState &state); GLenum checkStatusImpl(const ContextState &state);
void commitWebGL1DepthStencilIfConsistent();
void setAttachmentImpl(GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource);
FramebufferState mState; FramebufferState mState;
rx::FramebufferImpl *mImpl; rx::FramebufferImpl *mImpl;
......
...@@ -210,6 +210,11 @@ const egl::Surface *FramebufferAttachment::getSurface() const ...@@ -210,6 +210,11 @@ const egl::Surface *FramebufferAttachment::getSurface() const
return rx::GetAs<egl::Surface>(mResource); return rx::GetAs<egl::Surface>(mResource);
} }
FramebufferAttachmentObject *FramebufferAttachment::getResource() const
{
return mResource;
}
bool FramebufferAttachment::operator==(const FramebufferAttachment &other) const bool FramebufferAttachment::operator==(const FramebufferAttachment &other) const
{ {
if (mResource != other.mResource || mType != other.mType) if (mResource != other.mResource || mType != other.mType)
......
...@@ -126,6 +126,7 @@ class FramebufferAttachment final ...@@ -126,6 +126,7 @@ class FramebufferAttachment final
Renderbuffer *getRenderbuffer() const; Renderbuffer *getRenderbuffer() const;
Texture *getTexture() const; Texture *getTexture() const;
const egl::Surface *getSurface() const; const egl::Surface *getSurface() const;
FramebufferAttachmentObject *getResource() const;
// "T" must be static_castable from FramebufferAttachmentRenderTarget // "T" must be static_castable from FramebufferAttachmentRenderTarget
template <typename T> template <typename T>
...@@ -177,22 +178,26 @@ class FramebufferAttachmentObject ...@@ -177,22 +178,26 @@ class FramebufferAttachmentObject
inline Extents FramebufferAttachment::getSize() const inline Extents FramebufferAttachment::getSize() const
{ {
ASSERT(mResource);
return mResource->getAttachmentSize(mTarget); return mResource->getAttachmentSize(mTarget);
} }
inline const Format &FramebufferAttachment::getFormat() const inline const Format &FramebufferAttachment::getFormat() const
{ {
ASSERT(mResource);
return mResource->getAttachmentFormat(mTarget); return mResource->getAttachmentFormat(mTarget);
} }
inline GLsizei FramebufferAttachment::getSamples() const inline GLsizei FramebufferAttachment::getSamples() const
{ {
ASSERT(mResource);
return mResource->getAttachmentSamples(mTarget); return mResource->getAttachmentSamples(mTarget);
} }
inline gl::Error FramebufferAttachment::getRenderTargetImpl( inline gl::Error FramebufferAttachment::getRenderTargetImpl(
rx::FramebufferAttachmentRenderTarget **rtOut) const rx::FramebufferAttachmentRenderTarget **rtOut) const
{ {
ASSERT(mResource);
return mResource->getAttachmentRenderTarget(mTarget, rtOut); return mResource->getAttachmentRenderTarget(mTarget, rtOut);
} }
......
...@@ -779,7 +779,7 @@ GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const ...@@ -779,7 +779,7 @@ GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const
return it->second[sampler].id(); return it->second[sampler].id();
} }
void State::detachTexture(const TextureMap &zeroTextures, GLuint texture) void State::detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture)
{ {
// Textures have a detach method on State rather than a simple // Textures have a detach method on State rather than a simple
// removeBinding, because the zero/null texture objects are managed // removeBinding, because the zero/null texture objects are managed
...@@ -814,12 +814,12 @@ void State::detachTexture(const TextureMap &zeroTextures, GLuint texture) ...@@ -814,12 +814,12 @@ void State::detachTexture(const TextureMap &zeroTextures, GLuint texture)
if (mReadFramebuffer) if (mReadFramebuffer)
{ {
mReadFramebuffer->detachTexture(texture); mReadFramebuffer->detachTexture(context, texture);
} }
if (mDrawFramebuffer) if (mDrawFramebuffer)
{ {
mDrawFramebuffer->detachTexture(texture); mDrawFramebuffer->detachTexture(context, texture);
} }
} }
...@@ -883,7 +883,7 @@ Renderbuffer *State::getCurrentRenderbuffer() const ...@@ -883,7 +883,7 @@ Renderbuffer *State::getCurrentRenderbuffer() const
return mRenderbuffer.get(); return mRenderbuffer.get();
} }
void State::detachRenderbuffer(GLuint renderbuffer) void State::detachRenderbuffer(const Context *context, GLuint renderbuffer)
{ {
// [OpenGL ES 2.0.24] section 4.4 page 109: // [OpenGL ES 2.0.24] section 4.4 page 109:
// If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer
...@@ -904,12 +904,12 @@ void State::detachRenderbuffer(GLuint renderbuffer) ...@@ -904,12 +904,12 @@ void State::detachRenderbuffer(GLuint renderbuffer)
if (readFramebuffer) if (readFramebuffer)
{ {
readFramebuffer->detachRenderbuffer(renderbuffer); readFramebuffer->detachRenderbuffer(context, renderbuffer);
} }
if (drawFramebuffer && drawFramebuffer != readFramebuffer) if (drawFramebuffer && drawFramebuffer != readFramebuffer)
{ {
drawFramebuffer->detachRenderbuffer(renderbuffer); drawFramebuffer->detachRenderbuffer(context, renderbuffer);
} }
} }
......
...@@ -167,7 +167,7 @@ class State : angle::NonCopyable ...@@ -167,7 +167,7 @@ class State : angle::NonCopyable
Texture *getTargetTexture(GLenum target) const; Texture *getTargetTexture(GLenum target) const;
Texture *getSamplerTexture(unsigned int sampler, GLenum type) const; Texture *getSamplerTexture(unsigned int sampler, GLenum type) const;
GLuint getSamplerTextureId(unsigned int sampler, GLenum type) const; GLuint getSamplerTextureId(unsigned int sampler, GLenum type) const;
void detachTexture(const TextureMap &zeroTextures, GLuint texture); void detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture);
void initializeZeroTextures(const TextureMap &zeroTextures); void initializeZeroTextures(const TextureMap &zeroTextures);
// Sampler object binding manipulation // Sampler object binding manipulation
...@@ -180,7 +180,7 @@ class State : angle::NonCopyable ...@@ -180,7 +180,7 @@ class State : angle::NonCopyable
void setRenderbufferBinding(Renderbuffer *renderbuffer); void setRenderbufferBinding(Renderbuffer *renderbuffer);
GLuint getRenderbufferId() const; GLuint getRenderbufferId() const;
Renderbuffer *getCurrentRenderbuffer() const; Renderbuffer *getCurrentRenderbuffer() const;
void detachRenderbuffer(GLuint renderbuffer); void detachRenderbuffer(const Context *context, GLuint renderbuffer);
// Framebuffer binding manipulation // Framebuffer binding manipulation
void setReadFramebufferBinding(Framebuffer *framebuffer); void setReadFramebufferBinding(Framebuffer *framebuffer);
......
...@@ -628,8 +628,7 @@ void QueryRenderbufferiv(const Context *context, ...@@ -628,8 +628,7 @@ void QueryRenderbufferiv(const Context *context,
break; break;
case GL_RENDERBUFFER_INTERNAL_FORMAT: case GL_RENDERBUFFER_INTERNAL_FORMAT:
// Special case the WebGL 1 DEPTH_STENCIL format. // Special case the WebGL 1 DEPTH_STENCIL format.
if (context->getExtensions().webglCompatibility && if (context->isWebGL1() &&
context->getClientMajorVersion() == 2 &&
renderbuffer->getFormat().info->internalFormat == GL_DEPTH24_STENCIL8) renderbuffer->getFormat().info->internalFormat == GL_DEPTH24_STENCIL8)
{ {
*params = GL_DEPTH_STENCIL; *params = GL_DEPTH_STENCIL;
......
...@@ -91,7 +91,8 @@ TEST(ValidationESTest, DrawElementsWithMaxIndexGivesError) ...@@ -91,7 +91,8 @@ TEST(ValidationESTest, DrawElementsWithMaxIndexGivesError)
VertexArray *vertexArray = new VertexArray(&mockFactory, 0, 1, 1); VertexArray *vertexArray = new VertexArray(&mockFactory, 0, 1, 1);
Framebuffer *framebuffer = new Framebuffer(caps, &mockFactory, 1); Framebuffer *framebuffer = new Framebuffer(caps, &mockFactory, 1);
framebuffer->setAttachment(GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex::Make2D(0), texture); framebuffer->setAttachment(nullptr, GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex::Make2D(0),
texture);
Program *program = new Program(&mockFactory, nullptr, 1); Program *program = new Program(&mockFactory, nullptr, 1);
......
...@@ -37,6 +37,15 @@ class WebGLFramebufferTest : public ANGLETest ...@@ -37,6 +37,15 @@ class WebGLFramebufferTest : public ANGLETest
void TearDown() override { ANGLETest::TearDown(); } void TearDown() override { ANGLETest::TearDown(); }
void drawUByteColorQuad(GLuint program, GLint uniformLoc, const GLColor &color);
void testDepthStencilDepthStencil(GLint width, GLint height);
void testDepthStencilRenderbuffer(GLint width,
GLint height,
GLRenderbuffer *colorBuffer,
GLbitfield allowedStatuses);
void testRenderingAndReading(GLuint program);
void testUsingIncompleteFramebuffer(GLenum depthFormat, GLenum depthAttachment);
PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr; PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
}; };
...@@ -57,15 +66,17 @@ void checkFramebufferForAllowedStatuses(GLbitfield allowedStatuses) ...@@ -57,15 +66,17 @@ void checkFramebufferForAllowedStatuses(GLbitfield allowedStatuses)
EXPECT_TRUE(statusAllowed); EXPECT_TRUE(statusAllowed);
} }
void checkBufferBits(GLenum attachment) void checkBufferBits(GLenum attachment0, GLenum attachment1)
{ {
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
return; return;
bool haveDepthBuffer = bool haveDepthBuffer =
attachment == GL_DEPTH_ATTACHMENT || attachment == GL_DEPTH_STENCIL_ATTACHMENT; attachment0 == GL_DEPTH_ATTACHMENT || attachment0 == GL_DEPTH_STENCIL_ATTACHMENT ||
attachment1 == GL_DEPTH_ATTACHMENT || attachment1 == GL_DEPTH_STENCIL_ATTACHMENT;
bool haveStencilBuffer = bool haveStencilBuffer =
attachment == GL_STENCIL_ATTACHMENT || attachment == GL_DEPTH_STENCIL_ATTACHMENT; attachment0 == GL_STENCIL_ATTACHMENT || attachment0 == GL_DEPTH_STENCIL_ATTACHMENT ||
attachment1 == GL_STENCIL_ATTACHMENT || attachment1 == GL_DEPTH_STENCIL_ATTACHMENT;
GLint redBits = 0; GLint redBits = 0;
GLint greenBits = 0; GLint greenBits = 0;
...@@ -121,7 +132,7 @@ TEST_P(WebGLFramebufferTest, TestFramebufferRequiredCombinations) ...@@ -121,7 +132,7 @@ TEST_P(WebGLFramebufferTest, TestFramebufferRequiredCombinations)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
checkFramebufferForAllowedStatuses(ALLOW_COMPLETE); checkFramebufferForAllowedStatuses(ALLOW_COMPLETE);
checkBufferBits(GL_COLOR_ATTACHMENT0); checkBufferBits(GL_NONE, GL_NONE);
// 2. COLOR_ATTACHMENT0 = RGBA/UNSIGNED_BYTE texture + DEPTH_ATTACHMENT = DEPTH_COMPONENT16 // 2. COLOR_ATTACHMENT0 = RGBA/UNSIGNED_BYTE texture + DEPTH_ATTACHMENT = DEPTH_COMPONENT16
// renderbuffer // renderbuffer
...@@ -131,7 +142,7 @@ TEST_P(WebGLFramebufferTest, TestFramebufferRequiredCombinations) ...@@ -131,7 +142,7 @@ TEST_P(WebGLFramebufferTest, TestFramebufferRequiredCombinations)
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
checkFramebufferForAllowedStatuses(ALLOW_COMPLETE); checkFramebufferForAllowedStatuses(ALLOW_COMPLETE);
checkBufferBits(GL_DEPTH_ATTACHMENT); checkBufferBits(GL_DEPTH_ATTACHMENT, GL_NONE);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
// 3. COLOR_ATTACHMENT0 = RGBA/UNSIGNED_BYTE texture + DEPTH_STENCIL_ATTACHMENT = DEPTH_STENCIL // 3. COLOR_ATTACHMENT0 = RGBA/UNSIGNED_BYTE texture + DEPTH_STENCIL_ATTACHMENT = DEPTH_STENCIL
...@@ -141,7 +152,649 @@ TEST_P(WebGLFramebufferTest, TestFramebufferRequiredCombinations) ...@@ -141,7 +152,649 @@ TEST_P(WebGLFramebufferTest, TestFramebufferRequiredCombinations)
renderbuffer); renderbuffer);
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
checkFramebufferForAllowedStatuses(ALLOW_COMPLETE); checkFramebufferForAllowedStatuses(ALLOW_COMPLETE);
checkBufferBits(GL_DEPTH_STENCIL_ATTACHMENT); checkBufferBits(GL_DEPTH_STENCIL_ATTACHMENT, GL_NONE);
}
void testAttachment(GLint width,
GLint height,
GLRenderbuffer *colorBuffer,
GLenum attachment,
GLRenderbuffer *buffer,
GLbitfield allowedStatuses)
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, *colorBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, *buffer);
EXPECT_GL_NO_ERROR();
checkFramebufferForAllowedStatuses(allowedStatuses);
if ((allowedStatuses & ALLOW_COMPLETE) == 0)
{
std::vector<uint8_t> tempBuffer(width * height * 4);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_GL_ERROR(GL_INVALID_FRAMEBUFFER_OPERATION);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, tempBuffer.data());
EXPECT_GL_ERROR(GL_INVALID_FRAMEBUFFER_OPERATION);
}
checkBufferBits(attachment, GL_NONE);
}
void testAttachments(GLRenderbuffer &colorBuffer,
GLenum attachment0,
GLRenderbuffer &buffer0,
GLenum attachment1,
GLRenderbuffer &buffer1,
GLbitfield allowedStatuses)
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment0, GL_RENDERBUFFER, buffer0);
EXPECT_GL_NO_ERROR();
glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment1, GL_RENDERBUFFER, buffer1);
EXPECT_GL_NO_ERROR();
checkFramebufferForAllowedStatuses(allowedStatuses);
checkBufferBits(attachment0, attachment1);
}
void testColorRenderbuffer(GLint width,
GLint height,
GLenum internalformat,
GLbitfield allowedStatuses)
{
GLRenderbuffer colorBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, internalformat, width, height);
EXPECT_GL_NO_ERROR();
testAttachment(width, height, &colorBuffer, GL_COLOR_ATTACHMENT0, &colorBuffer,
allowedStatuses);
}
GLint getRenderbufferParameter(GLenum paramName)
{
GLint paramValue = 0;
glGetRenderbufferParameteriv(GL_RENDERBUFFER, paramName, &paramValue);
return paramValue;
}
void WebGLFramebufferTest::drawUByteColorQuad(GLuint program,
GLint uniformLoc,
const GLColor &color)
{
Vector4 vecColor = color.toNormalizedVector();
glUseProgram(program);
glUniform4fv(uniformLoc, 1, vecColor.data());
drawQuad(program, "position", 0.5f, 1.0f, true);
}
void WebGLFramebufferTest::testDepthStencilDepthStencil(GLint width, GLint height)
{
const std::string &vertexShader =
"attribute vec4 position;\n"
"void main() {\n"
" gl_Position = position;\n"
"}";
const std::string &fragmentShader =
"precision mediump float;\n"
"uniform vec4 color;\n"
"void main() {\n"
" gl_FragColor = color;\n"
"}";
if (width == 0 || height == 0)
{
return;
}
ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
GLint uniformLoc = glGetUniformLocation(program.get(), "color");
ASSERT_NE(-1, uniformLoc);
struct TestInfo
{
GLenum firstFormat;
GLenum firstAttach;
GLenum secondFormat;
GLenum secondAttach;
};
TestInfo tests[2] = {
{GL_DEPTH_COMPONENT16, GL_DEPTH_ATTACHMENT, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL_ATTACHMENT},
{GL_DEPTH_STENCIL, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH_COMPONENT16, GL_DEPTH_ATTACHMENT}};
for (const TestInfo &test : tests)
{
for (GLint opIndex = 0; opIndex < 2; ++opIndex)
{
GLFramebuffer fbo;
GLTexture tex;
GLRenderbuffer firstRb;
// test: firstFormat vs secondFormat with unbind or delete.
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
// attach texture as color
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
nullptr);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
// attach first
glBindRenderbuffer(GL_RENDERBUFFER, firstRb);
glRenderbufferStorage(GL_RENDERBUFFER, test.firstFormat, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, test.firstAttach, GL_RENDERBUFFER, firstRb);
EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
// TODO(jmadill): Remove clear - this should be implicit in WebGL_
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
// Test it works
drawUByteColorQuad(program.get(), uniformLoc, GLColor::green);
// should not draw since DEPTH_FUNC == LESS
drawUByteColorQuad(program.get(), uniformLoc, GLColor::red);
// should be green
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
GLuint secondRb = 0;
glGenRenderbuffers(1, &secondRb);
// attach second
glBindRenderbuffer(GL_RENDERBUFFER, secondRb);
glRenderbufferStorage(GL_RENDERBUFFER, test.secondFormat, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, test.secondAttach, GL_RENDERBUFFER, secondRb);
if (opIndex == 0)
{
// now delete it
glDeleteRenderbuffers(1, &secondRb);
secondRb = 0;
}
else
{
// unbind it
glFramebufferRenderbuffer(GL_FRAMEBUFFER, test.secondAttach, GL_RENDERBUFFER, 0);
}
// If the first attachment is not restored this may fail
EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
EXPECT_GL_NO_ERROR();
// If the first attachment is not restored this may fail.
glClear(GL_DEPTH_BUFFER_BIT);
drawUByteColorQuad(program.get(), uniformLoc, GLColor::green);
// should not draw since DEPTH_FUNC == LESS
drawUByteColorQuad(program.get(), uniformLoc, GLColor::red);
// should be green
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
glDisable(GL_DEPTH_TEST);
if (opIndex == 1)
{
glDeleteRenderbuffers(1, &secondRb);
secondRb = 0;
}
}
}
EXPECT_GL_NO_ERROR();
}
void WebGLFramebufferTest::testDepthStencilRenderbuffer(GLint width,
GLint height,
GLRenderbuffer *colorBuffer,
GLbitfield allowedStatuses)
{
GLRenderbuffer depthStencilBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, depthStencilBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, width, height);
EXPECT_GL_NO_ERROR();
// OpenGL itself doesn't seem to guarantee that e.g. a 2 x 0
// renderbuffer will report 2 for its width when queried.
if (!(height == 0 && width > 0))
EXPECT_EQ(width, getRenderbufferParameter(GL_RENDERBUFFER_WIDTH));
if (!(width == 0 && height > 0))
EXPECT_EQ(height, getRenderbufferParameter(GL_RENDERBUFFER_HEIGHT));
EXPECT_EQ(GL_DEPTH_STENCIL, getRenderbufferParameter(GL_RENDERBUFFER_INTERNAL_FORMAT));
EXPECT_EQ(0, getRenderbufferParameter(GL_RENDERBUFFER_RED_SIZE));
EXPECT_EQ(0, getRenderbufferParameter(GL_RENDERBUFFER_GREEN_SIZE));
EXPECT_EQ(0, getRenderbufferParameter(GL_RENDERBUFFER_BLUE_SIZE));
EXPECT_EQ(0, getRenderbufferParameter(GL_RENDERBUFFER_ALPHA_SIZE));
// Avoid verifying these for zero-sized renderbuffers for the time
// being since it appears that even OpenGL doesn't guarantee them.
if (width > 0 && height > 0)
{
EXPECT_GT(getRenderbufferParameter(GL_RENDERBUFFER_DEPTH_SIZE), 0);
EXPECT_GT(getRenderbufferParameter(GL_RENDERBUFFER_STENCIL_SIZE), 0);
}
EXPECT_GL_NO_ERROR();
testAttachment(width, height, colorBuffer, GL_DEPTH_STENCIL_ATTACHMENT, &depthStencilBuffer,
allowedStatuses);
testDepthStencilDepthStencil(width, height);
}
// Test various attachment combinations with WebGL framebuffers.
TEST_P(WebGLFramebufferTest, TestAttachments)
{
for (GLint width = 2; width <= 2; width += 2)
{
for (GLint height = 2; height <= 2; height += 2)
{
// Dimensions width x height.
GLRenderbuffer colorBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, width, height);
EXPECT_GL_NO_ERROR();
GLRenderbuffer depthBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
EXPECT_GL_NO_ERROR();
GLRenderbuffer stencilBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, stencilBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
EXPECT_GL_NO_ERROR();
GLRenderbuffer depthStencilBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, depthStencilBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, width, height);
EXPECT_GL_NO_ERROR();
GLbitfield allowedStatusForGoodCase =
(width == 0 || height == 0) ? ALLOW_INCOMPLETE_ATTACHMENT : ALLOW_COMPLETE;
// some cases involving stencil seem to be implementation-dependent
GLbitfield allowedStatusForImplDependentCase =
allowedStatusForGoodCase | ALLOW_UNSUPPORTED;
// Attach depth using DEPTH_ATTACHMENT.
testAttachment(width, height, &colorBuffer, GL_DEPTH_ATTACHMENT, &depthBuffer,
allowedStatusForGoodCase);
// Attach depth using STENCIL_ATTACHMENT.
testAttachment(width, height, &colorBuffer, GL_STENCIL_ATTACHMENT, &depthBuffer,
ALLOW_INCOMPLETE_ATTACHMENT);
// Attach depth using DEPTH_STENCIL_ATTACHMENT.
testAttachment(width, height, &colorBuffer, GL_DEPTH_STENCIL_ATTACHMENT, &depthBuffer,
ALLOW_INCOMPLETE_ATTACHMENT);
// Attach stencil using STENCIL_ATTACHMENT.
testAttachment(width, height, &colorBuffer, GL_STENCIL_ATTACHMENT, &stencilBuffer,
allowedStatusForImplDependentCase);
// Attach stencil using DEPTH_ATTACHMENT.
testAttachment(width, height, &colorBuffer, GL_DEPTH_ATTACHMENT, &stencilBuffer,
ALLOW_INCOMPLETE_ATTACHMENT);
// Attach stencil using DEPTH_STENCIL_ATTACHMENT.
testAttachment(width, height, &colorBuffer, GL_DEPTH_STENCIL_ATTACHMENT, &stencilBuffer,
ALLOW_INCOMPLETE_ATTACHMENT);
// Attach depthStencil using DEPTH_STENCIL_ATTACHMENT.
testAttachment(width, height, &colorBuffer, GL_DEPTH_STENCIL_ATTACHMENT,
&depthStencilBuffer, allowedStatusForGoodCase);
// Attach depthStencil using DEPTH_ATTACHMENT.
testAttachment(width, height, &colorBuffer, GL_DEPTH_ATTACHMENT, &depthStencilBuffer,
ALLOW_INCOMPLETE_ATTACHMENT);
// Attach depthStencil using STENCIL_ATTACHMENT.
testAttachment(width, height, &colorBuffer, GL_STENCIL_ATTACHMENT, &depthStencilBuffer,
ALLOW_INCOMPLETE_ATTACHMENT);
GLbitfield allowedStatusForConflictedAttachment =
(width == 0 || height == 0) ? ALLOW_UNSUPPORTED | ALLOW_INCOMPLETE_ATTACHMENT
: ALLOW_UNSUPPORTED;
// Attach depth, then stencil, causing conflict.
testAttachments(colorBuffer, GL_DEPTH_ATTACHMENT, depthBuffer, GL_STENCIL_ATTACHMENT,
stencilBuffer, allowedStatusForConflictedAttachment);
// Attach stencil, then depth, causing conflict.
testAttachments(colorBuffer, GL_STENCIL_ATTACHMENT, stencilBuffer, GL_DEPTH_ATTACHMENT,
depthBuffer, allowedStatusForConflictedAttachment);
// Attach depth, then depthStencil, causing conflict.
testAttachments(colorBuffer, GL_DEPTH_ATTACHMENT, depthBuffer,
GL_DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer,
allowedStatusForConflictedAttachment);
// Attach depthStencil, then depth, causing conflict.
testAttachments(colorBuffer, GL_DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer,
GL_DEPTH_ATTACHMENT, depthBuffer, allowedStatusForConflictedAttachment);
// Attach stencil, then depthStencil, causing conflict.
testAttachments(colorBuffer, GL_DEPTH_ATTACHMENT, depthBuffer,
GL_DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer,
allowedStatusForConflictedAttachment);
// Attach depthStencil, then stencil, causing conflict.
testAttachments(colorBuffer, GL_DEPTH_STENCIL_ATTACHMENT, depthStencilBuffer,
GL_STENCIL_ATTACHMENT, stencilBuffer,
allowedStatusForConflictedAttachment);
// Attach color renderbuffer with internalformat == RGBA4.
testColorRenderbuffer(width, height, GL_RGBA4, allowedStatusForGoodCase);
// Attach color renderbuffer with internalformat == RGB5_A1.
// This particular format seems to be bugged on NVIDIA Retina. http://crbug.com/635081
// TODO(jmadill): Figure out if we can add a format workaround.
if (!(IsNVIDIA() && IsOSX() && IsOpenGL()))
{
testColorRenderbuffer(width, height, GL_RGB5_A1, allowedStatusForGoodCase);
}
// Attach color renderbuffer with internalformat == RGB565.
testColorRenderbuffer(width, height, GL_RGB565, allowedStatusForGoodCase);
// Create and attach depthStencil renderbuffer.
testDepthStencilRenderbuffer(width, height, &colorBuffer, allowedStatusForGoodCase);
}
}
}
bool tryDepth(GLRenderbuffer *depthBuffer,
GLenum *depthFormat,
GLenum *depthAttachment,
GLenum try_format,
GLenum try_attachment)
{
if (*depthAttachment != GL_NONE)
{
// If we've tried once unattach the old one.
glFramebufferRenderbuffer(GL_FRAMEBUFFER, *depthAttachment, GL_RENDERBUFFER, 0);
}
*depthFormat = try_format;
*depthAttachment = try_attachment;
glFramebufferRenderbuffer(GL_FRAMEBUFFER, *depthAttachment, GL_RENDERBUFFER, *depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, *depthFormat, 16, 16);
EXPECT_GL_NO_ERROR();
return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
}
bool checkValidColorDepthCombination(GLenum *depthFormat, GLenum *depthAttachment)
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer colorBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 16, 16);
GLRenderbuffer depthBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
return tryDepth(&depthBuffer, depthFormat, depthAttachment, GL_DEPTH_COMPONENT16,
GL_DEPTH_ATTACHMENT) ||
tryDepth(&depthBuffer, depthFormat, depthAttachment, GL_DEPTH_STENCIL,
GL_DEPTH_STENCIL_ATTACHMENT);
}
// glCheckFramebufferStatus(GL_FRAMEBUFFER) should be either complete or (unsupported/expected).
void checkFramebuffer(GLenum expected)
{
GLenum actual = glCheckFramebufferStatus(GL_FRAMEBUFFER);
EXPECT_TRUE(actual == expected ||
(expected != GL_FRAMEBUFFER_COMPLETE && actual == GL_FRAMEBUFFER_UNSUPPORTED));
}
void WebGLFramebufferTest::testRenderingAndReading(GLuint program)
{
EXPECT_GL_NO_ERROR();
// drawArrays with incomplete framebuffer
drawQuad(program, "position", 0.5f, 1.0f, true);
EXPECT_GL_ERROR(GL_INVALID_FRAMEBUFFER_OPERATION);
// readPixels from incomplete framebuffer
std::vector<uint8_t> dummyBuffer(4);
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, dummyBuffer.data());
EXPECT_GL_ERROR(GL_INVALID_FRAMEBUFFER_OPERATION);
// copyTexImage and copyTexSubImage can be either INVALID_FRAMEBUFFER_OPERATION because
// the framebuffer is invalid OR INVALID_OPERATION because in the case of no attachments
// the framebuffer is not of a compatible type.
// copyTexSubImage2D from incomplete framebuffer
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
GLenum error = glGetError();
EXPECT_TRUE(error == GL_INVALID_FRAMEBUFFER_OPERATION || error == GL_INVALID_OPERATION);
// copyTexImage2D from incomplete framebuffer
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0);
error = glGetError();
EXPECT_TRUE(error == GL_INVALID_FRAMEBUFFER_OPERATION || error == GL_INVALID_OPERATION);
// clear with incomplete framebuffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
EXPECT_GL_ERROR(GL_INVALID_FRAMEBUFFER_OPERATION);
}
// Test drawing or reading from an incomplete framebuffer
void WebGLFramebufferTest::testUsingIncompleteFramebuffer(GLenum depthFormat,
GLenum depthAttachment)
{
// Simple draw program.
const std::string &vertexShader =
"attribute vec4 position; void main() { gl_Position = position; }";
const std::string &fragmentShader = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }";
ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer colorBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 16, 16);
GLRenderbuffer depthBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, depthAttachment, GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, depthFormat, 16, 16);
EXPECT_GL_NO_ERROR();
checkFramebuffer(GL_FRAMEBUFFER_COMPLETE);
// We pick this combination because it works on desktop OpenGL but should not work on OpenGL ES
// 2.0
glRenderbufferStorage(GL_RENDERBUFFER, depthFormat, 32, 16);
checkFramebuffer(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS);
// Drawing or reading from an incomplete framebuffer should generate
// INVALID_FRAMEBUFFER_OPERATION.
testRenderingAndReading(program.get());
GLFramebuffer fbo2;
glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
checkFramebuffer(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);
// Drawing or reading from an incomplete framebuffer should generate
// INVALID_FRAMEBUFFER_OPERATION.
testRenderingAndReading(program.get());
GLRenderbuffer colorBuffer2;
glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer2);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer2);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 0, 0);
// Drawing or reading from an incomplete framebuffer should generate
// INVALID_FRAMEBUFFER_OPERATION.
testRenderingAndReading(program.get());
}
void testFramebufferIncompleteAttachment(GLenum depthFormat)
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer colorBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 16, 16);
checkFramebuffer(GL_FRAMEBUFFER_COMPLETE);
// Wrong storage type for type of attachment be FRAMEBUFFER_INCOMPLETE_ATTACHMENT (OpenGL ES 2.0
// 4.4.5).
glRenderbufferStorage(GL_RENDERBUFFER, depthFormat, 16, 16);
checkFramebuffer(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 16, 16);
checkFramebuffer(GL_FRAMEBUFFER_COMPLETE);
// 0 size attachment should be FRAMEBUFFER_INCOMPLETE_ATTACHMENT (OpenGL ES 2.0 4.4.5).
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 0, 0);
checkFramebuffer(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
EXPECT_GL_NO_ERROR();
}
// No attachments should be INCOMPLETE_FRAMEBUFFER_MISSING_ATTACHMENT (OpenGL ES 2.0 4.4.5).
void testFramebufferIncompleteMissingAttachment()
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
checkFramebuffer(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);
GLRenderbuffer colorBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 16, 16);
checkFramebuffer(GL_FRAMEBUFFER_COMPLETE);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
checkFramebuffer(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);
EXPECT_GL_NO_ERROR();
}
// Attachments of different sizes should be FRAMEBUFFER_INCOMPLETE_DIMENSIONS (OpenGL ES 2.0 4.4.5).
void testFramebufferIncompleteDimensions(GLenum depthFormat, GLenum depthAttachment)
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GLRenderbuffer colorBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 16, 16);
GLRenderbuffer depthBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, depthAttachment, GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, depthFormat, 16, 16);
EXPECT_GL_NO_ERROR();
checkFramebuffer(GL_FRAMEBUFFER_COMPLETE);
glRenderbufferStorage(GL_RENDERBUFFER, depthFormat, 32, 16);
checkFramebuffer(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS);
glRenderbufferStorage(GL_RENDERBUFFER, depthFormat, 16, 16);
checkFramebuffer(GL_FRAMEBUFFER_COMPLETE);
glBindRenderbuffer(GL_RENDERBUFFER, colorBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 16, 32);
checkFramebuffer(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 16, 16);
checkFramebuffer(GL_FRAMEBUFFER_COMPLETE);
EXPECT_GL_NO_ERROR();
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
EXPECT_GL_NO_ERROR();
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
return;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
checkFramebuffer(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
checkFramebuffer(GL_FRAMEBUFFER_COMPLETE);
EXPECT_GL_NO_ERROR();
}
// Test drawing or reading from a missing framebuffer attachment.
void testReadingFromMissingAttachment()
{
GLFramebuffer fbo;
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
constexpr int size = 16;
// The only scenario we can verify is an attempt to read or copy
// from a missing color attachment while the framebuffer is still
// complete.
GLRenderbuffer depthBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, size, size);
// After depth renderbuffer setup
EXPECT_GL_NO_ERROR();
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
// Unable to allocate a framebuffer with just a depth attachment; this is legal.
// Try just a depth/stencil renderbuffer
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
GLRenderbuffer depthStencilBuffer;
glBindRenderbuffer(GL_RENDERBUFFER, depthStencilBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
depthStencilBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, size, size);
// After depth+stencil renderbuffer setup
EXPECT_GL_NO_ERROR();
// Unable to allocate a framebuffer with just a depth+stencil attachment; this is legal.
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
return;
}
}
// The FBO has no color attachment. ReadPixels, CopyTexImage2D,
// and CopyTexSubImage2D should all generate INVALID_OPERATION.
// Before ReadPixels from missing attachment
std::vector<uint8_t> dummyBuffer(4);
EXPECT_GL_NO_ERROR();
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, dummyBuffer.data());
// After ReadPixels from missing attachment
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex);
// Before CopyTexImage2D from missing attachment
EXPECT_GL_NO_ERROR();
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, size, size, 0);
// After CopyTexImage2D from missing attachment
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
// Before CopyTexSubImage2D from missing attachment
EXPECT_GL_NO_ERROR();
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, size, size);
// After CopyTexSubImage2D from missing attachment
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Determine if we can attach both color and depth or color and depth_stencil
TEST_P(WebGLFramebufferTest, CheckValidColorDepthCombination)
{
GLenum depthFormat = GL_NONE;
GLenum depthAttachment = GL_NONE;
if (checkValidColorDepthCombination(&depthFormat, &depthAttachment))
{
testFramebufferIncompleteDimensions(depthFormat, depthAttachment);
testFramebufferIncompleteAttachment(depthFormat);
testFramebufferIncompleteMissingAttachment();
testUsingIncompleteFramebuffer(depthFormat, depthAttachment);
testReadingFromMissingAttachment();
}
} }
// Only run against WebGL 1 validation, since much was changed in 2. // Only run against WebGL 1 validation, since much was changed in 2.
......
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