37 auto& fs = core::ServiceLocator<fs::VirtualFileSystem>::ref();
38 auto data = fs.read_binary(file);
42 texture.load_mem(data);
44 const auto path = std::filesystem::path(file);
45 const auto name = path.filename().string();
47 if (!
m_data.contains(name))
51 std::optional<math::iRect> packed = std::nullopt;
52 for (
auto i = 0; i <
m_sheets.size(); i++)
56 m_sheets[i] = std::make_unique<Sheet>();
61 packed =
m_sheets[i]->m_packer.pack(texture.get_width(), texture.get_height());
62 if (packed.has_value())
69 if (packed.has_value())
72 auto& renderer = core::ServiceLocator<graphics::Renderer>::ref();
74 m_data[name].m_handle = sheet->m_render_texture.get_texture();
75 m_data[name].m_region = packed.value();
78 const auto sw = sheet->m_render_texture.get_width();
79 const auto sh = sheet->m_render_texture.get_height();
81 m_data[name].m_sheet_width = sw;
82 m_data[name].m_sheet_height = sh;
100 std::array<graphics::Vertex, 4>
vertices;
102 vertices[0].m_texels = {0.0f, 0.0f};
105 vertices[1].m_texels = {1.0f, 0.0f};
108 vertices[2].m_texels = {1.0f, 1.0f};
111 vertices[3].m_texels = {0.0f, 1.0f};
115 sheet->m_render_texture.bind(
false);
116 renderer.draw_texture_to_target(sheet->m_render_texture, texture,
m_vao,
m_transform);
117 glBindFramebuffer(GL_FRAMEBUFFER, 0);
126 GALAXY_LOG(GALAXY_WARNING,
"Attempted to add duplicate texture to texture atlas.");
129 glBindTexture(GL_TEXTURE_2D, 0);
130 glBindFramebuffer(GL_FRAMEBUFFER, 0);
200 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &
m_max_bindings);
201 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &
m_size);
203 auto& config = core::ServiceLocator<core::Config>::ref();
204 auto user_size = config.get<
int>(
"texture_atlas_size",
"graphics");
221 auto vertices = graphics::Vertex::gen_quad_vertices(1, 1);
222 m_vao.create(
vertices, graphics::StorageFlag::DYNAMIC_DRAW, graphics::Vertex::get_default_indices(), graphics::StorageFlag::STATIC_DRAW);