Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::text::OutlineBuilder Class Reference

OutlineBuilder is a derived Builder class that can render text with outlines. More...

#include "outlinebuilder.h"

Inheritance diagram for ion::text::OutlineBuilder:
Collaboration diagram for ion::text::OutlineBuilder:

Public Member Functions

 OutlineBuilder (const FontImagePtr &font_image, const gfxutils::ShaderManagerPtr &shader_manager, const base::AllocatorPtr &allocator)
 OutlineBuilder functions. More...
 
bool SetSdfPadding (float padding)
 These convenience functions can be used to modify uniform values in the built Node returned by GetNode(). More...
 
bool SetTextColor (const math::VectorBase4f &color)
 
bool SetOutlineColor (const math::VectorBase4f &color)
 
bool SetOutlineWidth (float width)
 
bool SetHalfSmoothWidth (float width)
 
const FontImagePtrGetFontImage () const
 Returns the FontImage passed to the constructor. More...
 
void SetFontImage (const FontImagePtr &font_image)
 Modifies the Builder to use a different FontImage in subsequent calls to Build(). More...
 
const FontPtr GetFont () const
 Returns the Font from the FontImage. This may be a NULL pointer. More...
 
bool Build (const Layout &layout, gfx::BufferObject::UsageMode usage_mode)
 Builds an Ion Node representing the text string defined by a Layout, using the FontImage passed to the constructor. More...
 
const gfx::NodePtrGetNode () const
 Returns the Node set up by the last successful call to Build(). More...
 
math::Range3f GetExtents () const
 Returns the canonical 3D extents of the last generated geometry. More...
 
const AllocatorPtr & GetAllocator () const
 Returns the Allocator that was used for the instance. More...
 
const AllocatorPtr & GetNonNullAllocator () const
 Return our allocator, or the default allocator if the instance was declared on the stack. More...
 
const AllocatorPtr & GetAllocatorForLifetime (AllocationLifetime lifetime) const
 Convenience function that returns the Allocator to use to allocate an object with a specific lifetime. More...
 
void * operator new (size_t size)
 The standard no-parameter new operator uses the default Allocator. More...
 
void * operator new (size_t size, AllocationLifetime lifetime)
 This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime. More...
 
void * operator new (size_t size, const AllocatorPtr &allocator)
 This overloaded version of the new operator takes the Allocator to use directly as a parameter. More...
 
void * operator new (size_t size, const AllocatorPtr &allocator, void *ptr)
 Special operator new for using placement new with Allocatables. More...
 
void * operator new (size_t size, void *ptr)
 The placement new operator is defined conventionally. More...
 
void operator delete (void *ptr)
 Define the delete operator to use specialized functions dealing with an Allocator. More...
 
void operator delete (void *ptr, AllocationLifetime lifetime)
 Windows requires these (or it issues C4291 warnings). More...
 
void operator delete (void *ptr, const AllocatorPtr &allocator)
 
void operator delete (void *ptr, void *ptr2)
 The placement delete operator does nothing, as usual. More...
 
int GetRefCount () const
 GetRefCount() is part of the interface necessary for SharedPtr. More...
 

Protected Member Functions

 ~OutlineBuilder () override
 The destructor is protected because all base::Referent classes must have protected or private destructors. More...
 
const gfx::ShaderInputRegistryPtr GetShaderInputRegistry () override
 Required Builder functions. More...
 
void GetShaderStrings (std::string *id_string, std::string *vertex_source, std::string *fragment_source) override
 Returns the strings needed for shader definition. More...
 
void UpdateUniforms (const gfx::ShaderInputRegistryPtr &registry, gfx::Node *node) override
 Adds or updates uniforms for the shaders in the node. More...
 
void BindAttributes (const gfx::AttributeArrayPtr &attr_array, const gfx::BufferObjectPtr &buffer_object) override
 Binds attributes for the Builder's shader program. More...
 
base::AllocVector< char > BuildVertexData (const Layout &layout, size_t *vertex_size, size_t *num_vertices) override
 Returns a vector of data that represents vertex data, the size of a vertex, the number of vertices, and the pixel size of the generated geometry. More...
 
const base::AllocatorPtrGetAllocator ()
 Returns the Allocator passed to the constructor. More...
 
const FontImage::ImageDataGetImageData () const
 Convenience functions for derived classes. More...
 
const gfx::TexturePtr GetFontImageTexture ()
 Returns a Texture that contains the FontImage image. More...
 
bool UpdateFontImageTextureUniform (size_t index, gfx::Node *node)
 Modifies the indexed Texture uniform in the node if necessary to contain the current FontImage image. More...
 
void StoreGlyphVertices (const Layout &layout, size_t glyph_index, math::Point3f positions[4], math::Point2f texture_coords[4])
 Fills in the position and texture_coords for the 4 vertices of the indexed Layout glyph quad, using the current FontImage for texture coordinates. More...
 

Detailed Description

OutlineBuilder is a derived Builder class that can render text with outlines.

The Node returned by Builder::BuildNode() contains the following uniforms: uSdfPadding [float, derived from Font] Number of pixels used to pad SDF images. uSdfSampler [sampler2D, derived from FontImage] Sampler for the SDF texture. uTextColor: [VectorBase4f, default (1,1,1,1)] Foreground color of the text. uOutlineColor: [VectorBase4f, default (0,0,0,0)] Color of the text outline. uOutlineWidth: [float, default 2] Outline width in font pixels, where 0 means no outlines. uHalfSmoothWidth: [float, default 3] Half the number of pixels over which edges are smoothed on each side of outlines for antialiasing.

The shaders in the returned node require the global registry's uViewportSize, uProjectionMatrix, and uModelviewMatrix uniforms to be set to the proper values.

Definition at line 48 of file outlinebuilder.h.

Constructor & Destructor Documentation

ion::text::OutlineBuilder::OutlineBuilder ( const FontImagePtr font_image,
const gfxutils::ShaderManagerPtr shader_manager,
const base::AllocatorPtr allocator 
)

OutlineBuilder functions.

Definition at line 189 of file outlinebuilder.cc.

ion::text::OutlineBuilder::~OutlineBuilder ( )
overrideprotected

The destructor is protected because all base::Referent classes must have protected or private destructors.

Definition at line 194 of file outlinebuilder.cc.

Member Function Documentation

void ion::text::OutlineBuilder::BindAttributes ( const gfx::AttributeArrayPtr attr_array,
const gfx::BufferObjectPtr buffer_object 
)
overrideprotectedvirtual
bool ion::text::Builder::Build ( const Layout layout,
gfx::BufferObject::UsageMode  usage_mode 
)
inherited

Builds an Ion Node representing the text string defined by a Layout, using the FontImage passed to the constructor.

The usage_mode is used for buffer objects in the shape, allowing Ion to make certain optimizations. (In general, buffer data will be marked as wipeable if the usage_mode is gfx::BufferObject::kStaticDraw.) If anything goes wrong, this logs an error and returns false. Otherwise, the node can be accessed with GetNode(). If this is called more than once, the Builder will attempt to reuse objects from the previous call, meaning that any changes to them made from outside the Builder may persist. The node will contain a StateTable that disables face culling, enables alpha blending, sets the blend equations to kAdd, and sets both blend functions to kOne, kOneMinusSrcAlpha, so colors must be premultiplied by their alpha values.

Definition at line 148 of file builder.cc.

References DCHECK, ion::base::SharedPtr< T >::Get(), ion::base::Allocator::GetAllocatorForLifetime(), ion::text::Layout::GetGlyphCount(), image_data, ion::base::IsInvalidReference(), ion::base::kShortTerm, ion::base::SharedPtr< T >::Reset(), and ion::text::Builder::UpdateUniforms().

base::AllocVector< char > ion::text::OutlineBuilder::BuildVertexData ( const Layout layout,
size_t vertex_size,
size_t num_vertices 
)
overrideprotectedvirtual

Returns a vector of data that represents vertex data, the size of a vertex, the number of vertices, and the pixel size of the generated geometry.

Implements ion::text::Builder.

Definition at line 285 of file outlinebuilder.cc.

References DCHECK, ion::text::Builder::GetAllocator(), ion::base::Allocatable::GetAllocatorForLifetime(), ion::text::Builder::GetFont(), ion::text::Layout::GetGlyphCount(), ion::base::kShortTerm, ion::text::Builder::StoreGlyphVertices(), and texture_coords.

const AllocatorPtr& ion::base::Allocatable::GetAllocator ( ) const
inlineinherited

Returns the Allocator that was used for the instance.

This will be NULL if the instance was declared on the stack or created with normal placement new.

Definition at line 68 of file allocatable.h.

References allocator_.

Referenced by ion::base::DataContainer::CreateAndCopy(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), and ion::text::DynamicFontImage::FindImageDataIndex().

const base::AllocatorPtr& ion::text::Builder::GetAllocator ( )
inlineprotectedinherited

Returns the Allocator passed to the constructor.

This should never be NULL.

Definition at line 97 of file builder.h.

References allocator_.

Referenced by ion::text::BasicBuilder::BuildVertexData(), BuildVertexData(), ion::text::BasicBuilder::GetShaderInputRegistry(), and GetShaderInputRegistry().

const AllocatorPtr& ion::base::Allocatable::GetAllocatorForLifetime ( AllocationLifetime  lifetime) const
inlineinherited
math::Range3f ion::text::Builder::GetExtents ( ) const
inlineinherited

Returns the canonical 3D extents of the last generated geometry.

Definition at line 79 of file builder.h.

const FontPtr ion::text::Builder::GetFont ( ) const
inlineinherited

Returns the Font from the FontImage. This may be a NULL pointer.

Definition at line 57 of file builder.h.

References ion::base::SharedPtr< T >::Get().

Referenced by BuildVertexData(), and ion::text::BasicBuilder::UpdateUniforms().

const FontImagePtr& ion::text::Builder::GetFontImage ( ) const
inlineinherited

Returns the FontImage passed to the constructor.

Definition at line 48 of file builder.h.

Referenced by UpdateUniforms().

const gfx::TexturePtr ion::text::Builder::GetFontImageTexture ( )
protectedinherited

Returns a Texture that contains the FontImage image.

This returns a NULL pointer if there is no valid FontImage.

Definition at line 223 of file builder.cc.

References DCHECK, ion::base::SharedPtr< T >::Get(), ion::text::FontImage::ImageData::texture, and texture.

Referenced by ion::text::Builder::UpdateFontImageTextureUniform(), ion::text::BasicBuilder::UpdateUniforms(), and UpdateUniforms().

const FontImage::ImageData* ion::text::Builder::GetImageData ( ) const
inlineprotectedinherited

Convenience functions for derived classes.

Returns a pointer to the FontImage::ImageData that specifies an image containing all glyphs necessary for representing the characters in the Layout being built. This will be NULL if this is called when Build() is not currently in operation.

Definition at line 134 of file builder.h.

const gfx::NodePtr& ion::text::Builder::GetNode ( ) const
inlineinherited

Returns the Node set up by the last successful call to Build().

Definition at line 76 of file builder.h.

Referenced by SetHalfSmoothWidth(), SetOutlineColor(), SetOutlineWidth(), ion::text::BasicBuilder::SetSdfPadding(), SetSdfPadding(), ion::text::BasicBuilder::SetTextColor(), and SetTextColor().

const AllocatorPtr& ion::base::Allocatable::GetNonNullAllocator ( ) const
inlineinherited

Return our allocator, or the default allocator if the instance was declared on the stack.

Definition at line 72 of file allocatable.h.

References allocator_, and ion::base::AllocationManager::GetNonNullAllocator().

int ion::base::Shareable::GetRefCount ( ) const
inlineinherited

GetRefCount() is part of the interface necessary for SharedPtr.

Definition at line 34 of file shareable.h.

Referenced by ion::base::Notifier::RemoveReceiver().

const gfx::ShaderInputRegistryPtr ion::text::OutlineBuilder::GetShaderInputRegistry ( )
overrideprotectedvirtual
void ion::text::OutlineBuilder::GetShaderStrings ( std::string *  id_string,
std::string *  vertex_source,
std::string *  fragment_source 
)
overrideprotectedvirtual

Returns the strings needed for shader definition.

Implements ion::text::Builder.

Definition at line 236 of file outlinebuilder.cc.

void ion::base::Allocatable::operator delete ( void *  ptr)
inlineinherited

Define the delete operator to use specialized functions dealing with an Allocator.

Definition at line 109 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
AllocationLifetime  lifetime 
)
inlineinherited

Windows requires these (or it issues C4291 warnings).

Definition at line 112 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
const AllocatorPtr allocator 
)
inlineinherited

Definition at line 113 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
void *  ptr2 
)
inlineinherited

The placement delete operator does nothing, as usual.

Definition at line 118 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size)
inlineinherited

The standard no-parameter new operator uses the default Allocator.

Definition at line 84 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
AllocationLifetime  lifetime 
)
inlineinherited

This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime.

Definition at line 88 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator 
)
inlineinherited

This overloaded version of the new operator takes the Allocator to use directly as a parameter.

If the Allocator pointer is NULL, this uses the default Allocator.

Definition at line 95 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator,
void *  ptr 
)
inlineinherited

Special operator new for using placement new with Allocatables.

Definition at line 100 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
void *  ptr 
)
inlineinherited

The placement new operator is defined conventionally.

Definition at line 105 of file allocatable.h.

void ion::text::Builder::SetFontImage ( const FontImagePtr font_image)
inlineinherited

Modifies the Builder to use a different FontImage in subsequent calls to Build().

Definition at line 52 of file builder.h.

bool ion::text::OutlineBuilder::SetHalfSmoothWidth ( float  width)
bool ion::text::OutlineBuilder::SetOutlineColor ( const math::VectorBase4f &  color)
bool ion::text::OutlineBuilder::SetOutlineWidth ( float  width)
bool ion::text::OutlineBuilder::SetSdfPadding ( float  padding)

These convenience functions can be used to modify uniform values in the built Node returned by GetNode().

Each returns false if the Node is NULL or the uniform does not exist in it.

Definition at line 196 of file outlinebuilder.cc.

References ion::base::SharedPtr< T >::Get(), and ion::text::Builder::GetNode().

bool ion::text::OutlineBuilder::SetTextColor ( const math::VectorBase4f &  color)
void ion::text::Builder::StoreGlyphVertices ( const Layout layout,
size_t  glyph_index,
math::Point3f  positions[4],
math::Point2f  texture_coords[4] 
)
protectedinherited

Fills in the position and texture_coords for the 4 vertices of the indexed Layout glyph quad, using the current FontImage for texture coordinates.

Definition at line 246 of file builder.cc.

References DCHECK, ion::text::Layout::GetGlyph(), ion::text::FontImage::GetTextureCoords(), ion::text::Layout::Glyph::glyph_index, ion::base::IsInvalidReference(), ion::text::Layout::Quad::points, and ion::text::Layout::Glyph::quad.

Referenced by ion::text::BasicBuilder::BuildVertexData(), and BuildVertexData().

bool ion::text::Builder::UpdateFontImageTextureUniform ( size_t  index,
gfx::Node node 
)
protectedinherited

Modifies the indexed Texture uniform in the node if necessary to contain the current FontImage image.

Returns false if the node is NULL, the index is invalid, or the indexed uniform is invalid or is of the wrong type.

Definition at line 232 of file builder.cc.

References ion::text::Builder::GetFontImageTexture(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetType(), ion::gfx::UniformHolder::GetUniforms(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::GetValue(), ion::gfx::ShaderInput< ValueHolderType, ValueEnumType >::IsValid(), ion::gfx::kTextureUniform, ion::gfx::UniformHolder::SetUniformValue(), and texture.

Referenced by ion::text::BasicBuilder::UpdateUniforms(), and UpdateUniforms().


The documentation for this class was generated from the following files: