Add a few missing dirty bit cases.

Discovered some of these while investigating Texture dirty bits.

BUG=angleproject:1387

Change-Id: I8b170462bfd283e4b0f9d47b7f7ddbaa7957914d
Reviewed-on: https://chromium-review.googlesource.com/648051
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
index 1d69e85..209032e 100644
--- a/src/libANGLE/Context.cpp
+++ b/src/libANGLE/Context.cpp
@@ -861,6 +861,10 @@
 
     std::string labelName = GetObjectLabelFromPointer(length, label);
     object->setLabel(labelName);
+
+    // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
+    // specified object is active until we do this.
+    mGLState.setObjectDirty(identifier);
 }
 
 void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
diff --git a/src/libANGLE/Framebuffer.cpp b/src/libANGLE/Framebuffer.cpp
index 3892f1f..66fbe8b 100644
--- a/src/libANGLE/Framebuffer.cpp
+++ b/src/libANGLE/Framebuffer.cpp
@@ -597,22 +597,27 @@
     return mState.mLabel;
 }
 
-void Framebuffer::detachTexture(const Context *context, GLuint textureId)
+bool Framebuffer::detachTexture(const Context *context, GLuint textureId)
 {
-    detachResourceById(context, GL_TEXTURE, textureId);
+    return detachResourceById(context, GL_TEXTURE, textureId);
 }
 
-void Framebuffer::detachRenderbuffer(const Context *context, GLuint renderbufferId)
+bool Framebuffer::detachRenderbuffer(const Context *context, GLuint renderbufferId)
 {
-    detachResourceById(context, GL_RENDERBUFFER, renderbufferId);
+    return detachResourceById(context, GL_RENDERBUFFER, renderbufferId);
 }
 
-void Framebuffer::detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId)
+bool Framebuffer::detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId)
 {
+    bool found = false;
+
     for (size_t colorIndex = 0; colorIndex < mState.mColorAttachments.size(); ++colorIndex)
     {
-        detachMatchingAttachment(context, &mState.mColorAttachments[colorIndex], resourceType,
-                                 resourceId, DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex);
+        if (detachMatchingAttachment(context, &mState.mColorAttachments[colorIndex], resourceType,
+                                     resourceId, DIRTY_BIT_COLOR_ATTACHMENT_0 + colorIndex))
+        {
+            found = true;
+        }
     }
 
     if (context->isWebGL1())
@@ -626,19 +631,28 @@
                 attachment->id() == resourceId)
             {
                 resetAttachment(context, attachment->getBinding());
+                found = true;
             }
         }
     }
     else
     {
-        detachMatchingAttachment(context, &mState.mDepthAttachment, resourceType, resourceId,
-                                 DIRTY_BIT_DEPTH_ATTACHMENT);
-        detachMatchingAttachment(context, &mState.mStencilAttachment, resourceType, resourceId,
-                                 DIRTY_BIT_STENCIL_ATTACHMENT);
+        if (detachMatchingAttachment(context, &mState.mDepthAttachment, resourceType, resourceId,
+                                     DIRTY_BIT_DEPTH_ATTACHMENT))
+        {
+            found = true;
+        }
+        if (detachMatchingAttachment(context, &mState.mStencilAttachment, resourceType, resourceId,
+                                     DIRTY_BIT_STENCIL_ATTACHMENT))
+        {
+            found = true;
+        }
     }
+
+    return found;
 }
 
-void Framebuffer::detachMatchingAttachment(const Context *context,
+bool Framebuffer::detachMatchingAttachment(const Context *context,
                                            FramebufferAttachment *attachment,
                                            GLenum matchType,
                                            GLuint matchId,
@@ -648,7 +662,10 @@
     {
         attachment->detach(context);
         mDirtyBits.set(dirtyBit);
+        return true;
     }
+
+    return false;
 }
 
 const FramebufferAttachment *Framebuffer::getColorbuffer(size_t colorAttachment) const
diff --git a/src/libANGLE/Framebuffer.h b/src/libANGLE/Framebuffer.h
index 1d0191c..52c702c 100644
--- a/src/libANGLE/Framebuffer.h
+++ b/src/libANGLE/Framebuffer.h
@@ -169,8 +169,8 @@
                                           const GLint *viewportOffsets);
     void resetAttachment(const Context *context, GLenum binding);
 
-    void detachTexture(const Context *context, GLuint texture);
-    void detachRenderbuffer(const Context *context, GLuint renderbuffer);
+    bool detachTexture(const Context *context, GLuint texture);
+    bool detachRenderbuffer(const Context *context, GLuint renderbuffer);
 
     const FramebufferAttachment *getColorbuffer(size_t colorAttachment) const;
     const FramebufferAttachment *getDepthbuffer() const;
@@ -308,8 +308,8 @@
                                       GLint copyTextureLayer) const;
 
   private:
-    void detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId);
-    void detachMatchingAttachment(const Context *context,
+    bool detachResourceById(const Context *context, GLenum resourceType, GLuint resourceId);
+    bool detachMatchingAttachment(const Context *context,
                                   FramebufferAttachment *attachment,
                                   GLenum matchType,
                                   GLuint matchId,
diff --git a/src/libANGLE/Sampler.h b/src/libANGLE/Sampler.h
index e281021..7ad0c98 100644
--- a/src/libANGLE/Sampler.h
+++ b/src/libANGLE/Sampler.h
@@ -79,6 +79,6 @@
     SamplerState mSamplerState;
 };
 
-}
+}  // namespace gl
 
 #endif // LIBANGLE_SAMPLER_H_
diff --git a/src/libANGLE/State.cpp b/src/libANGLE/State.cpp
index 070bf7e..017a054 100644
--- a/src/libANGLE/State.cpp
+++ b/src/libANGLE/State.cpp
@@ -197,9 +197,9 @@
 
 void State::reset(const Context *context)
 {
-    for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++)
+    for (auto &bindingVec : mSamplerTextures)
     {
-        TextureBindingVector &textureVector = bindingVec->second;
+        TextureBindingVector &textureVector = bindingVec.second;
         for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
         {
             textureVector[textureIdx].set(context, nullptr);
@@ -834,14 +834,14 @@
     // as if Texture2DAttachment had been called, with a texture of 0, for each attachment point to which this
     // image was attached in the currently bound framebuffer.
 
-    if (mReadFramebuffer)
+    if (mReadFramebuffer && mReadFramebuffer->detachTexture(context, texture))
     {
-        mReadFramebuffer->detachTexture(context, texture);
+        mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
     }
 
-    if (mDrawFramebuffer)
+    if (mDrawFramebuffer && mDrawFramebuffer->detachTexture(context, texture))
     {
-        mDrawFramebuffer->detachTexture(context, texture);
+        mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
     }
 }
 
@@ -893,6 +893,7 @@
 void State::setRenderbufferBinding(const Context *context, Renderbuffer *renderbuffer)
 {
     mRenderbuffer.set(context, renderbuffer);
+    mDirtyBits.set(DIRTY_BIT_RENDERBUFFER_BINDING);
 }
 
 GLuint State::getRenderbufferId() const
@@ -913,7 +914,7 @@
 
     if (mRenderbuffer.id() == renderbuffer)
     {
-        mRenderbuffer.set(context, nullptr);
+        setRenderbufferBinding(context, nullptr);
     }
 
     // [OpenGL ES 2.0.24] section 4.4 page 111:
@@ -924,14 +925,17 @@
     Framebuffer *readFramebuffer = mReadFramebuffer;
     Framebuffer *drawFramebuffer = mDrawFramebuffer;
 
-    if (readFramebuffer)
+    if (readFramebuffer && readFramebuffer->detachRenderbuffer(context, renderbuffer))
     {
-        readFramebuffer->detachRenderbuffer(context, renderbuffer);
+        mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER);
     }
 
     if (drawFramebuffer && drawFramebuffer != readFramebuffer)
     {
-        drawFramebuffer->detachRenderbuffer(context, renderbuffer);
+        if (drawFramebuffer->detachRenderbuffer(context, renderbuffer))
+        {
+            mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER);
+        }
     }
 
 }
diff --git a/src/libANGLE/Texture.h b/src/libANGLE/Texture.h
index 5d912a2..c1e0ca0 100644
--- a/src/libANGLE/Texture.h
+++ b/src/libANGLE/Texture.h
@@ -445,6 +445,6 @@
 {
     return !(a == b);
 }
-}
+}  // namespace gl
 
 #endif  // LIBANGLE_TEXTURE_H_