Ion
|
Builder is an abstract base class for building graphics objects used to render text. More...
#include "builder.h"
Public Member Functions | |
const FontImagePtr & | GetFontImage () 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::NodePtr & | GetNode () 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::AllocatorPtr & | GetAllocator () |
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 ®istry, 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::ImageData * | GetImageData () 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... | |
Builder is an abstract base class for building graphics objects used to render text.
|
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.
|
overrideprotected |
The destructor is protected because all base::Referent classes must have protected or private destructors.
Definition at line 146 of file builder.cc.
|
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().
|
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.
|
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().
|
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().
|
inlineinherited |
Convenience function that returns the Allocator to use to allocate an object with a specific lifetime.
Definition at line 78 of file allocatable.h.
References ion::base::Allocator::GetAllocatorForLifetime().
Referenced by ion::text::BasicBuilder::BuildVertexData(), ion::text::OutlineBuilder::BuildVertexData(), ion::gfxutils::ShaderManager::CreateShaderProgram(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), ion::text::DynamicFontImage::FindImageDataIndex(), ion::gfx::Renderer::Renderer(), and ion::gfx::UpdateStateTable().
|
inline |
|
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().
|
inline |
Returns the FontImage passed to the constructor.
Definition at line 48 of file builder.h.
Referenced by ion::text::OutlineBuilder::UpdateUniforms().
|
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().
|
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.
|
inline |
Returns the Node set up by the last successful call to Build().
Definition at line 76 of file builder.h.
Referenced by ion::text::OutlineBuilder::SetHalfSmoothWidth(), ion::text::OutlineBuilder::SetOutlineColor(), ion::text::OutlineBuilder::SetOutlineWidth(), ion::text::BasicBuilder::SetSdfPadding(), ion::text::OutlineBuilder::SetSdfPadding(), ion::text::BasicBuilder::SetTextColor(), and ion::text::OutlineBuilder::SetTextColor().
|
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().
|
inlineinherited |
GetRefCount() is part of the interface necessary for SharedPtr.
Definition at line 34 of file shareable.h.
Referenced by ion::base::Notifier::RemoveReceiver().
|
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.
|
protectedpure virtual |
Returns the strings needed for shader definition.
Implemented in ion::text::OutlineBuilder, and ion::text::BasicBuilder.
|
inlineinherited |
Define the delete operator to use specialized functions dealing with an Allocator.
Definition at line 109 of file allocatable.h.
|
inlineinherited |
Windows requires these (or it issues C4291 warnings).
Definition at line 112 of file allocatable.h.
|
inlineinherited |
Definition at line 113 of file allocatable.h.
|
inlineinherited |
The placement delete operator does nothing, as usual.
Definition at line 118 of file allocatable.h.
|
inlineinherited |
The standard no-parameter new operator uses the default Allocator.
Definition at line 84 of file allocatable.h.
|
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.
|
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.
|
inlineinherited |
Special operator new for using placement new with Allocatables.
Definition at line 100 of file allocatable.h.
|
inlineinherited |
The placement new operator is defined conventionally.
Definition at line 105 of file allocatable.h.
|
inline |
|
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().
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().
|
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().