VertexArray Object implementation

Added VertexArray.cpp with a few
trivial function implementations.

Change-Id: I9ea0bf47b2c6a1f76392c5fc84837f1778946855
Reviewed-on: https://swiftshader-review.googlesource.com/2984
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/libGLESv2/Android.mk b/src/OpenGL/libGLESv2/Android.mk
index 3f4ed33..b28364a 100644
--- a/src/OpenGL/libGLESv2/Android.mk
+++ b/src/OpenGL/libGLESv2/Android.mk
@@ -24,6 +24,7 @@
 	Texture.cpp \
 	TransformFeedback.cpp \
 	utilities.cpp \
+	VertexArray.cpp \
 	VertexDataManager.cpp \
 
 LOCAL_CFLAGS += -DLOG_TAG=\"libGLESv2_swiftshader\"
diff --git a/src/OpenGL/libGLESv2/VertexArray.cpp b/src/OpenGL/libGLESv2/VertexArray.cpp
new file mode 100644
index 0000000..81ce677
--- /dev/null
+++ b/src/OpenGL/libGLESv2/VertexArray.cpp
@@ -0,0 +1,81 @@
+// SwiftShader Software Renderer

+//

+// Copyright(c) 2015 Google Inc.

+//

+// All rights reserved. No part of this software may be copied, distributed, transmitted,

+// transcribed, stored in a retrieval system, translated into any human or computer

+// language by any means, or disclosed to third parties without the explicit written

+// agreement of Google Inc. Without such an agreement, no rights or licenses, express

+// or implied, including but not limited to any patent rights, are granted to you.

+//

+

+#include "VertexArray.h"

+

+namespace es2

+{

+

+VertexArray::VertexArray(GLuint name) : gl::NamedObject(name)

+{

+}

+

+VertexArray::~VertexArray()

+{

+	for(size_t i = 0; i < MAX_VERTEX_ATTRIBS; i++)

+    {

+		mVertexAttributes[i].mBoundBuffer = NULL;

+    }

+    mElementArrayBuffer = NULL;

+}

+

+void VertexArray::detachBuffer(GLuint bufferName)

+{

+	for(size_t attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++)

+    {

+		if(mVertexAttributes[attribute].mBoundBuffer.name() == bufferName)

+        {

+			mVertexAttributes[attribute].mBoundBuffer = NULL;

+        }

+    }

+

+    if (mElementArrayBuffer.name() == bufferName)

+    {

+        mElementArrayBuffer = NULL;

+    }

+}

+

+const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const

+{

+	ASSERT(attributeIndex < MAX_VERTEX_ATTRIBS);

+    return mVertexAttributes[attributeIndex];

+}

+

+void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)

+{

+	ASSERT(index < MAX_VERTEX_ATTRIBS);

+	mVertexAttributes[index].mDivisor = divisor;

+}

+

+void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)

+{

+	ASSERT(attributeIndex < MAX_VERTEX_ATTRIBS);

+	mVertexAttributes[attributeIndex].mArrayEnabled = enabledState;

+}

+

+void VertexArray::setAttributeState(unsigned int attributeIndex, Buffer *boundBuffer, GLint size, GLenum type,

+                                    bool normalized, GLsizei stride, const void *pointer)

+{

+	ASSERT(attributeIndex < MAX_VERTEX_ATTRIBS);

+    mVertexAttributes[attributeIndex].mBoundBuffer = boundBuffer;

+    mVertexAttributes[attributeIndex].mSize = size;

+    mVertexAttributes[attributeIndex].mType = type;

+    mVertexAttributes[attributeIndex].mNormalized = normalized;

+	mVertexAttributes[attributeIndex].mStride = stride;

+	mVertexAttributes[attributeIndex].mPointer = pointer;

+}

+

+void VertexArray::setElementArrayBuffer(Buffer *buffer)

+{

+    mElementArrayBuffer = buffer;

+}

+

+}

diff --git a/src/OpenGL/libGLESv2/VertexArray.h b/src/OpenGL/libGLESv2/VertexArray.h
index c3c2b87..2c80477 100644
--- a/src/OpenGL/libGLESv2/VertexArray.h
+++ b/src/OpenGL/libGLESv2/VertexArray.h
@@ -14,17 +14,33 @@
 #ifndef LIBGLESV2_VERTEX_ARRAY_H_

 #define LIBGLESV2_VERTEX_ARRAY_H_

 

-#include "common/Object.hpp"

-#include "Renderer/Renderer.hpp"

-

-#define GL_APICALL

-#include <GLES2/gl2.h>

+#include "Buffer.h"

+#include "Context.h"

 

 namespace es2

 {

 

-class VertexArray : public gl::Object

+class VertexArray : public gl::NamedObject

 {

+public:

+	VertexArray(GLuint name);

+	~VertexArray();

+

+	const VertexAttribute& getVertexAttribute(size_t attributeIndex) const;

+	VertexAttributeArray& getVertexAttributes() { return mVertexAttributes; }

+

+	void detachBuffer(GLuint bufferName);

+	void setVertexAttribDivisor(GLuint index, GLuint divisor);

+	void enableAttribute(unsigned int attributeIndex, bool enabledState);

+	void setAttributeState(unsigned int attributeIndex, Buffer *boundBuffer, GLint size, GLenum type,

+	                       bool normalized, GLsizei stride, const void *pointer);

+

+	Buffer *getElementArrayBuffer() const { return mElementArrayBuffer; }

+	void setElementArrayBuffer(Buffer *buffer);

+

+private:

+	VertexAttributeArray mVertexAttributes;

+	gl::BindingPointer<Buffer> mElementArrayBuffer;

 };

 

 }

diff --git a/src/OpenGL/libGLESv2/libGLESv2.cbp b/src/OpenGL/libGLESv2/libGLESv2.cbp
index 8f33535..d66dd06 100644
--- a/src/OpenGL/libGLESv2/libGLESv2.cbp
+++ b/src/OpenGL/libGLESv2/libGLESv2.cbp
@@ -368,6 +368,7 @@
 		<Unit filename="Texture.h" />
 		<Unit filename="TransformFeedback.cpp" />
 		<Unit filename="TransformFeedback.h" />
+		<Unit filename="VertexArray.cpp" />
 		<Unit filename="VertexArray.h" />
 		<Unit filename="VertexDataManager.cpp" />
 		<Unit filename="VertexDataManager.h" />
diff --git a/src/OpenGL/libGLESv2/libGLESv2.vcxproj b/src/OpenGL/libGLESv2/libGLESv2.vcxproj
index 7bba1e6..53592e9 100644
--- a/src/OpenGL/libGLESv2/libGLESv2.vcxproj
+++ b/src/OpenGL/libGLESv2/libGLESv2.vcxproj
@@ -339,6 +339,7 @@
     <ClCompile Include="Texture.cpp" />

     <ClCompile Include="TransformFeedback.cpp" />

     <ClCompile Include="utilities.cpp" />

+    <ClCompile Include="VertexArray.cpp" />

     <ClCompile Include="VertexDataManager.cpp" />

   </ItemGroup>

   <ItemGroup>

diff --git a/src/OpenGL/libGLESv2/libGLESv2.vcxproj.filters b/src/OpenGL/libGLESv2/libGLESv2.vcxproj.filters
index fa96948..05ea0bd 100644
--- a/src/OpenGL/libGLESv2/libGLESv2.vcxproj.filters
+++ b/src/OpenGL/libGLESv2/libGLESv2.vcxproj.filters
@@ -77,6 +77,9 @@
     <ClCompile Include="TransformFeedback.cpp">

       <Filter>Source Files</Filter>

     </ClCompile>

+    <ClCompile Include="VertexArray.cpp">

+      <Filter>Source Files</Filter>

+    </ClCompile>

   </ItemGroup>

   <ItemGroup>

     <ClInclude Include="Buffer.h">