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) |
| 18 | : RefCountObject(id), |
| 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 | |
| 36 | void VertexArray::detachBuffer(GLuint bufferName) |
| 37 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 38 | for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 39 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 40 | if (mVertexAttributes[attribute].buffer.id() == bufferName) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 41 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 42 | mVertexAttributes[attribute].buffer.set(NULL); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | if (mElementArrayBuffer.id() == bufferName) |
| 47 | { |
| 48 | mElementArrayBuffer.set(NULL); |
| 49 | } |
| 50 | } |
| 51 | |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 52 | const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 53 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 54 | ASSERT(attributeIndex < getMaxAttribs()); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 55 | return mVertexAttributes[attributeIndex]; |
| 56 | } |
| 57 | |
| 58 | void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor) |
| 59 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 60 | ASSERT(index < getMaxAttribs()); |
| 61 | mVertexAttributes[index].divisor = divisor; |
| 62 | mVertexArray->setAttributeDivisor(index, divisor); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState) |
| 66 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 67 | ASSERT(attributeIndex < getMaxAttribs()); |
| 68 | mVertexAttributes[attributeIndex].enabled = enabledState; |
| 69 | mVertexArray->enableAttribute(attributeIndex, enabledState); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type, |
| 73 | bool normalized, bool pureInteger, GLsizei stride, const void *pointer) |
| 74 | { |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 75 | ASSERT(attributeIndex < getMaxAttribs()); |
| 76 | mVertexAttributes[attributeIndex].buffer.set(boundBuffer); |
| 77 | mVertexAttributes[attributeIndex].size = size; |
| 78 | mVertexAttributes[attributeIndex].type = type; |
| 79 | mVertexAttributes[attributeIndex].normalized = normalized; |
| 80 | mVertexAttributes[attributeIndex].pureInteger = pureInteger; |
| 81 | mVertexAttributes[attributeIndex].stride = stride; |
| 82 | mVertexAttributes[attributeIndex].pointer = pointer; |
| 83 | mVertexArray->setAttribute(attributeIndex, mVertexAttributes[attributeIndex]); |
| 84 | } |
| 85 | |
| 86 | void VertexArray::setElementArrayBuffer(Buffer *buffer) |
| 87 | { |
| 88 | mElementArrayBuffer.set(buffer); |
| 89 | mVertexArray->setElementArrayBuffer(buffer); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | } |