]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texture.cpp
Set OpenGL debug labels on various objects loaded from Resources
[libs/gl.git] / source / core / texture.cpp
index 3eb48b8b2eb426dafebd1791ab11d4fba09b4c63..967a7fe31562d8509619b3bef3d060c3bd75d714 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/gl/extensions/arb_direct_state_access.h>
 #include <msp/gl/extensions/arb_texture_swizzle.h>
 #include <msp/gl/extensions/ext_framebuffer_object.h>
+#include <msp/gl/extensions/khr_debug.h>
 #include <msp/io/memory.h>
 #include "bindable.h"
 #include "error.h"
@@ -55,6 +56,11 @@ void Texture::generate_id()
                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)
@@ -277,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<Texture>(t, 0)
@@ -361,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);