Fonts, Textures: main code for ImGuiBackendFlags_RendererHasTextures feature.

# Conflicts:
#	imgui.h
#	imgui_demo.cpp
This commit is contained in:
ocornut
2025-06-11 15:03:46 +02:00
committed by ocornut
parent 191a728ecc
commit 0f0473bf1c
8 changed files with 1750 additions and 802 deletions
+166 -46
View File
@@ -31,6 +31,7 @@
#define IMGUI_VERSION "1.92.0 WIP"
#define IMGUI_VERSION_NUM 19197
#define IMGUI_HAS_TABLE
#define IMGUI_HAS_TEXTURES // 1.92+ WIP branch with ImGuiBackendFlags_RendererHasTextures
/*
@@ -48,6 +49,7 @@ Index of this file:
// [SECTION] Helpers (ImGuiOnceUponAFrame, ImGuiTextFilter, ImGuiTextBuffer, ImGuiStorage, ImGuiListClipper, Math Operators, ImColor)
// [SECTION] Multi-Select API flags and structures (ImGuiMultiSelectFlags, ImGuiMultiSelectIO, ImGuiSelectionRequest, ImGuiSelectionBasicStorage, ImGuiSelectionExternalStorage)
// [SECTION] Drawing API (ImDrawCallback, ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListSplitter, ImDrawFlags, ImDrawListFlags, ImDrawList, ImDrawData)
// [SECTION] Texture API (ImTextureFormat, ImTextureStatus, ImTextureRect, ImTextureData)
// [SECTION] Font API (ImFontConfig, ImFontGlyph, ImFontGlyphRangesBuilder, ImFontAtlasFlags, ImFontAtlas, ImFont)
// [SECTION] Viewports (ImGuiViewportFlags, ImGuiViewport)
// [SECTION] ImGuiPlatformIO + other Platform Dependent Interfaces (ImGuiPlatformImeData)
@@ -169,10 +171,13 @@ struct ImDrawListSplitter; // Helper to split a draw list into differen
struct ImDrawVert; // A single vertex (pos + uv + col = 20 bytes by default. Override layout with IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT)
struct ImFont; // Runtime data for a single font within a parent ImFontAtlas
struct ImFontAtlas; // Runtime data for multiple fonts, bake multiple fonts into a single texture, TTF/OTF font loader
struct ImFontBuilderIO; // Opaque interface to a font builder (stb_truetype or FreeType).
struct ImFontAtlasBuilder; // Opaque storage for building a ImFontAtlas
struct ImFontConfig; // Configuration data when adding a font or merging fonts
struct ImFontGlyph; // A single font glyph (code point + coordinates within in ImFontAtlas + offset)
struct ImFontGlyphRangesBuilder; // Helper to build glyph ranges from text/string data
struct ImFontLoader; // Opaque interface to a font loading backend (stb_truetype, FreeType etc.).
struct ImTextureData; // Specs and pixel storage for a texture used by Dear ImGui.
struct ImTextureRect; // Coordinates of a rectangle within a texture.
struct ImColor; // Helper functions to create a color that can be converted to either u32 or float4 (*OBSOLETE* please avoid using)
// Forward declarations: ImGui layer
@@ -328,8 +333,8 @@ struct ImTextureRef
#endif
// Members
ImFontAtlas* _Atlas; // Texture/Atlas pointer
ImTextureID _TexID; // _OR_ Underlying user/backend texture identifier, or zero if not yet uploaded.
ImTextureData* _TexData; // Texture, generally owned by a ImFontAtlas
ImTextureID _TexID; // _OR_ Underlying texture identifier for backend, if already uploaded (otherwise pulled from _TexData)
};
IM_MSVC_RUNTIME_CHECKS_RESTORE
@@ -1638,6 +1643,7 @@ enum ImGuiBackendFlags_
ImGuiBackendFlags_HasMouseCursors = 1 << 1, // Backend Platform supports honoring GetMouseCursor() value to change the OS cursor shape.
ImGuiBackendFlags_HasSetMousePos = 1 << 2, // Backend Platform supports io.WantSetMousePos requests to reposition the OS mouse position (only used if io.ConfigNavMoveSetMousePos is set).
ImGuiBackendFlags_RendererHasVtxOffset = 1 << 3, // Backend Renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bit indices.
ImGuiBackendFlags_RendererHasTextures = 1 << 4, // Backend Renderer supports ImTextureData requests to create/update/destroy textures. This enables incremental texture updates and texture reloads.
};
// Enumeration for PushStyleColor() / PopStyleColor()
@@ -2794,6 +2800,14 @@ static inline bool operator!=(const ImVec4& lhs, const ImVec4& rhs) { return
IM_MSVC_RUNTIME_CHECKS_RESTORE
#endif
// Helpers: ImTexture ==/!= operators provided as convenience (not strictly necessary)
static inline bool operator==(const ImTextureRef& lhs, const ImTextureRef& rhs) { return lhs._TexID == rhs._TexID && lhs._TexData == rhs._TexData; }
static inline bool operator!=(const ImTextureRef& lhs, const ImTextureRef& rhs) { return lhs._TexID != rhs._TexID || lhs._TexData != rhs._TexData; }
//#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS // For legacy backends
//static inline bool operator==(ImTextureID lhs, const ImTextureRef& rhs) { return lhs == rhs._TexID && rhs._TexData == NULL; }
//static inline bool operator==(const ImTextureRef& lhs, ImTextureID rhs) { return lhs._TexID == rhs && lhs._TexData == NULL; }
//#endif
// Helpers macros to generate 32-bit encoded colors
// - User can declare their own format by #defining the 5 _SHIFT/_MASK macros in their imconfig file.
// - Any setting other than the default will need custom backend support. The only standard backend that supports anything else than the default is DirectX9.
@@ -3041,7 +3055,8 @@ struct ImDrawCmd
// Since 1.83: returns ImTextureID associated with this draw call. Warning: DO NOT assume this is always same as 'TextureId' (we will change this function for an upcoming feature)
// Since 1.92: removed ImDrawCmd::TextureId field, the getter function must be used!
inline ImTextureID GetTexID() const { return TexRef._TexID; }
// If for some reason you non C++ tech stack makes it difficult to call it, we may decide to separate the fields in ImDrawCmd.
inline ImTextureID GetTexID() const;
};
// Vertex layout
@@ -3273,6 +3288,7 @@ struct ImDrawList
//inline void PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments = 0) { PathBezierCubicCurveTo(p2, p3, p4, num_segments); } // OBSOLETED in 1.80 (Jan 2021)
// [Internal helpers]
IMGUI_API void _SetDrawListSharedData(ImDrawListSharedData* data);
IMGUI_API void _ResetForNewFrame();
IMGUI_API void _ClearFreeMemory();
IMGUI_API void _PopUnusedDrawCmd();
@@ -3309,6 +3325,73 @@ struct ImDrawData
IMGUI_API void ScaleClipRects(const ImVec2& fb_scale); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than Dear ImGui expects, or if there is a difference between your window resolution and framebuffer resolution.
};
//-----------------------------------------------------------------------------
// [SECTION] Texture API (ImTextureFormat, ImTextureStatus, ImTextureDataUpdate, ImTextureData
//-----------------------------------------------------------------------------
// We intentionally support a limited amount of texture formats to limit burden on CPU-side code and extension.
enum ImTextureFormat
{
ImTextureFormat_RGBA32, // 4 components per pixel, each is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
ImTextureFormat_Alpha8, // 1 component per pixel, each is unsigned 8-bit. Total size = TexWidth * TexHeight
};
// Status of a texture
enum ImTextureStatus
{
ImTextureStatus_OK,
ImTextureStatus_Destroyed, // Backend destroyed the texture.
ImTextureStatus_WantCreate, // Requesting backend to create the texture. Set status OK when done.
ImTextureStatus_WantUpdates, // Requesting backend to update specific blocks of pixels (write to texture portions which have never been used before). Set status OK when done.
ImTextureStatus_WantDestroy, // Requesting backend to destroy the texture. Set status to Destroyed when done.
};
// Coordinates of a rectangle within a texture.
// When a texture is in ImTextureStatus_WantUpdates state, we provide a list of individual rectangles to copy to GPU texture.
// You may use ImTextureData::Updates[] for the list, or ImTextureData::UpdateBox for a single bounding box.
struct ImTextureRect
{
unsigned short x, y; // Upper-left coordinates of rectangle to update
unsigned short w, h; // Size of rectangle to update (in pixels)
};
// Specs and pixel storage for a texture used by Dear ImGui.
// The renderer backend will generally create a GPU-side version of this.
// Why does we store two identifiers: TexID and BackendUserData?
// - ImTextureID TexID = lower-level identifier stored in ImDrawCmd. ImDrawCmd can refer to textures not created by the backend, and for which there's no ImTextureData.
// - void* BackendUserData = higher-level opaque storage for backend own book-keeping. Some backends may have enough with TexID and not need both.
struct IMGUI_API ImTextureData
{
ImTextureStatus Status; // ImTextureStatus_OK/_WantCreate/_WantUpdates/_WantDestroy
ImTextureFormat Format; // ImTextureFormat_RGBA32 (default) or ImTextureFormat_Alpha8
int Width; // Texture width
int Height; // Texture height
int BytesPerPixel; // 4 or 1
int UniqueID; // Sequential index to facilitate identifying a texture when debugging/printing. Only unique per atlas.
unsigned char* Pixels; // Pointer to buffer holding 'Width*Height' pixels and 'Width*Height*BytesPerPixels' bytes.
ImTextureID TexID; // Identifier stored in ImDrawCmd::GetTexID() and passed to backend RenderDrawData loop.
void* BackendUserData; // Convenience storage for backend. Some backends may have enough with TexID.
ImTextureRect UpdateRect; // Bounding box encompassing all individual updates.
ImVector<ImTextureRect> Updates; // Array of individual updates.
int UnusedFrames; // In order to facilitate handling Status==WantDestroy in some backend: this is a count successive frames where the texture was not used. Always >0 when Status==WantDestroy.
// [Internal]
bool UseColors; // [Internal] Tell whether our texture data is known to use colors (rather than just white + alpha).
bool WantDestroyNextFrame; // [Internal] Queued to set ImTextureStatus_WantDestroy next frame. May still be used in the current frame.
// Functions
ImTextureData() { memset(this, 0, sizeof(*this)); }
~ImTextureData() { DestroyPixels(); }
void Create(ImTextureFormat format, int w, int h);
void DestroyPixels();
unsigned char* GetPixels() { IM_ASSERT(Pixels != NULL); return Pixels; }
unsigned char* GetPixelsAt(int x, int y) { IM_ASSERT(Pixels != NULL); return Pixels + (x + y * Width) * BytesPerPixel; }
int GetSizeInBytes() const { return Width * Height * BytesPerPixel; }
int GetPitch() const { return Width * BytesPerPixel; }
ImTextureRef GetTexRef() const { ImTextureRef tex_ref; tex_ref._TexData = (ImTextureData*)(void*)this; tex_ref._TexID = TexID; return tex_ref; }
ImTextureID GetTexID() const { return TexID; }
};
//-----------------------------------------------------------------------------
// [SECTION] Font API (ImFontConfig, ImFontGlyph, ImFontAtlasFlags, ImFontAtlas, ImFontGlyphRangesBuilder, ImFont)
//-----------------------------------------------------------------------------
@@ -3338,7 +3421,8 @@ struct ImFontConfig
// [Internal]
char Name[40]; // Name (strictly to ease debugging)
ImFont* DstFont;
ImFont* DstFont; // Target font (as we merging fonts, multiple ImFontConfig may target the same font)
void* FontLoaderData; // Font loader opaque storage (per font config)
IMGUI_API ImFontConfig();
};
@@ -3353,6 +3437,9 @@ struct ImFontGlyph
float AdvanceX; // Horizontal distance to advance layout with
float X0, Y0, X1, Y1; // Glyph corners
float U0, V0, U1, V1; // Texture coordinates
int PackId; // [Internal] ImFontAtlasRectId value (FIXME: Cold data, could be moved elsewhere?)
ImFontGlyph() { memset(this, 0, sizeof(*this)); PackId = -1; }
};
// Helper to build glyph ranges from text/string data. Feed your application strings/characters to it then call BuildRanges().
@@ -3400,12 +3487,14 @@ enum ImFontAtlasFlags_
// - One or more fonts.
// - Custom graphics data needed to render the shapes needed by Dear ImGui.
// - Mouse cursor shapes for software cursor rendering (unless setting 'Flags |= ImFontAtlasFlags_NoMouseCursors' in the font atlas).
// It is the user-code responsibility to setup/build the atlas, then upload the pixel data into a texture accessible by your graphics api.
// - Optionally, call any of the AddFont*** functions. If you don't call any, the default font embedded in the code will be loaded for you.
// - Call GetTexDataAsAlpha8() or GetTexDataAsRGBA32() to build and retrieve pixels data.
// - Upload the pixels data into a texture within your graphics system (see imgui_impl_xxxx.cpp examples)
// - If you don't call any AddFont*** functions, the default font embedded in the code will be loaded for you.
// It is the rendering backend responsibility to upload texture into your graphics API:
// - ImGui_ImplXXXX_RenderDrawData() functions generally iterate atlas->TexList[] to create/update/destroy each ImTextureData instance.
// - Backend then set ImTextureData's TexID and BackendUserData.
// - Texture id are passed back to you during rendering to identify the texture. Read FAQ entry about ImTextureID for more details.
// Legacy path:
// - Call Build() + GetTexDataAsAlpha8() or GetTexDataAsRGBA32() to build and retrieve pixels data.
// - Call SetTexID(my_tex_id); and pass the pointer/identifier to your texture in a format natural to your graphics API.
// This value will be passed back to you during rendering to identify the texture. Read FAQ entry about ImTextureID for more details.
// Common pitfalls:
// - If you pass a 'glyph_ranges' array to AddFont*** functions, you need to make sure that your array persist up until the
// atlas is build (when calling GetTexData*** or Build()). We only copy the pointer, not the data.
@@ -3423,25 +3512,30 @@ struct ImFontAtlas
IMGUI_API ImFont* AddFontFromMemoryTTF(void* font_data, int font_data_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg->FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed.
IMGUI_API ImFont* AddFontFromMemoryCompressedTTF(const void* compressed_font_data, int compressed_font_data_size, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp.
IMGUI_API ImFont* AddFontFromMemoryCompressedBase85TTF(const char* compressed_font_data_base85, float size_pixels, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_font_data_base85' still owned by caller. Compress with binary_to_compressed_c.cpp with -base85 parameter.
// FIXME-NEWATLAS: Clarify meaning/purpose
IMGUI_API void ClearInputData(); // Clear input data (all ImFontConfig structures including sizes, TTF data, glyph ranges, etc.) = all the data used to build the texture and fonts.
IMGUI_API void ClearFonts(); // Clear input+output font data (same as ClearInputData() + glyphs storage, UV coordinates).
IMGUI_API void ClearTexData(); // Clear output texture data (CPU side). Saves RAM once the texture has been copied to graphics memory.
IMGUI_API void Clear(); // Clear all input and output.
IMGUI_API void ClearCache(); // Clear cached glyphs
// Build atlas, retrieve pixel data.
// User is in charge of copying the pixels into graphics memory (e.g. create a texture with your engine). Then store your texture handle with SetTexID().
// The pitch is always = Width * BytesPerPixels (1 or 4)
// Building in RGBA32 format is provided for convenience and compatibility, but note that unless you manually manipulate or copy color data into
// the texture (e.g. when using the AddCustomRect*** api), then the RGB pixels emitted will always be white (~75% of memory/bandwidth waste.
IMGUI_API bool Build(); // Build pixels data. This is called automatically for you by the GetTexData*** functions.
IMGUI_API void GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 1 byte per-pixel
IMGUI_API void GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 4 bytes-per-pixel
bool IsBuilt() const { return Fonts.Size > 0 && TexReady; } // Bit ambiguous: used to detect when user didn't build texture but effectively we should check TexID != 0 except that would be backend dependent...
IMGUI_API void BuildGrowTexture();
IMGUI_API void BuildCompactTexture();
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
void SetTexID(ImTextureID id){ TexID._Atlas = this; TexID._TexID = id; } // FIXME-NEWATLAS: Called by legacy backends.
void SetTexID(ImTextureRef id) { TexID = id; } // FIXME-NEWATLAS: Called by legacy backends.
IMGUI_API void GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 1 byte per-pixel
IMGUI_API void GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 4 bytes-per-pixel
void SetTexID(ImTextureID id) { TexRef._TexData = NULL; TexRef._TexID = id; } // Called by legacy backends.
void SetTexID(ImTextureRef id) { TexRef = id; } // Called by legacy backends.
#endif
bool IsBuilt() const { return Fonts.Size > 0 && TexIsBuilt; } // Bit ambiguous: used to detect when user didn't build texture but effectively we should check TexID != 0 except that would be backend dependent...
//-------------------------------------------
// Glyph Ranges
@@ -3466,10 +3560,15 @@ struct ImFontAtlas
//-------------------------------------------
// You can request arbitrary rectangles to be packed into the atlas, for your own purposes.
// - After calling Build(), you can query the rectangle position and render your pixels.
// - If you render colored output, set 'atlas->TexPixelsUseColors = true' as this may help some backends decide of preferred texture format.
// - You can also request your rectangles to be mapped as font glyph (given a font + Unicode point),
// so you can render e.g. custom colorful icons and use them as regular glyphs.
// You can request your rectangles to be mapped as font glyph (given a font + Unicode point),
// so you can render e.g. custom colorful icons and use them as regular glyphs.
// - If your backend supports ImGuiBackendFlags_RendererHasTextures (since 1.92.X):
// - Packing is done immediately. Returns >= on success. Return <0 on error.
// - You can render your pixels into the texture right after calling the AddCustomRectXXX functions.
// - Texture may be resized, so you cannot cache UV coordinates. // FIXME-NEWATLAS-V1: How to handle that smoothly?
// - If your backend does NOT supports ImGuiBackendFlags_RendererHasTextures (older than 1.92.X):
// - After calling Build(), you can query the rectangle position and render your pixels.
// - If you render colored output, set 'atlas->TexPixelsUseColors = true' as this may help some backends decide of preferred texture format.
// - Read docs/FONTS.md for more details about using colorful icons.
// - Note: this API may be redesigned later in order to support multi-monitor varying DPI settings.
IMGUI_API int AddCustomRectRegular(int width, int height);
@@ -3485,34 +3584,38 @@ struct ImFontAtlas
// Input
ImFontAtlasFlags Flags; // Build flags (see ImFontAtlasFlags_)
ImTextureRef TexID; // User data to refer to the texture once it has been uploaded to user's graphic systems. It is passed back to you during rendering via the ImDrawCmd structure.
ImTextureRef TexRef; // User data to refer to the latest texture once it has been uploaded to user's graphic systems. It is passed back to you during rendering via the ImDrawCmd structure.
int TexDesiredWidth; // Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height.
ImTextureFormat TexDesiredFormat; // Desired texture format (default to ImTextureFormat_RGBA32 but may be changed to ImTextureFormat_Alpha8).
int TexGlyphPadding; // FIXME: Should be called "TexPackPadding". Padding between glyphs within texture in pixels. Defaults to 1. If your rendering method doesn't rely on bilinear filtering you may set this to 0 (will also need to set AntiAliasedLinesUseTex = false).
void* UserData; // Store your own atlas related user-data (if e.g. you have multiple font atlas).
// Output
ImTextureData* TexData; // Current texture
ImVector<ImTextureData*> TexList; // Texture list (most often TexList.Size == 1). TexData is always == TexList.back().
// [Internal]
// NB: Access texture data via GetTexData*() calls! Which will setup a default font for you.
bool Locked; // Marked as Locked by ImGui::NewFrame() so attempt to modify the atlas will assert.
bool TexReady; // Set when texture was built matching current font input
bool TexPixelsUseColors; // Tell whether our texture data is known to use colors (rather than just alpha channel), in order to help backend select a format.
unsigned char* TexPixelsAlpha8; // 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight
unsigned int* TexPixelsRGBA32; // 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
int TexWidth; // Texture width calculated during Build().
int TexHeight; // Texture height calculated during Build().
ImVec2 TexUvScale; // = (1.0f/TexWidth, 1.0f/TexHeight)
bool TexIsBuilt; // Set when texture was built matching current font input
bool TexPixelsUseColors; // Tell whether our texture data is known to use colors (rather than just alpha channel), in order to help backend select a format or conversion process.
ImVec2 TexUvScale; // = (1.0f/TexData->TexWidth, 1.0f/TexData->TexHeight)
ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel
ImVector<ImFont*> Fonts; // Hold all the fonts returned by AddFont*. Fonts[0] is the default font upon calling ImGui::NewFrame(), use ImGui::PushFont()/PopFont() to change the current font.
ImVector<ImFontAtlasCustomRect> CustomRects; // Rectangles for packing custom texture data into the atlas.
ImVector<ImFontConfig> Sources; // Source/configuration data
ImVec4 TexUvLines[IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1]; // UVs for baked anti-aliased lines
int TexNextUniqueID; // Next value to be stored in TexData->UniqueID
ImDrawListSharedData* DrawListSharedData; // In principle this could become an array (e.g. multiple contexts using same atlas)
// [Internal] Font builder
const ImFontBuilderIO* FontBuilderIO; // Opaque interface to a font builder (default to stb_truetype, can be changed to use FreeType by defining IMGUI_ENABLE_FREETYPE).
unsigned int FontBuilderFlags; // Shared flags (for all fonts) for custom font builder. THIS IS BUILD IMPLEMENTATION DEPENDENT. Per-font override is also available in ImFontConfig.
// [Internal] Packing data
int PackIdMouseCursors; // Custom texture rectangle ID for white pixel and mouse cursors
int PackIdLines; // Custom texture rectangle ID for baked anti-aliased lines
ImFontAtlasBuilder* Builder; // Opaque interface to our data that doesn't need to be public
const ImFontLoader* FontLoader; // Font loader opaque interface (default to stb_truetype, can be changed to use FreeType by defining IMGUI_ENABLE_FREETYPE). Don't set directly!
const char* FontLoaderName; // Font loader name (for display e.g. in About box) == FontLoader->Name
void* FontLoaderData; // Font backend opaque storage
unsigned int FontBuilderFlags; // [FIXME: Should be called FontLoaderFlags] Shared flags (for all fonts) for font loader. THIS IS BUILD IMPLEMENTATION DEPENDENT (e.g. . Per-font override is also available in ImFontConfig.
int _PackedSurface; // Number of packed pixels. Used when compacting to heuristically find the ideal texture size.
int _PackedRects; // Number of packed rectangles.
float _PackNodesFactor = 1.0f;
// [Obsolete]
//typedef ImFontAtlasCustomRect CustomRect; // OBSOLETED in 1.72+
@@ -3525,13 +3628,13 @@ struct ImFont
{
// [Internal] Members: Hot ~20/24 bytes (for CalcTextSize)
ImVector<float> IndexAdvanceX; // 12-16 // out // Sparse. Glyphs->AdvanceX in a directly indexable way (cache-friendly for CalcTextSize functions which only this info, and are often bottleneck in large UI).
float FallbackAdvanceX; // 4 // out // = FallbackGlyph->AdvanceX
float FallbackAdvanceX; // 4 // out // FindGlyph(FallbackChar)->AdvanceX
float FontSize; // 4 // in // Height of characters/line, set during loading (don't change after loading)
// [Internal] Members: Hot ~28/40 bytes (for RenderText loop)
ImVector<ImU16> IndexLookup; // 12-16 // out // Sparse. Index glyphs by Unicode code-point.
ImVector<ImFontGlyph> Glyphs; // 12-16 // out // All glyphs.
ImFontGlyph* FallbackGlyph; // 4-8 // out // = FindGlyph(FontFallbackChar)
int FallbackGlyphIndex; // 4 // out // Index of FontFallbackChar
// [Internal] Members: Cold ~32/40 bytes
// Conceptually Sources[] is the list of font sources merged to create this font.
@@ -3543,18 +3646,21 @@ struct ImFont
ImWchar FallbackChar; // 2-4 // out // Character used if a glyph isn't found (U+FFFD, '?')
float EllipsisWidth; // 4 // out // Total ellipsis Width
float EllipsisCharStep; // 4 // out // Step between characters when EllipsisCount > 0
float Scale; // 4 // in // Base font scale (1.0f), multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
float Scale; // 4 // in // Base font scale (~1.0f), multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
float Ascent, Descent; // 4+4 // out // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] (unscaled)
int MetricsTotalSurface;// 4 // out // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs)
bool DirtyLookupTables; // 1 // out //
ImU8 Used8kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/8192/8]; // 1 bytes if ImWchar=ImWchar16, 16 bytes if ImWchar==ImWchar32. Store 1-bit for each block of 4K codepoints that has one active glyph. This is mainly used to facilitate iterations across all used codepoints.
bool LockDisableLoading;
ImFontConfig* LockSingleSrcConfig;
// Methods
IMGUI_API ImFont();
IMGUI_API ~ImFont();
IMGUI_API ImFontGlyph* FindGlyph(ImWchar c);
IMGUI_API ImFontGlyph* FindGlyphNoFallback(ImWchar c);
float GetCharAdvance(ImWchar c) { return ((int)c < IndexAdvanceX.Size) ? IndexAdvanceX[(int)c] : FallbackAdvanceX; }
IMGUI_API ImFontGlyph* FindGlyph(ImWchar c); // Return fallback glyph if requested glyph doesn't exists.
IMGUI_API ImFontGlyph* FindGlyphNoFallback(ImWchar c); // Return NULL if glyph doesn't exist
IMGUI_API float GetCharAdvance(ImWchar c);
IMGUI_API bool IsGlyphLoaded(ImWchar c);
IMGUI_API bool IsGlyphInFont(ImWchar c);
bool IsLoaded() const { return ContainerAtlas != NULL; }
const char* GetDebugName() const { return Sources ? Sources->Name : "<unknown>"; }
@@ -3571,14 +3677,24 @@ struct ImFont
#endif
// [Internal] Don't use!
IMGUI_API void BuildLookupTable();
IMGUI_API void ClearOutputData();
IMGUI_API void GrowIndex(int new_size);
IMGUI_API void AddGlyph(const ImFontConfig* src_cfg, ImWchar c, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float advance_x);
IMGUI_API void AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint, bool overwrite_dst);// , bool overwrite_dst = true); // Makes 'from_codepoint' character points to 'to_codepoint' character. Currently needs to be called AFTER fonts have been built.
IMGUI_API void AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint, bool overwrite_dst);// , bool overwrite_dst = true); // Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built.
IMGUI_API bool IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last);
IMGUI_API ImFontGlyph* BuildLoadGlyph(ImWchar c);
IMGUI_API void BuildRegisterGlyph(ImFontConfig* src, const ImFontGlyph* glyph);
IMGUI_API void BuildGrowIndex(int new_size);
IMGUI_API void BuildClearGlyphs();
};
// FIXME-NEWATLAS: Added indirection to avoid patching ImDrawCmd after texture updates.
inline ImTextureID ImDrawCmd::GetTexID() const
{
ImTextureID tex_id = TexRef._TexData ? TexRef._TexData->TexID : TexRef._TexID;
if (TexRef._TexData != NULL)
IM_ASSERT(tex_id && "ImDrawCmd is referring to Atlas texture that wasn't uploaded to graphics system.");
return tex_id;
}
//-----------------------------------------------------------------------------
// [SECTION] Viewports
//-----------------------------------------------------------------------------
@@ -3657,6 +3773,10 @@ struct ImGuiPlatformIO
// Input - Interface with Renderer Backend
//------------------------------------------------------------------
// Optional: Maximum texture size supported by renderer (used to adjust how we size textures). 0 if not known.
int Renderer_TextureMaxWidth;
int Renderer_TextureMaxHeight;
// Written by some backends during ImGui_ImplXXXX_RenderDrawData() call to point backend_specific ImGui_ImplXXXX_RenderState* structure.
void* Renderer_RenderState;
};