X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Ftext.cpp;h=b3d85deb899a5f837d9e0d64d8720c89925b14bc;hb=e92de029768eef5f0fd744329e589161b46d0762;hp=639beac142e1d66f85edfaa2bef2354074344f78;hpb=6dc5c41fe93ed0cb4f9051387b5551182bc5df41;p=libs%2Fgl.git diff --git a/source/render/text.cpp b/source/render/text.cpp index 639beac1..b3d85deb 100644 --- a/source/render/text.cpp +++ b/source/render/text.cpp @@ -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,35 +22,31 @@ 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("font_tex")>=0) + if(shprog->get_uniform_location(Tag("font_tex"))>=0) tex_slot = "font_tex"; - else if(shprog->get_uniform_location("color_tex")>=0) + else if(shprog->get_uniform_location(Tag("color_tex"))>=0) tex_slot = "color_tex"; - else if(shprog->get_uniform_location("diffuse_map")>=0) + else if(shprog->get_uniform_location(Tag("diffuse_map"))>=0) tex_slot = "diffuse_map"; - else if(shprog->get_uniform_location("base_color_map")>=0) + 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); + 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) @@ -104,15 +102,16 @@ void Text::set_alignment(float h, float v) unsigned n_vertices = mesh.get_n_vertices(); for(unsigned i=0; i(mesh.modify_vertex(i)+pos_offset); pos[0] += horz_adjust; pos[1] += vert_adjust; } } -void Text::render(Renderer &renderer, const 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