]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/text.cpp
Redesign Text as an ObjectInstance
[libs/gl.git] / source / render / text.cpp
index 3b2380c4200cf74cd1d4080ddd35b14d76042ca9..b43061c522a5addbbf2ff474742efd97fb78fbef 100644 (file)
@@ -1,5 +1,6 @@
 #include "meshbuilder.h"
 #include "program.h"
+#include "renderer.h"
 #include "text.h"
 #include "texture2d.h"
 
@@ -8,7 +9,8 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-Text::Text(const Font &f, const Technique *tech, const string &tex_slot):
+Text::Text(const Font &f, const Technique *tech, Tag tex_slot):
+       ObjectInstance(object),
        font(f),
        mesh((TEXCOORD2, VERTEX2)),
        horz_align(0.0f),
@@ -20,12 +22,11 @@ Text::Text(const Font &f, const Technique *tech, const string &tex_slot):
                set_technique(tech, tex_slot);
 }
 
-void Text::set_technique(const Technique *tech, const string &ts)
+void Text::set_technique(const Technique *tech, Tag tex_slot)
 {
        if(tech)
        {
-               const char *tex_slot = ts.c_str();
-               if(!*tex_slot && tech->has_pass(Tag()))
+               if(!tex_slot.id && tech->has_pass(Tag()))
                        if(const Program *shprog = tech->get_pass(Tag()).get_shader_program())
                        {
                                if(shprog->get_uniform_location(Tag("font_tex"))>=0)
@@ -38,17 +39,14 @@ void Text::set_technique(const Technique *tech, const string &ts)
                                        tex_slot = "base_color_map";
                        }
 
-               if(tex_slot)
-               {
-                       technique = *tech;
-                       technique.replace_texture(tex_slot, font.get_texture());
-                       object.set_technique(&technique);
-               }
-               else
-                       object.set_technique(tech);
+               object.set_technique(tech);
+               texture_slot = tex_slot;
        }
        else
+       {
                object.set_technique(0);
+               texture_slot = Tag();
+       }
 }
 
 void Text::set_text(const string &text, StringCodec::Decoder &dec)
@@ -110,9 +108,10 @@ void Text::set_alignment(float h, float v)
        }
 }
 
-void Text::render(Renderer &renderer, Tag tag) const
+void Text::setup_render(Renderer &renderer, Tag tag) const
 {
-       object.render(renderer, tag);
+       ObjectInstance::setup_render(renderer, tag);
+       renderer.set_texture(texture_slot, &font.get_texture());
 }
 
 } // namespace GL