-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture_loader.cpp
More file actions
53 lines (41 loc) · 2 KB
/
texture_loader.cpp
File metadata and controls
53 lines (41 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <stb_image.h>
#include "texture_loader.hpp"
#include <spdlog/spdlog.h>
#include "sbpt_generated_includes.hpp"
void default_texture_callback(int width, int height, int num_components, char *data) {};
// Function to load texture from file and return TextureData
TextureData load_texture_from_file(const std::string &filepath, bool gamma) {
int width, height, num_components;
unsigned char *data = stbi_load(filepath.c_str(), &width, &height, &num_components, 0);
/*if (!data) {*/
/* spdlog::get(Systems::asset_loading)*/
/* ->error("Unable to load image: {} with error: {}", filepath, stbi_failure_reason());*/
/* throw std::runtime_error("Failed to load image data");*/
/*}*/
/**/
/*spdlog::get(Systems::asset_loading)*/
/* ->info("Loaded file: {} with width: {}, height: {}, and {} components", filepath, width, height,*/
/* num_components);*/
// Copy the image data into a std::vector
std::vector<unsigned char> image_data(data, data + (width * height * num_components));
// Free the dynamically allocated image data
stbi_image_free(data);
// Return the texture data encapsulated in a struct
return {width, height, num_components, std::move(image_data)};
}
void load_texture_from_file_with_callback(const std::string &filepath, bool gamma, TextureCallback texture_callback) {
int width, height, num_components;
unsigned char *data = stbi_load(filepath.c_str(), &width, &height, &num_components, 0);
if (!data) {
/*spdlog::get(Systems::asset_loading)*/
/* ->error("unable to load image: {} with error: {}", filepath, stbi_failure_reason());*/
/*// throw;*/
} else {
/*spdlog::get(Systems::asset_loading)*/
/* ->info("loading file: {} with width: {}, height: {}, and has {} components", filepath, width, height,*/
/* num_components);*/
texture_callback(width, height, num_components, data);
}
stbi_image_free(data);
}