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