From 69c44e3609e4ea5e23bcf5a822be8c299583c523 Mon Sep 17 00:00:00 2001 From: emamaker Date: Thu, 1 Dec 2022 23:37:57 +0100 Subject: [PATCH] enable faceculling Doesn't give a massive improve in performance right now, but a nice one to have and was already made from the jme3 porting --- src/chunkmesh.cpp | 38 ++++++++++++++++++++------------------ src/main.cpp | 13 +++++++------ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/chunkmesh.cpp b/src/chunkmesh.cpp index 8fd9618..b3d737e 100755 --- a/src/chunkmesh.cpp +++ b/src/chunkmesh.cpp @@ -99,10 +99,10 @@ void ChunkMesh::mesh() { for (x[u] = 0; x[u] < CHUNK_SIZE; x[u]++) { - Block b1 = (x[dim] >= 0) ? blocks[HILBERT_XYZ_ENCODE[x[0]][x[1]][x[2]]]: Block::NULLBLK; + Block b1 = (x[dim] >= 0) ? blocks[HILBERT_XYZ_ENCODE[x[0]][x[1]][x[2]]] : Block::NULLBLK; Block b2 = (x[dim] < CHUNK_SIZE - 1) ? blocks[HILBERT_XYZ_ENCODE[x[0] + q[0]][x[1] + q[1]][x[2] + q[2]]] - : Block::NULLBLK; + : Block::NULLBLK; // This is the original line taken from rob's code, readapted (replace voxelFace // with b1 and b2). @@ -263,23 +263,25 @@ void ChunkMesh::quad(glm::vec3 bottomLeft, glm::vec3 topLeft, glm::vec3 topRight vertices.push_back(topRight.y); vertices.push_back(topRight.z); - indices.push_back(vIndex + 2); - indices.push_back(vIndex + 3); - indices.push_back(vIndex + 1); - indices.push_back(vIndex + 1); - indices.push_back(vIndex); - indices.push_back(vIndex + 2); + if (backFace) + { + indices.push_back(vIndex + 2); + indices.push_back(vIndex); + indices.push_back(vIndex + 1); + indices.push_back(vIndex + 1); + indices.push_back(vIndex + 3); + indices.push_back(vIndex + 2); + } + else + { + indices.push_back(vIndex + 2); + indices.push_back(vIndex + 3); + indices.push_back(vIndex + 1); + indices.push_back(vIndex + 1); + indices.push_back(vIndex); + indices.push_back(vIndex + 2); + } vIndex += 4; - // } - // else - // { - // indices.push_back(i + 2); - // indices.push_back(i + 3); - // indices.push_back(i + 1); - // indices.push_back(i + 1); - // indices.push_back(i); - // indices.push_back(i + 2); - // } // ugly switch case GLfloat r, g, b; diff --git a/src/main.cpp b/src/main.cpp index 8bb9220..3b38088 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,6 +50,7 @@ int main() glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetCursorPosCallback(window, mouse_callback); glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); //GL_BACK GL_CCW by default SpaceFilling::initLUT(); chunkmanager::init(); @@ -62,12 +63,12 @@ int main() lastFrame = currentFrame; // FPS Counter - // frames++; - // if(currentFrame - lastFPSFrame >= 1.0f){ - // std::cout << "FPS: " << frames << std::endl; - // frames = 0; - // lastFPSFrame = currentFrame; - // } + frames++; + if(currentFrame - lastFPSFrame >= 1.0f){ + std::cout << "FPS: " << frames << " Frametime: " << deltaTime << std::endl; + frames = 0; + lastFPSFrame = currentFrame; + } glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);