refactor: chunk render (#15)

* refactor(renderer): centralize VAO setup and rename init_underwater

* refactor(gameplay): replace VBO with VAO for vertex data

* fix(renderer): move depth test enable to world rendering

The `glEnable(GL_DEPTH_TEST)` call was incorrectly placed in the general `render()` function, affecting UI and text rendering. Moved it to the start of the world rendering loop to ensure depth testing is only active during 3D world pass.
This commit is contained in:
zhenyan121
2026-06-11 14:58:39 +08:00
committed by GitHub
parent d0bc8d627f
commit bac3df801b
8 changed files with 136 additions and 118 deletions

View File

@@ -101,16 +101,16 @@ public:
const std::array<const std::vector<BlockType>*, 4>& neighbor_block);
void upload_to_gpu();
GLuint get_normal_vbo() const;
GLuint get_normal_vao() const;
size_t get_normal_vertices_sum() const;
GLuint get_cross_vbo() const;
GLuint get_cross_vao() const;
size_t get_cross_vertices_sum() const;
GLuint get_normal_discard_vbo() const;
GLuint get_normal_discard_vao() const;
size_t get_normal_discard_vertices_sum() const;
GLuint get_normal_blend_vbo() const;
GLuint get_normal_blend_vao() const;
size_t get_normal_blend_vertices_sum() const;
bool is_dirty() const;

View File

@@ -9,6 +9,7 @@ class World;
struct VertexData {
std::vector<Vertex> m_vertices;
GLuint m_vbo = 0;
GLuint m_vao = 0;
std::atomic<std::size_t> m_sum{0};
World& m_world;
VertexData(World& world);

View File

@@ -15,13 +15,13 @@
namespace Cubed {
struct ChunkRenderSnapshot {
GLuint normal_vbo;
GLuint normal_vao;
size_t normal_vertices_count;
GLuint cross_vbo;
GLuint cross_vao;
size_t cross_vertices_count;
GLuint normal_discard_vbo;
GLuint normal_discard_vao;
size_t normal_discard_vertices_count;
GLuint normal_blend_vbo;
GLuint normal_blend_vao;
size_t normal_blend_vertices_count;
glm::vec3 center;
glm::vec3 half_extents;
@@ -47,8 +47,10 @@ private:
std::mutex m_gen_signal_mutex;
std::mutex m_new_chunk_queue_mutex;
std::mutex m_delete_vbo_mutex;
std::mutex m_delete_vao_mutex;
std::mutex m_gen_player_pos_mutex;
std::vector<GLuint> m_pending_delete_vbo;
std::vector<GLuint> m_pending_delete_vao;
std::condition_variable m_gen_cv;
std::atomic<bool> m_gen_running{false};
std::atomic<bool> m_need_gen_chunk{false};
@@ -104,7 +106,7 @@ public:
void update(float delta_time);
void push_delete_vbo(GLuint vbo);
void push_delete_vao(GLuint vao);
void hot_reload();
void rebuild_world();

View File

@@ -67,10 +67,18 @@ private:
glm::mat4 m_ui_proj;
glm::mat4 m_ui_m_matrix;
std::unordered_map<std::size_t, Shader> m_shaders;
/*
0 - quad vao
1 - sky vao
2 - outline vao
3 - ui vao
4 - text vao
*/
std::vector<GLuint> m_vao;
std::vector<Vertex2D> m_ui;
void init_underwater();
void init_quad();
void init_text();
void render_outline();