X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frender%2Ftext.cpp;h=a51d2cf16778a82bc3778c47203a618f39b5cc91;hp=b408bbe1780040cef29e600d2dab1b504b2d41b8;hb=HEAD;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266 diff --git a/source/render/text.cpp b/source/render/text.cpp index b408bbe1..a51d2cf1 100644 --- a/source/render/text.cpp +++ b/source/render/text.cpp @@ -1,4 +1,7 @@ #include "meshbuilder.h" +#include "program.h" +#include "renderer.h" +#include "technique.h" #include "text.h" #include "texture2d.h" @@ -7,28 +10,41 @@ using namespace std; namespace Msp { namespace GL { -Text::Text(const Font &f, const Technique *tech): +Text::Text(const Font &f, const Technique *tech, Tag tex_slot): + ObjectInstance(object), font(f), - mesh((TEXCOORD2, VERTEX2)), - horz_align(0.0f), - vert_offset(0.0f), - width(0.0f) + mesh((TEXCOORD2, VERTEX2)) { 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, Tag tex_slot) { if(tech) { - technique = *tech; - technique.replace_texture("diffuse_map", font.get_texture()); - object.set_technique(&technique); + if(!tex_slot.id && tech->has_method(Tag())) + if(const Program *shprog = tech->get_method(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"; + } + + 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) @@ -84,15 +100,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