Brenta Engine 1.2
Loading...
Searching...
No Matches
cubemap.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <brenta/renderer/opengl/texture.hpp>
9#include <brenta/logger.hpp>
10
11#include <stb_image.h>
12
13namespace brenta
14{
15
16class Cubemap : public Texture
17{
18public:
19
20 Cubemap(const tenno::vector<std::filesystem::path>& faces)
21 : Texture(Cubemap::default_config)
22 {
23 glGenTextures(1, &this->id);
24 glBindTexture(GL_TEXTURE_CUBE_MAP, this->id);
25
26 stbi_set_flip_vertically_on_load(Cubemap::default_config.properties.flipped);
27 int width, height, nrChannels;
28 for (unsigned int i = 0; i < faces.size(); ++i)
29 {
30 unsigned char *data = stbi_load(faces[i].string().c_str(),
31 &width,
32 &height,
33 &nrChannels,
34 0);
35 if (!data)
36 {
37 ERROR("Error loading cubemap face {}", faces[i].string());
38 stbi_image_free(data);
39 continue;
40 }
41
42 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
43 0, GL_RGB, width, height, 0, GL_RGB,
44 GL_UNSIGNED_BYTE, data);
45 stbi_image_free(data);
46
47 this->memory += 3 * width * height;
48 Texture::memory += this->memory;
49
50 }
51 }
52
53private:
54
55 static const Texture::Config default_config;
56
57};
58
59} // namespace brenta