Skip to content

Commit

Permalink
fix rare grass-only chunk meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Oct 25, 2024
1 parent 79e8528 commit 2bd52ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/graphics/render/BlocksRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,13 @@ void BlocksRenderer::build(const Chunk* chunk, const ChunksStorage* chunks) {
overflow = false;
vertexOffset = 0;
indexOffset = indexSize = 0;
if (voxelsBuffer->pickBlockId(
chunk->x * CHUNK_W, 0, chunk->z * CHUNK_D
) == BLOCK_VOID) {
cancelled = true;
return;
}
cancelled = false;
const voxel* voxels = chunk->voxels;
render(voxels);
}
Expand Down
5 changes: 5 additions & 0 deletions src/graphics/render/BlocksRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BlocksRenderer {
size_t capacity;
int voxelBufferPadding = 2;
bool overflow = false;
bool cancelled = false;
const Chunk* chunk = nullptr;
std::unique_ptr<VoxelsVolume> voxelsBuffer;

Expand Down Expand Up @@ -149,4 +150,8 @@ class BlocksRenderer {
std::shared_ptr<Mesh> render(const Chunk* chunk, const ChunksStorage* chunks);
std::shared_ptr<Mesh> createMesh();
VoxelsVolume* getVoxelsBuffer() const;

bool isCancelled() const {
return cancelled;
}
};
4 changes: 3 additions & 1 deletion src/graphics/render/ChunksRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ ChunksRenderer::ChunksRenderer(
"chunks-render-pool",
[=](){return std::make_shared<RendererWorker>(level, cache, settings);},
[=](RendererResult& mesh){
meshes[mesh.key] = mesh.renderer->createMesh();
if (!mesh.renderer->isCancelled()) {
meshes[mesh.key] = mesh.renderer->createMesh();
}
inwork.erase(mesh.key);
}, settings->graphics.chunkMaxRenderers.get())
{
Expand Down

0 comments on commit 2bd52ef

Please sign in to comment.