Rename VertexBuffer to VertexArray
because it was misleading
This commit is contained in:
@@ -4,7 +4,7 @@ add_executable(Fall-Fever
|
||||
Window.cpp
|
||||
EventHandler.cpp
|
||||
ShaderProgram.cpp
|
||||
VertexBuffer.cpp
|
||||
VertexArray.cpp
|
||||
Texture.cpp
|
||||
Camera.cpp
|
||||
Mesh.cpp
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "EventHandler.h"
|
||||
#include "Camera.h"
|
||||
#include "ShaderProgram.h"
|
||||
#include "VertexBuffer.h"
|
||||
#include "Entity.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<uint32_t> indices, std::vector<Texture*> textures)
|
||||
: numElements(indices.size()),
|
||||
textures(textures),
|
||||
vertexBuffer(static_cast<void*>(vertices.data()), static_cast<void*>(indices.data()), vertices.size(), indices.size()) {
|
||||
vertexArray(static_cast<void*>(vertices.data()), static_cast<void*>(indices.data()), vertices.size(), indices.size()) {
|
||||
|
||||
// Empty...
|
||||
|
||||
@@ -25,9 +25,9 @@ void Mesh::draw(ShaderProgram *shaderProgram) {
|
||||
}
|
||||
|
||||
// Draw elements
|
||||
vertexBuffer.bind();
|
||||
vertexArray.bind();
|
||||
glDrawElements(GL_TRIANGLES, numElements, GL_UNSIGNED_INT, 0);
|
||||
vertexBuffer.unbind();
|
||||
vertexArray.unbind();
|
||||
|
||||
// Unbind all textures
|
||||
for(auto it = textures.begin(); it != textures.end(); it++) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "ShaderProgram.h"
|
||||
#include "VertexBuffer.h"
|
||||
#include "VertexArray.h"
|
||||
#include "Texture.h"
|
||||
#include "defines.h"
|
||||
|
||||
@@ -21,7 +21,7 @@ private:
|
||||
uint32_t numElements;
|
||||
std::vector<Texture*> textures;
|
||||
|
||||
VertexBuffer vertexBuffer;
|
||||
VertexArray vertexArray;
|
||||
|
||||
void setupMesh();
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include <cstddef>
|
||||
|
||||
#include "VertexBuffer.h"
|
||||
#include "VertexArray.h"
|
||||
#include "defines.h"
|
||||
|
||||
VertexBuffer::VertexBuffer(void *vertexData, void *indexData, uint32_t numVertices, uint32_t numIndices) {
|
||||
VertexArray::VertexArray(void *vertexData, void *indexData, uint32_t numVertices, uint32_t numIndices) {
|
||||
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
glGenBuffers(1, &bufferId);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, bufferId);
|
||||
glGenBuffers(1, &VBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, numVertices * sizeof(Vertex), vertexData, GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &EBO);
|
||||
@@ -32,14 +32,14 @@ VertexBuffer::VertexBuffer(void *vertexData, void *indexData, uint32_t numVertic
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
VertexBuffer::~VertexBuffer() {
|
||||
glDeleteBuffers(1, &bufferId);
|
||||
VertexArray::~VertexArray() {
|
||||
glDeleteBuffers(1, &VBO);
|
||||
}
|
||||
|
||||
void VertexBuffer::bind() {
|
||||
void VertexArray::bind() {
|
||||
glBindVertexArray(VAO);
|
||||
}
|
||||
|
||||
void VertexBuffer::unbind() {
|
||||
void VertexArray::unbind() {
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
21
src/VertexArray.h
Normal file
21
src/VertexArray.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
class VertexArray {
|
||||
|
||||
public:
|
||||
|
||||
VertexArray(void *vertexData, void *indexData, uint32_t numVertices, uint32_t numIndices);
|
||||
~VertexArray();
|
||||
|
||||
void bind();
|
||||
void unbind();
|
||||
|
||||
private:
|
||||
|
||||
GLuint VAO;
|
||||
GLuint VBO;
|
||||
GLuint EBO;
|
||||
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
class VertexBuffer {
|
||||
|
||||
public:
|
||||
|
||||
VertexBuffer(void *vertexData, void *indexData, uint32_t numVertices, uint32_t numIndices);
|
||||
~VertexBuffer();
|
||||
|
||||
void bind();
|
||||
void unbind();
|
||||
|
||||
private:
|
||||
|
||||
GLuint bufferId;
|
||||
GLuint VAO;
|
||||
GLuint EBO;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user