Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 1 | #include "precompiled.h" |
| 2 | // |
| 3 | // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. |
| 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | // Implementation of the state class for mananging GLES 3 Vertex Array Objects. |
| 8 | // |
| 9 | |
| 10 | #include "libGLESv2/VertexArray.h" |
| 11 | #include "libGLESv2/Buffer.h" |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 12 | #include "libGLESv2/renderer/VertexArrayImpl.h" |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 13 | |
| 14 | namespace gl |
| 15 | { |
| 16 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 17 | VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs) |
Shannon Woods | aa2ab7d | 2014-06-24 17:51:51 -0400 | [diff] [blame^] | 18 | : mId(id), |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 19 | mVertexArray(impl), |
| 20 | mVertexAttributes(maxAttribs) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 21 | { |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 22 | ASSERT(impl != NULL); |
Jamie Madill | 004a6f9 | 2013-07-10 15:13:38 -0400 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | VertexArray::~VertexArray() |
| 26 | { |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 27 | SafeDelete(mVertexArray); |
| 28 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 29 | for (size_t i = 0; i < getMaxAttribs(); i++) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 30 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 31 | mVertexAttributes[i].buffer.set(NULL); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 32 | } |
| 33 | mElementArrayBuffer.set(NULL); |
| 34 | } |
| 35 | |
Shannon Woods | aa2ab7d | 2014-06-24 17:51:51 -0400 | [diff] [blame^] | 36 | GLuint VertexArray::id() const |
| 37 | { |
| 38 | return mId; |
| 39 | } |
| 40 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 41 | void VertexArray::detachBuffer(GLuint bufferName) |
| 42 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 43 | for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 44 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 45 | if (mVertexAttributes[attribute].buffer.id() == bufferName) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 46 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 47 | mVertexAttributes[attribute].buffer.set(NULL); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | if (mElementArrayBuffer.id() == bufferName) |
| 52 | { |
| 53 | mElementArrayBuffer.set(NULL); |
| 54 | } |
| 55 | } |
| 56 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 57 | const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 58 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 59 | ASSERT(attributeIndex < getMaxAttribs()); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 60 | return mVertexAttributes[attributeIndex]; |
| 61 | } |
| 62 | |
| 63 | void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor) |
| 64 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 65 | ASSERT(index < getMaxAttribs()); |
| 66 | mVertexAttributes[index].divisor = divisor; |
| 67 | mVertexArray->setAttributeDivisor(index, divisor); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState) |
| 71 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 72 | ASSERT(attributeIndex < getMaxAttribs()); |
| 73 | mVertexAttributes[attributeIndex].enabled = enabledState; |
| 74 | mVertexArray->enableAttribute(attributeIndex, enabledState); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type, |
| 78 | bool normalized, bool pureInteger, GLsizei stride, const void *pointer) |
| 79 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 80 | ASSERT(attributeIndex < getMaxAttribs()); |
| 81 | mVertexAttributes[attributeIndex].buffer.set(boundBuffer); |
| 82 | mVertexAttributes[attributeIndex].size = size; |
| 83 | mVertexAttributes[attributeIndex].type = type; |
| 84 | mVertexAttributes[attributeIndex].normalized = normalized; |
| 85 | mVertexAttributes[attributeIndex].pureInteger = pureInteger; |
| 86 | mVertexAttributes[attributeIndex].stride = stride; |
| 87 | mVertexAttributes[attributeIndex].pointer = pointer; |
| 88 | mVertexArray->setAttribute(attributeIndex, mVertexAttributes[attributeIndex]); |
| 89 | } |
| 90 | |
| 91 | void VertexArray::setElementArrayBuffer(Buffer *buffer) |
| 92 | { |
| 93 | mElementArrayBuffer.set(buffer); |
| 94 | mVertexArray->setElementArrayBuffer(buffer); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | } |