1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "VertexArray.h"
16
17 namespace es2
18 {
19
VertexArray(GLuint name)20 VertexArray::VertexArray(GLuint name) : gl::NamedObject(name)
21 {
22 }
23
~VertexArray()24 VertexArray::~VertexArray()
25 {
26 for(size_t i = 0; i < MAX_VERTEX_ATTRIBS; i++)
27 {
28 mVertexAttributes[i].mBoundBuffer = nullptr;
29 }
30 mElementArrayBuffer = nullptr;
31 }
32
detachBuffer(GLuint bufferName)33 void VertexArray::detachBuffer(GLuint bufferName)
34 {
35 for(size_t attribute = 0; attribute < MAX_VERTEX_ATTRIBS; attribute++)
36 {
37 if(mVertexAttributes[attribute].mBoundBuffer.name() == bufferName)
38 {
39 mVertexAttributes[attribute].mBoundBuffer = nullptr;
40 }
41 }
42
43 if(mElementArrayBuffer.name() == bufferName)
44 {
45 mElementArrayBuffer = nullptr;
46 }
47 }
48
getVertexAttribute(size_t attributeIndex) const49 const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const
50 {
51 ASSERT(attributeIndex < MAX_VERTEX_ATTRIBS);
52 return mVertexAttributes[attributeIndex];
53 }
54
setVertexAttribDivisor(GLuint index,GLuint divisor)55 void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
56 {
57 ASSERT(index < MAX_VERTEX_ATTRIBS);
58 mVertexAttributes[index].mDivisor = divisor;
59 }
60
enableAttribute(unsigned int attributeIndex,bool enabledState)61 void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState)
62 {
63 ASSERT(attributeIndex < MAX_VERTEX_ATTRIBS);
64 mVertexAttributes[attributeIndex].mArrayEnabled = enabledState;
65 }
66
setAttributeState(unsigned int attributeIndex,Buffer * boundBuffer,GLint size,GLenum type,bool normalized,GLsizei stride,const void * pointer)67 void VertexArray::setAttributeState(unsigned int attributeIndex, Buffer *boundBuffer, GLint size, GLenum type,
68 bool normalized, GLsizei stride, const void *pointer)
69 {
70 ASSERT(attributeIndex < MAX_VERTEX_ATTRIBS);
71 mVertexAttributes[attributeIndex].mBoundBuffer = boundBuffer;
72 mVertexAttributes[attributeIndex].mSize = size;
73 mVertexAttributes[attributeIndex].mType = type;
74 mVertexAttributes[attributeIndex].mNormalized = normalized;
75 mVertexAttributes[attributeIndex].mStride = stride;
76 mVertexAttributes[attributeIndex].mPointer = pointer;
77 }
78
setElementArrayBuffer(Buffer * buffer)79 void VertexArray::setElementArrayBuffer(Buffer *buffer)
80 {
81 mElementArrayBuffer = buffer;
82 }
83
84 }
85