#include "meshbuilder.h"
#include "program.h"
+#include "renderer.h"
#include "text.h"
#include "texture2d.h"
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),
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)
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)
}
}
-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
#include "font.h"
#include "mesh.h"
#include "object.h"
+#include "objectinstance.h"
#include "technique.h"
namespace Msp {
namespace GL {
/**
-Creates an object consisting of the visual representation of a string. Can be
-used with an ObjectInstance to further customize the appearance.
+Creates an object consisting of the visual representation of a string. If you
+derive from Text to customize it, make sure you call Text::setup_render or
+otherwise bind the appropriate texture.
*/
-class Text: public Renderable
+class Text: public ObjectInstance
{
public:
enum HorizontalAlign
const Font &font;
Mesh mesh;
Object object;
- Technique technique;
+ Tag texture_slot;
float horz_align;
float vert_offset;
float width;
public:
- Text(const Font &, const Technique * = 0, const std::string & = std::string());
+ Text(const Font &, const Technique * = 0, Tag = Tag());
const Mesh *get_mesh() const { return &mesh; }
/** Sets technique to render with, replacing the given texture slot with
the font texture. If no texture slot is specified, heuristics are used to
choose a suitable one. */
- void set_technique(const Technique *, const std::string & = std::string());
+ void set_technique(const Technique *, Tag = Tag());
const Technique *get_technique() const { return object.get_technique(); }
float get_width() const { return width; }
- virtual void render(Renderer &, Tag = Tag()) const;
+ virtual void setup_render(Renderer &, Tag) const;
- operator const Object &() const { return object; }
+ DEPRECATED operator const Object &() const { return object; }
};
} // namespace GL