move normal data to own array
parent
a7b4671517
commit
bff9e6ad4f
|
@ -56,7 +56,7 @@ namespace Chunk
|
||||||
std::unique_ptr<Block[]> getBlocksArray(int* len) { return (this->blocks.toArray(len)); }
|
std::unique_ptr<Block[]> getBlocksArray(int* len) { return (this->blocks.toArray(len)); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GLuint VAO{0}, VBO{0}, EBO{0}, colorBuffer{0}, numTriangles{0};
|
GLuint VAO{0}, VBO{0}, EBO{0}, colorBuffer{0}, normalsBuffer{0}, numTriangles{0};
|
||||||
std::atomic<float> unload_timer{0};
|
std::atomic<float> unload_timer{0};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace chunkmesher{
|
||||||
GLuint numVertices{0};
|
GLuint numVertices{0};
|
||||||
|
|
||||||
std::vector<GLfloat> vertices;
|
std::vector<GLfloat> vertices;
|
||||||
|
std::vector<GLfloat> normals;
|
||||||
std::vector<GLfloat> colors;
|
std::vector<GLfloat> colors;
|
||||||
std::vector<GLuint> indices;
|
std::vector<GLuint> indices;
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace Chunk
|
||||||
void Chunk::createBuffers(){
|
void Chunk::createBuffers(){
|
||||||
glGenVertexArrays(1, &(this->VAO));
|
glGenVertexArrays(1, &(this->VAO));
|
||||||
glGenBuffers(1, &(this->colorBuffer));
|
glGenBuffers(1, &(this->colorBuffer));
|
||||||
|
glGenBuffers(1, &(this->normalsBuffer));
|
||||||
glGenBuffers(1, &(this->VBO));
|
glGenBuffers(1, &(this->VBO));
|
||||||
glGenBuffers(1, &(this->EBO));
|
glGenBuffers(1, &(this->EBO));
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ namespace Chunk
|
||||||
|
|
||||||
void Chunk::deleteBuffers(){
|
void Chunk::deleteBuffers(){
|
||||||
glDeleteBuffers(1, &(this->colorBuffer));
|
glDeleteBuffers(1, &(this->colorBuffer));
|
||||||
|
glDeleteBuffers(1, &(this->normalsBuffer));
|
||||||
glDeleteBuffers(1, &(this->VBO));
|
glDeleteBuffers(1, &(this->VBO));
|
||||||
glDeleteBuffers(1, &(this->EBO));
|
glDeleteBuffers(1, &(this->EBO));
|
||||||
glDeleteVertexArrays(1, &(this->VAO));
|
glDeleteVertexArrays(1, &(this->VAO));
|
||||||
|
|
|
@ -228,25 +228,24 @@ void sendtogpu(MeshData* mesh_data)
|
||||||
// bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).
|
// bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).
|
||||||
glBindVertexArray(mesh_data->chunk->VAO);
|
glBindVertexArray(mesh_data->chunk->VAO);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh_data->chunk->VBO);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh_data->chunk->EBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, mesh_data->vertices.size() * sizeof(GLfloat), &(mesh_data->vertices[0]), GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, mesh_data->indices.size() * sizeof(GLuint), &(mesh_data->indices[0]), GL_STATIC_DRAW);
|
||||||
|
|
||||||
// position attribute
|
// position attribute
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void *)0);
|
glBindBuffer(GL_ARRAY_BUFFER, mesh_data->chunk->VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, mesh_data->vertices.size() * sizeof(GLfloat), &(mesh_data->vertices[0]), GL_STATIC_DRAW);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void *)0);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
// normal attribute
|
// normal attribute
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void *)(3*
|
glBindBuffer(GL_ARRAY_BUFFER, mesh_data->chunk->normalsBuffer);
|
||||||
sizeof(float)));
|
glBufferData(GL_ARRAY_BUFFER, mesh_data->normals.size() * sizeof(GLfloat), &(mesh_data->normals[0]), GL_STATIC_DRAW);
|
||||||
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void *)(0));
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh_data->chunk->EBO);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, mesh_data->indices.size() * sizeof(GLuint), &(mesh_data->indices[0]), GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
// texcoords attribute
|
// texcoords attribute
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, mesh_data->chunk->colorBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, mesh_data->chunk->colorBuffer);
|
||||||
glBufferData(GL_ARRAY_BUFFER, mesh_data->colors.size() * sizeof(GLfloat), &(mesh_data->colors[0]), GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, mesh_data->colors.size() * sizeof(GLfloat), &(mesh_data->colors[0]), GL_STATIC_DRAW);
|
||||||
|
|
||||||
glEnableVertexAttribArray(2);
|
glEnableVertexAttribArray(2);
|
||||||
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void *)0);
|
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void *)0);
|
||||||
|
|
||||||
|
@ -257,6 +256,7 @@ void sendtogpu(MeshData* mesh_data)
|
||||||
|
|
||||||
// once data has been sent to the GPU, it can be cleared from system RAM
|
// once data has been sent to the GPU, it can be cleared from system RAM
|
||||||
mesh_data->vertices.clear();
|
mesh_data->vertices.clear();
|
||||||
|
mesh_data->normals.clear();
|
||||||
mesh_data->indices.clear();
|
mesh_data->indices.clear();
|
||||||
mesh_data->colors.clear();
|
mesh_data->colors.clear();
|
||||||
}
|
}
|
||||||
|
@ -271,30 +271,24 @@ void quad(MeshData* mesh_data, glm::vec3 bottomLeft, glm::vec3 topLeft, glm::vec
|
||||||
mesh_data->vertices.push_back(bottomLeft.x);
|
mesh_data->vertices.push_back(bottomLeft.x);
|
||||||
mesh_data->vertices.push_back(bottomLeft.y);
|
mesh_data->vertices.push_back(bottomLeft.y);
|
||||||
mesh_data->vertices.push_back(bottomLeft.z);
|
mesh_data->vertices.push_back(bottomLeft.z);
|
||||||
mesh_data->vertices.push_back(normal.x);
|
|
||||||
mesh_data->vertices.push_back(normal.y);
|
|
||||||
mesh_data->vertices.push_back(normal.z);
|
|
||||||
|
|
||||||
mesh_data->vertices.push_back(bottomRight.x);
|
mesh_data->vertices.push_back(bottomRight.x);
|
||||||
mesh_data->vertices.push_back(bottomRight.y);
|
mesh_data->vertices.push_back(bottomRight.y);
|
||||||
mesh_data->vertices.push_back(bottomRight.z);
|
mesh_data->vertices.push_back(bottomRight.z);
|
||||||
mesh_data->vertices.push_back(normal.x);
|
|
||||||
mesh_data->vertices.push_back(normal.y);
|
|
||||||
mesh_data->vertices.push_back(normal.z);
|
|
||||||
|
|
||||||
mesh_data->vertices.push_back(topLeft.x);
|
mesh_data->vertices.push_back(topLeft.x);
|
||||||
mesh_data->vertices.push_back(topLeft.y);
|
mesh_data->vertices.push_back(topLeft.y);
|
||||||
mesh_data->vertices.push_back(topLeft.z);
|
mesh_data->vertices.push_back(topLeft.z);
|
||||||
mesh_data->vertices.push_back(normal.x);
|
|
||||||
mesh_data->vertices.push_back(normal.y);
|
|
||||||
mesh_data->vertices.push_back(normal.z);
|
|
||||||
|
|
||||||
mesh_data->vertices.push_back(topRight.x);
|
mesh_data->vertices.push_back(topRight.x);
|
||||||
mesh_data->vertices.push_back(topRight.y);
|
mesh_data->vertices.push_back(topRight.y);
|
||||||
mesh_data->vertices.push_back(topRight.z);
|
mesh_data->vertices.push_back(topRight.z);
|
||||||
mesh_data->vertices.push_back(normal.x);
|
|
||||||
mesh_data->vertices.push_back(normal.y);
|
for(int i = 0; i < 4; i++){
|
||||||
mesh_data->vertices.push_back(normal.z);
|
mesh_data->normals.push_back(normal.x);
|
||||||
|
mesh_data->normals.push_back(normal.y);
|
||||||
|
mesh_data->normals.push_back(normal.z);
|
||||||
|
}
|
||||||
|
|
||||||
// texcoords
|
// texcoords
|
||||||
if(dim == 0){
|
if(dim == 0){
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 263 B |
Loading…
Reference in New Issue