Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 1 | // |
| 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 Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame^] | 9 | #include "libANGLE/VertexArray.h" |
| 10 | #include "libANGLE/Buffer.h" |
| 11 | #include "libANGLE/renderer/VertexArrayImpl.h" |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 12 | |
| 13 | namespace gl |
| 14 | { |
| 15 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 16 | VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs) |
Shannon Woods | aa2ab7d | 2014-06-24 17:51:51 -0400 | [diff] [blame] | 17 | : mId(id), |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 18 | mVertexArray(impl), |
| 19 | mVertexAttributes(maxAttribs) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 20 | { |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 21 | ASSERT(impl != NULL); |
Jamie Madill | 004a6f9 | 2013-07-10 15:13:38 -0400 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | VertexArray::~VertexArray() |
| 25 | { |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 26 | SafeDelete(mVertexArray); |
| 27 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 28 | for (size_t i = 0; i < getMaxAttribs(); i++) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 29 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 30 | mVertexAttributes[i].buffer.set(NULL); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 31 | } |
| 32 | mElementArrayBuffer.set(NULL); |
| 33 | } |
| 34 | |
Shannon Woods | aa2ab7d | 2014-06-24 17:51:51 -0400 | [diff] [blame] | 35 | GLuint VertexArray::id() const |
| 36 | { |
| 37 | return mId; |
| 38 | } |
| 39 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 40 | void VertexArray::detachBuffer(GLuint bufferName) |
| 41 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 42 | for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 43 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 44 | if (mVertexAttributes[attribute].buffer.id() == bufferName) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 45 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 46 | mVertexAttributes[attribute].buffer.set(NULL); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
| 50 | if (mElementArrayBuffer.id() == bufferName) |
| 51 | { |
| 52 | mElementArrayBuffer.set(NULL); |
| 53 | } |
| 54 | } |
| 55 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 56 | const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 57 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 58 | ASSERT(attributeIndex < getMaxAttribs()); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 59 | return mVertexAttributes[attributeIndex]; |
| 60 | } |
| 61 | |
| 62 | void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor) |
| 63 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 64 | ASSERT(index < getMaxAttribs()); |
| 65 | mVertexAttributes[index].divisor = divisor; |
| 66 | mVertexArray->setAttributeDivisor(index, divisor); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState) |
| 70 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 71 | ASSERT(attributeIndex < getMaxAttribs()); |
| 72 | mVertexAttributes[attributeIndex].enabled = enabledState; |
| 73 | mVertexArray->enableAttribute(attributeIndex, enabledState); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type, |
| 77 | bool normalized, bool pureInteger, GLsizei stride, const void *pointer) |
| 78 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 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]); |
| 88 | } |
| 89 | |
| 90 | void VertexArray::setElementArrayBuffer(Buffer *buffer) |
| 91 | { |
| 92 | mElementArrayBuffer.set(buffer); |
| 93 | mVertexArray->setElementArrayBuffer(buffer); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | } |