blob: f0aded905d40d88405c5668b3e0d3836c5175805 [file] [log] [blame]
Jamie Madill57a89722013-07-02 11:57:03 -04001//
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.
5//
6// Implementation of the state class for mananging GLES 3 Vertex Array Objects.
7//
8
Geoff Lang2b5420c2014-11-19 14:20:15 -05009#include "libANGLE/VertexArray.h"
10#include "libANGLE/Buffer.h"
11#include "libANGLE/renderer/VertexArrayImpl.h"
Jamie Madill57a89722013-07-02 11:57:03 -040012
13namespace gl
14{
15
Brandon Jones5bf98292014-06-06 17:19:38 -070016VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs)
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040017 : mId(id),
Brandon Jones5bf98292014-06-06 17:19:38 -070018 mVertexArray(impl),
19 mVertexAttributes(maxAttribs)
Jamie Madill57a89722013-07-02 11:57:03 -040020{
Brandon Jonesd38f9262014-06-18 16:26:45 -070021 ASSERT(impl != NULL);
Jamie Madill004a6f92013-07-10 15:13:38 -040022}
23
24VertexArray::~VertexArray()
25{
Brandon Jonesd38f9262014-06-18 16:26:45 -070026 SafeDelete(mVertexArray);
27
Brandon Jones5bf98292014-06-06 17:19:38 -070028 for (size_t i = 0; i < getMaxAttribs(); i++)
Jamie Madill57a89722013-07-02 11:57:03 -040029 {
Brandon Jones5bf98292014-06-06 17:19:38 -070030 mVertexAttributes[i].buffer.set(NULL);
Jamie Madill57a89722013-07-02 11:57:03 -040031 }
32 mElementArrayBuffer.set(NULL);
33}
34
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040035GLuint VertexArray::id() const
36{
37 return mId;
38}
39
Jamie Madill57a89722013-07-02 11:57:03 -040040void VertexArray::detachBuffer(GLuint bufferName)
41{
Brandon Jones5bf98292014-06-06 17:19:38 -070042 for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++)
Jamie Madill57a89722013-07-02 11:57:03 -040043 {
Brandon Jones5bf98292014-06-06 17:19:38 -070044 if (mVertexAttributes[attribute].buffer.id() == bufferName)
Jamie Madill57a89722013-07-02 11:57:03 -040045 {
Brandon Jones5bf98292014-06-06 17:19:38 -070046 mVertexAttributes[attribute].buffer.set(NULL);
Jamie Madill57a89722013-07-02 11:57:03 -040047 }
48 }
49
50 if (mElementArrayBuffer.id() == bufferName)
51 {
52 mElementArrayBuffer.set(NULL);
53 }
54}
55
Brandon Jones5bf98292014-06-06 17:19:38 -070056const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const
Jamie Madill57a89722013-07-02 11:57:03 -040057{
Brandon Jones5bf98292014-06-06 17:19:38 -070058 ASSERT(attributeIndex < getMaxAttribs());
Jamie Madill57a89722013-07-02 11:57:03 -040059 return mVertexAttributes[attributeIndex];
60}
61
Geoff Lang5ead9272015-03-25 12:27:43 -040062const std::vector<VertexAttribute> &VertexArray::getVertexAttributes() const
63{
64 return mVertexAttributes;
65}
66
Jamie Madill57a89722013-07-02 11:57:03 -040067void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
68{
Brandon Jones5bf98292014-06-06 17:19:38 -070069 ASSERT(index < getMaxAttribs());
70 mVertexAttributes[index].divisor = divisor;
71 mVertexArray->setAttributeDivisor(index, divisor);
Jamie Madill57a89722013-07-02 11:57:03 -040072}
73
74void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)
75{
Brandon Jones5bf98292014-06-06 17:19:38 -070076 ASSERT(attributeIndex < getMaxAttribs());
77 mVertexAttributes[attributeIndex].enabled = enabledState;
78 mVertexArray->enableAttribute(attributeIndex, enabledState);
Jamie Madill57a89722013-07-02 11:57:03 -040079}
80
81void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
82 bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
83{
Brandon Jones5bf98292014-06-06 17:19:38 -070084 ASSERT(attributeIndex < getMaxAttribs());
85 mVertexAttributes[attributeIndex].buffer.set(boundBuffer);
86 mVertexAttributes[attributeIndex].size = size;
87 mVertexAttributes[attributeIndex].type = type;
88 mVertexAttributes[attributeIndex].normalized = normalized;
89 mVertexAttributes[attributeIndex].pureInteger = pureInteger;
90 mVertexAttributes[attributeIndex].stride = stride;
91 mVertexAttributes[attributeIndex].pointer = pointer;
92 mVertexArray->setAttribute(attributeIndex, mVertexAttributes[attributeIndex]);
93}
94
95void VertexArray::setElementArrayBuffer(Buffer *buffer)
96{
97 mElementArrayBuffer.set(buffer);
98 mVertexArray->setElementArrayBuffer(buffer);
Jamie Madill57a89722013-07-02 11:57:03 -040099}
100
Jamie Madilldff56332015-01-05 16:17:00 -0500101}