Use logger instead of std::cout/cerr
This commit is contained in:
parent
108382ed54
commit
dd55b40e60
2
cmrc
2
cmrc
|
@ -1 +1 @@
|
|||
Subproject commit a64bea50c05594c8e7cf1f08e441bb9507742e2e
|
||||
Subproject commit e386a629eb537d384811e598a3c96b9ca928f65e
|
|
@ -106,24 +106,14 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
se::log::LoggerManager::set_level(spdlog::level::trace);
|
||||
|
||||
se::log::LoggerPtr logger = se::log::LoggerManager::get_core_logger();
|
||||
logger->info("Hmmmm very cool. {}", "Yeah, I guess...");
|
||||
|
||||
SE_CLOG(spdlog::level::info, "This is a test. {}", "Did it work?");
|
||||
SE_CINFO("This is a 2nd test. {}!", "Did it work?");
|
||||
|
||||
// Load core shaders from SimpleEngine resources
|
||||
se::gfx::shaders::Core3dShader core_shader;
|
||||
|
||||
auto camera = std::make_shared<se::Camera>(game.get_window(), core_shader, 70, glm::vec3(0, 0, 0));
|
||||
//game.add_event(camera);
|
||||
|
||||
// Create a renderer
|
||||
auto renderer = std::make_shared<se::gfx::Renderer>(game.get_window(), core_shader, camera);
|
||||
renderer->initialize();
|
||||
//game.add_renderable(renderer);
|
||||
|
||||
logger->error("AHHHHH SOMETHING BAD!");
|
||||
|
||||
// Create a Scene and give it the renderer
|
||||
auto scene = std::make_shared<se::Scene>(renderer, camera);
|
||||
|
@ -162,7 +152,7 @@ int main(int argc, char *argv[]) {
|
|||
game.set_fps_limit(100); */
|
||||
int res = game.run();
|
||||
|
||||
std::cout << "Engine result: " << res << std::endl;
|
||||
SE_CINFO("Engine result: {}", res);
|
||||
|
||||
renderer->destroy();
|
||||
scene->destroy();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../camera.h"
|
||||
#include "../log/logger.h"
|
||||
#include "shader.h"
|
||||
#include "../renderable.h"
|
||||
#include "rendering_type.h"
|
||||
|
@ -30,7 +31,7 @@ namespace simpleengine::gfx {
|
|||
bool is_initialized = false;
|
||||
|
||||
void check_if_initialized();
|
||||
|
||||
simpleengine::log::Logger logger;
|
||||
public:
|
||||
std::queue<RenderingJob> transparent_render_queue;
|
||||
std::queue<RenderingJob> other_render_queue;
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace simpleengine::gfx {
|
|||
}
|
||||
|
||||
~VAO() {
|
||||
std::cout << "~vao(" << handle << ")" << std::endl;
|
||||
// TODO: Anything to do here?
|
||||
}
|
||||
|
||||
VAO& operator=(const VAO& other) {
|
||||
|
@ -30,9 +30,6 @@ namespace simpleengine::gfx {
|
|||
handle = other.handle;
|
||||
}
|
||||
|
||||
|
||||
std::cout << "Copied " << handle << std::endl;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace simpleengine::gfx {
|
|||
}
|
||||
|
||||
~VBO() {
|
||||
std::cout << "~vbo(" << handle << ")" << std::endl;
|
||||
// TODO: Anything to do here?
|
||||
}
|
||||
|
||||
static VBO init(GLint type, bool dynamic) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//#define SPDLOG_FMT_EXTERNAL
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
@ -223,7 +223,7 @@ namespace simpleengine::log {
|
|||
|
||||
class LoggerManager {
|
||||
private:
|
||||
const static std::shared_ptr<Logger> core_logger;
|
||||
static std::shared_ptr<Logger> core_logger;
|
||||
public:
|
||||
/**
|
||||
* @brief Initialize the logger.
|
||||
|
@ -308,7 +308,7 @@ namespace simpleengine::log {
|
|||
* @param message The (to be) formatted message to log.
|
||||
* @param ... The variables that will be formatted in the text.
|
||||
*/
|
||||
#define SE_ERROR(logger_name, message, ...) SE_LOG(logger_name, spdlog::level::error, message, ##__VA_ARGS__);
|
||||
#define SE_ERROR(logger_name, message, ...) SE_LOG(logger_name, spdlog::level::err, message, ##__VA_ARGS__);
|
||||
|
||||
/**
|
||||
* @brief Log an error message to the core logger.
|
||||
|
@ -316,7 +316,7 @@ namespace simpleengine::log {
|
|||
* @param message The (to be) formatted message to log.
|
||||
* @param ... The variables that will be formatted in the text.
|
||||
*/
|
||||
#define SE_CERROR(message, ...) SE_CLOG(spdlog::level::error, message, ##__VA_ARGS__);
|
||||
#define SE_CERROR(message, ...) SE_CLOG(spdlog::level::err, message, ##__VA_ARGS__);
|
||||
|
||||
/**
|
||||
* @brief Log a warning message to a logger.
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "event/event.h"
|
||||
#include "gfx/shader.h"
|
||||
#include "log/logger.h"
|
||||
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
|
@ -99,7 +100,7 @@ namespace simpleengine {
|
|||
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
||||
|
||||
if (!success) {
|
||||
std::cerr << "Failed to link shader program!" << std::endl;
|
||||
SE_CERROR("Failed to link shader program!");
|
||||
throw gfx::ShaderException("Failed to link shader program!");
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ simpleengine::Game::Game(int w, int h, const std::string& window_name, const int
|
|||
glewExperimental = GL_TRUE;
|
||||
|
||||
if (glewInit() != GLEW_OK) {
|
||||
std::cout << "Failed to initialize glew!" << std::endl;
|
||||
SE_CERROR("Failed to initialize glew!");
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "gfx/rendering_type.h"
|
||||
#include "gfx/texture.h"
|
||||
#include "vector.h"
|
||||
#include "log/logger.h"
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/material.h>
|
||||
|
@ -38,7 +39,7 @@ namespace simpleengine::gfx {
|
|||
const aiScene *scene = importer.ReadFile(path, aiProcess_GenNormals | aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
|
||||
std::cout << "ERROR::ASSIMP::" << importer.GetErrorString() << std::endl;
|
||||
SE_CERROR("Assimp error when attempting to import \"{}\"", importer.GetErrorString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -117,8 +118,6 @@ namespace simpleengine::gfx {
|
|||
gfx::Material mat(default_textures, rendering_type);
|
||||
|
||||
if (mesh->mMaterialIndex >= 0) {
|
||||
std::cout << "TODO: Process model materials!" << std::endl;
|
||||
|
||||
std::unordered_map<aiTextureType, std::vector<std::shared_ptr<Texture>>> textures;
|
||||
aiMaterial *material = scene->mMaterials[mesh->mMaterialIndex];
|
||||
|
||||
|
@ -217,7 +216,7 @@ namespace simpleengine::gfx {
|
|||
texture.path = texture_path;
|
||||
textures.emplace_back(std::make_shared<Texture>(texture));
|
||||
|
||||
std::cout << "Texture full path: " << full_path << ", texture_path: " << texture_path << std::endl;
|
||||
SE_CDEBUG("Loaded texture! Full path: {}, relative path: {}", full_path, texture_path);
|
||||
}
|
||||
|
||||
return textures;
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace simpleengine::gfx {
|
|||
: rendering_type(rendering_type), rendering_mesh(&mesh), last_transform_mat(last_pos), transform_mat(position) {}
|
||||
|
||||
Renderer::Renderer(GLFWwindow *window, gfx::Shader shader, std::shared_ptr<Camera> camera)
|
||||
: window(window), shader(shader), camera(camera)/* , transparent_render_queue(CameraDistanceComparator(camera)) */ {}
|
||||
: window(window), shader(shader), camera(camera), logger(log::LoggerManager::create_logger("render")) {}
|
||||
|
||||
Renderer::Renderer(GLFWwindow *window, GLuint shader_program, std::shared_ptr<Camera> camera)
|
||||
: Renderer(window, gfx::Shader(shader_program), camera) {}
|
||||
|
@ -31,13 +31,13 @@ namespace simpleengine::gfx {
|
|||
void debug_message_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
|
||||
const GLchar *message, const void *userParam) {
|
||||
|
||||
fprintf(stderr, "%s type = 0x%x, severity = 0x%x, message = %s\n",
|
||||
(type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message);
|
||||
SE_ERROR("render", "{} type = 0x%x, severity = 0x%x, message = {}",
|
||||
(type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message);
|
||||
}
|
||||
|
||||
void Renderer::check_if_initialized() {
|
||||
if (!is_initialized) {
|
||||
std::cerr << "Renderer is not initialized!" << std::endl;
|
||||
logger.critical("Renderer not initialized!"); // TODO: Automatic initialization
|
||||
throw std::runtime_error("Renderer is not initialized!");
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ namespace simpleengine::gfx {
|
|||
|
||||
rendering_mesh->are_buffers_created = true;
|
||||
|
||||
std::cout << "Created render job buffers" << std::endl;
|
||||
logger.debug("Created render job buffers");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,11 +126,11 @@ namespace simpleengine::gfx {
|
|||
|
||||
this->is_initialized = true;
|
||||
|
||||
std::cout << "Base Renderer initialized" << std::endl;
|
||||
logger.debug("Base renderer initialized");
|
||||
}
|
||||
|
||||
void Renderer::destroy() {
|
||||
std::cout << "Destroying renderer..." << std::endl;
|
||||
logger.debug("Destroying renderer");
|
||||
|
||||
shader.delete_program();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "gfx/shader.h"
|
||||
#include "log/logger.h"
|
||||
|
||||
#include <glm/fwd.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
@ -40,7 +41,7 @@ namespace simpleengine::gfx {
|
|||
char log[512];
|
||||
glGetShaderInfoLog(shd.shader, 512, NULL, log);
|
||||
|
||||
std::cerr << "Failed to load shader from source:" << std::endl << log << std::endl;
|
||||
SE_CERROR("Failed to load shader from source:\n{}", log);
|
||||
throw ShaderException("Failed to compile shader!");
|
||||
}
|
||||
|
||||
|
@ -63,7 +64,7 @@ namespace simpleengine::gfx {
|
|||
std::ifstream fstream(shader_path, std::ios::in);
|
||||
|
||||
if (!fstream.is_open()) {
|
||||
std::cerr << "Failed to open shader file: " << shader_path << std::endl;
|
||||
SE_CERROR("Failed to open shader file: {}", shader_path);
|
||||
throw ShaderException("Failed to open shader file!");
|
||||
}
|
||||
|
||||
|
@ -91,7 +92,7 @@ namespace simpleengine::gfx {
|
|||
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
||||
|
||||
if (!success) {
|
||||
std::cerr << "Failed to link shader program!" << std::endl;
|
||||
SE_CERROR("Failed to link shader program!");
|
||||
throw ShaderException("Failed to link shader program!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "gfx/texture.h"
|
||||
#include "log/logger.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
|
@ -27,10 +29,11 @@ namespace simpleengine::gfx {
|
|||
unsigned char*img_data = stbi_load(path, &width, &height, &channels, 0);
|
||||
if(!img_data) {
|
||||
const char* failure = stbi_failure_reason();
|
||||
std::cerr << "Failed to load texture! (" << failure << ")" << std::endl;
|
||||
|
||||
SE_CERROR("Failed to load texture! Reason: {}", failure);
|
||||
throw std::runtime_error("Failed to load texture from memory!");
|
||||
}
|
||||
std::cout << "Loaded image with a width of " << width << "px, a height of " << height << "px and " << channels << " channels" << std::endl;
|
||||
SE_CDEBUG("Loading image! Width = {}px, height = {}px, channel count = {}", width, height, channels);
|
||||
|
||||
// Get the color type
|
||||
int color_format = 0;
|
||||
|
@ -41,7 +44,7 @@ namespace simpleengine::gfx {
|
|||
} else if (channels == 4) {
|
||||
color_format = GL_RGBA;
|
||||
} else {
|
||||
std::cerr << "Unknown texture color format with " << channels << " channels!" << std::endl;
|
||||
SE_CERROR("Unknown texture color format with {} channels!", channels);
|
||||
throw std::runtime_error("Unknown texture color format!");
|
||||
}
|
||||
|
||||
|
@ -79,10 +82,11 @@ namespace simpleengine::gfx {
|
|||
unsigned char* img_data = stbi_load_from_memory(buffer, buffer_length, &width, &height, &channels, 0);
|
||||
if(!img_data) {
|
||||
const char* failure = stbi_failure_reason();
|
||||
std::cerr << "Failed to load texture! (" << failure << ")" << std::endl;
|
||||
|
||||
SE_CERROR("Failed to load texture! Reason: ", failure);
|
||||
throw std::runtime_error("Failed to load texture from memory!");
|
||||
}
|
||||
std::cout << "Loaded image with a width of " << width << "px, a height of " << height << "px and " << channels << " channels" << std::endl;
|
||||
SE_CDEBUG("Loading image! Width = {}px, height = {}px, channel count = {}", width, height, channels);
|
||||
|
||||
// Get the color type
|
||||
int color_format = 0;
|
||||
|
@ -93,7 +97,7 @@ namespace simpleengine::gfx {
|
|||
} else if (channels == 4) {
|
||||
color_format = GL_RGBA;
|
||||
} else {
|
||||
std::cerr << "Unknown texture color format with " << channels << " channels!" << std::endl;
|
||||
SE_CERROR("Unknown texture color format with {} channels!", channels);
|
||||
throw std::runtime_error("Unknown texture color format!");
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace simpleengine::log {
|
||||
std::shared_ptr<Logger> LoggerManager::core_logger;
|
||||
|
||||
void LoggerManager::init() {
|
||||
spdlog::set_pattern("[%T %D] [thread %t] [%n] [%l] %v");
|
||||
|
||||
|
@ -16,8 +18,6 @@ namespace simpleengine::log {
|
|||
spdlog::set_level(lvl);
|
||||
}
|
||||
|
||||
std::shared_ptr<Logger> LoggerManager::core_logger;
|
||||
|
||||
std::shared_ptr<Logger> LoggerManager::get_core_logger() {
|
||||
return core_logger;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "ecs/component/rotating_component.h"
|
||||
#include "ecs/entity.h"
|
||||
#include "gfx/renderer.h"
|
||||
#include "log/logger.h"
|
||||
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <stdexcept>
|
||||
|
@ -60,7 +61,7 @@ namespace simpleengine {
|
|||
}
|
||||
|
||||
void Scene::destroy() {
|
||||
std::cout << "Destroying Scene..." << std::endl;
|
||||
SE_DEBUG("scene", "Destroying Scene...");
|
||||
registry.view<ModelComponent>().each([this](ModelComponent& model_component) {
|
||||
for (auto& mesh : model_component.model.meshes) {
|
||||
mesh.destroy();
|
||||
|
|
Loading…
Reference in New Issue