blob: d7ec7bffc67ce89c3d725cfb592b034a08690701 [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"
12
13namespace gl
14{
15
16VertexArray::VertexArray(rx::Renderer *renderer, GLuint id)
17 : RefCountObject(id)
18{
19 for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++)
20 {
21 mVertexAttributes[i].mBoundBuffer.set(NULL);
22 }
23 mElementArrayBuffer.set(NULL);
24}
25
26void VertexArray::detachBuffer(GLuint bufferName)
27{
28 for (int attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++)
29 {
30 if (mVertexAttributes[attribute].mBoundBuffer.id() == bufferName)
31 {
32 mVertexAttributes[attribute].mBoundBuffer.set(NULL);
33 }
34 }
35
36 if (mElementArrayBuffer.id() == bufferName)
37 {
38 mElementArrayBuffer.set(NULL);
39 }
40}
41
42const VertexAttribute& VertexArray::getVertexAttribute(unsigned int attributeIndex) const
43{
44 ASSERT(attributeIndex < MAX_VERTEX_ATTRIBS);
45 return mVertexAttributes[attributeIndex];
46}
47
48void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
49{
50 ASSERT(index < gl::MAX_VERTEX_ATTRIBS);
51 mVertexAttributes[index].mDivisor = divisor;
52}
53
54void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)
55{
56 ASSERT(attributeIndex < gl::MAX_VERTEX_ATTRIBS);
57 mVertexAttributes[attributeIndex].mArrayEnabled = enabledState;
58}
59
60void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
61 bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
62{
63 ASSERT(attributeIndex < gl::MAX_VERTEX_ATTRIBS);
64 mVertexAttributes[attributeIndex].setState(boundBuffer, size, type, normalized, pureInteger, stride, pointer);
65}
66
67}