blob: 16f75d6f19b30166acbc8d2af15cf57f1129420c [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{
Brandon Jonesd38f9262014-06-18 16:26:45 -070022 ASSERT(impl != NULL);
Jamie Madill004a6f92013-07-10 15:13:38 -040023}
24
25VertexArray::~VertexArray()
26{
Brandon Jonesd38f9262014-06-18 16:26:45 -070027 SafeDelete(mVertexArray);
28
Brandon Jones5bf98292014-06-06 17:19:38 -070029 for (size_t i = 0; i < getMaxAttribs(); i++)
Jamie Madill57a89722013-07-02 11:57:03 -040030 {
Brandon Jones5bf98292014-06-06 17:19:38 -070031 mVertexAttributes[i].buffer.set(NULL);
Jamie Madill57a89722013-07-02 11:57:03 -040032 }
33 mElementArrayBuffer.set(NULL);
34}
35
36void VertexArray::detachBuffer(GLuint bufferName)
37{
Brandon Jones5bf98292014-06-06 17:19:38 -070038 for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++)
Jamie Madill57a89722013-07-02 11:57:03 -040039 {
Brandon Jones5bf98292014-06-06 17:19:38 -070040 if (mVertexAttributes[attribute].buffer.id() == bufferName)
Jamie Madill57a89722013-07-02 11:57:03 -040041 {
Brandon Jones5bf98292014-06-06 17:19:38 -070042 mVertexAttributes[attribute].buffer.set(NULL);
Jamie Madill57a89722013-07-02 11:57:03 -040043 }
44 }
45
46 if (mElementArrayBuffer.id() == bufferName)
47 {
48 mElementArrayBuffer.set(NULL);
49 }
50}
51
Brandon Jones5bf98292014-06-06 17:19:38 -070052const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const
Jamie Madill57a89722013-07-02 11:57:03 -040053{
Brandon Jones5bf98292014-06-06 17:19:38 -070054 ASSERT(attributeIndex < getMaxAttribs());
Jamie Madill57a89722013-07-02 11:57:03 -040055 return mVertexAttributes[attributeIndex];
56}
57
58void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
59{
Brandon Jones5bf98292014-06-06 17:19:38 -070060 ASSERT(index < getMaxAttribs());
61 mVertexAttributes[index].divisor = divisor;
62 mVertexArray->setAttributeDivisor(index, divisor);
Jamie Madill57a89722013-07-02 11:57:03 -040063}
64
65void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)
66{
Brandon Jones5bf98292014-06-06 17:19:38 -070067 ASSERT(attributeIndex < getMaxAttribs());
68 mVertexAttributes[attributeIndex].enabled = enabledState;
69 mVertexArray->enableAttribute(attributeIndex, enabledState);
Jamie Madill57a89722013-07-02 11:57:03 -040070}
71
72void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
73 bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
74{
Brandon Jones5bf98292014-06-06 17:19:38 -070075 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
86void VertexArray::setElementArrayBuffer(Buffer *buffer)
87{
88 mElementArrayBuffer.set(buffer);
89 mVertexArray->setElementArrayBuffer(buffer);
Jamie Madill57a89722013-07-02 11:57:03 -040090}
91
92}