Ion
|
OutlineBuilder is a derived Builder class that can render text with outlines. More...
#include "outlinebuilder.h"
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 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 | |
~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 ®istry, 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::AllocatorPtr & | GetAllocator () |
Returns the Allocator passed to the constructor. 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... | |
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.
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.
|
overrideprotected |
The destructor is protected because all base::Referent classes must have protected or private destructors.
Definition at line 194 of file outlinebuilder.cc.
|
overrideprotectedvirtual |
Binds attributes for the Builder's shader program.
Implements ion::text::Builder.
Definition at line 274 of file outlinebuilder.cc.
References ion::gfxutils::BufferToAttributeBinder< T >::Apply(), ion::gfxutils::BufferToAttributeBinder< T >::Bind(), and ion::gfx::ShaderInputRegistry::GetGlobalRegistry().
|
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().
|
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.
|
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().
|
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().
|
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(), BuildVertexData(), ion::gfxutils::ShaderManager::CreateShaderProgram(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), ion::text::DynamicFontImage::FindImageDataIndex(), ion::gfx::Renderer::Renderer(), and ion::gfx::UpdateStateTable().
|
inlineinherited |
|
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().
|
inlineinherited |
Returns the FontImage passed to the constructor.
Definition at line 48 of file builder.h.
Referenced by UpdateUniforms().
|
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().
|
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.
|
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().
|
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().
|
overrideprotectedvirtual |
Required Builder functions.
Implements ion::text::Builder.
Definition at line 217 of file outlinebuilder.cc.
References ion::text::Builder::GetAllocator(), ion::gfx::kFloatUniform, ion::gfx::kFloatVector4Uniform, and ion::gfx::kTextureUniform.
|
overrideprotectedvirtual |
Returns the strings needed for shader definition.
Implements ion::text::Builder.
Definition at line 236 of file outlinebuilder.cc.
|
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.
|
inlineinherited |
bool ion::text::OutlineBuilder::SetHalfSmoothWidth | ( | float | width | ) |
Definition at line 212 of file outlinebuilder.cc.
References ion::base::SharedPtr< T >::Get(), and ion::text::Builder::GetNode().
bool ion::text::OutlineBuilder::SetOutlineColor | ( | const math::VectorBase4f & | color | ) |
Definition at line 204 of file outlinebuilder.cc.
References ion::base::SharedPtr< T >::Get(), and ion::text::Builder::GetNode().
bool ion::text::OutlineBuilder::SetOutlineWidth | ( | float | width | ) |
Definition at line 208 of file outlinebuilder.cc.
References ion::base::SharedPtr< T >::Get(), and ion::text::Builder::GetNode().
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 | ) |
Definition at line 200 of file outlinebuilder.cc.
References ion::base::SharedPtr< T >::Get(), and ion::text::Builder::GetNode().
|
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().
|
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().
|
overrideprotectedvirtual |
Adds or updates uniforms for the shaders in the node.
The registry returned by GetShaderInputRegistry() is passed in.
Implements ion::text::Builder.
Definition at line 244 of file outlinebuilder.cc.
References ion::gfx::UniformHolder::AddUniform(), ion::gfx::UniformHolder::ClearUniforms(), DCHECK, DCHECK_GE, ion::text::Builder::GetFontImage(), ion::text::Builder::GetFontImageTexture(), ion::text::Font::GetSdfPadding(), ion::gfx::UniformHolder::GetUniforms(), ion::gfx::UniformHolder::SetUniformValue(), and ion::text::Builder::UpdateFontImageTextureUniform().