Loading...
Searching...
No Matches
SkyboxRenderer.cpp
Go to the documentation of this file.
1//
2// Created by denzel on 14/06/2025.
3//
4
5#include "hellfire/graphics/renderer/SkyboxRenderer.h"
6
7#include <glm/gtc/type_ptr.hpp>
8
9#include "../core/Application.h"
10#include <GL/glew.h>
11
12#include "Mesh.h"
13#include "Skybox.h"
14#include "Geometry/Cube.h"
15#include "hellfire/utilities/ServiceLocator.h"
16
17namespace hellfire {
19 if (!initialized_) {
22 }
23 }
24
26 skybox_mesh_ = Cube::create_mesh();
27 }
28
30 skybox_shader_id_ = ServiceLocator::get_service<ShaderManager>()->load_shader_from_files(
31 "assets/shaders/skybox.vert", "assets/shaders/skybox.frag");
33 }
34
35 void SkyboxRenderer::render(const Skybox &skybox, const CameraComponent *camera) const {
36 if (!skybox.is_loaded() || !skybox_shader_.is_valid()) return;
37
38 // Save current depth state
39 glDepthFunc(GL_LEQUAL);
41
42 // Remove translation from view matrix
43 glm::mat4 view = glm::mat4(glm::mat3(camera->get_view_matrix()));
44 glm::mat4 projection = camera->get_projection_matrix();
45
46 skybox_shader_.set_mat4("view", view);
47 skybox_shader_.set_mat4("projection", projection);
48
49 // Set tint and exposure
50 skybox_shader_.set_vec3("tint", skybox.get_tint());
52
53 // Bind cubemap
54 glActiveTexture(GL_TEXTURE0);
55 glBindTexture(GL_TEXTURE_CUBE_MAP, skybox.get_cubemap());
56 skybox_shader_.set_int("skyboxes", 0);
57
58 // Draw skyboxes cube
59 skybox_mesh_->bind();
60 skybox_mesh_->draw();
61 skybox_mesh_->unbind();
62
63 // Restore depth state
64 glDepthFunc(GL_LESS);
65 }
66}
static Shader from_id(const uint32_t shader_id)
Definition Shader.h:34
bool is_valid() const
Definition Shader.h:46
void use() const
Definition Shader.h:39
Shader & operator=(Shader &&other) noexcept
Definition Shader.h:26
void set_float(const std::string &name, const float value) const
Definition Shader.h:61
void set_int(const std::string &name, const int value) const
Definition Shader.h:53
void set_vec3(const std::string &name, const float x, const float y, const float z) const
Definition Shader.h:78
void render(const Skybox &skybox, const CameraComponent *camera) const
bool is_loaded() const
Definition Skybox.h:31
float get_exposure() const
Definition Skybox.h:29