1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
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
16#include "mesh.h"
17
18namespace OHOS {
19namespace Rosen {
20Mesh::Mesh()
21{
22    glGenVertexArrays(1, &VAO_);
23    glGenBuffers(1, &VBO_);
24    glGenBuffers(1, &EBO_);
25}
26
27Mesh::~Mesh()
28{
29    Delete();
30}
31
32void Mesh::Use()
33{
34    glBindVertexArray(VAO_);
35
36    glBindBuffer(GL_ARRAY_BUFFER, VBO_);
37    glBufferData(GL_ARRAY_BUFFER, sizeof(VERTICES), VERTICES, GL_STATIC_DRAW);
38
39    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO_);
40    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(INDICES), INDICES, GL_STATIC_DRAW);
41
42    glVertexAttribPointer(0, DEFAULT_VERTEX_POINT_SIZE, GL_FLOAT, GL_FALSE, DEFAULT_STRIDE * sizeof(float), (void*)0);
43    glEnableVertexAttribArray(0);
44    // color attribute
45    glVertexAttribPointer(1, DEFAULT_TEXTURE_POINT_SIZE, GL_FLOAT, GL_FALSE,
46        DEFAULT_STRIDE * sizeof(float), (void*)(DEFAULT_OFFSET * sizeof(float)));
47    glEnableVertexAttribArray(1);
48}
49
50void Mesh::Delete()
51{
52    glDeleteVertexArrays(1, &VAO_);
53    glDeleteBuffers(1, &VBO_);
54    glDeleteBuffers(1, &EBO_);
55}
56} // namespcae Rosen
57} // namespace OHOS