117 auto& fs = core::ServiceLocator<fs::VirtualFileSystem>::ref();
118 auto& config = core::ServiceLocator<core::Config>::ref();
120 auto buffer = fs.read_binary(file);
123 stbi_set_flip_vertically_on_load(
true);
124 unsigned char* data = stbi_load_from_memory(buffer.data(),
static_cast<int>(buffer.size() *
sizeof(std::uint8_t)), &
m_width, &
m_height,
nullptr, STBI_rgb_alpha);
128 const auto tiles_x =
m_width / tile_size;
129 const auto tiles_y =
m_height / tile_size;
130 const auto tile_count = tiles_x * tiles_y;
132 glTextureStorage3D(
m_id, 1, GL_RGBA8, tile_size, tile_size, tile_count);
134 unsigned int tilesheet = 0;
135 glCreateTextures(GL_TEXTURE_2D, 1, &tilesheet);
137 glTextureSubImage2D(tilesheet, 0, 0, 0,
m_width,
m_height, GL_RGBA, GL_UNSIGNED_BYTE, data);
139 for (
auto i = 0; i < tile_count; ++i)
141 const auto x = (i % tiles_x) * tile_size;
142 const auto y = (i / tiles_x) * tile_size;
144 glCopyImageSubData(tilesheet, GL_TEXTURE_2D, 0, x, y, 0,
m_id, GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, tile_size, tile_size, 1);
147 glDeleteTextures(1, &tilesheet);
148 glGenerateTextureMipmap(
m_id);
150 if (config.get<
int>(
"trilinear_filtering",
"graphics"))
160 anisotropy(config.get<
int>(
"ansiotrophic_filtering",
"graphics"));
168 stbi_image_free(data);
bool add(const std::string &file)
Add a texture to the texture array.
meta::vector< unsigned char * > m_data
Data from adding a file to the texture array. Not kept after building.
void build(const int width, const int height)
Creates the array texture.
TextureArray & operator=(TextureArray &&)
Move assignment operator.
bool build_from_tileset(const std::string &file, const int tile_size)
Creates an array texture from a tileset.
int anisotropy() const
Get current anisotropy level.
Texture & operator=(Texture &&)
Move assignment operator.
TextureFilter filter() const
Get texture filter.