Ion
|
BasicBuilder is a derived Builder class that uses a very basic shader to render text. More...
#include "basicbuilder.h"
Public Member Functions | |
BasicBuilder (const FontImagePtr &font_image, const gfxutils::ShaderManagerPtr &shader_manager, const base::AllocatorPtr &allocator) | |
BasicBuilder 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) |
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 | |
~BasicBuilder () 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... | |
BasicBuilder is a derived Builder class that uses a very basic shader to render text.
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.
Definition at line 38 of file basicbuilder.h.
ion::text::BasicBuilder::BasicBuilder | ( | const FontImagePtr & | font_image, |
const gfxutils::ShaderManagerPtr & | shader_manager, | ||
const base::AllocatorPtr & | allocator | ||
) |
BasicBuilder functions.
Definition at line 93 of file basicbuilder.cc.
|
overrideprotected |
The destructor is protected because all base::Referent classes must have protected or private destructors.
Definition at line 98 of file basicbuilder.cc.
|
overrideprotectedvirtual |
Binds attributes for the Builder's shader program.
Implements ion::text::Builder.
Definition at line 152 of file basicbuilder.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 162 of file basicbuilder.cc.
References ion::text::Builder::GetAllocator(), ion::base::Allocatable::GetAllocatorForLifetime(), 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 BuildVertexData(), ion::text::OutlineBuilder::BuildVertexData(), 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 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().
|
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 ion::text::OutlineBuilder::BuildVertexData(), and UpdateUniforms().
|
inlineinherited |
Returns the FontImage passed to the constructor.
Definition at line 48 of file builder.h.
Referenced by ion::text::OutlineBuilder::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(), UpdateUniforms(), and ion::text::OutlineBuilder::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 ion::text::OutlineBuilder::SetHalfSmoothWidth(), ion::text::OutlineBuilder::SetOutlineColor(), ion::text::OutlineBuilder::SetOutlineWidth(), SetSdfPadding(), ion::text::OutlineBuilder::SetSdfPadding(), 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().
|
overrideprotectedvirtual |
Required Builder functions.
Implements ion::text::Builder.
Definition at line 108 of file basicbuilder.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 120 of file basicbuilder.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::BasicBuilder::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 100 of file basicbuilder.cc.
References ion::base::SharedPtr< T >::Get(), and ion::text::Builder::GetNode().
bool ion::text::BasicBuilder::SetTextColor | ( | const math::VectorBase4f & | color | ) |
Definition at line 104 of file basicbuilder.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 BuildVertexData(), and ion::text::OutlineBuilder::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 UpdateUniforms(), and ion::text::OutlineBuilder::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 128 of file basicbuilder.cc.
References ion::gfx::UniformHolder::AddUniform(), ion::gfx::UniformHolder::ClearUniforms(), DCHECK_GE, ion::base::SharedPtr< T >::Get(), ion::text::Builder::GetFont(), ion::text::Builder::GetFontImageTexture(), ion::text::Font::GetSdfPadding(), ion::gfx::UniformHolder::GetUniforms(), ion::gfx::UniformHolder::SetUniformValue(), and ion::text::Builder::UpdateFontImageTextureUniform().