Skip to main content

PageRenderer

A class in Root.Township, Alta.Pages.

Client: renders page glyphs into render texture materials with its own camera, caching and pooling them per PageData. A singleton; does nothing on a headless server.

Constructors​

MemberWhat it is
PageRenderer()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

18 private and internal fields
MemberWhat it is
private bool btnClearInspector button for Clear.
private bool btnLoadInspector button for LoadEditor.
private bool btnSaveInspector button for Save.
private bool btnSaveAsInspector button for SaveAs.
private Camera cameraCamera that renders the glyphs into page textures.
private SerializedRenderTextureDescriptor descriptorRender texture settings for page textures.
private RenderTextureFormat[] fallBackFormatsRender texture formats tried in order if the set one isn't supported.
private GlyphInstance firstGlyphTemplate glyph cloned for extra glyphs.
private List<GlyphInstance> glyphsGlyph objects currently laid out.
private static PageRenderer instanceThe singleton.
private bool isCalibratingInspector flag; not read in this file.
private bool isFirstTextureTrue until the first render, so the initial temporary target can be released.
private Page pagePage loaded by the editor Load button.
private Material pageMaterialBase page material; also returned for empty pages.
private List<Material> poolUnused page materials ready for reuse.
private List<PageData> poolDataPage data last rendered into each pooled material, so a match can skip re-rendering.
private Dictionary<PageData, Material> savedPagesMaterials in use, by page data.
private Dictionary<PageData, int> useCountsHow many users each page data's material has.

Methods​

MemberWhat it is
void Load(PageData data)Lays out glyph objects to match the page data, adding or hiding glyphs as needed.
static void Release(PageData data)Lowers the use count for page data; at zero the material goes back to the pool.
static Material Render(PageData data)Returns a material showing the page data, reusing a cached or pooled one, or rendering a new one. Null on headless.
10 private and internal methods
MemberWhat it is
private IEnumerator CleanCamera() (iterator)Coroutine that clears the camera's target texture a frame later and releases it.
private void Clear()Editor button: removes all but the first glyph and blanks it.
private static Material CreateNewMaterial()Clones the page material and gives it a new render texture.
private static bool EnsureMaterialTextureIsCreated(Material material)Recreates a material's render texture if it has been lost.
private void LoadEditor()Editor button: loads the page field's data.
private void OnEnable()Makes this the singleton, destroying any older instance.
private void OnValidate()Empty.
private void Save()Editor button; empty in this build.
private void SaveAs()Editor button; empty in this build.
private void Start()Gets the camera, picks a supported render texture format and sets an initial target. Skipped on headless.

Used in​

Members of other types that take, return or hold a PageRenderer: