X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Ftexture.cpp;h=967a7fe31562d8509619b3bef3d060c3bd75d714;hb=d40673bd28c4b4524d3642b949d9d109dc6f9f24;hp=f6594ab14c7e5143434ac0823c862427c70f2c9d;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266;p=libs%2Fgl.git diff --git a/source/core/texture.cpp b/source/core/texture.cpp index f6594ab1..967a7fe3 100644 --- a/source/core/texture.cpp +++ b/source/core/texture.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "bindable.h" #include "error.h" @@ -34,10 +35,8 @@ Texture::Texture(GLenum t, ResourceManager *m): { if(m) set_manager(m); - else if(ARB_direct_state_access) - glCreateTextures(target, 1, &id); else - glGenTextures(1, &id); + generate_id(); } Texture::~Texture() @@ -49,6 +48,21 @@ Texture::~Texture() glDeleteTextures(1, &id); } +void Texture::generate_id() +{ + if(id) + throw invalid_operation("Texture::generate_id"); + if(ARB_direct_state_access) + glCreateTextures(target, 1, &id); + else + glGenTextures(1, &id); + +#ifdef DEBUG + if(!debug_name.empty() && KHR_debug) + glObjectLabel(GL_TEXTURE, id, debug_name.size(), debug_name.c_str()); +#endif +} + void Texture::set_format(PixelFormat fmt) { PixelComponents comp = get_components(fmt); @@ -75,7 +89,7 @@ void Texture::set_format(PixelFormat fmt) default:; } - PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt)); + PixelFormat st_fmt = make_pixelformat(st_comp, get_component_type(fmt), is_srgb(fmt)); require_pixelformat(st_fmt); if(swiz!=NO_SWIZZLE) static Require _req(ARB_texture_swizzle); @@ -269,6 +283,17 @@ void Texture::unbind_from(unsigned i) } } +void Texture::set_debug_name(const string &name) +{ +#ifdef DEBUG + debug_name = name; + if(id && KHR_debug) + glObjectLabel(GL_TEXTURE, id, name.size(), name.c_str()); +#else + (void)name; +#endif +} + Texture::Loader::Loader(Texture &t): DataFile::CollectionObjectLoader(t, 0) @@ -287,7 +312,7 @@ void Texture::Loader::init() levels = 0; add("external_image", &Loader::external_image); - add("external_image_srgb", &Loader::external_image); + add("external_image_srgb", &Loader::external_image_srgb); add("filter", &Loader::filter); add("generate_mipmap", &Loader::generate_mipmap); add("image_data", &Loader::image_data); @@ -309,7 +334,7 @@ unsigned Texture::Loader::get_levels() const #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" -void Texture::Loader::load_external_image(Graphics::Image &img, const std::string &fn) +void Texture::Loader::load_external_image(Graphics::Image &img, const string &fn) { RefPtr io = get_collection().open_raw(fn); if(!io) @@ -353,6 +378,13 @@ void Texture::Loader::generate_mipmap(bool gm) void Texture::Loader::image_data(const string &data) { + if(obj.manager) + { + obj.set_manager(0); + if(!obj.id) + obj.generate_id(); + } + Graphics::Image img; IO::Memory mem(data.data(), data.size()); img.load_io(mem);