]> git.tdb.fi Git - libs/gl.git/commitdiff
Add debug name capability to more classes
authorMikko Rasa <tdb@tdb.fi>
Sun, 9 May 2021 12:31:32 +0000 (15:31 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 9 May 2021 12:31:32 +0000 (15:31 +0300)
24 files changed:
source/builders/sequencebuilder.cpp
source/builders/sequencebuilder.h
source/core/framebuffer.cpp
source/core/framebuffer.h
source/core/renderbuffer.cpp
source/core/renderbuffer.h
source/effects/ambientocclusion.cpp
source/effects/ambientocclusion.h
source/effects/bloom.cpp
source/effects/bloom.h
source/effects/colorcurve.cpp
source/effects/colorcurve.h
source/effects/effect.h
source/effects/environmentmap.cpp
source/effects/environmentmap.h
source/effects/postprocessor.h
source/effects/shadowmap.cpp
source/effects/shadowmap.h
source/effects/sky.cpp
source/effects/sky.h
source/render/rendertarget.cpp
source/render/rendertarget.h
source/render/sequence.cpp
source/render/sequence.h

index 317b68846126b3330a5e5592dfbc3deee01cf2af..6cf34c0ee1b38307654699c43969e78b082cb59f 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
+#include <msp/strings/format.h>
 #include "error.h"
 #include "renderbuffer.h"
 #include "sequence.h"
@@ -33,8 +34,22 @@ void SequenceBuilder::set_postprocessor(const string &name, PostProcessor &pproc
        get_item(postprocessors, name) = &pproc;
 }
 
+void SequenceBuilder::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       debug_name = name;
+#else
+       (void)name;
+#endif
+}
+
 void SequenceBuilder::build(Sequence &sequence) const
 {
+#ifdef DEBUG
+       if(!debug_name.empty())
+               sequence.set_debug_name(debug_name);
+#endif
+
        sequence.set_hdr(tmpl.get_hdr());
        sequence.set_alpha(tmpl.get_alpha());
        unsigned samples = min(tmpl.get_maximum_multisample(), Renderbuffer::get_max_samples());
@@ -68,7 +83,13 @@ void SequenceBuilder::build(Sequence &sequence) const
                {
                        proc = i->postprocessor_template->create(sequence.get_width(), sequence.get_height());
                        if(proc)
+                       {
+#ifdef DEBUG
+                               if(!debug_name.empty())
+                                       proc->set_debug_name(format("%s/%d.pproc", debug_name, i-postprocs.begin()));
+#endif
                                sequence.add_postprocessor_owned(proc);
+                       }
                }
        }
 }
index 739cc5edf4fd076e532aef5a4795caf06d0f50f5..d696dbf888df9f8c0cc8f800a21035a3a9739bb1 100644 (file)
@@ -20,6 +20,7 @@ private:
        const SequenceTemplate &tmpl;
        std::map<std::string, Renderable *> renderables;
        std::map<std::string, PostProcessor *> postprocessors;
+       std::string debug_name;
 
 public:
        SequenceBuilder(const SequenceTemplate &);
@@ -27,6 +28,8 @@ public:
        void set_renderable(const std::string &, Renderable &);
        void set_postprocessor(const std::string &, PostProcessor &);
 
+       void set_debug_name(const std::string &);
+
        void build(Sequence &) const;
        Sequence *build(unsigned, unsigned) const;
        Sequence *build(const View &) const;
index 810f0cf1c2675da6741648568408d221412d7c77..23b39f2d691c8de06aeaf378be10c25fe39db601 100644 (file)
@@ -5,6 +5,7 @@
 #include <msp/gl/extensions/ext_texture_array.h>
 #include <msp/gl/extensions/ext_texture3d.h>
 #include <msp/gl/extensions/msp_buffer_control.h>
+#include <msp/gl/extensions/khr_debug.h>
 #include "error.h"
 #include "framebuffer.h"
 #include "misc.h"
@@ -393,6 +394,16 @@ void Framebuffer::unbind()
        system().bind();
 }
 
+void Framebuffer::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       if(KHR_debug)
+               glObjectLabel(GL_FRAMEBUFFER, id, name.size(), name.c_str());
+#else
+       (void)name;
+#endif
+}
+
 Framebuffer &Framebuffer::system()
 {
        static Framebuffer sys_framebuf(0);
index 88ab465aaea52a8fb68f5fa7a774f43923443589..ca97ed17e45d021f9b9b779aa7579754640949ef 100644 (file)
@@ -164,6 +164,8 @@ public:
        static const Framebuffer *current();
        static void unbind();
 
+       void set_debug_name(const std::string &);
+
        static Framebuffer &system();
 };
 
index e86a97a50b63393d3220c02dd96e9d0e5037b85c..9af18daec9f1082ccd54c6e432e33a77478e9ed7 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/gl/extensions/arb_direct_state_access.h>
 #include <msp/gl/extensions/ext_framebuffer_multisample.h>
 #include <msp/gl/extensions/ext_framebuffer_object.h>
+#include <msp/gl/extensions/khr_debug.h>
 #include "misc.h"
 #include "renderbuffer.h"
 
@@ -78,5 +79,15 @@ void Renderbuffer::unbind()
                glBindRenderbuffer(GL_RENDERBUFFER, 0);
 }
 
+void Renderbuffer::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       if(KHR_debug)
+               glObjectLabel(GL_RENDERBUFFER, id, name.size(), name.c_str());
+#else
+       (void)name;
+#endif
+}
+
 } // namespace GL
 } // namespace Msp
index afc6ed204298a7bbcfe02d6c95a87af83c6a1bba..aea230804173c570fda45c1c2f0f016d2231f850 100644 (file)
@@ -47,6 +47,8 @@ public:
        void bind() const;
 
        static void unbind();
+
+       void set_debug_name(const std::string &);
 };
 
 } // namespace GL
index c35e5771de1d76f3a7ea95e8ab9c2125f7156754..21271acf2555d8a7f6b474d9cf3657cc69dccdb9 100644 (file)
@@ -116,6 +116,16 @@ void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const
        quad.draw(renderer);
 }
 
+void AmbientOcclusion::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       occlude_target.set_debug_name(name+" [RT]");
+       shdata.set_debug_name(name+" [UBO]");
+#else
+       (void)name;
+#endif
+}
+
 
 AmbientOcclusion::Template::Template():
        n_samples(16),
index f186db3dcd073a9577d20d44d68c6bd6f9d8185f..0171d89e87ac2e781ba267f72d67e918ff3d29c1 100644 (file)
@@ -64,6 +64,8 @@ public:
        void set_darkness(float);
 
        virtual void render(Renderer &, const Texture2D &, const Texture2D &);
+
+       virtual void set_debug_name(const std::string &);
 };
 
 } // namespace GL
index af2057d908a03afa25075330ddbbfe0b2ef6f0d5..8612ec06e8e10d6ba871143bc58568336c7aa38e 100644 (file)
@@ -82,6 +82,19 @@ void Bloom::render(Renderer &renderer, const Texture2D &src, const Texture2D &)
        quad.draw(renderer);
 }
 
+void Bloom::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       for(unsigned i=0; i<2; ++i)
+               target[i]->set_debug_name(format("%s [RT:%d]", name, i));
+       common_shdata.set_debug_name(name+" [UBO:common]");
+       blur_shdata[0].set_debug_name(name+" [UBO:blur_x]");
+       blur_shdata[1].set_debug_name(name+" [UBO:blur_y]");
+#else
+       (void)name;
+#endif
+}
+
 
 Bloom::Template::Template():
        radius(2.0f),
index 7315075b1f68c43553ba1de7f103834ef4cc947c..b80388d6b6848b2af6023b8de17d165fb467a653 100644 (file)
@@ -62,6 +62,8 @@ public:
        void set_strength(float);
 
        virtual void render(Renderer &, const Texture2D &, const Texture2D &);
+
+       virtual void set_debug_name(const std::string &);
 };
 
 } // namespace GL
index d35b7928e52c5ff7212a8869d3a01802cbf5667a..697a0583de0c43df6fc37f7408823c4ec74f3388 100644 (file)
@@ -76,6 +76,16 @@ void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Te
        quad.draw(renderer);
 }
 
+void ColorCurve::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       shdata.set_debug_name(name+" [UBO]");
+       curve.set_debug_name(name+"/curve.tex1d");
+#else
+       (void)name;
+#endif
+}
+
 
 ColorCurve::Template::Template():
        exposure_adjust(0.0f),
index f274bf06bde57040e7ae1f489fa6793d3f6560ac..3ccfbf76b00d8c99493d63394ee2e59dad796fdc 100644 (file)
@@ -75,6 +75,8 @@ public:
        void set_linear();
 
        virtual void render(Renderer &, const Texture2D &, const Texture2D &);
+
+       virtual void set_debug_name(const std::string &);
 };
 
 } // namespace GL
index c43cda3a39303822361f23405b74bedf2dfbc635..a4f108fbcf9f739bcca08fc55b520fe0d5fab202 100644 (file)
@@ -34,6 +34,8 @@ public:
 
        virtual void setup_frame(Renderer &r) { renderable.setup_frame(r); }
        virtual void finish_frame() { renderable.finish_frame(); }
+
+       virtual void set_debug_name(const std::string &) = 0;
 };
 
 } // namespace GL
index a82731e1e218a1514d9a930a776a2ac08a6a90d1..e33295dabba94249c75f75812efd855dc0e00160 100644 (file)
@@ -191,5 +191,28 @@ void EnvironmentMap::render(Renderer &renderer, Tag tag) const
        renderer.render(renderable, tag);
 }
 
+void EnvironmentMap::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       env_tex.set_debug_name(name+"/environment.texcb");
+       depth_buf.set_debug_name(name+"/environment_depth.rbuf");
+       static const char *face_names[] = { "X+", "X-", "Y+", "Y-", "Z+", "Z-" };
+       for(unsigned i=0; i<6; ++i)
+       {
+               faces[i].fbo.set_debug_name(format("%s [FBO:%s]", name, face_names[i]));
+               faces[i].camera.set_debug_name(format("%s/%s.camera", name, face_names[i]));
+       }
+
+       irradiance.set_debug_name(name+"/irradiance.texcb");
+       irradiance_fbo.set_debug_name(name+" [FBO:irradiance]");
+       for(unsigned i=0; i<specular_fbos.size(); ++i)
+               specular_fbos[i].set_debug_name(format("%s [FBO:specular_mip%d]", name, i+1));
+       prefilter_shdata.set_debug_name(name+" [UBO:prefilter]");
+       shdata.set_debug_name(name+" [UBO]");
+#else
+       (void)name;
+#endif
+}
+
 } // namespace GL
 } // namespace Msp
index b671c91b10ee067d8de7e44b24fe2e5aa8d5a58b..4936d162781aac4087fcfdf26eb318abdac69ec5 100644 (file)
@@ -75,6 +75,8 @@ public:
        virtual void finish_frame();
 
        virtual void render(Renderer &, Tag = Tag()) const;
+
+       virtual void set_debug_name(const std::string &);
 };
 
 } // namespace GL
index aabace6c94159aa120a6e59e4352ce18f5f4f9cc..aba1b0e641ae2838a1e64d4a3d81ec834c55586d 100644 (file)
@@ -45,6 +45,8 @@ public:
        virtual void render(const Texture2D &, const Texture2D &) { }
 
        virtual void render(Renderer &, const Texture2D &, const Texture2D &);
+
+       virtual void set_debug_name(const std::string &) = 0;
 };
 
 } // namespace GL
index cd9ad8274c7f6f61a7ee1a68347c5b4c4201f757..a6d431bc200da86e025dcc2b640aa9d2a342d0e0 100644 (file)
@@ -122,5 +122,17 @@ void ShadowMap::render(Renderer &renderer, Tag tag) const
        renderer.render(renderable, tag);
 }
 
+void ShadowMap::set_debug_name(const std::string &name)
+{
+#ifdef DEBUG
+       fbo.set_debug_name(name+" [FBO]");
+       shadow_camera.set_debug_name(name+".camera");
+       depth_buf.set_debug_name(name+"/depth.tex2d");
+       shdata.set_debug_name(name+" [UBO]");
+#else
+       (void)name;
+#endif
+}
+
 } // namespace GL
 } // namespace Msp
index a3c3a8f2f6335fb63a460887d25055a4e8e32943..dc1ce548cb325bd233f39a600afacbcd4e0ccddd 100644 (file)
@@ -67,6 +67,8 @@ public:
        virtual void finish_frame();
 
        virtual void render(Renderer &, Tag = Tag()) const;
+
+       virtual void set_debug_name(const std::string &);
 };
 
 } // namespace GL
index 9a5f73bc73f8d1b6405c810935721b220b53804d..19fb526b1bdaa83b911954ef6f26b7c37c241c4b 100644 (file)
@@ -137,6 +137,17 @@ void Sky::render(Renderer &renderer, Tag tag) const
        fullscreen_mesh.draw(renderer);
 }
 
+void Sky::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       transmittance_lookup.set_debug_name(name+" [RT:transmittance]");
+       distant.set_debug_name(name+" [RT:distant]");
+       shdata.set_debug_name(name+" [UBO]");
+#else
+       (void)name;
+#endif
+}
+
 
 Sky::Planet::Planet():
        rayleigh_scatter(0.0f),
index 5f84c861689249bc0533d1772be61f2e401473b0..74580d7502a165fb1b8e1d48f8206c600ab7397d 100644 (file)
@@ -67,6 +67,8 @@ public:
        virtual void setup_frame(Renderer &);
        virtual void finish_frame();
        virtual void render(Renderer &, Tag = Tag()) const;
+
+       virtual void set_debug_name(const std::string &);
 };
 
 } // namespace GL
index 5c4cc20ffdcbd05c477eacde748fb2a8a3170c8a..7b603252b6e1c97f0b80ad953734147e6c8efcc2 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/core/maputils.h>
+#include <msp/strings/format.h>
 #include "error.h"
 #include "renderbuffer.h"
 #include "rendertarget.h"
@@ -202,5 +203,30 @@ void RenderTarget::blit_from(const RenderTarget &other)
        fbo.blit_from(other.fbo, COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT, false);
 }
 
+void RenderTarget::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       fbo.set_debug_name(name+" [FBO]");
+       unsigned i = 0;
+       for(const unsigned char *j=format.begin(); j!=format.end(); ++i, ++j)
+       {
+               unsigned type = get_output_type(*j);
+
+               string buf_name;
+               if(type>=get_output_type(RENDER_DEPTH))
+                       buf_name = name+"/depth";
+               else
+                       buf_name = Msp::format("%s/color%d", name, type);
+
+               if(samples)
+                       buffers[i].buffer->set_debug_name(buf_name+".tex2d");
+               else
+                       buffers[i].texture->set_debug_name(buf_name+".rbuf");
+       }
+#else
+       (void)name;
+#endif
+}
+
 } // namespace GL
 } // namespace Msp
index 7d796a3cefe80540a409f5e6b80a6535aefa87f0..cb6d6b97280d85c1ca2f252c6ed65b5ca2917377 100644 (file)
@@ -81,6 +81,8 @@ public:
        const Texture2D &get_target_texture(unsigned) const;
        const Texture2D &get_target_texture(RenderOutput) const;
        void blit_from(const RenderTarget &);
+
+       void set_debug_name(const std::string &);
 };
 
 } // namespace GL
index 06b1403bd827e934400a550cd29f2bcef919e64b..05cbafff08d66b406242da77228d83d0252d037b 100644 (file)
@@ -241,6 +241,33 @@ void Sequence::create_targets(unsigned recreate)
 
        if(!target_ms && samples)
                target_ms = new RenderTarget(width, height, samples, fmt);
+
+#ifdef DEBUG
+       if(!debug_name.empty())
+               set_target_debug_names();
+#endif
+}
+
+void Sequence::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       debug_name = name;
+       if(!name.empty())
+               set_target_debug_names();
+#else
+       (void)name;
+#endif
+}
+
+void Sequence::set_target_debug_names()
+{
+#ifdef DEBUG
+       for(unsigned i=0; i<2; ++i)
+               if(target[i])
+                       target[i]->set_debug_name(format("%s [RT:%d]", debug_name, i));
+       if(target_ms)
+               target_ms->set_debug_name(debug_name+" [RT:ms]");
+#endif
 }
 
 
index 8a480add82050cf2575ecc451908b175f3f3ed82..b1d2c7cabc54f81eea9d0a1ac2abcaf6bf4f2b69 100644 (file)
@@ -84,6 +84,7 @@ private:
        unsigned samples;
        RenderTarget *target[2];
        RenderTarget *target_ms;
+       std::string debug_name;
 
 public:
        Sequence(unsigned, unsigned, bool = false);
@@ -134,6 +135,11 @@ public:
 
 private:
        void create_targets(unsigned);
+
+public:
+       void set_debug_name(const std::string &);
+private:
+       void set_target_debug_names();
 };
 
 } // namespace GL