TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::GradientManager Class Reference

The atlas that the colors of color styles are baked into: pages of 2D textures, one row per gradient, with solid and 2..4-color blocks packed into shared rows. More...

#include <gui_core/style/gui_gradient_manager.h>

Public Member Functions

 GradientManager (size_t width=256)
 An empty atlas whose pages are width texels wide.
void ReleaseAll (GraphicsContext *graphicsContext)
 Destroys every GPU image of the atlas (deferred through graphicsContext).
void AddRef (GradientHandle handle)
 Raises the refcount of a live handle; pair with one Release.
bool Release (GradientHandle handle)
 Lowers the refcount; true when it reached zero and the slot was reclaimed.
AtlasLocation GetLocation (GradientHandle handle) const
 The atlas position of a handle; all zero for an invalid or stale handle.
bool IsValid (GradientHandle handle) const
 True if the handle is live (slot occupied and generation matches).
uint16_t GetRefcount (GradientHandle handle) const
 Refcount of a live handle; 0 for an invalid or stale handle.
size_t Width () const noexcept
 Page width in texels, the same for every page.
uint32_t PageCount () const noexcept
 Number of pages allocated.
size_t PageHeight (uint32_t pageIndex) const noexcept
 Allocated height of a page in rows; the rows in use are at most this.
std::span< const color4b > PageTextureData (uint32_t pageIndex) const noexcept
 CPU texels of a page, PageHeight x Width.
std::span< color4b > PageTextureData (uint32_t pageIndex) noexcept
 Writable CPU texels of a page; call MarkPageModified after writing.
void MarkPageModified (uint32_t pageIndex) noexcept
 Makes the next GetGradientImage upload the whole page.
void ClearAll () noexcept
 Releases every slot; every outstanding GradientHandle becomes stale, so holders (StyleManager, the text system's caret) re-register.
tachyon::Image * GetGradientImage (GraphicsContext *graphicsContext, uint32_t pageIndex=0)
 The GPU image of a page, made when it's new or has grown; otherwise the rows written since go up into it (GraphicsContext::UpdateImageRows), or, where the backend can't, it's made again.

Static Public Attributes

static constexpr uint32_t kMaxPageHeight = 8192
 Page height cap; a full page gets a new page instead of growing.
static constexpr int32_t kUnregisteredPage = -1
 GetPagePhysicalImageIndex of a page the renderer hasn't registered.

Acquire

A slot holding the colors (solid, 2..4-color block or full gradient row).

Identical content returns the same handle with its refcount raised; each call pairs with one Release.

GradientHandle AcquireSolidColor (const color4b &color)
 A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireSolidColor (const color4f &color)
 A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireColors (const color4b &c0, const color4b &c1)
 A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireColors (const color4f &c0, const color4f &c1)
 A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireColors (const color4b &c0, const color4b &c1, const color4b &c2)
 A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireColors (const color4f &c0, const color4f &c1, const color4f &c2)
 A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireColors (const color4b &c0, const color4b &c1, const color4b &c2, const color4b &c3)
 A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireColors (const color4f &c0, const color4f &c1, const color4f &c2, const color4f &c3)
 A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireGradient (const Gradient &g)
 A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.
GradientHandle AcquireRowPixels (std::span< const color4b > pixels)
 A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Renderer page table

The renderer registers each page in its bindless image set and records the 0-based shader slot here; color style uploads map logical pages through it.

HasPageTableChanged is set when the mapping changes, so the color styles must be re-uploaded.

int32_t GetPagePhysicalImageIndex (uint32_t pageIndex) const noexcept
void SetPagePhysicalImageIndex (uint32_t pageIndex, int32_t shaderSlotZeroBased) noexcept
bool HasPageTableChanged () const noexcept
void ClearPageTableChanged () noexcept

Detailed Description

The atlas that the colors of color styles are baked into: pages of 2D textures, one row per gradient, with solid and 2..4-color blocks packed into shared rows.

Slots are reference counted and deduplicated by content; a slot is reclaimed at refcount 0 and may be reused by a later Acquire.

A page doubles its height up to kMaxPageHeight; then a new page is added. A grown page's old GPU image is destroyed at the end of the frame.

Constructor & Destructor Documentation

◆ GradientManager()

tachyon::GradientManager::GradientManager ( size_t width = 256)

An empty atlas whose pages are width texels wide.

Member Function Documentation

◆ ReleaseAll()

void tachyon::GradientManager::ReleaseAll ( GraphicsContext * graphicsContext)

Destroys every GPU image of the atlas (deferred through graphicsContext).

Safe to call more than once.

◆ AcquireSolidColor() [1/2]

GradientHandle tachyon::GradientManager::AcquireSolidColor ( const color4b & color)

A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Invalid for no pixels.

◆ AcquireSolidColor() [2/2]

GradientHandle tachyon::GradientManager::AcquireSolidColor ( const color4f & color)

A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Invalid for no pixels.

◆ AcquireColors() [1/6]

GradientHandle tachyon::GradientManager::AcquireColors ( const color4b & c0,
const color4b & c1 )

A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Invalid for no pixels.

◆ AcquireColors() [2/6]

GradientHandle tachyon::GradientManager::AcquireColors ( const color4f & c0,
const color4f & c1 )

A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Invalid for no pixels.

◆ AcquireColors() [3/6]

GradientHandle tachyon::GradientManager::AcquireColors ( const color4b & c0,
const color4b & c1,
const color4b & c2 )

A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Invalid for no pixels.

◆ AcquireColors() [4/6]

GradientHandle tachyon::GradientManager::AcquireColors ( const color4f & c0,
const color4f & c1,
const color4f & c2 )

A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Invalid for no pixels.

◆ AcquireColors() [5/6]

GradientHandle tachyon::GradientManager::AcquireColors ( const color4b & c0,
const color4b & c1,
const color4b & c2,
const color4b & c3 )

A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Invalid for no pixels.

◆ AcquireColors() [6/6]

GradientHandle tachyon::GradientManager::AcquireColors ( const color4f & c0,
const color4f & c1,
const color4f & c2,
const color4f & c3 )

A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Invalid for no pixels.

◆ AcquireGradient()

GradientHandle tachyon::GradientManager::AcquireGradient ( const Gradient & g)

A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Invalid for no pixels.

◆ AcquireRowPixels()

GradientHandle tachyon::GradientManager::AcquireRowPixels ( std::span< const color4b > pixels)

A full row of these pixels (a GradientF's WriteTo, say), resampled to Width() when it's another size.

Invalid for no pixels.

◆ AddRef()

void tachyon::GradientManager::AddRef ( GradientHandle handle)

Raises the refcount of a live handle; pair with one Release.

◆ Release()

bool tachyon::GradientManager::Release ( GradientHandle handle)

Lowers the refcount; true when it reached zero and the slot was reclaimed.

◆ GetLocation()

AtlasLocation tachyon::GradientManager::GetLocation ( GradientHandle handle) const

The atlas position of a handle; all zero for an invalid or stale handle.

◆ IsValid()

bool tachyon::GradientManager::IsValid ( GradientHandle handle) const

True if the handle is live (slot occupied and generation matches).

◆ GetRefcount()

uint16_t tachyon::GradientManager::GetRefcount ( GradientHandle handle) const

Refcount of a live handle; 0 for an invalid or stale handle.

◆ Width()

size_t tachyon::GradientManager::Width ( ) const
inlinenoexcept

Page width in texels, the same for every page.

◆ PageCount()

uint32_t tachyon::GradientManager::PageCount ( ) const
inlinenoexcept

Number of pages allocated.

◆ PageHeight()

size_t tachyon::GradientManager::PageHeight ( uint32_t pageIndex) const
noexcept

Allocated height of a page in rows; the rows in use are at most this.

◆ PageTextureData() [1/2]

std::span< const color4b > tachyon::GradientManager::PageTextureData ( uint32_t pageIndex) const
noexcept

CPU texels of a page, PageHeight x Width.

◆ PageTextureData() [2/2]

std::span< color4b > tachyon::GradientManager::PageTextureData ( uint32_t pageIndex)
noexcept

Writable CPU texels of a page; call MarkPageModified after writing.

◆ MarkPageModified()

void tachyon::GradientManager::MarkPageModified ( uint32_t pageIndex)
noexcept

Makes the next GetGradientImage upload the whole page.

◆ GetPagePhysicalImageIndex()

int32_t tachyon::GradientManager::GetPagePhysicalImageIndex ( uint32_t pageIndex) const
noexcept

◆ SetPagePhysicalImageIndex()

void tachyon::GradientManager::SetPagePhysicalImageIndex ( uint32_t pageIndex,
int32_t shaderSlotZeroBased )
noexcept

◆ HasPageTableChanged()

bool tachyon::GradientManager::HasPageTableChanged ( ) const
inlinenoexcept

◆ ClearPageTableChanged()

void tachyon::GradientManager::ClearPageTableChanged ( )
inlinenoexcept

◆ ClearAll()

void tachyon::GradientManager::ClearAll ( )
noexcept

Releases every slot; every outstanding GradientHandle becomes stale, so holders (StyleManager, the text system's caret) re-register.

For a theme reload.

◆ GetGradientImage()

tachyon::Image * tachyon::GradientManager::GetGradientImage ( GraphicsContext * graphicsContext,
uint32_t pageIndex = 0 )

The GPU image of a page, made when it's new or has grown; otherwise the rows written since go up into it (GraphicsContext::UpdateImageRows), or, where the backend can't, it's made again.

nullptr when pageIndex is out of range.

Member Data Documentation

◆ kMaxPageHeight

uint32_t tachyon::GradientManager::kMaxPageHeight = 8192
staticconstexpr

Page height cap; a full page gets a new page instead of growing.

Stays well under the usual maxImageDimension2D (16384 on desktop GPUs).

◆ kUnregisteredPage

int32_t tachyon::GradientManager::kUnregisteredPage = -1
staticconstexpr

GetPagePhysicalImageIndex of a page the renderer hasn't registered.


The documentation for this class was generated from the following file: