feat(renderer): add --no-debug flag to disable OpenGL debug output

This commit is contained in:
2026-07-07 20:29:01 +08:00
parent f0e339822d
commit 8259b211ea
4 changed files with 22 additions and 11 deletions

View File

@@ -18,6 +18,7 @@ public:
int port = 25530;
std::string ip{"127.0.0.1"};
std::string player{"Unknown"};
bool debug_on = true;
};
App();

View File

@@ -22,7 +22,7 @@ public:
const TextureManager& texture_manager, DevPanel& dev_panel);
~Renderer();
void hot_reload();
void init();
void init(bool debug_on);
const Shader& get_shader(const std::string& name) const;
void render();
void update(float delta_time);

View File

@@ -63,7 +63,7 @@ void App::init(int argc, char** argv) {
ChunkGenerator::init();
BlockManager::init();
m_renderer.init();
m_renderer.init(m_argument.debug_on);
Logger::info("Renderer Init Success");
m_window.update_viewport();
// MapTable::init_map();
@@ -127,6 +127,12 @@ void App::handle_argument(int argc, char** argv) {
[&](ArgParser) {
std::cout << CUBED_VERSION << "\n";
exit(EXIT_SUCCESS);
}},
{"--no-debug",
[&](ArgParser) {
m_argument.debug_on = false;
Logger::info("Switch off opengl debug out put");
}}
};

View File

@@ -57,7 +57,7 @@ void Renderer::hot_reload() {
update_fov(config.get<double>("player.fov"));
}
void Renderer::init() {
void Renderer::init(bool debug_on) {
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
Logger::error("Failed to initialize glad");
exit(EXIT_FAILURE);
@@ -118,14 +118,18 @@ void Renderer::init() {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
#ifdef DEBUG_MODE
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(
[](GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar* message,
const void*) {
Logger::log(Logger::Level::L_DEBUG, std::source_location::current(),
"GL Debug: {}", reinterpret_cast<const char*>(message));
},
nullptr);
if (debug_on) {
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(
[](GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar* message,
const void*) {
Logger::log(Logger::Level::L_DEBUG,
std::source_location::current(), "GL Debug: {}",
reinterpret_cast<const char*>(message));
},
nullptr);
}
#endif
m_vao.resize(NUM_VAO);