2 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 // Implementation of the state class for mananging GLES 3 Vertex Array Objects.
9 #include "libGLESv2/VertexArray.h"
10 #include "libGLESv2/Buffer.h"
11 #include "libGLESv2/renderer/VertexArrayImpl.h"
16 VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs)
19 mVertexAttributes(maxAttribs)
24 VertexArray::~VertexArray()
26 SafeDelete(mVertexArray);
28 for (size_t i = 0; i < getMaxAttribs(); i++)
30 mVertexAttributes[i].buffer.set(NULL);
32 mElementArrayBuffer.set(NULL);
35 GLuint VertexArray::id() const
40 void VertexArray::detachBuffer(GLuint bufferName)
42 for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++)
44 if (mVertexAttributes[attribute].buffer.id() == bufferName)
46 mVertexAttributes[attribute].buffer.set(NULL);
50 if (mElementArrayBuffer.id() == bufferName)
52 mElementArrayBuffer.set(NULL);
56 const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const
58 ASSERT(attributeIndex < getMaxAttribs());
59 return mVertexAttributes[attributeIndex];
62 void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
64 ASSERT(index < getMaxAttribs());
65 mVertexAttributes[index].divisor = divisor;
66 mVertexArray->setAttributeDivisor(index, divisor);
69 void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)
71 ASSERT(attributeIndex < getMaxAttribs());
72 mVertexAttributes[attributeIndex].enabled = enabledState;
73 mVertexArray->enableAttribute(attributeIndex, enabledState);
76 void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
77 bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
79 ASSERT(attributeIndex < getMaxAttribs());
80 mVertexAttributes[attributeIndex].buffer.set(boundBuffer);
81 mVertexAttributes[attributeIndex].size = size;
82 mVertexAttributes[attributeIndex].type = type;
83 mVertexAttributes[attributeIndex].normalized = normalized;
84 mVertexAttributes[attributeIndex].pureInteger = pureInteger;
85 mVertexAttributes[attributeIndex].stride = stride;
86 mVertexAttributes[attributeIndex].pointer = pointer;
87 mVertexArray->setAttribute(attributeIndex, mVertexAttributes[attributeIndex]);
90 void VertexArray::setElementArrayBuffer(Buffer *buffer)
92 mElementArrayBuffer.set(buffer);
93 mVertexArray->setElementArrayBuffer(buffer);