feat: add logger class

This commit is contained in:
2025-10-13 17:30:05 +02:00
parent 74a0bfca41
commit 41c9b68eb9
8 changed files with 185 additions and 22 deletions

View File

@@ -1,13 +1,13 @@
#include "shader.h"
#include <vector>
#include <fstream>
#include <sstream>
#include <iostream>
#include <vector>
#include "../lib/glew/GL/glew.h"
#include "../lib/glfw/glfw3.h"
#include "logger.h"
#include "vertex.h"
Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath)
@@ -106,7 +106,8 @@ std::string Shader::read_shader_file(const std::string& filename)
{
std::ifstream file(filename);
if (!file) {
error_ = "Failed to open shader file: " + filename + "\n";
error_ = "Failed to open shader file: " + filename;
Logger::error(sstr("Failed to open shader file: ", filename));
return std::string{0};
}
@@ -117,11 +118,16 @@ std::string Shader::read_shader_file(const std::string& filename)
uint32_t Shader::compile_shader(uint32_t type, const std::string& source_path)
{
const char* shader_type_name =
(type == GL_VERTEX_SHADER) ? "vertex" : "fragment";
std::string source = read_shader_file(source_path);
// std::cout << "SHADER FILE: " << source << "\n";
if (source.empty())
return 0;
Logger::info(
sstr("Compiling ", shader_type_name, " shader: ", source_path));
const uint32_t shader = glCreateShader(type);
const char* shader_code = source.c_str();
@@ -135,9 +141,13 @@ uint32_t Shader::compile_shader(uint32_t type, const std::string& source_path)
char buffer[1024];
glGetShaderInfoLog(shader, sizeof(buffer), nullptr, buffer);
error_ = buffer;
Logger::error(
sstr("Shader compilation failed (", shader_type_name, "): ",
buffer));
glDeleteShader(shader);
return 0;
}
Logger::info(sstr(shader_type_name, " shader compiled successfully"));
return shader;
}