38 lines
815 B
C++
38 lines
815 B
C++
//
|
|
// Created by Vicente Ferrari Smith on 01.03.26.
|
|
//
|
|
|
|
#include "texture.h"
|
|
#include "graphics.h"
|
|
|
|
TextureManager::TextureManager() {
|
|
|
|
}
|
|
|
|
Texture TextureManager::load(const std::string& path) {
|
|
// Dedup: Don't load the same file twice!
|
|
// if (path_to_id.contains(path)) return path_to_id[path];
|
|
|
|
int w, h, ch;
|
|
unsigned char* data = stbi_load(path.c_str(), &w, &h, &ch, STBI_rgb_alpha);
|
|
|
|
// Tell the renderer to make the GPU version
|
|
Texture res;
|
|
res.width = w;
|
|
res.height = h;
|
|
res.channels = STBI_rgb_alpha;
|
|
res.srgb = true;
|
|
upload_texture(w, h, data, &res);
|
|
|
|
stbi_image_free(data);
|
|
|
|
res.id = path;
|
|
res.path = path;
|
|
res.uploaded = true;
|
|
|
|
textures[path] = res;
|
|
// path_to_id[path] = id;
|
|
|
|
return res; // This is the textureID for your sprites
|
|
}
|