mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat: pbr (#20)
* feat: add pbr texture * feat(rendering): add normal mapping support for blocks * fix: normal map load * feat(scripts): add batch nearest neighbor upscale script
This commit is contained in:
@@ -118,16 +118,31 @@ std::string read_shader_source(const std::string& file_path) {
|
||||
return content;
|
||||
}
|
||||
|
||||
void delete_image_data(unsigned char* data) { SOIL_free_image_data(data); }
|
||||
void delete_image_data(unsigned char* data) {
|
||||
if (data == nullptr) {
|
||||
return;
|
||||
}
|
||||
SOIL_free_image_data(data);
|
||||
}
|
||||
|
||||
unsigned char* load_image_data(const std::string& tex_image_path) {
|
||||
unsigned char* load_image_data(const std::string& tex_image_path,
|
||||
bool check_exist) {
|
||||
fs::path path = ASSETS_PATH + tex_image_path;
|
||||
ASSERT_MSG(fs::is_regular_file(path), path.c_str());
|
||||
if (check_exist) {
|
||||
ASSERT_MSG(fs::is_regular_file(path), path.c_str());
|
||||
}
|
||||
unsigned char* data = nullptr;
|
||||
int width, height, channels;
|
||||
data = SOIL_load_image(path.string().c_str(), &width, &height, &channels,
|
||||
SOIL_LOAD_AUTO);
|
||||
ASSERT_MSG(data, "Could not load texture" + path.string());
|
||||
data =
|
||||
SOIL_load_image(path.string().c_str(), &width, &height, &channels,
|
||||
SOIL_LOAD_RGBA); // Materials are all RGBA; must force
|
||||
// RGBA, otherwise sampling will fail.
|
||||
if (check_exist) {
|
||||
if (!data) {
|
||||
ASSERT_MSG(data, "Could not load texture" + path.string());
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user