31 lines
755 B
C++
31 lines
755 B
C++
//
|
|
// Created by Vicente Ferrari Smith on 14.02.26.
|
|
//
|
|
|
|
#include "texture.h"
|
|
#include <stb_image.h>
|
|
#include "renderer.h"
|
|
|
|
TextureManager::TextureManager() {
|
|
|
|
}
|
|
|
|
uint32_t TextureManager::load(const std::string& path, Renderer &renderer) {
|
|
// 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 = renderer.upload_texture(w, h, data);
|
|
|
|
stbi_image_free(data);
|
|
|
|
uint32_t id = static_cast<uint32_t>(textures.size());
|
|
textures[path] = res;
|
|
// path_to_id[path] = id;
|
|
|
|
return id; // This is the textureID for your sprites
|
|
}
|