![]() |
VR-Forces Developer's Guide
|
Packs bitmaps into a series of 2048×2048 RGBA atlas pages.
Slots are filled left-to-right, top-to-bottom within each page. When the current page is full a new AtlasPage is appended automatically.
Client code looks up an existing slot by key via find() and packs new bitmaps via pack(). The returned DtAtlasSlot contains a non-owning DtTextureInterface* into the atlas page plus UV coordinates for use with DtQuadProxyInterface::setTextureParameters().
Using an atlas amortises GPU texture binding cost – a batch of quads that all reference the same atlas page generates a single bind per page rather than one per symbol.
Classes | |
| struct | AtlasPage |
Public Member Functions | |
| DtTextureAtlas (DtDe &de, int slotWidth, int slotHeight) | |
| virtual | ~DtTextureAtlas () |
| DtAtlasSlot | pack (const std::string &key, const uint8_t *rgba, int srcWidth=-1, int srcHeight=-1) |
| const DtAtlasSlot * | find (const std::string &key) const |
| void | overwrite (const std::string &key, const uint8_t *rgba, int srcWidth=-1, int srcHeight=-1) |
| bool | readSlot (const DtAtlasSlot &slot, std::vector< uint8_t > &rgba, int &widthOut, int &heightOut) const |
| void | clear () |
| const std::unordered_map < std::string, DtAtlasSlot > & | slotIndex () const |
| int | slotHeight () const |
| int | slotWidth () const |
| DtTextureAtlas (const DtTextureAtlas &)=delete | |
| DtTextureAtlas & | operator= (const DtTextureAtlas &)=delete |
| DtTextureAtlas (DtTextureAtlas &&)=default | |
| DtTextureAtlas & | operator= (DtTextureAtlas &&)=default |
Static Public Attributes | |
| static constexpr int | theAtlasSize = 2048 |
Protected Attributes | |
| DtDe & | myDe |
| int | mySlotWidth |
| int | mySlotHeight |
| std::vector< AtlasPage > | myPages |
| std::unordered_map < std::string, DtAtlasSlot > | mySlotIndex |
Construct an atlas for symbols of the given slot dimensions.
| de | Engine context; the atlas holds a non-owning reference. |
| slotWidth | Width of one symbol slot in pixels. |
| slotHeight | Height of one symbol slot in pixels. |
|
delete |
Not allowed – slot dimensions are required.
|
default |
Not allowed – slot dimensions are required.
|
virtual |
|
delete |
Not allowed – slot dimensions are required.
|
default |
Not allowed – slot dimensions are required.
| DtAtlasSlot makVrv::DtTextureAtlas::pack | ( | const std::string & | key, |
| const uint8_t * | rgba, | ||
| int | srcWidth = -1, |
||
| int | srcHeight = -1 |
||
| ) |
Pack a new symbol into the atlas and return its slot.
If key already exists the existing slot is returned without re-packing.
| key | Unique identifier for this symbol (SIDC virtual key). |
| rgba | Pointer to srcWidth * srcHeight * 4 bytes of RGBA data (or slotWidth * slotHeight * 4 bytes when defaults are used). |
| srcWidth | Actual pixel width of the source buffer. Pass -1 (default) to use the atlas slot width. Values larger than the slot are clamped to the slot size. The UV coordinates returned address only the content region. |
| srcHeight | Actual pixel height of the source buffer. Pass -1 (default) to use the atlas slot height. Values larger than the slot are clamped to the slot size. The UV coordinates returned address only the content region. |
| const DtAtlasSlot* makVrv::DtTextureAtlas::find | ( | const std::string & | key | ) | const |
Look up an already-packed slot by key.
| key | Unique identifier previously passed to pack(). |
| void makVrv::DtTextureAtlas::overwrite | ( | const std::string & | key, |
| const uint8_t * | rgba, | ||
| int | srcWidth = -1, |
||
| int | srcHeight = -1 |
||
| ) |
Overwrite an existing slot with new pixel data and re-upload the page texture.
The key must already exist in the atlas (i.e. pack() was called previously). The UV coordinates and texture pointer are unchanged – callers holding a DtAtlasSlot snapshot remain valid. No-op if the key does not exist.
| key | Key that was previously passed to pack(). |
| rgba | Pointer to srcWidth * srcHeight * 4 bytes of new RGBA data (or slotWidth * slotHeight * 4 bytes when defaults are used). |
| srcWidth | Actual pixel width of the source buffer. Pass -1 (default) to use the atlas slot width. Values larger than the slot are clamped to the slot size. UV coordinates are NOT updated. |
| srcHeight | Actual pixel height of the source buffer. Pass -1 (default) to use the atlas slot height. Values larger than the slot are clamped to the slot size. UV coordinates are NOT updated. |
| bool makVrv::DtTextureAtlas::readSlot | ( | const DtAtlasSlot & | slot, |
| std::vector< uint8_t > & | rgba, | ||
| int & | widthOut, | ||
| int & | heightOut | ||
| ) | const |
Copy the RGBA pixels for a slot into rgba out-buffer.
Locates the slot by matching texture pointer across all pages, then copies the sub-rect identified by the given UV coordinates.
| slot | The atlas slot whose pixels should be read. |
| rgba | Filled with slotWidth * slotHeight * 4 bytes of RGBA data. |
| widthOut | Set to the per-slot width in pixels. |
| heightOut | Set to the per-slot height in pixels. |
| void makVrv::DtTextureAtlas::clear | ( | ) |
| const std::unordered_map<std::string, DtAtlasSlot>& makVrv::DtTextureAtlas::slotIndex | ( | ) | const |
Read-only access to the full slot map for iteration.
|
inline |
Return the individual slot height in pixels.
|
inline |
Return the individual slot width in pixels.
|
static |
Width and height of each atlas page in pixels.
|
protected |
Engine context; not owned.
|
protected |
Width of each symbol slot in pixels.
|
protected |
Height of each symbol slot in pixels.
|
protected |
All atlas pages, in allocation order.
|
protected |
Maps packing key to DtAtlasSlot for O(1) lookup.