X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Ftexture.cpp;h=967a7fe31562d8509619b3bef3d060c3bd75d714;hb=2d3113a7dbbe4be2f1d1e8980c1c4e42175163da;hp=3a4b1096f99cb2edee54137194f64cb3b805b808;hpb=baf53e7a2db1c27376a04b088b6954eeee81f009;p=libs%2Fgl.git diff --git a/source/core/texture.cpp b/source/core/texture.cpp index 3a4b1096..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); @@ -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) @@ -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);