VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtTextureAtlas.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2026 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
13 
16 
17 #include <cstdint>
18 #include <map>
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
24 namespace makVrv
25 {
26  class DtDe;
27 
35  {
36  DtTextureInterface* myTexture = nullptr;
37  float myU0 = 0.f;
38  float myU1 = 1.f;
39  float myV0 = 0.f;
40  float myV1 = 1.f;
41  };
42 
63  {
64  public:
66  static constexpr int theAtlasSize = 2048;
67 
72  DtTextureAtlas( DtDe& de, int slotWidth, int slotHeight );
73 
76  DtTextureAtlas( const DtTextureAtlas& ) = delete;
77  DtTextureAtlas& operator=( const DtTextureAtlas& ) = delete;
78 
79  DtTextureAtlas( DtTextureAtlas&& ) = default;
80  DtTextureAtlas& operator=( DtTextureAtlas&& ) = default;
82 
83  virtual ~DtTextureAtlas();
84 
100  DtAtlasSlot pack( const std::string& key, const uint8_t* rgba,
101  int srcWidth = -1, int srcHeight = -1 );
102 
106  const DtAtlasSlot* find( const std::string& key ) const;
107 
122  void overwrite( const std::string& key, const uint8_t* rgba,
123  int srcWidth = -1, int srcHeight = -1 );
124 
134  bool readSlot( const DtAtlasSlot& slot,
135  std::vector<uint8_t>& rgba,
136  int& widthOut, int& heightOut ) const;
137 
141  void clear();
142 
145  const std::unordered_map<std::string, DtAtlasSlot>& slotIndex() const;
146 
148  int slotHeight() const
149  {
150  return mySlotHeight;
151  }
152 
154  int slotWidth() const
155  {
156  return mySlotWidth;
157  }
158  protected:
160 
161  struct AtlasPage
162  {
163  std::vector<uint8_t> myPixels;
164  std::unique_ptr<DtTextureInterface> myTexture;
165  int myNextSlot = 0;
166  };
167 
170  std::vector<AtlasPage> myPages;
171  std::unordered_map<std::string, DtAtlasSlot> mySlotIndex;
172  };
173 
181  {
182  public:
184  static DtTextureAtlasManager& instance( DtDe& de );
185 
187  static void registerInstance( DtDe& de, DtTextureAtlasManager* mgr );
188 
191  DtTextureAtlas* getAtlas( int slotWidth, int slotHeight );
192 
193  virtual ~DtTextureAtlasManager();
194 
196  DtTextureAtlasManager( const DtTextureAtlasManager& ) = delete;
197  DtTextureAtlasManager& operator=( const DtTextureAtlasManager& ) = delete;
198 
199  protected:
201  std::map<std::pair<int,int>, std::unique_ptr<DtTextureAtlas>> myAtlases;
202  };
203 
204 } // namespace makVrv
int slotWidth() const
Return the individual slot width in pixels.
Definition: DtTextureAtlas.h:154
DtDe & myDe
Definition: DtTextureAtlas.h:200
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
std::unordered_map< std::string, DtAtlasSlot > mySlotIndex
Maps packing key to DtAtlasSlot for O(1) lookup.
Definition: DtTextureAtlas.h:171
Interface for a texture. Used to pass in a texture to vrvGraphics.
Definition: DtTextureInterface.h:26
std::vector< AtlasPage > myPages
All atlas pages, in allocation order.
Definition: DtTextureAtlas.h:170
std::vector< uint8_t > myPixels
CPU-side pixel buffer; theAtlasSize * theAtlasSize * 4 bytes (RGBA).
Definition: DtTextureAtlas.h:163
Definition: DtTextureAtlas.h:161
Contains makVrv::DtTextureInterface class.
std::map< std::pair< int, int >, std::unique_ptr< DtTextureAtlas > > myAtlases
Definition: DtTextureAtlas.h:201
Contains makVrv::DtVirtualBaseClass class.
#define DT_DLL_VRVGRAPHICS
Contains DLL export macros.
Definition: vrvGraphics.h:19
Packs bitmaps into a series of 2048×2048 RGBA atlas pages.
Definition: DtTextureAtlas.h:62
int mySlotHeight
Height of each symbol slot in pixels.
Definition: DtTextureAtlas.h:169
DtDe & myDe
Engine context; not owned.
Definition: DtTextureAtlas.h:159
std::unique_ptr< DtTextureInterface > myTexture
Owned GPU texture for this page.
Definition: DtTextureAtlas.h:164
UV sub-rect identifying one symbol&#39;s location within an atlas page.
Definition: DtTextureAtlas.h:34
int mySlotWidth
Width of each symbol slot in pixels.
Definition: DtTextureAtlas.h:168
Per-DtDe manager that auto-creates and caches texture atlases by slot size.
Definition: DtTextureAtlas.h:180
int slotHeight() const
Return the individual slot height in pixels.
Definition: DtTextureAtlas.h:148
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:76

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)