Using asynchronous text rendering
説明Description
The candera エンジンは非同期テキストengine レンダリングを提供し、時間のかかるテキスト処理の処理を改善します。焦点は、パフォーマンスの向上ではなく、リソース処理の向上です。provides asynchronous text rendering to improve the handling of time-consuming text processings. The focus is not to improve performance but to improve resource handling.
非同期テキストAsynchronous レンダリングには、テキストtext ノードの動作に関する知識が必要です。rendering requires knowledge of how text nodes work.
General information of how to use Candera::TextNode2Dの使用方法に関する一般的な情報は、次のセクションにあります。 can be found in the following section:
非同期テキストAsynchronous レンダリングには、テキストを表示するためにどの手順が必要かについての詳細な知識が必要です。次のセクションを参照してください。text rendering requires further knowledge of which steps are necessary to display a text. Please refer to the following section:
Based on the knowledge about the TextNode2D とand CanvasTextCanvasText, に関する知識に基づいて、次の章では非同期テキストthe レンダリングのしくみについて説明します。さらに、これらの章では、非同期テキストfollowing レンダリングをカスタマイズする方法と、この機能を使用する際に考慮すべき制限について説明します。ドキュメントは主にchapters describe how asynchronous text rendering works. Further, these chapters explain how to customize the asynchronous text rendering and which restrictions should be considered when using this feature. The documentation focuses mainly on Candera::TextNode2Dに焦点を当てています。これらの章で説明されている概念は、. The concepts described inside these chapters are applicable to Candera::CanvasTextにも適用できます。, too.
章Chapters
テキストレンダリングText rendering - 役に立つ知識Useful knowledge
TextNode2D – テキストtext レンダリングrender プロセスprocess
テキストは、そのレンダリングA プロセスでtext 3uses つのステップを使用します。three steps in its render process:
測定と配置Measurement and placement事前レンダリングPrerendering –テキスト用にレンダリングPreparesデバイスを準備しますthe render device for the text (必要な場合)。if necessary)- Render –
実際に表示される出力Actual visible output
目に見える結果を得るには、これらすべての手順を実行する必要があります。All of these steps have to be fulfilled to come to a visible result. Using a TextNode2D の使用には、そのテキストを更新するhas 3three つの異なる方法があるため、最終結果にアプローチするdifferent 3ways つの異なる方法があります。主な違いは、情報の提供とto 3update つのプロセスits ステップの処理にあります。text and therefore three different ways to approach the final result. The main difference lies in providing information and handling the three process steps:
最初のケース:First レイアウトの使用なしcase: No layout usage
Candera::TextNode2D には実際のレイアウト情報はありません。has no real layout information. There is also no layout in which the Candera::TextNode2Dが統合されたレイアウトもありません。したがって、テキスト レンダリングis プロセスのレンダリングintegrated. プロセスをトリガーするだけで十分です。テキストは領域にバインドされておらず、シーンTherefore, グラフ内の他のノードに対する可視レイヤー以外の関係はありません。trigger the render process for text render process is enough. The text is not bound to an area and has no relationship other than the visible layer to any other node in the scene graph.
プロ:Pro:
- Lightweight version of text
とandcandera の軽量版。candera. 簡単なテキストは、さほど苦労せずに表示できます。Simple text can be shown without much effort.
反対:Contra:
テキスト配置機能のほとんどが無効になっています。Most of text placement features are disabled.取り決めは存在しません。No arrangement exists.

2Second 番目のケース:case: レイアウトLayout プロセスはあるが、process but no TextNode2D レイアウターがないlayouter
Candera::TextNode2D には実際のレイアウト情報はありません。ただし、レイアウトhas no real layout information. However, it is arranged within a layout (GridLayoute.g. など)GridLayout). 内に配置されます。これは、This implies that Candera::TextNode2D が実際のレイアウト結果を提供して、レイアウト領域内にテキストを配置する必要があることを意味します。したがって、レイアウトhas プロセスは、事前にテキストto レンダリングprovide プロセスを開始する必要があります。テキストactual レンダリングlayout プロセスは、レイアウトresults プロセスがテキストのバウンディングto ボックスを評価するときに、最初のステップarrange the text within the layout area. Therefore, the layout process has to start the text render process beforehand. The text render process has to complete the first step (測定と配置)measurement を完了する必要があります。レイアウトand プロセスは、境界ボックスのサイズには影響しません。境界ボックスの情報のみを受け取り、テキストの周りに他のすべてのノードを配置できます。この情報の実際の処理は、使用するレイアウタによって定義されます。placement) when the layout process evaluates the bounding box of the text. The layout process has no influence on the size of the bounding box. It only receives the information of the bounding box and can place all the other nodes around the text. The actual handling of this information is defined by the used layouter.
プロ:Pro:
シーンLightweightグラフversionノードの配置の利点を備えた軽量バージョンのテキスト。of text with advantages of an arrangement of scene graph nodes.最初のケースとSwitching2between番目のケースの切り替えは、通常、大きな問題はありません。first and second case is normally without major issues.
反対:Contra:
テキストの配置は、レイアウトTheプロセスの影響を受けません。text placement cannot be influenced by the layout process.- TextNode2D
自体は、最初のケースとitself2cannot番目のケースを区別できません。distinguish between first case and second case.

ケースThird 3:case: Layout process with TextNode2D レイアウターを使用したレイアウト処理layouter
Candera::TextNode2D はレイアウト情報を提供します。さらに、一般的なレイアウトprovides プロセスは、テキストの表示方法にも影響を与える可能性があります。レイアウトlayout プロセスでは、テキストが収まる必要がある最大領域を提案できます。これは配置に直接影響します。テキスト自体は、レイアウトinformation. プロセスで実際に使用されたバウンディングAdditionally, ボックスを提供します。the general layout process can influence the way text is displayed, too. The layout process can propose a maximum area in which the text has to fit. This has a direct impact on the placement. The text itself provides the layout process a bounding box which were actually used by it.
プロ:Pro:
シーンFullグラフの配置に統合されたテキスト配置の完全な機能セット。feature set for text placement integrated in the scene graph arrangements.
反対:Contra:
テキストの重量バージョン。より多くの計算を行う必要があります。Heavyweight version of text; more calculations have to be done.付属のレイアウターは、レイアウターの使用を想定しています。An attached layouter expects using the layouter.
-
レイアウターがアタッチされている場合、デフォルトの動作を複雑なものに置き換えるため、レイアウターを使用する必要があります。ただし、レイアウトプロセスをトリガーして情報を提供する必要があります。そうしないと、ほとんどの情報が失われます。これは、他の使用法が間違っていて、未定義または望ましくない動作につながることを意味します。When a layouter is attached, it has to be used as it replaces the default behavior with a complex one. However, the information has to be provided by triggering the layout process otherwise it misses most of the information. This implies that other usages are wrong and lead to undefined or unwanted behavior.

-
拡大縮小や回転などの変換は、テキストがレンダリングされた後に適用されます。つまり、スケーリングを使用して狭いテキストまたは広いテキストを生成することはできません。これは、視覚的なレイアウトが変更されるためですTransformations like scale and rotation are applied after the text has been rendered. This means that you cannot use scaling to produce narrow or wide text, because the visual layout would be altered (右揃えのテキストは、スケーリング後に整列されなくなります)。この場合、代わりにスケーリングされたフォントをインポートします。right-aligned text will not be aligned any more after scaling). In this case, import a scaled font instead.
CanvasText – テキストtext レンダリングrender プロセスprocess
Candera::CanvasText はuses the third approach of Candera::TextNode2Dの 3 番目のアプローチを使用します。:
処理の複雑さを軽減するために、他のすべてのアプローチはAll other approaches have been removed from Candera::CanvasTextから削除されました。 to reduce the complexity of processing. Another difference to Candera::TextNode2Dとのもう 1is つの違いは、実際のthe actual Render() 部分です。part. Whilst the Candera::TextNode2D は各ノードでcalls the Render() を呼び出しますが、on each node, Candera::CanvasTextは同じレンダリング設定でテキストを収集し、それらを 1renders 回の描画呼び出しで描画することにより、バッチ形式でレンダリングします。it in a batched form by collecting texts with equal render settings and drawing them with a single draw call. Candera::CanvasText はGlyphAtlasuses を使用しています。GlyphAtlas.
非同期テキスト処理を使用する場合は、次の制限にも注意してください。Please note also the following restriction when using asynchronous text processing:
非同期テキストAsynchronous レンダリングtext rendering
非同期テキストAsynchronous レンダリングは、テキストtext レンダリングrendering ステップを独自のスレッドまたはレンダリングis スロットに移動するために導入された機能です。正確には、3a つのレンダリングfeature ステップのうち最初のステップのみを非同期で処理できます。他のすべてのステップは、おそらくintroduced to move text render steps to an own thread or render slot. To be precise only the first of the three render steps can be handled asynchronously. All the other steps are possibly bound to GPU にバインドされているか、フレームワークとユーザーor アプリケーションの両方で目的の出力を受け取る方法の複雑さを拡張する必要があります。has to extend the complexity of how to receive the desired output for both framework and user application.
非同期テキストAsynchronous レンダリングtext rendering – ワーカーWorker スレッドthread
非同期テキストThe レンダリングのデフォルトの方法は、ワーカーdefault スレッドの使用です。レンダリングway ループは、最初のステップである測定と配置をワーカーof スレッドに委任します。すべてのデリゲートはキューに入れられ、処理の準備が整います。ワーカーasynchronous スレッドを使用する主な利点は、レンダーtext ループをブロックしないことです。テキストの測定と配置が完了するまで、レンダリングrendering ループ自体はブロックされません。このアプローチの欠点は、実行の瞬間と結果の到着時間を制御できないことです。これは、単一のレンダリングis サイクルの後に発生する可能性がありますが、未定義のサイクル数の後に発生することもあります。the usage of a worker thread. The render loop delegates the first step, Measurement and Placement, to a worker thread. Every delegate is placed in a queue and ready for processing. Using a worker thread has its main advantage in not blocking the render loop. The render loop itself will not block until the text has been measured and placed. The disadvantage of this approach is that there is no control over the execution moment and result arrival time. It can happen after a single render cycle but also after an undefined amount of cycles.
次の図は、非同期テキストThe レンダリングを使用する場合に、測定と配置のプロセスがどのように置き換えられるかを下書きで示しています。簡単にするために、レイアウターを使用しない方法のみを使用します。他のすべての方法は、測定と配置のプロセスをフローチャートの同じアプローチに置き換えます。next figure shows in a draft how the measure and placement process has been replaced when asynchronous text rendering is used. For simplicity only the way without a layouter is used. All other ways do replace the measurement and placement process with the same approach in their flow chart.
非同期プロセスを実際にトリガーする関数は、2The 回トリガーする必要があります。1function 回はプロセスをキューに入れ、2which 回目は結果を取得します。このフローチャートのサンプルでは、Renderactually メソッドをtriggers 2the 回呼び出す必要があります。2asynchronous 番目の呼び出しは、非同期プロセスが実際に終了したときに実行する必要があります。process has to be triggered twice. One time to queue the process and a second time to retrieve the result. In this flow chart sample the Render-method has to be called twice. The second call has to be done when the asynchronous process has actually finished.

非同期テキストAsynchronous レンダリングtext rendering - シングルSingle スレッドthreaded
非同期とは、作業負荷を別のスレッドで処理する必要があるという意味ではありません。また、別の時点で同じスレッドによって実行されることもあります。シングルAsynchronous スレッドdoes バージョンの主な欠点は、レンダリングnot ループmean スレッドがまだテキストを処理していることです。ただし、今回は、1the 回のレンダリングwork サイクルですべてのテキストを処理する必要はありません。サイクルでレンダリングされるテキストの量を決定できます。load has to be done by another thread. It can also be done by the same thread at another point in time. The main disadvantage of the single threaded version is that the render loop thread is still handling the text. However, this time it does not have to handle every text in a single render cycle. The amount of texts which will be rendered in a cycle can be determined.
これは、テキスト/サイクルと処理するテキストのThis 2implies つの要素が与えられていることを意味します。この情報に基づいて、すべてのテキストを計算するために必要なサイクル数を見積もることができます。ただし、各サイクルの期間を決定することはできません。that two factors are given: Text/cycle and text to handle. Based on this information the amount of cycles needed to calculate all texts can be estimated. The duration of each cycle cannot be determined, though.

同期方法Synchronization methods
テキスト同期Text-Synchronization
非同期テキストWith レンダリングの導入により、すべてのテキストthe ノードを同期する方法を提供する必要があります。基本的な考え方は、すべての非同期テキストを同じレンダリングintroduction サイクルで視覚的に更新することです。テキストがランダムにポップアップするのを防ぐ必要があります。もう1つの側面は、レイアウトプロセスを減らすことです。レイアウターがof asynchronous text rendering a way to synchronize all text nodes have to be provided. The basic idea is to visually update all asynchronous texts at the same render cycle. It should prevent text popping up randomly. Another aspect is to decrease layout processes. When a layouter is attached to a Candera::TextNode2Dにアタッチされている場合、レイアウト プロセスはCandera::TextNode2Dのサイズを評価します。これは、レイアウト, プロセスが必要に応じて非同期テキストthe レンダリングを開始することも意味します。レイアウトlayout プロセスがプロセスを開始するとき、結果を待つべきではありません。これは、以前と同じブロッキングの問題が発生するためです。process will evaluate the size of a Candera::TextNode2D. This also means the layout process starts the asynchronous text rendering if necessary. When the layout process starts the process, it should not wait for the result as this results in the same blocking issue as before.
レイアウタは、非同期テキストThe レンダリングがまだ行われていない限り有効な古い情報とテキストを使用します。レイアウトlayouter プロセスを再実行すると、新しいテキストがまだ有効かどうかがチェックされます。そうでない場合は、古い情報を引き続き使用します。新しいテキストが現在有効な場合、テキストが更新されます。同じ手順は、レイアウターがアタッチされていなくても発生します。ただし、結果の開始と収集の部分は、uses the old information and text which is still valid as long as the asynchronous text rendering is not done yet. Rerunning the layout process will check whether the new text is valid yet or not. If not, it will continue using the old information. If the new text is valid now, it will update the text. The same procedure happens without a layouter attached. However, the part of starting and collecting the results is done by the render 呼び出し自体によって行われます。つまり、非同期テキストcall レンダリングを開始し、最低itself. 2In 回の呼び出しで結果を受け取る必要があります。呼び出し元が実際に誰であるかは、レイアウトshort プロシージャの使用法に依存します。an asynchronous text rendering has to be started and the result has to be received in a minimum of two calls. It depends on the usage of layout procedures who the caller really is.
このセクションでは、同期の可能性について説明します。This section describes the possibilities of synchronization:
テキスト同期Text-Synchronization –デフォルトの同期Default synchronizationライフサイクルLifecycle同期Synchronization -フローflow同期Synchronization -制限事項Restrictions
テキスト同期Text-Synchronization –カスタムCustom実装implementation新しい同期グループA new synchronization group追加のトリガーAdditionalオブジェクトtrigger objects独自の同期の実装Implementation of an own synchronization
テキスト同期Text-Synchronization – デフォルトの同期Default synchronization
デフォルトの同期は、可能な限りシンプルに保たれています。このセクションでは、検証のライフサイクルと、その欠陥を含めて同期がどのように機能するかについて説明します。The default synchronization is kept as simple as possible. This section describes the lifecycle of the validation and how does the synchronization works including its flaws.
ライフサイクルLifecycle
同期する必要があるすべてのオブジェクトは、インターフェイスEvery object which has to be synchronized implements the interface Candera::TextRendering::ITextValidationUserを実装します(例:, TextNode2D)。次のステップで、このオブジェクトをe.g. TextNode2D. In the next step this object has to be attached to a Candera::TextRendering::TextValidationGroupにアタッチする必要があります。デフォルト. グループはシングルトンThe インスタンスです。Canderadefault group is a singleton instance. The :Candera::TextRendering::TextValidationGroup は特定のバリデータを作成し、それをオブジェクトに添付します。バリデーターの切り離しは、このプロセスに匹敵します。creates a specific validator and attaches it to the object. Detaching the validator is comparable to this process.

同期Synchronization - フローflow
The object can be invalidated at any time by calling the invalidation method of the Candera::TextRendering::TextValidatorの無効化メソッドを呼び出すことで、いつでもオブジェクトを無効化できます。無効化されたオブジェクトがその状態を検証に変更するたびに、. Every time an invalidated object changes it state to validate, the Candera::TextRendering::TextValidator は検証の変更をグループに通知します。グループのすべてのオブジェクトが現在有効である場合、これらのオブジェクトのすべての更新メソッドが呼び出されます。notifies the group of its validation change. If all objects of the group are valid now, all update methods of these objects will be called.

In case of the Candera::TextNode2Dにレイアウターがアタッチされている場合、 with an attached layouter, the layout of the scene in which the Candera::TextNode2D が存在するシーンのレイアウトは無効になります。レイアウトlies プロセスがまったく使用されている場合will be invalidated. If there is layout process used at all (カンデラdisabled レイアウト機能が無効になっている場合)、更新メソッドでは何も実行されません。ただし、candera layout functionality) nothing will be done in the update method. However, the render メソッド自体は、新しく呼び出されたときにこのケースを処理できます。ここでの問題は、誰がレンダリングをトリガーするかが明示的に指定されていないことです。のレンダリングmethod メカニズムとレイアウトitself メカニズムの両方が、グループ全体が有効かどうかをチェックします。グループ全体が有効な場合にのみ、テキストが更新されます。グループが無効であるにもかかわらず、別のオブジェクトによってレイアウトがトリガーされた場合、テキストは更新されません。can handle this case when it is newly called. The issue here is that it is not explicitly specified who will trigger the render. Both render and layout mechanisms of will check whether the whole group is valid or not. Only in case that the whole group is valid, the text will be updated. If the layout is triggered by another object despite the fact that the group is not valid, the text will not be updated.
-
Candera::TextNode2D
は、デフォルトでattaches itself to the Candera::TextRendering::TextValidationGroupシングルトンインスタンスにアタッチされます。同期グループから除外するには、最初に明示的に切り離す必要があります。singleton instance per default. To exclude it from the synchronization group it has to be explicitly detached first.
同期Synchronization - 制限事項Restrictions
デフォルトの同期は可能な限り軽量であり、テキストが視覚的に更新されるまでグループ内のすべてのテキストが有効でなければならないという機能を提供します。テキストはさまざまな組み合わせで使用できるため、同期のための普遍的なソリューションではありません。したがって、場合によっては、本来あるべきほど実用的ではありません。The default synchronization is as lightweight as possible and still provides the feature that all texts in the group have to be valid until the text can be visibly updated. Due to the variety of combinations a text can be used, it is not a universal solution for synchronization. Therefore in some cases it is not as practical as it should be.
CanderaA :Candera::TextNode2D は、同期または非同期にすることも、実行時に両方のケースを切り替えることもできます。したがって、デフォルトでは、非同期フラグが変更されたときにcan be synchronous or asynchronous or switch between both cases at runtime. Therefore it is not advisable per default to attach/detach the TextNode2D をグループにアタッチ/デタッチすることはお勧めできません。保留中のリクエストは、ここでの主要な問題のto 1the つです。group when the asynchronous flag changes. Pending requests are one of the major issues here.
同期A synchronous Candera::TextNode2D は同期でなければなりません。これは、テキストが変更された場合、その後の最初のレンダリングhas サイクルでテキストを表示する必要があることを意味します。そのため、テキストが実際に表示されることが確定的になります。これらのノードで同期グループを使用すると、この決定論に反します。ノードはグループに接続されていますが、常に有効な状態です。デフォルトの同期では、ノードは完全に無視されます。to be synchronous. This implies when the text has been changed the text has to be visible in the first render cycle afterwards. So it becomes deterministic that the text is truly displayed. Using the synchronization groups on these nodes is opposing this determinism. The node is attached to the group but it is always in the valid state. The node will be ignored completely by the default synchronization.
もうAnother 1critical つの重要な制限は、テキストの更新率です。これは、同期がなくても発生する問題ですが、同期によって激化します。つまり、テキストが変更されるたびに、グループが無効になります。無効化率が、グループ全体のテキストrestriction レンダリングis プロセス全体がレンダリングする必要があるよりも高い場合、表示されるはずのテキストが表示されなくなります。2the つのテキストがより高い割合でそれ自体を無効にしている場合、グループ全体が常に無効な状態になる可能性もあります。グループ自体には、既に終了したテキストをカウントするメカニズムがあるため、グループが有効であるか、まだ表示されていない保留中の有効なテキストがあるという事実に基づいて、テキストを更新できます。この情報に基づいて、新しいテキストを設定したためにテキストのupdate 1rate つが無効に戻った場合でも、有効なグループを認識することができます。of a text. This is an issue that happens even without a synchronization but will be intensified by it. In short, every time a text changes, it invalidates the group. When the invalidation rate is higher than the overall text render process of the whole group needs to render, text which should have been shown will never occur. If two texts are invalidating itself in a higher rate, it can also happen that whole group is always in an invalid state. The group itself has a mechanism to count already finished texts and is therefore able to update the text based on the fact that the group is valid or has pending valid texts which are not displayed yet. Based on this information it can recognize a valid group even if one of the texts already changed back to invalid due to setting a new text. However this is not a guarantee that the texts will be updated correctly.
同期は単純であるため、テキスト更新を相互にリンクすることはできません。たとえば、すべてのテキストを一度に別の言語に変更することは機能しています。保留中のテキストの変更に関する問題はBecause 1of つだけです。通常、どのテキスト変更が相互に関連しており、同時に変更する必要があるかを特定することはできません。the simplicity of the synchronization it cannot link text updates to each other. For example changing all texts at once to another language is working. There is only one issue with already pending text changes. It is not possible to generally specify which text changes are related to each other and have to be changed at the same time.
顧客のすべてのユースケースが、単一の同期方法で満たされるわけではありません。ある方法では、別の方法とは異なる副作用が生じます。Not every use case of a customer can be satisfied by a single way of synchronization. One way produce other side effects than another.
したがって、独自の同期を実装または使用できます。Therefore, own synchronizations can be implemented or used.
テキスト同期Text-Synchronization – カスタム実装Custom implementation
同期のカスタマイズには、いくつかのレベルの複雑さといくつかの異なる目標があります。The customization of the synchronization has several levels of complexity and several different goals.
-
ランタイム中の同期方法の変更は、影響を受けるテキストChangingオブジェクトthe way of synchronization during runtime should only be done, when the affected text object (e.g. Candera::TextNode2Dなど))に保留中のテキスト変更がない場合にのみ行う必要があります。これは、予期しない副作用を引き起こす可能性があるためです。has no pending text changes – as this can have unexpected side effects.
新しい同期グループA new synchronization group
最も単純なカスタマイズは、追加の同期グループです。The simplest customization is an additional synchronization group. As default, all TextNode2Ds are attached to the singleton instance of the デフォルトでは、すべての TextNode2D がCandera:Candera::TextRendering::TextValidationGroupのシングルトン. インスタンスにアタッチされています。カスタムIt コードでこのクラスの追加インスタンスを作成することができます。is possible to create an additional instance of this class in custom code. Now two steps have to be done to correctly bind a Candera::TextNode2D をto the new group.
First, detach the Candera::TextNode2D新しいグループに正しくバインドするには、2 つの手順を実行する必要があります。最初に、古いfrom Canderaits old group by using the Detach-method of the old :Candera::TextRendering::TextValidationGroupの. Detach-method
Second, を使用して、古いグループからattach the Candera::TextNode2Dを切り離します。次に、新しい Canderato ::TextRendering::TextValidationGroupのthe new group by using the Attach-method を使用して、of the new Candera::TextNode2DTextRendering::TextValidationGroupを新しいグループに接続します。
.
追加のトリガーAdditional オブジェクトtrigger objects
A common issue is that setting the underlying scene layout of a 一般的な問題は、 Candera::TextNode2Dの基礎となるシーン レイアウトを無効に設定するだけでは、実際のレンダリングto サイクルをトリガーするのに十分ではないということです。たとえば、レンダリングinvalid ウェイクアップis メカニズムには、ウェイクアップしてレンダリングnot サイクルを開始するためのトリガーも必要です。enough to trigger the actual render cycle. For example a render wakeup mechanism needs a trigger to wake up and start the render cycle, too.
CanderaThe :Candera::TextNode2D自体は、特定のアプリケーションに依存するため、どの追加のトリガーが必要かを知りません。 itself does not know which additional trigger are needed because this depends on the given application.
これを拡張すると、グループが有効になるとすぐにシーンAn グラフ内のノードを更新できます。簡単な使用例は、新しいシーン内のすべてのテキストが有効な場合にのみ新しいシーンを表示するように設定するか、そのテキストが有効な場合にのみコントロールがポップアップするように設定することです。extension of this would be to update nodes within the scene graph as soon as the group is valid. A simple use case is to set a new scene visible only when all texts in the new scene are valid or a control pops up only when its text in it is valid.
これを達成するために、これらの呼び出しを担当する特定のオブジェクトは、インターフェイスTo accomplish this the specified object which is responsible for these calls has to implement the interface Candera::TextRendering::ITextValidationUserを実装する必要があります。オブジェクトは、既定の同期の記述されたライフ. サイクルに等しいThe object can be attached to the Candera::TextRendering::TextValidationGroupにアタッチできます。TextValidationGroupその中の Canderaequal to the described life cycle of the default synchronization. The ::TextRendering::ITextValidationUser::TriggerValidUpdate()メソッドは、グループ全体が有効になり、カスタム コードを実行できるようになるとすぐに呼び出されます。さらに、オブジェクトは独自のCandera::TextRendering::TextValidatorを受け取ります。これは、グループが有効な時間またはCandera::TextRendering::ITextValidationUser::TriggerValidUpdate()の時間に影響を与える可能性があります。グループ全体のすべてのオブジェクトに対して、追加で呼び出す必要があります。-method in it will be called as soon as the whole group is valid and the custom code can be executed. Additionally, the object receives an own Candera::TextRendering::TextValidator which can influence the time when a group is valid or when the Candera::TextRendering::ITextValidationUser::TriggerValidUpdate() on all objects in the whole group has to be additionally called.
独自の同期の実装Implementation of an own synchronization
最もカスタマイズされたソリューションは、独自の同期メカニズムを作成することです。The most customized solution is to write an own synchronization mechanism.
独自の実装にはThere 2are つの重要なインターフェイスがあります。two important interfaces for an own implementation:
- Candera::TextRendering::ITextValidationUser
によって実装されたimplemented by Candera::TextNode2D、, - FeatStd::ValidationHelperBase
を実装するto be implemented
Candera::TextRendering::ITextValidationUser は、is the interface which provides the Candera::TextNode2Dに任意の検証メソッドを提供するインターフェースです。このような検証メソッドを正しくアタッチおよびデタッチします。Candera with any validation method. It correctly attaches and detaches such a validation method. And :Candera::TextRendering::ITextValidationUser::TriggerValidUpdate() は、invalidates the scene layout of the Candera::TextNode2Dのシーン. レイアウトを無効にします。インターフェイスThe interface FeatStd::ValidationHelperBase は、オブジェクトを検証および無効化する機能を提供します。それがどのように機能するかはカスタム実装です。ここでの制限はprovides 1functionality つだけです。同期的に使用されるto validate and invalidate the object. It is a custom implementation how it will work. There is only one restriction here. A synchronously used TextNode2D は、カスタム実装の有効な状態を常に無視します。ただし、will always ignore the valid state of the custom implementation. It will call the validate メソッドとand invalidate メソッドは呼び出されます。Canderamethods, though. A :Candera::TextNode2D次のように関数を呼び出します。 calls the functions as following:
- Candera::TextNode2D
は測定と配置を開始します:starts measure and place: SetInvalid() - Candera::TextNode2D
は測定と配置を終了します:finishes measure and place: SetValid() - Candera::TextNode2D
は、結果を処理できるかどうかをチェックします:checks if it can handle the result: IsValid() (非同期ノードのみ)only asynchronous nodes) - Candera::TextNode2D
が結果を処理しましたhas handled the result (表示可能)ready for display): ConfirmValidHandled()
構成の可能性Configuration possibilities
一般的なセットアップと構成の可能性General setup and configuration possibilities
このセクションでは、非同期テキストThis レンダリングを構成する方法について説明します。section describes how to configure the asynchronous text rendering.
非同期Asynchronous TextNode2D およびand CanvasText
Enabling the asynchronous text rendering is something that has to be done on each 非同期テキスト レンダリングの有効化は、各Candera:Candera::TextNode2Dまたは or Candera::CanvasTextで行う必要があります。これは、SceneComposer. 内で実行できます。This can be done within the SceneComposer:

またはコード自体で:Or in code itself:
void SetAsyncPreRenderEnabled(bool enabled); bool IsAsyncPreRenderEnabled() const;
使用例:Example usage:
TextNode2D node; node.SetAsyncPreRenderEnabled(true); //Enables async rendering node.IsAsyncPreRenderEnabled(); //returns true node.SetAsyncPreRenderEnabled(false); //Disables async rendering node.IsAsyncPreRenderEnabled(); //returns false
The flag in SceneComposer とコードのフラグは、and code can be equally configured in Candera::CanvasTextで同様に構成できます。.
非同期ディスパッチ方法Asynchronous dispatching methods
CMake には、ワーカーprovides スレッドa ソリューションとシングルflag スレッドto バージョンのどちらかを選択するためのフラグが用意されています。フラグを有効にすると、ワーカーchoose スレッドが使用されます。このフラグはデフォルトで有効になっています。スレッドが利用できない場合、またはスレッドbetween セーフが無効になっている場合、コードはこのフラグを無視してシングルthe スレッドworker バージョンにフォールバックします。フラグはシステム全体です。これは、すべての非同期thread TextNode2Dsolution でカウントされます。これはプログラムで定義することもできますが、スレッドand セーフthe チェックはありません。single threaded version. When the flag is enabled a worker thread is used. The flag is enabled by default. If threading is not available or thread safety is disabled, the code will fall back to the single threaded version ignoring this flag. The flag is system wide. It counts for all asynchronous TextNode2D. This can also be defined programmatically, whereas there are no thread safety checks.

ディスパッチャー設定Dispatcher settings
The TextRenderDispatcher には、以下を呼び出して取得できる設定オブジェクトが含まれています。contains a settings object which can be retrieved by calling:
class Candera::TextRendering::TextRenderDispatcher::TextRenderSettings{…}; Candera::TextRendering:: TextRenderDispatcher::GetTextRenderSettings();
非同期ディスパッチ方法をプログラムで変更するには、設定の関数を使用します。To programmatically change the asynchronous dispatching method use the function of settings:
#include <Candera/TextEngine/Async/ AsyncTextRenderDispatcher.h> #include <Candera/TextEngine/Async/ ThreadingTextRenderDispatcher.h> void SetDefaultTextRenderer(Candera::TextRendering::TextRenderer * val);
シングルIf スレッドthe バージョンを使用する場合、single threaded version is used, the amount of processed text per DispatchNext ごとに処理されるテキストの量を設定できます。can be set:
void SetAsyncLoopCount(UInt8 const val);
制限Restrictions
このセクションでは、非同期機能を使用する際に留意すべき問題について説明します。This section describes issues which should be kept in mind when using the asynchronous feature.
パフォーマンスの向上Performance improvements
非同期テキストThe レンダリングの主な目的は、テキストmain レンダリングのパフォーマンスを向上させることではなく、レンダリングidea ループ自体のパフォーマンスを向上させることです。結果を表示するためにレンダリングbehind ループのasynchronous 2text 回目のサイクルが必要な場合でも。最初のサイクルはテキストrendering レンダリング呼び出しをキューに追加するだけなので、2is 番目のサイクルは必須です。最初のサイクルでは、古い結果を使用してテキストを処理します。not to improve the performance of text rendering but to improve the performance of the render loop itself. Even if a second cycle through the render loop is necessary to display the results. The second cycle is mandatory as the first cycle only adds the text render call into a queue. The first cycle uses the old result to handle the text.
ワーカーUsing スレッドはa 2worker 番目のコアで処理できるため、実際のパフォーマンスを向上させるには、ワーカーthread スレッドを使用し、最小限のデュアルand コアhaving プロセッサを使用することが必須です。a minimum of dual core processor is mandatory to gain an actual performance improvement as the worker thread can be handled by the second core.
高周波変化High frequency changes
最も必須の制限は、非同期テキストの更新間隔です。テキストエンジンが処理できるよりも速くテキストを変更すると、システムの決定論が確実に破られます。高速更新テキストを処理するためのThe 3most つの異なるアプローチを概説できます。最初のアプローチは、すべてのテキストの変更を視覚的に示すことです。すべてのテキストを表示することは決定論的です。それらが単一のフレームでしか表示されず、テキストが表示されるときに決定論的ではない場合でも.mandatory 2restriction 番目のアプローチは、キューに入れられた古いテキストを新しいテキストで上書きすることです。すべてのテキストを見るという決定論は失われました。ただし、レンダリングis プロセスが開始される前に既に古いテキストをレンダリングすると、パフォーマンスが低下しますが、発生することはありません。3the 番目の解決策は、これらのテキストを同期的にレンダリングすることです。update interval of an asynchronous text. Changing the text faster than the text engine can handle will definitely break the determinism of a system. Three different approaches can be outlined for handling fast updated texts. The first approach is to visibly show every text change. It is deterministic to see every text. Even if they are only visible for a single frame and it is not deterministic when the text is shown. The second approach is overriding the old queued text with the new one. The determinism of seeing every text has been lost. However, rendering a text which is already outdated before the render process started is a performance drop which will not occur. The third solution is to render these texts synchronously.
現在利用できるのは、2Currently 番目とavailable 3are 番目のアプローチです。この決定は、考えられるユースケースに基づいています。the second and the third approach. This decision is based on the possible use cases.
最初のユースThe ケースは、フレームfirst レート、クロックuse タイムなどの代替テキストです。基本的に、このようなテキストcase タイプにはis 3an つの共通点があります。まず、指定された時間間隔でコンテンツを常に変更します。テキストの背後にあるロジックは、最初はalternating 1text, フレーム後、2e.g. 回目はframe 6rate, フレーム後に更新が表示された時点で既に壊れています。第二に、テキストは通常短いテキストです。長いテキストの頻繁な変更は、おそらくユーザビリティの問題です。第clock 3time. に、頻度がそれ自体を追い越すほど高く、テキストが常に交互に表示される場合、キューは無期限に積み重なっていきます。新しいテキストが到着するまで、キューに入れられたすべてのテキストを表示する時間はありません。視覚的なテキスト自体はますます時代遅れになっています。テキストの長さは、キューイングBasically テキストの変化をさらに大きくします。such a text type has three things in common. First, it changes its content all the time in a specified time interval. The logic behind the text is already broken when the update is visible the first time after a single frame and the second time after six frames. Second, the texts are usually short texts. A high frequency alternation of a long text is most probably an issue in the usability. Third, if the frequency is high enough to outrun itself and the text is alternating all the time, the queue will stack up indefinitely. There is no time to show all queued text until new texts arrive. The visual text itself becomes more and more outdated. The length of the text would increase the change of queuing text even more.
そのため、周期的な交替でそれらを同期的にレンダリングすることをお勧めします。短いテキストは、レンダリングTherefore, ループ自体にはそれほど影響しません。また、長いテキストは再検討し、その合理性をチェックする必要があります。it is recommended for cyclic alternation to render them synchronously. Short texts will not affect the render loop itself that much. And long texts should be reconsidered and checked against its reasonableness.
2The 番目の使用例は、テキストをすばやく切り替える場合です。たとえば、テキストが表示されますが、ユーザー入力によって次のテキスト更新が既にトリガーされています。この場合、テキストの長さは任意です。主な違いは、テキストの更新が無期限にキューに入れられるわけではなく、おそらく厳しい時間間隔の期限がないことです。この場合、非同期テキストsecond レンダリングを使用できますが、両方のテキストをレンダリングすると、ユーザーuse エクスペリエンスに影響を与える可能性もあります。ほとんどの場合、これらは長いテキストで顕著になります。したがって、古いテキストが表示されるまで目に見える遅延があり、新しいテキストが表示されるまで別の目に見える遅延があります。case is to have occasionally a fast switch between texts, e.g. a text will be shown, but a user input already triggered the next text update. In this case the text can have any length. The main difference is that the text update does not queue indefinitely and there is most probably not a hard time interval deadline. In this case asynchronous text rendering can be used but rendering both texts can also impact the user experience. In most cases these will be noticeable in long texts. So there will be a visible delay until the outdated text is displayed and another visible delay until the new text is displayed.
したがって、非同期アプローチでは、古いテキストが新しいテキストでできるだけ早くオーバーライドされます。古いテキストが既にレンダリングされている場合は、古いテキストが表示されます。古いテキストのレンダリングが開始されていない場合、古いテキストは置き換えられます。古いテキストと新しいテキストの両方が既にレンダリングされていて、レンダリングTherefore, ループが古いテキストを表示する時間がない場合は、新しいテキストが表示されます。この場合、古いテキストの可視時間はthe 1asynchronous フレームだけである可能性が最も高くなります。approach overrides the old text with the new one as soon as possible. If the old text is already rendering, the old text will be displayed. If the old text have not even started rendering, the old text will be replaced. If the old text and the new text both are already rendered and the render loop had no time to show the old text, the new text will be shown. In this case it would be most likely that the old text has only a visibility time of a single frame.
Destruction of a TextNode2D の破棄
添付テキストのレンダリング中にDestroying a TextNode2D を破棄すると、未定義の動作が発生する可能性があります。while the attached text is being rendered can lead to undefined behavior.
レイアウトLayout プロセスの呼び出しprocess calls
非同期アプローチを使用するということは、非同期プロセスを開始する機能と、プロセスの結果を処理する別の機能があることを意味します。同期に基づいて、有効な結果のチェックは、結果が利用可能になるまでポーリングすることで解決できます。Using an asynchronous approach means that there a functionality which starts the asynchronous process and another one which handles the result of the process. Based on the synchronization the check for a valid result can be solved by polling until a result is available.
特定のユースケースで同期が適切に行われている場合、ポーリングは必要ありません。If the synchronization is done properly for a given use case, no polling will be needed.
ただし、非同期プロセスを開始するには、レイアウト情報が必要です。また、レイアウトHowever, プロセスでは、テキストthe ノードと依存ノードを配置するための結果が必要です。したがって、レイアウトasynchronous プロセスをprocess 2requires 回実行する必要があります。最低要件はlayout 2information 回の呼び出しです。2to 回目の呼び出しまでテキストが完成していない場合は、結果のポーリングと同じであるため、さらに呼び出しが必要です。start. And the layout process requires the result to place the text node and depending nodes. Therefore, it is required to run the layout process twice now. Two calls are the minimum requirement. If the text has not been finished until the second call, more calls are necessary as this is equal to polling for results.
キャッシュCache タイプの制限type restrictions
一部のキャッシュSome タイプは、cache types are GPU コンテキストにバインドされています。したがって、ラスタライズされたグリフのアップロードは、正しいコンテキストで行う必要があります。ワーカーcontext スレッドを使用しても、アップロードが正しい場所にあるとは限りません。これには、追加のラスタライズとレンダリングbound. スレッド内のグリフごとのアップロードが必要になる場合があります。これらの問題が発生すると予想されるキャッシュTherefore, タイプは、the upload of rasterized glyphs has to happen in the correct context. Using a worker thread cannot guarantee the upload at the correct location. This might require an additional rasterization and upload per glyph within the render thread. Expected cache types to have these issues are SurfaceCache とand GlyphAtlasGlyphAtlas. です。Candera::CanvasText は主にuses GlyphAtlasprimarily を使用します。この場合、共有コンテキストと非スレッド方式が推奨されます。GlyphAtlas. A shared context and the non-threading method is preferred in this case.