• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // Implementation of the state class for mananging GLES 3 Vertex Array Objects.
7 //
8 
9 #include "libGLESv2/VertexArray.h"
10 #include "libGLESv2/Buffer.h"
11 #include "libGLESv2/renderer/VertexArrayImpl.h"
12 
13 namespace gl
14 {
15 
VertexArray(rx::VertexArrayImpl * impl,GLuint id,size_t maxAttribs)16 VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs)
17     : mId(id),
18       mVertexArray(impl),
19       mVertexAttributes(maxAttribs)
20 {
21     ASSERT(impl != NULL);
22 }
23 
~VertexArray()24 VertexArray::~VertexArray()
25 {
26     SafeDelete(mVertexArray);
27 
28     for (size_t i = 0; i < getMaxAttribs(); i++)
29     {
30         mVertexAttributes[i].buffer.set(NULL);
31     }
32     mElementArrayBuffer.set(NULL);
33 }
34 
id() const35 GLuint VertexArray::id() const
36 {
37     return mId;
38 }
39 
detachBuffer(GLuint bufferName)40 void VertexArray::detachBuffer(GLuint bufferName)
41 {
42     for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++)
43     {
44         if (mVertexAttributes[attribute].buffer.id() == bufferName)
45         {
46             mVertexAttributes[attribute].buffer.set(NULL);
47         }
48     }
49 
50     if (mElementArrayBuffer.id() == bufferName)
51     {
52         mElementArrayBuffer.set(NULL);
53     }
54 }
55 
getVertexAttribute(size_t attributeIndex) const56 const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const
57 {
58     ASSERT(attributeIndex < getMaxAttribs());
59     return mVertexAttributes[attributeIndex];
60 }
61 
setVertexAttribDivisor(GLuint index,GLuint divisor)62 void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
63 {
64     ASSERT(index < getMaxAttribs());
65     mVertexAttributes[index].divisor = divisor;
66     mVertexArray->setAttributeDivisor(index, divisor);
67 }
68 
enableAttribute(unsigned int attributeIndex,bool enabledState)69 void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)
70 {
71     ASSERT(attributeIndex < getMaxAttribs());
72     mVertexAttributes[attributeIndex].enabled = enabledState;
73     mVertexArray->enableAttribute(attributeIndex, enabledState);
74 }
75 
setAttributeState(unsigned int attributeIndex,gl::Buffer * boundBuffer,GLint size,GLenum type,bool normalized,bool pureInteger,GLsizei stride,const void * pointer)76 void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
77                                     bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
78 {
79     ASSERT(attributeIndex < getMaxAttribs());
80     mVertexAttributes[attributeIndex].buffer.set(boundBuffer);
81     mVertexAttributes[attributeIndex].size = size;
82     mVertexAttributes[attributeIndex].type = type;
83     mVertexAttributes[attributeIndex].normalized = normalized;
84     mVertexAttributes[attributeIndex].pureInteger = pureInteger;
85     mVertexAttributes[attributeIndex].stride = stride;
86     mVertexAttributes[attributeIndex].pointer = pointer;
87     mVertexArray->setAttribute(attributeIndex, mVertexAttributes[attributeIndex]);
88 }
89 
setElementArrayBuffer(Buffer * buffer)90 void VertexArray::setElementArrayBuffer(Buffer *buffer)
91 {
92     mElementArrayBuffer.set(buffer);
93     mVertexArray->setElementArrayBuffer(buffer);
94 }
95 
96 }