blob: cb3bfd3030e9fca3cce25d8709cc846c230361a3 [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
62void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
63{
Brandon Jones5bf98292014-06-06 17:19:38 -070064 ASSERT(index < getMaxAttribs());
65 mVertexAttributes[index].divisor = divisor;
66 mVertexArray->setAttributeDivisor(index, divisor);
Jamie Madill57a89722013-07-02 11:57:03 -040067}
68
69void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)
70{
Brandon Jones5bf98292014-06-06 17:19:38 -070071 ASSERT(attributeIndex < getMaxAttribs());
72 mVertexAttributes[attributeIndex].enabled = enabledState;
73 mVertexArray->enableAttribute(attributeIndex, enabledState);
Jamie Madill57a89722013-07-02 11:57:03 -040074}
75
76void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
77 bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
78{
Brandon Jones5bf98292014-06-06 17:19:38 -070079 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]);
88}
89
90void VertexArray::setElementArrayBuffer(Buffer *buffer)
91{
92 mElementArrayBuffer.set(buffer);
93 mVertexArray->setElementArrayBuffer(buffer);
Jamie Madill57a89722013-07-02 11:57:03 -040094}
95
96}