chunkmesh: do not create shader for every object

vertex-deduplication
EmaMaker 2023-02-12 12:18:30 +01:00
parent 2e0ed7b057
commit 9f82a17bd2
5 changed files with 13 additions and 9 deletions

View File

@ -11,6 +11,7 @@
#include "block.hpp"
#include "spacefilling.hpp"
#include "intervalmap.hpp"
#include "shader.hpp"
#define CHUNK_SIZE 16
#define CHUNK_VOLUME (CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE)

View File

@ -7,7 +7,9 @@
#include <vector>
#include "chunk.hpp"
#include "globals.hpp"
#include "shader.hpp"
#include <string>
class ChunkMesh
{
@ -20,7 +22,6 @@ public:
void draw();
Chunk::Chunk *chunk{nullptr};
// static Shader theShader("shaders/shader.vs", "shaders/shader.fs");
glm::mat4 model = glm::mat4(1.0f);
private:
@ -32,7 +33,6 @@ private:
GLuint VAO{0}, VBO{0}, EBO{0}, colorBuffer{0}, vIndex{0};
Shader *theShader{nullptr};
};
#endif

View File

@ -13,6 +13,7 @@
#define RENDER_DISTANCE 8
extr Camera theCamera;
extr Shader* theShader;
extr uint32_t MORTON_XYZ_ENCODE[CHUNK_SIZE][CHUNK_SIZE][CHUNK_SIZE];
extr uint32_t MORTON_XYZ_DECODE[CHUNK_VOLUME][3];

View File

@ -16,8 +16,7 @@ ChunkMesh::~ChunkMesh()
if(this->colorBuffer) glDeleteBuffers(1, &(this->colorBuffer));
delete this->chunk;
delete (this->theShader);
}
}
ChunkMesh::ChunkMesh(Chunk::Chunk *c)
{
@ -28,7 +27,6 @@ ChunkMesh::ChunkMesh(Chunk::Chunk *c)
glGenBuffers(1, &(this->VBO));
glGenBuffers(1, &(this->EBO));
this->theShader = new Shader{"shaders/shader.vs", "shaders/shader.fs"};
this->model = glm::translate(model, (float)CHUNK_SIZE * c->getPosition());
// std::cout << "CHUNK MESH " << c << std::endl;

View File

@ -1,15 +1,17 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#define GLOBALS_DEFINER
#include "globals.hpp"
#undef GLOBALS_DEFINER
#include <iostream>
#include "chunkmanager.hpp"
#include "main.hpp"
#include "spacefilling.hpp"
#include "shader.hpp"
#define GLOBALS_DEFINER
#include "globals.hpp"
#undef GLOBALS_DEFINER
float deltaTime = 0.0f; // Time between current frame and last frame
float lastFrame = 0.0f; // Time of last frame
@ -55,6 +57,8 @@ int main()
SpaceFilling::initLUT();
chunkmanager::init();
theShader = new Shader{"shaders/shader.vs", "shaders/shader.fs"};
while (!glfwWindowShouldClose(window))
{
// DeltaTime