|
|
@@ -22,45 +22,45 @@
|
|
|
unsigned char * stbi_load(char const *, int *, int *, int *, int);
|
|
|
void stbi_image_free(void *);
|
|
|
|
|
|
+using namespace graphics;
|
|
|
+
|
|
|
namespace {
|
|
|
- std::unordered_map<std::string, flyweight<graphics::texture>> g_textures;
|
|
|
+ std::unordered_map<std::string, flyweight<texture>> g_textures;
|
|
|
}
|
|
|
|
|
|
-namespace graphics {
|
|
|
- static textures::format format(int comps) {
|
|
|
- switch (comps) {
|
|
|
- case 3:
|
|
|
- return textures::format::RGB;
|
|
|
- case 4:
|
|
|
- return textures::format::RGBA;
|
|
|
- default:
|
|
|
- throw;
|
|
|
- }
|
|
|
+static textures::format format(int comps) {
|
|
|
+ switch (comps) {
|
|
|
+ case 3:
|
|
|
+ return textures::format::RGB;
|
|
|
+ case 4:
|
|
|
+ return textures::format::RGBA;
|
|
|
+ default:
|
|
|
+ throw;
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- flyweight<texture> texture::create(std::string const & imagefile) {
|
|
|
- auto found = g_textures.find(imagefile);
|
|
|
- if (found != g_textures.end()) { return found->second; }
|
|
|
+flyweight<texture> texture::create(std::string const & imagefile) {
|
|
|
+ auto found = g_textures.find(imagefile);
|
|
|
+ if (found != g_textures.end()) { return found->second; }
|
|
|
|
|
|
- int components = 0;
|
|
|
- math::vec2i size;
|
|
|
- unsigned char * data =
|
|
|
- stbi_load(imagefile.c_str(), &size.x(), &size.y(), &components, 0);
|
|
|
- scope(exit) { stbi_image_free(data); };
|
|
|
- texture tex{textures::init(format(components), size, data), size};
|
|
|
- return g_textures.emplace(imagefile, std::move(tex)).first->second;
|
|
|
- }
|
|
|
+ int components = 0;
|
|
|
+ math::vec2i size;
|
|
|
+ unsigned char * data =
|
|
|
+ stbi_load(imagefile.c_str(), &size.x(), &size.y(), &components, 0);
|
|
|
+ scope(exit) { stbi_image_free(data); };
|
|
|
+ texture tex{textures::init(format(components), size, data), size};
|
|
|
+ return g_textures.emplace(imagefile, std::move(tex)).first->second;
|
|
|
+}
|
|
|
|
|
|
- texture texture::create(char const * data, math::vec2i size) {
|
|
|
- return {textures::init(format(4), size, data), size};
|
|
|
- }
|
|
|
+texture texture::create(char const * data, math::vec2i size) {
|
|
|
+ return {textures::init(format(4), size, data), size};
|
|
|
+}
|
|
|
|
|
|
- texture::texture(unsigned int id, math::vec2i sz)
|
|
|
- : identity<texture>(id), size(sz) {}
|
|
|
+texture::texture(unsigned int id, math::vec2i sz)
|
|
|
+ : identity<texture>(id), size(sz) {}
|
|
|
|
|
|
- texture const texture::WHITE = texture::create("\xFF\xFF\xFF\xFF", {{1, 1}});
|
|
|
- texture const texture::DARK_YELLOW =
|
|
|
- texture::create("\x80\x80\x00\xFF", {{1, 1}});
|
|
|
- texture const texture::LIGHT_BLUE =
|
|
|
- texture::create("\x80\x80\xFF\xFF", {{1, 1}});
|
|
|
-}
|
|
|
+texture const texture::WHITE = texture::create("\xFF\xFF\xFF\xFF", {{1, 1}});
|
|
|
+texture const texture::DARK_YELLOW =
|
|
|
+ texture::create("\x80\x80\x00\xFF", {{1, 1}});
|
|
|
+texture const texture::LIGHT_BLUE =
|
|
|
+ texture::create("\x80\x80\xFF\xFF", {{1, 1}});
|