Store the applied element array buffer as a binding pointer.

to be consistent with how we start vertex attributes. A null pointer
indicates we're using the streaming buffer.

Will also aid the dirty state bits refactor.

BUG=angleproject:1040
TEST=WebGL CTS, end2end_tests, unittests

Change-Id: I7a9167282b60dbe0cbb9f0e5d9e3770890ffeb71
Reviewed-on: https://chromium-review.googlesource.com/284619
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/VertexArrayImpl.h b/src/libANGLE/renderer/VertexArrayImpl.h
index a5e4d1b..8381676 100644
--- a/src/libANGLE/renderer/VertexArrayImpl.h
+++ b/src/libANGLE/renderer/VertexArrayImpl.h
@@ -22,11 +22,6 @@
     VertexArrayImpl(const gl::VertexArray::Data &data) : mData(data) { }
     virtual ~VertexArrayImpl() { }
 
-    virtual void setElementArrayBuffer(const gl::Buffer *buffer) = 0;
-    virtual void setAttribute(size_t idx, const gl::VertexAttribute &attr) = 0;
-    virtual void setAttributeDivisor(size_t idx, GLuint divisor) = 0;
-    virtual void enableAttribute(size_t idx, bool enabledState) = 0;
-
   protected:
     const gl::VertexArray::Data &mData;
 };
diff --git a/src/libANGLE/renderer/d3d/d3d11/VertexArray11.h b/src/libANGLE/renderer/d3d/d3d11/VertexArray11.h
index ac12bf4..b397140 100644
--- a/src/libANGLE/renderer/d3d/d3d11/VertexArray11.h
+++ b/src/libANGLE/renderer/d3d/d3d11/VertexArray11.h
@@ -23,12 +23,7 @@
         : VertexArrayImpl(data)
     {
     }
-    virtual ~VertexArray11() { }
-
-    virtual void setElementArrayBuffer(const gl::Buffer *buffer) { }
-    virtual void setAttribute(size_t idx, const gl::VertexAttribute &attr) { }
-    virtual void setAttributeDivisor(size_t idx, GLuint divisor) { }
-    virtual void enableAttribute(size_t idx, bool enabledState) { }
+    virtual ~VertexArray11() {}
 };
 
 }
diff --git a/src/libANGLE/renderer/d3d/d3d9/VertexArray9.h b/src/libANGLE/renderer/d3d/d3d9/VertexArray9.h
index 21db8c5..9922017 100644
--- a/src/libANGLE/renderer/d3d/d3d9/VertexArray9.h
+++ b/src/libANGLE/renderer/d3d/d3d9/VertexArray9.h
@@ -25,11 +25,6 @@
     }
 
     virtual ~VertexArray9() { }
-
-    virtual void setElementArrayBuffer(const gl::Buffer *buffer) { }
-    virtual void setAttribute(size_t idx, const gl::VertexAttribute &attr) { }
-    virtual void setAttributeDivisor(size_t idx, GLuint divisor) { }
-    virtual void enableAttribute(size_t idx, bool enabledState) { }
 };
 
 }
diff --git a/src/libANGLE/renderer/gl/VertexArrayGL.cpp b/src/libANGLE/renderer/gl/VertexArrayGL.cpp
index f345ab1..84722a4 100644
--- a/src/libANGLE/renderer/gl/VertexArrayGL.cpp
+++ b/src/libANGLE/renderer/gl/VertexArrayGL.cpp
@@ -26,7 +26,7 @@
       mFunctions(functions),
       mStateManager(stateManager),
       mVertexArrayID(0),
-      mAppliedElementArrayBuffer(0),
+      mAppliedElementArrayBuffer(),
       mStreamingElementArrayBufferSize(0),
       mStreamingElementArrayBuffer(0),
       mStreamingArrayBufferSize(0),
@@ -55,34 +55,13 @@
     mStreamingArrayBufferSize = 0;
     mStreamingArrayBuffer = 0;
 
+    mAppliedElementArrayBuffer.set(nullptr);
     for (size_t idx = 0; idx < mAppliedAttributes.size(); idx++)
     {
         mAppliedAttributes[idx].buffer.set(nullptr);
     }
 }
 
-void VertexArrayGL::setElementArrayBuffer(const gl::Buffer *buffer)
-{
-    // If the buffer is being unbound/deleted, reset the currently applied buffer ID
-    // so that even if a new buffer is generated with the same ID, it will be re-bound.
-    if (buffer == nullptr && mAppliedElementArrayBuffer != mStreamingElementArrayBuffer)
-    {
-        mAppliedElementArrayBuffer = 0;
-    }
-}
-
-void VertexArrayGL::setAttribute(size_t idx, const gl::VertexAttribute &attr)
-{
-}
-
-void VertexArrayGL::setAttributeDivisor(size_t idx, GLuint divisor)
-{
-}
-
-void VertexArrayGL::enableAttribute(size_t idx, bool enabledState)
-{
-}
-
 gl::Error VertexArrayGL::syncDrawArraysState(const std::vector<GLuint> &activeAttribLocations, GLint first, GLsizei count) const
 {
     return syncDrawState(activeAttribLocations, first, count, GL_NONE, nullptr, nullptr);
@@ -96,7 +75,7 @@
 
 gl::Error VertexArrayGL::syncDrawState(const std::vector<GLuint> &activeAttribLocations, GLint first, GLsizei count, GLenum type, const GLvoid *indices, const GLvoid **outIndices) const
 {
-    mStateManager->bindVertexArray(mVertexArrayID, mAppliedElementArrayBuffer);
+    mStateManager->bindVertexArray(mVertexArrayID, getAppliedElementArrayBufferID());
 
     // Check if any attributes need to be streamed, determines if the index range needs to be computed
     bool attributesNeedStreaming = doAttributesNeedStreaming(activeAttribLocations);
@@ -250,12 +229,11 @@
     // Need to check the range of indices if attributes need to be streamed
     if (elementArrayBuffer != nullptr)
     {
-        const BufferGL *bufferGL = GetImplAs<BufferGL>(elementArrayBuffer);
-        GLuint elementArrayBufferID = bufferGL->getBufferID();
-        if (elementArrayBufferID != mAppliedElementArrayBuffer)
+        if (elementArrayBuffer != mAppliedElementArrayBuffer.get())
         {
-            mStateManager->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementArrayBufferID);
-            mAppliedElementArrayBuffer = elementArrayBufferID;
+            const BufferGL *bufferGL = GetImplAs<BufferGL>(elementArrayBuffer);
+            mStateManager->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferGL->getBufferID());
+            mAppliedElementArrayBuffer.set(elementArrayBuffer);
         }
 
         // Only compute the index range if the attributes also need to be streamed
@@ -291,7 +269,7 @@
         }
 
         mStateManager->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, mStreamingElementArrayBuffer);
-        mAppliedElementArrayBuffer = mStreamingElementArrayBuffer;
+        mAppliedElementArrayBuffer.set(nullptr);
 
         // Make sure the element array buffer is large enough
         const gl::Type &indexTypeInfo = gl::GetTypeInfo(type);
@@ -414,7 +392,8 @@
 
 GLuint VertexArrayGL::getAppliedElementArrayBufferID() const
 {
-    return mAppliedElementArrayBuffer;
+    return mAppliedElementArrayBuffer.get() == nullptr ? mStreamingElementArrayBuffer
+                                                       : mAppliedElementArrayBuffer.id();
 }
 
 }
diff --git a/src/libANGLE/renderer/gl/VertexArrayGL.h b/src/libANGLE/renderer/gl/VertexArrayGL.h
index 85bd6fb..f277bdb 100644
--- a/src/libANGLE/renderer/gl/VertexArrayGL.h
+++ b/src/libANGLE/renderer/gl/VertexArrayGL.h
@@ -23,11 +23,6 @@
     VertexArrayGL(const gl::VertexArray::Data &data, const FunctionsGL *functions, StateManagerGL *stateManager);
     ~VertexArrayGL() override;
 
-    void setElementArrayBuffer(const gl::Buffer *buffer) override;
-    void setAttribute(size_t idx, const gl::VertexAttribute &attr) override;
-    void setAttributeDivisor(size_t idx, GLuint divisor) override;
-    void enableAttribute(size_t idx, bool enabledState) override;
-
     gl::Error syncDrawArraysState(const std::vector<GLuint> &activeAttribLoations, GLint first, GLsizei count) const;
     gl::Error syncDrawElementsState(const std::vector<GLuint> &activeAttribLoations, GLsizei count, GLenum type,
                                     const GLvoid *indices, const GLvoid **outIndices) const;
@@ -61,7 +56,7 @@
 
     GLuint mVertexArrayID;
 
-    mutable GLuint mAppliedElementArrayBuffer;
+    mutable BindingPointer<gl::Buffer> mAppliedElementArrayBuffer;
     mutable std::vector<gl::VertexAttribute> mAppliedAttributes;
 
     mutable size_t mStreamingElementArrayBufferSize;