1e9297d28Sopenharmony_ci/* 2e9297d28Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3e9297d28Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e9297d28Sopenharmony_ci * you may not use this file except in compliance with the License. 5e9297d28Sopenharmony_ci * You may obtain a copy of the License at 6e9297d28Sopenharmony_ci * 7e9297d28Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e9297d28Sopenharmony_ci * 9e9297d28Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e9297d28Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e9297d28Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e9297d28Sopenharmony_ci * See the License for the specific language governing permissions and 13e9297d28Sopenharmony_ci * limitations under the License. 14e9297d28Sopenharmony_ci */ 15e9297d28Sopenharmony_ci 16e9297d28Sopenharmony_ci#include "mesh.h" 17e9297d28Sopenharmony_ci 18e9297d28Sopenharmony_cinamespace OHOS { 19e9297d28Sopenharmony_cinamespace Rosen { 20e9297d28Sopenharmony_ciMesh::Mesh() 21e9297d28Sopenharmony_ci{ 22e9297d28Sopenharmony_ci glGenVertexArrays(1, &VAO_); 23e9297d28Sopenharmony_ci glGenBuffers(1, &VBO_); 24e9297d28Sopenharmony_ci glGenBuffers(1, &EBO_); 25e9297d28Sopenharmony_ci} 26e9297d28Sopenharmony_ci 27e9297d28Sopenharmony_ciMesh::~Mesh() 28e9297d28Sopenharmony_ci{ 29e9297d28Sopenharmony_ci Delete(); 30e9297d28Sopenharmony_ci} 31e9297d28Sopenharmony_ci 32e9297d28Sopenharmony_civoid Mesh::Use() 33e9297d28Sopenharmony_ci{ 34e9297d28Sopenharmony_ci glBindVertexArray(VAO_); 35e9297d28Sopenharmony_ci 36e9297d28Sopenharmony_ci glBindBuffer(GL_ARRAY_BUFFER, VBO_); 37e9297d28Sopenharmony_ci glBufferData(GL_ARRAY_BUFFER, sizeof(VERTICES), VERTICES, GL_STATIC_DRAW); 38e9297d28Sopenharmony_ci 39e9297d28Sopenharmony_ci glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO_); 40e9297d28Sopenharmony_ci glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(INDICES), INDICES, GL_STATIC_DRAW); 41e9297d28Sopenharmony_ci 42e9297d28Sopenharmony_ci glVertexAttribPointer(0, DEFAULT_VERTEX_POINT_SIZE, GL_FLOAT, GL_FALSE, DEFAULT_STRIDE * sizeof(float), (void*)0); 43e9297d28Sopenharmony_ci glEnableVertexAttribArray(0); 44e9297d28Sopenharmony_ci // color attribute 45e9297d28Sopenharmony_ci glVertexAttribPointer(1, DEFAULT_TEXTURE_POINT_SIZE, GL_FLOAT, GL_FALSE, 46e9297d28Sopenharmony_ci DEFAULT_STRIDE * sizeof(float), (void*)(DEFAULT_OFFSET * sizeof(float))); 47e9297d28Sopenharmony_ci glEnableVertexAttribArray(1); 48e9297d28Sopenharmony_ci} 49e9297d28Sopenharmony_ci 50e9297d28Sopenharmony_civoid Mesh::Delete() 51e9297d28Sopenharmony_ci{ 52e9297d28Sopenharmony_ci glDeleteVertexArrays(1, &VAO_); 53e9297d28Sopenharmony_ci glDeleteBuffers(1, &VBO_); 54e9297d28Sopenharmony_ci glDeleteBuffers(1, &EBO_); 55e9297d28Sopenharmony_ci} 56e9297d28Sopenharmony_ci} // namespcae Rosen 57e9297d28Sopenharmony_ci} // namespace OHOS