blob: 249ae192afce41c3165abfe3994c94ddcab7429a [file] [log] [blame]
Jamie Madill57a89722013-07-02 11:57:03 -04001#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 Jones5bf98292014-06-06 17:19:38 -070012#include "libGLESv2/renderer/VertexArrayImpl.h"
Jamie Madill57a89722013-07-02 11:57:03 -040013
14namespace gl
15{
16
Brandon Jones5bf98292014-06-06 17:19:38 -070017VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs)
18 : RefCountObject(id),
19 mVertexArray(impl),
20 mVertexAttributes(maxAttribs)
Jamie Madill57a89722013-07-02 11:57:03 -040021{
Jamie Madill004a6f92013-07-10 15:13:38 -040022}
23
24VertexArray::~VertexArray()
25{
Brandon Jones5bf98292014-06-06 17:19:38 -070026 for (size_t i = 0; i < getMaxAttribs(); i++)
Jamie Madill57a89722013-07-02 11:57:03 -040027 {
Brandon Jones5bf98292014-06-06 17:19:38 -070028 mVertexAttributes[i].buffer.set(NULL);
Jamie Madill57a89722013-07-02 11:57:03 -040029 }
30 mElementArrayBuffer.set(NULL);
31}
32
33void VertexArray::detachBuffer(GLuint bufferName)
34{
Brandon Jones5bf98292014-06-06 17:19:38 -070035 for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++)
Jamie Madill57a89722013-07-02 11:57:03 -040036 {
Brandon Jones5bf98292014-06-06 17:19:38 -070037 if (mVertexAttributes[attribute].buffer.id() == bufferName)
Jamie Madill57a89722013-07-02 11:57:03 -040038 {
Brandon Jones5bf98292014-06-06 17:19:38 -070039 mVertexAttributes[attribute].buffer.set(NULL);
Jamie Madill57a89722013-07-02 11:57:03 -040040 }
41 }
42
43 if (mElementArrayBuffer.id() == bufferName)
44 {
45 mElementArrayBuffer.set(NULL);
46 }
47}
48
Brandon Jones5bf98292014-06-06 17:19:38 -070049const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const
Jamie Madill57a89722013-07-02 11:57:03 -040050{
Brandon Jones5bf98292014-06-06 17:19:38 -070051 ASSERT(attributeIndex < getMaxAttribs());
Jamie Madill57a89722013-07-02 11:57:03 -040052 return mVertexAttributes[attributeIndex];
53}
54
55void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
56{
Brandon Jones5bf98292014-06-06 17:19:38 -070057 ASSERT(index < getMaxAttribs());
58 mVertexAttributes[index].divisor = divisor;
59 mVertexArray->setAttributeDivisor(index, divisor);
Jamie Madill57a89722013-07-02 11:57:03 -040060}
61
62void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)
63{
Brandon Jones5bf98292014-06-06 17:19:38 -070064 ASSERT(attributeIndex < getMaxAttribs());
65 mVertexAttributes[attributeIndex].enabled = enabledState;
66 mVertexArray->enableAttribute(attributeIndex, enabledState);
Jamie Madill57a89722013-07-02 11:57:03 -040067}
68
69void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
70 bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
71{
Brandon Jones5bf98292014-06-06 17:19:38 -070072 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
83void VertexArray::setElementArrayBuffer(Buffer *buffer)
84{
85 mElementArrayBuffer.set(buffer);
86 mVertexArray->setElementArrayBuffer(buffer);
Jamie Madill57a89722013-07-02 11:57:03 -040087}
88
89}