Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class VAO {
- public static List<Integer> vaos = new ArrayList<>();
- public static List<Integer> vbos = new ArrayList<>();
- int vaoID;
- int vCount;
- public VAO(float[] vertices, float[] normals, float[] texCoords, int[] indices) {
- vaoID = createVAO();
- vCount = indices.length;
- bindIndices(indices);
- storeDataInVAO(0, 3, vertices);
- storeDataInVAO(1, 3, normals);
- storeDataInVAO(2, 2, texCoords);
- glBindVertexArray(0);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- }
- private int createVAO() {
- int vao = glGenVertexArrays();
- vaos.add(vao);
- glBindVertexArray(vao);
- return vao;
- }
- private void bindIndices(int[] indices) {
- int vboiID = glGenBuffers();
- vbos.add(vboiID);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboiID);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, asIntBuffer(indices), GL_STATIC_DRAW);
- }
- private void storeDataInVAO(int index, int coordsize, float[] data) {
- int vboID = glGenBuffers();
- vbos.add(vboID);
- glBindBuffer(GL_ARRAY_BUFFER, vboID);
- glBufferData(GL_ARRAY_BUFFER, asFloatBuffer(data), GL_STATIC_DRAW);
- glVertexAttribPointer(index, coordsize, GL_FLOAT, false, 0, 0);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- }
- public int getVaoID() {
- return vaoID;
- }
- public int getVertexCount() {
- return vCount;
- }
- public static void cleanUp() {
- for(int i = 0; i < vaos.size(); i++) {
- glDeleteVertexArrays(i);
- System.out.println("[MODEL] Deleted VAO #"+(i+1));
- }
- System.out.println("--------------------");
- for(int i = 0; i < vbos.size(); i++) {
- glDeleteBuffers(i);
- System.out.println("[MODEL] Deleted VBO #"+(i+1));
- }
- System.out.println("--------------------");
- for(int i = 0; i < Render.textures.size(); i++) {
- glDeleteTextures(i);
- Render.textures.get(i).release();
- System.out.println("[MODEL] Deleted texture #"+(i+1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment