| Lucas Dupin | ad66337 | 2020-03-19 12:44:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright 2020 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
 | 18 |  | 
 | 19 | #include "GLVertexBuffer.h" | 
 | 20 |  | 
 | 21 | #include <GLES/gl.h> | 
 | 22 | #include <GLES2/gl2.h> | 
 | 23 | #include <nativebase/nativebase.h> | 
 | 24 | #include <utils/Trace.h> | 
 | 25 |  | 
 | 26 | namespace android { | 
 | 27 | namespace renderengine { | 
 | 28 | namespace gl { | 
 | 29 |  | 
 | 30 | GLVertexBuffer::GLVertexBuffer() { | 
 | 31 |     glGenBuffers(1, &mBufferName); | 
 | 32 | } | 
 | 33 |  | 
 | 34 | GLVertexBuffer::~GLVertexBuffer() { | 
 | 35 |     glDeleteBuffers(1, &mBufferName); | 
 | 36 | } | 
 | 37 |  | 
 | 38 | void GLVertexBuffer::allocateBuffers(const GLfloat data[], const GLuint size) { | 
 | 39 |     ATRACE_CALL(); | 
 | 40 |     bind(); | 
 | 41 |     glBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat), data, GL_STATIC_DRAW); | 
 | 42 |     unbind(); | 
 | 43 | } | 
 | 44 |  | 
 | 45 | void GLVertexBuffer::bind() const { | 
 | 46 |     glBindBuffer(GL_ARRAY_BUFFER, mBufferName); | 
 | 47 | } | 
 | 48 |  | 
 | 49 | void GLVertexBuffer::unbind() const { | 
 | 50 |     glBindBuffer(GL_ARRAY_BUFFER, 0); | 
 | 51 | } | 
 | 52 |  | 
 | 53 | } // namespace gl | 
 | 54 | } // namespace renderengine | 
 | 55 | } // namespace android |