88 stbi_set_flip_vertically_on_load(
true);
89 unsigned char* data = stbi_load_from_memory(buffer.data(),
static_cast<int>(buffer.size_bytes()), &
m_width, &
m_height,
nullptr, STBI_rgb_alpha);
98 glGenerateTextureMipmap(
m_id);
101 m_handle = glGetTextureSamplerHandleARB(
m_id, entt::locator<Sampler>::value().
id());
102 glMakeTextureHandleResidentARB(
m_handle);
110 stbi_image_free(data);
123 auto& fs = entt::locator<VirtualFileSystem>::value();
125 auto path = std::filesystem::path(file);
126 if (!path.is_absolute())
131 if (!path.has_extension())
133 path.replace_extension(
".png");
136 if (!std::filesystem::exists(path.parent_path()))
138 std::filesystem::create_directories(path.parent_path());
141 std::vector<unsigned int> pixels(
static_cast<unsigned int>(
m_width) *
static_cast<unsigned int>(
m_height) * 4u, 0);
143 glGetTextureImage(
m_id, 0, GL_RGBA, GL_UNSIGNED_BYTE,
static_cast<GLsizei
>(pixels.size()), pixels.data());
145 stbi_flip_vertically_on_write(
true);
149 unsigned char* png = stbi_write_png_to_mem((
const unsigned char*)pixels.data(),
m_width * 4,
m_width,
m_height, 4, &len);
151 if (!fs.write_raw(png, len, path.string()))
Bindless OpenGL 2D Texture.
void unbind() const noexcept
Unbind sampler.
Texture & operator=(Texture &&) noexcept
Move assignment operator.
bool load(const std::string &file)
Load a texture from vfs.
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 bind() const noexcept
Bind to sampler.
float height() const noexcept
Get texture height.
unsigned int id() const noexcept
Get OpenGL texture id.
TextureView get_view(const unsigned int minlevel, const unsigned int numlevels, const unsigned int minlayer, const unsigned int numlayers) const noexcept
Generate a texture view handle.
std::uint64_t handle() const noexcept
Get OpenGL bindless handle.
float width() const noexcept
Get texture width.