]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/text.cpp
Use Tag to identify uniforms in Program and ProgramData
[libs/gl.git] / source / render / text.cpp
index b408bbe1780040cef29e600d2dab1b504b2d41b8..3b2380c4200cf74cd1d4080ddd35b14d76042ca9 100644 (file)
@@ -1,4 +1,5 @@
 #include "meshbuilder.h"
+#include "program.h"
 #include "text.h"
 #include "texture2d.h"
 
@@ -7,7 +8,7 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-Text::Text(const Font &f, const Technique *tech):
+Text::Text(const Font &f, const Technique *tech, const string &tex_slot):
        font(f),
        mesh((TEXCOORD2, VERTEX2)),
        horz_align(0.0f),
@@ -16,16 +17,35 @@ Text::Text(const Font &f, const Technique *tech):
 {
        object.set_mesh(&mesh);
        if(tech)
-               set_technique(tech);
+               set_technique(tech, tex_slot);
 }
 
-void Text::set_technique(const Technique *tech)
+void Text::set_technique(const Technique *tech, const string &ts)
 {
        if(tech)
        {
-               technique = *tech;
-               technique.replace_texture("diffuse_map", font.get_texture());
-               object.set_technique(&technique);
+               const char *tex_slot = ts.c_str();
+               if(!*tex_slot && tech->has_pass(Tag()))
+                       if(const Program *shprog = tech->get_pass(Tag()).get_shader_program())
+                       {
+                               if(shprog->get_uniform_location(Tag("font_tex"))>=0)
+                                       tex_slot = "font_tex";
+                               else if(shprog->get_uniform_location(Tag("color_tex"))>=0)
+                                       tex_slot = "color_tex";
+                               else if(shprog->get_uniform_location(Tag("diffuse_map"))>=0)
+                                       tex_slot = "diffuse_map";
+                               else if(shprog->get_uniform_location(Tag("base_color_map"))>=0)
+                                       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);
        }
        else
                object.set_technique(0);
@@ -90,7 +110,7 @@ void Text::set_alignment(float h, float v)
        }
 }
 
-void Text::render(Renderer &renderer, const Tag &tag) const
+void Text::render(Renderer &renderer, Tag tag) const
 {
        object.render(renderer, tag);
 }