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

Builder is an abstract base class for building graphics objects used to render text. More...

#include "builder.h"

Inheritance diagram for ion::text::Builder:
Collaboration diagram for ion::text::Builder:

Public Member Functions

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

 Builder (const FontImagePtr &font_image, const gfxutils::ShaderManagerPtr &shader_manager, const base::AllocatorPtr &allocator)
 The constructor is protected because this is an abstract class. More...
 
 ~Builder () override
 The destructor is protected because all base::Referent classes must have protected or private destructors. More...
 
const base::AllocatorPtrGetAllocator ()
 Returns the Allocator passed to the constructor. More...
 
virtual const
gfx::ShaderInputRegistryPtr 
GetShaderInputRegistry ()=0
 Functions that derived classes must implement. More...
 
virtual void GetShaderStrings (std::string *id_string, std::string *vertex_source, std::string *fragment_source)=0
 Returns the strings needed for shader definition. More...
 
virtual void UpdateUniforms (const gfx::ShaderInputRegistryPtr &registry, gfx::Node *node)=0
 Adds or updates uniforms for the shaders in the node. More...
 
virtual void BindAttributes (const gfx::AttributeArrayPtr &attr_array, const gfx::BufferObjectPtr &buffer_object)=0
 Binds attributes for the Builder's shader program. More...
 
virtual base::AllocVector< char > BuildVertexData (const Layout &layout, size_t *vertex_size, size_t *num_vertices)=0
 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 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

Builder is an abstract base class for building graphics objects used to render text.

Definition at line 45 of file builder.h.

Constructor & Destructor Documentation

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

The constructor is protected because this is an abstract class.

Builder functions.

The FontImage is used to set up the texture image and texture coordinates. The ShaderManager, if it is not NULL, is used to create ShaderProgram instances to enable remote editing of shader source. The Allocator is used when building; if it is NULL, the default allocator is used.

Definition at line 138 of file builder.cc.

ion::text::Builder::~Builder ( )
overrideprotected

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

Definition at line 146 of file builder.cc.

Member Function Documentation

virtual void ion::text::Builder::BindAttributes ( const gfx::AttributeArrayPtr attr_array,
const gfx::BufferObjectPtr buffer_object 
)
protectedpure virtual

Binds attributes for the Builder's shader program.

Implemented in ion::text::OutlineBuilder, and ion::text::BasicBuilder.

bool ion::text::Builder::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.

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 UpdateUniforms().

virtual base::AllocVector<char> ion::text::Builder::BuildVertexData ( const Layout layout,
size_t vertex_size,
size_t num_vertices 
)
protectedpure virtual

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.

Implemented in ion::text::OutlineBuilder, and ion::text::BasicBuilder.

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 ( )
inlineprotected

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(), ion::text::OutlineBuilder::BuildVertexData(), ion::text::BasicBuilder::GetShaderInputRegistry(), and ion::text::OutlineBuilder::GetShaderInputRegistry().

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

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
inline

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 ion::text::OutlineBuilder::BuildVertexData(), and ion::text::BasicBuilder::UpdateUniforms().

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

Returns the FontImage passed to the constructor.

Definition at line 48 of file builder.h.

Referenced by ion::text::OutlineBuilder::UpdateUniforms().

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

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 UpdateFontImageTextureUniform(), ion::text::BasicBuilder::UpdateUniforms(), and ion::text::OutlineBuilder::UpdateUniforms().

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

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 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().

virtual const gfx::ShaderInputRegistryPtr ion::text::Builder::GetShaderInputRegistry ( )
protectedpure virtual

Functions that derived classes must implement.

Returns the ShaderInputRegistry for the Builder's shaders.

Implemented in ion::text::OutlineBuilder, and ion::text::BasicBuilder.

virtual void ion::text::Builder::GetShaderStrings ( std::string *  id_string,
std::string *  vertex_source,
std::string *  fragment_source 
)
protectedpure virtual

Returns the strings needed for shader definition.

Implemented in ion::text::OutlineBuilder, and ion::text::BasicBuilder.

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)
inline

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

Definition at line 52 of file builder.h.

void ion::text::Builder::StoreGlyphVertices ( const Layout layout,
size_t  glyph_index,
math::Point3f  positions[4],
math::Point2f  texture_coords[4] 
)
protected

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 ion::text::OutlineBuilder::BuildVertexData().

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

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 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 ion::text::OutlineBuilder::UpdateUniforms().

virtual void ion::text::Builder::UpdateUniforms ( const gfx::ShaderInputRegistryPtr registry,
gfx::Node node 
)
protectedpure virtual

Adds or updates uniforms for the shaders in the node.

The registry returned by GetShaderInputRegistry() is passed in.

Implemented in ion::text::OutlineBuilder, and ion::text::BasicBuilder.

Referenced by Build().


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