blob: 120064a5326a9e3ca3024a41805778680c824475 [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)
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040018 : mId(id),
Brandon Jones5bf98292014-06-06 17:19:38 -070019 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
Shannon Woodsaa2ab7d2014-06-24 17:51:51 -040036GLuint VertexArray::id() const
37{
38 return mId;
39}
40
Jamie Madill57a89722013-07-02 11:57:03 -040041void VertexArray::detachBuffer(GLuint bufferName)
42{
Brandon Jones5bf98292014-06-06 17:19:38 -070043 for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++)
Jamie Madill57a89722013-07-02 11:57:03 -040044 {
Brandon Jones5bf98292014-06-06 17:19:38 -070045 if (mVertexAttributes[attribute].buffer.id() == bufferName)
Jamie Madill57a89722013-07-02 11:57:03 -040046 {
Brandon Jones5bf98292014-06-06 17:19:38 -070047 mVertexAttributes[attribute].buffer.set(NULL);
Jamie Madill57a89722013-07-02 11:57:03 -040048 }
49 }
50
51 if (mElementArrayBuffer.id() == bufferName)
52 {
53 mElementArrayBuffer.set(NULL);
54 }
55}
56
Brandon Jones5bf98292014-06-06 17:19:38 -070057const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const
Jamie Madill57a89722013-07-02 11:57:03 -040058{
Brandon Jones5bf98292014-06-06 17:19:38 -070059 ASSERT(attributeIndex < getMaxAttribs());
Jamie Madill57a89722013-07-02 11:57:03 -040060 return mVertexAttributes[attributeIndex];
61}
62
63void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
64{
Brandon Jones5bf98292014-06-06 17:19:38 -070065 ASSERT(index < getMaxAttribs());
66 mVertexAttributes[index].divisor = divisor;
67 mVertexArray->setAttributeDivisor(index, divisor);
Jamie Madill57a89722013-07-02 11:57:03 -040068}
69
70void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)
71{
Brandon Jones5bf98292014-06-06 17:19:38 -070072 ASSERT(attributeIndex < getMaxAttribs());
73 mVertexAttributes[attributeIndex].enabled = enabledState;
74 mVertexArray->enableAttribute(attributeIndex, enabledState);
Jamie Madill57a89722013-07-02 11:57:03 -040075}
76
77void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
78 bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
79{
Brandon Jones5bf98292014-06-06 17:19:38 -070080 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
91void VertexArray::setElementArrayBuffer(Buffer *buffer)
92{
93 mElementArrayBuffer.set(buffer);
94 mVertexArray->setElementArrayBuffer(buffer);
Jamie Madill57a89722013-07-02 11:57:03 -040095}
96
97}