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