73 auto& config = core::ServiceLocator<core::Config>::ref();
75 stbi_set_flip_vertically_on_load(
true);
76 unsigned char* data = stbi_load_from_memory(buffer.data(),
static_cast<int>(buffer.size_bytes()), &
m_width, &
m_height,
nullptr, STBI_rgb_alpha);
82 glGenerateTextureMipmap(
m_id);
84 if (config.get<
int>(
"trilinear_filtering",
"graphics"))
94 anisotropy(config.get<
int>(
"ansiotrophic_filtering",
"graphics"));
103 stbi_image_free(data);
109 auto& fs = core::ServiceLocator<fs::VirtualFileSystem>::ref();
111 auto path = std::filesystem::path(file);
112 if (!path.is_absolute())
114 path = GALAXY_ROOT_DIR / path;
117 if (!path.has_extension())
119 path.replace_extension(
".png");
122 if (!std::filesystem::exists(path.parent_path()))
124 std::filesystem::create_directories(path.parent_path());
127 meta::vector<unsigned int> pixels(
static_cast<unsigned int>(
m_width) *
static_cast<unsigned int>(
m_height) * 4u, 0);
129 glGetTextureImage(
m_id, 0, GL_RGBA, GL_UNSIGNED_BYTE,
static_cast<GLsizei
>(pixels.size()), pixels.data());
131 stbi_flip_vertically_on_write(
true);
134 unsigned char* png = stbi_write_png_to_mem((
const unsigned char*)pixels.data(),
m_width * 4,
m_width,
m_height, 4, &len);
136 if (!fs.write_raw(png, len, path.string()))
bool load(const std::string &file)
Load a texture from vfs.
Texture2D & operator=(Texture2D &&)
Move assignment operator.
bool load_mem(std::span< std::uint8_t > buffer)
Loads texture from memory.
void save(std::string_view file)
Saves texture to file on disk.
void recreate()
Deletes texture data and configuration in OpenGL and creates new texture handle.
int anisotropy() const
Get current anisotropy level.
Texture & operator=(Texture &&)
Move assignment operator.
TextureFilter filter() const
Get texture filter.