diff --git a/src/content/Content.cpp b/src/content/Content.cpp index 6184edb7..d1074005 100644 --- a/src/content/Content.cpp +++ b/src/content/Content.cpp @@ -20,6 +20,7 @@ void ContentBuilder::add(Block* def) { Content* ContentBuilder::build() { vector blockDefsIndices; + DrawGroups* groups = new DrawGroups; for (const string& name : blockIds) { Block* def = blockDefs[name]; @@ -44,18 +45,22 @@ Content* ContentBuilder::build() { } blockDefsIndices.push_back(def); + if (groups->find(def->drawGroup) == groups->end()) { + groups->insert(def->drawGroup); + } } ContentIndices* indices = new ContentIndices(blockDefsIndices); - return new Content(indices, blockDefs); + return new Content(indices, groups, blockDefs); } ContentIndices::ContentIndices(vector blockDefs) : blockDefs(blockDefs) { } -Content::Content(ContentIndices* indices, +Content::Content(ContentIndices* indices, DrawGroups* drawGroups, unordered_map blockDefs) : blockDefs(blockDefs), + drawGroups(drawGroups), indices(indices) { } diff --git a/src/content/Content.h b/src/content/Content.h index 184d866d..70c68cc6 100644 --- a/src/content/Content.h +++ b/src/content/Content.h @@ -4,8 +4,11 @@ #include #include #include +#include #include "../typedefs.h" +typedef std::set DrawGroups; + class Block; class Content; @@ -46,8 +49,9 @@ class Content { std::unordered_map blockDefs; public: ContentIndices* const indices; - - Content(ContentIndices* indices, + DrawGroups* const drawGroups; + + Content(ContentIndices* indices, DrawGroups* drawGroups, std::unordered_map blockDefs); ~Content(); diff --git a/src/definitions.cpp b/src/definitions.cpp index 354c293e..20c80b2c 100644 --- a/src/definitions.cpp +++ b/src/definitions.cpp @@ -57,7 +57,7 @@ void setup_definitions(ContentBuilder* builder) { builder->add(block); block = new Block("base:water", "water"); - block->drawGroup = 4; + block->drawGroup = 3; block->lightPassing = true; block->skyLightPassing = false; block->obstacle = false; @@ -73,7 +73,7 @@ void setup_definitions(ContentBuilder* builder) { builder->add(block); block = new Block("base:grass", "grass"); - block->drawGroup = 5; + block->drawGroup = 1; block->lightPassing = true; block->obstacle = false; block->replaceable = true; @@ -82,7 +82,7 @@ void setup_definitions(ContentBuilder* builder) { builder->add(block); block = new Block("base:flower", "flower"); - block->drawGroup = 5; + block->drawGroup = 1; block->lightPassing = true; block->obstacle = false; block->replaceable = true; diff --git a/src/graphics/BlocksRenderer.cpp b/src/graphics/BlocksRenderer.cpp index 1e75ee93..922cf72f 100644 --- a/src/graphics/BlocksRenderer.cpp +++ b/src/graphics/BlocksRenderer.cpp @@ -374,12 +374,12 @@ vec4 BlocksRenderer::pickSoftLight(float x, float y, float z, void BlocksRenderer::render(const voxel* voxels, int atlas_size) { int begin = chunk->bottom * (CHUNK_W * CHUNK_D); int end = chunk->top * (CHUNK_W * CHUNK_D); - for (ubyte group = 0; group < 8; group++) { + for (const auto drawGroup : *content->drawGroups) { for (int i = begin; i < end; i++) { const voxel& vox = voxels[i]; blockid_t id = vox.id; const Block& def = *blockDefsCache[id]; - if (!id || def.drawGroup != group) + if (!id || def.drawGroup != drawGroup) continue; const UVRegion texfaces[6]{ cache->getRegion(id, 0), cache->getRegion(id, 1), cache->getRegion(id, 2), cache->getRegion(id, 3), diff --git a/src/graphics/Framebuffer.cpp b/src/graphics/Framebuffer.cpp index ab980b1b..77ae7462 100644 --- a/src/graphics/Framebuffer.cpp +++ b/src/graphics/Framebuffer.cpp @@ -26,6 +26,7 @@ Framebuffer::Framebuffer(uint width, uint height) : width(width), height(height) Framebuffer::~Framebuffer() { delete texture; glDeleteFramebuffers(1, &fbo); + glDeleteRenderbuffers(1, &depth); } void Framebuffer::bind() { diff --git a/src/voxels/Chunks.h b/src/voxels/Chunks.h index 5798555b..687499f2 100644 --- a/src/voxels/Chunks.h +++ b/src/voxels/Chunks.h @@ -8,7 +8,7 @@ class VoxelRenderer; -class AABB; +struct AABB; class Content; class ContentIndices; class Chunk;