Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
builder.h
Go to the documentation of this file.
1 
18 #ifndef ION_TEXT_BUILDER_H_
19 #define ION_TEXT_BUILDER_H_
20 
21 #include <string>
22 
23 #include "ion/base/referent.h"
25 #include "ion/gfx/attributearray.h"
26 #include "ion/gfx/bufferobject.h"
27 #include "ion/gfx/node.h"
28 #include "ion/gfx/sampler.h"
31 #include "ion/math/vector.h"
32 #include "ion/text/font.h"
33 #include "ion/text/fontimage.h"
34 
35 namespace ion {
36 namespace gfx {
37 class Shape;
38 }
39 
40 namespace text {
41 class Layout;
42 
45 class ION_API Builder : public base::Referent {
46  public:
48  const FontImagePtr& GetFontImage() const { return font_image_; }
49 
52  void SetFontImage(const FontImagePtr& font_image) {
53  font_image_ = font_image;
54  }
55 
57  const FontPtr GetFont() const {
58  return font_image_.Get() ? font_image_->GetFont() : FontPtr();
59  }
60 
73  bool Build(const Layout& layout, gfx::BufferObject::UsageMode usage_mode);
74 
76  const gfx::NodePtr& GetNode() const { return node_; }
77 
79  math::Range3f GetExtents() const { return text_extents_; }
80 
81  protected:
87  Builder(const FontImagePtr& font_image,
88  const gfxutils::ShaderManagerPtr& shader_manager,
89  const base::AllocatorPtr& allocator);
90 
93  ~Builder() override;
94 
98 
100 
102 
104  virtual const gfx::ShaderInputRegistryPtr GetShaderInputRegistry() = 0;
105 
107  virtual void GetShaderStrings(std::string* id_string,
108  std::string* vertex_source,
109  std::string* fragment_source) = 0;
110 
113  virtual void UpdateUniforms(const gfx::ShaderInputRegistryPtr& registry,
114  gfx::Node* node) = 0;
115 
117  virtual void BindAttributes(const gfx::AttributeArrayPtr& attr_array,
118  const gfx::BufferObjectPtr& buffer_object) = 0;
119 
122  virtual base::AllocVector<char> BuildVertexData(const Layout& layout,
123  size_t* vertex_size,
124  size_t* num_vertices) = 0;
125 
127 
129 
134  const FontImage::ImageData* GetImageData() const { return image_data_; }
135 
138  const gfx::TexturePtr GetFontImageTexture();
139 
143  bool UpdateFontImageTextureUniform(size_t index, gfx::Node* node);
144 
147  void StoreGlyphVertices(const Layout& layout, size_t glyph_index,
148  math::Point3f positions[4],
149  math::Point2f texture_coords[4]);
150 
151  private:
154  const gfx::ShaderProgramPtr BuildShaderProgram();
155 
160  bool UpdateAttributeArray(
161  const Layout& layout, gfx::BufferObject::UsageMode usage_mode,
162  const gfx::AttributeArrayPtr& attr_array);
163 
165  void UpdateShape(const Layout& layout,
166  gfx::BufferObject::UsageMode usage_mode, gfx::Shape* shape);
167 
170  FontImagePtr font_image_;
172  gfxutils::ShaderManagerPtr shader_manager_;
176  gfx::NodePtr node_;
180  gfx::ShaderInputRegistryPtr registry_;
182  gfx::SamplerPtr sampler_;
184  math::Range3f text_extents_;
187  const FontImage::ImageData* image_data_;
188 };
189 
192 
193 } // namespace text
194 } // namespace ion
195 
196 #endif // ION_TEXT_BUILDER_H_
base::AllocatorPtr allocator_
The Allocator for the FreeTypeManager and all its Fonts.
const FontPtr GetFont() const
Returns the Font from the FontImage. This may be a NULL pointer.
Definition: builder.h:57
std::string text
Point2f texture_coords
Definition: shapeutils.cc:74
const base::AllocatorPtr & GetAllocator()
Returns the Allocator passed to the constructor.
Definition: builder.h:97
base::ReferentPtr< Builder >::Type BuilderPtr
Convenience typedef for shared pointer to a Builder.
Definition: builder.h:191
Thread-safe abstract base class.
Definition: referent.h:49
const FontImage::ImageData * GetImageData() const
Convenience functions for derived classes.
Definition: builder.h:134
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
Definition: sharedptr.h:89
Range< 3, float > Range3f
Definition: range.h:381
base::ReferentPtr< Font >::Type FontPtr
Definition: font.h:38
A Shape object represents a shape (vertices + indices) to draw.
Definition: shape.h:32
const gfx::NodePtr & GetNode() const
Returns the Node set up by the last successful call to Build().
Definition: builder.h:76
A Layout instance specifies how glyphs are arranged to form text.
Definition: layout.h:127
math::Range3f GetExtents() const
Returns the canonical 3D extents of the last generated geometry.
Definition: builder.h:79
Builder is an abstract base class for building graphics objects used to render text.
Definition: builder.h:45
A Node instance represents a node in a scene graph.
Definition: node.h:45
Data for each image in the FontImage.
Definition: fontimage.h:71
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60
void SetFontImage(const FontImagePtr &font_image)
Modifies the Builder to use a different FontImage in subsequent calls to Build(). ...
Definition: builder.h:52
This class can be used in place of std::vector to allow an Ion Allocator to be used for memory alloca...
Definition: allocvector.h:50
const FontImagePtr & GetFontImage() const
Returns the FontImage passed to the constructor.
Definition: builder.h:48