mirror of
https://github.com/ocornut/imgui.git
synced 2026-08-21 23:01:10 +00:00
ImFontAtlas: moved TexUv buffers and configurable defines to internals.
This commit is contained in:
21
imgui.h
21
imgui.h
@@ -3318,23 +3318,6 @@ struct ImGuiSelectionExternalStorage
|
||||
// Hold a series of drawing commands. The user provides a renderer for ImDrawData which essentially contains an array of ImDrawList.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef IM_DRAWLIST_TEX_LINES_WIDTH_MAX
|
||||
#define IM_DRAWLIST_TEX_LINES_WIDTH_MAX (32) // The maximum line width to bake anti-aliased textures for. Build atlas with ImFontAtlasFlags_NoBakedLines to disable baking.
|
||||
#endif
|
||||
#ifndef IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH
|
||||
#define IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH (4) // Calculate detailed textures for width [1..IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH]
|
||||
#endif
|
||||
#ifndef IM_DRAWLIST_TEX_LINES_SAMPLE_COUNT
|
||||
#define IM_DRAWLIST_TEX_LINES_SAMPLE_COUNT (4) // How many samples per integer thickness level.
|
||||
#endif
|
||||
#ifndef IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX
|
||||
#define IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX (16)
|
||||
#endif
|
||||
#ifndef IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX
|
||||
#define IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX (4) // 0: fill, 1-3: strokes thickness
|
||||
#endif
|
||||
#define IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH_MAX (IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH * IM_DRAWLIST_TEX_LINES_SAMPLE_COUNT)
|
||||
|
||||
// ImDrawIdx: vertex index. [Compile-time configurable type]
|
||||
// - To use 16-bit indices + allow large meshes: backend need to set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' and handle ImDrawCmd::VtxOffset (recommended).
|
||||
// - To use 32-bit indices: override with '#define ImDrawIdx unsigned int' in your imconfig.h file.
|
||||
@@ -3455,7 +3438,7 @@ enum ImDrawFlags_
|
||||
// Stroke position relative to the shape outline
|
||||
ImDrawFlags_StrokeInside = 1 << 16, // Draw stroke inside of the shape outline (default for closed shapes and AddLineH, AddLineV functions)
|
||||
ImDrawFlags_StrokeCenter = 2 << 16, // Draw stroke at the center of the shape outline (default for paths, bezier, and AddLine functions)
|
||||
ImDrawFlags_StrokeCenterBiased = 3 << 16, // Draw stroke at the center of the shape outline, so that half thickness (rounded down) will be outside, and rest inside the shape outline. Does not animate well!
|
||||
ImDrawFlags_StrokeCenterBiased = 3 << 16, // Draw stroke at the center of the shape outline, so that half thickness rounded down will be outside, and rest inside the shape outline. Useful for axis-aligned shapes: AddLineH, AddLineV, AddRect. Does not animate well!
|
||||
ImDrawFlags_StrokeOutside = 4 << 16, // Draw stroke outside of the shape outline
|
||||
ImDrawFlags_StrokeLegacy = 5 << 16, // Use legacy positioning + enable MiterOnly and NoAAEnds flags.
|
||||
ImDrawFlags_StrokeMask_ = 0x07 << 16,
|
||||
@@ -4022,8 +4005,6 @@ struct ImFontAtlas
|
||||
ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel. May change as new texture gets created.
|
||||
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<ImFontConfig> Sources; // Source/configuration data
|
||||
ImVec4 TexUvLines[IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1 + IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH_MAX + 1]; // UVs for baked anti-aliased lines
|
||||
ImVec4 TexUvCorners[IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX * IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX]; // UVs for baked anti-aliased corners (0= fill, 1> stroke thickness)
|
||||
int TexNextUniqueID; // Next value to be stored in TexData->UniqueID
|
||||
int FontNextUniqueID; // Next value to be stored in ImFont->FontID
|
||||
ImVector<ImDrawListSharedData*> DrawListSharedDatas; // List of users for this atlas. Typically one per Dear ImGui context.
|
||||
|
||||
@@ -5332,7 +5332,7 @@ static void ImFontAtlasBuildUpdateTexDataCorners(ImFontAtlas* atlas)
|
||||
// Refresh UV coordinates
|
||||
ImVec2 uv0 = ImVec2((float)(x + 1), (float)(y + 1)) * atlas->TexUvScale;
|
||||
ImVec2 uv1 = ImVec2((float)(x + 1 + s), (float)(y + 1 + s)) * atlas->TexUvScale;
|
||||
atlas->TexUvCorners[n] = ImVec4(uv0.x, uv0.y, uv1.x, uv1.y);
|
||||
builder->TexUvCorners[n] = ImVec4(uv0.x, uv0.y, uv1.x, uv1.y);
|
||||
|
||||
x += w;
|
||||
row_height = ImMax(row_height, h);
|
||||
@@ -5386,7 +5386,7 @@ static void ImFontAtlasBuildUpdateTexDataCorners(ImFontAtlas* atlas)
|
||||
// Refresh UV coordinates
|
||||
ImVec2 uv0 = ImVec2((float)(x + 1), (float)(y + 1)) * atlas->TexUvScale;
|
||||
ImVec2 uv1 = ImVec2((float)(x + 1 + s), (float)(y + 1 + s)) * atlas->TexUvScale;
|
||||
atlas->TexUvCorners[thickness * IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX + n] = ImVec4(uv0.x, uv0.y, uv1.x, uv1.y);
|
||||
builder->TexUvCorners[thickness * IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX + n] = ImVec4(uv0.x, uv0.y, uv1.x, uv1.y);
|
||||
|
||||
x += w;
|
||||
row_height = ImMax(row_height, h);
|
||||
@@ -5456,7 +5456,7 @@ static void ImFontAtlasBuildUpdateTexDataLines(ImFontAtlas* atlas)
|
||||
ImVec2 uv0 = ImVec2((float)(r.x + pad_left - 1), (float)(r.y + y)) * atlas->TexUvScale;
|
||||
ImVec2 uv1 = ImVec2((float)(r.x + pad_left + line_width + 1), (float)(r.y + y + 1)) * atlas->TexUvScale;
|
||||
float half_v = (uv0.y + uv1.y) * 0.5f; // Calculate a constant V in the middle of the row to avoid sampling artifacts
|
||||
atlas->TexUvLines[n] = ImVec4(uv0.x, half_v, uv1.x, half_v);
|
||||
builder->TexUvLines[n] = ImVec4(uv0.x, half_v, uv1.x, half_v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5523,7 +5523,7 @@ static void ImFontAtlasBuildUpdateTexDataLines(ImFontAtlas* atlas)
|
||||
ImVec2 uv0 = ImVec2((float)(r.x), (float)(r.y + y)) * atlas->TexUvScale;
|
||||
ImVec2 uv1 = ImVec2((float)(r.x + IM_DRAWLIST_TEX_LINES_SAMPLE_COUNT * 2 + line_width), (float)(r.y + y + 1)) * atlas->TexUvScale;
|
||||
float half_v = (uv0.y + uv1.y) * 0.5f; // Calculate a constant V in the middle of the row to avoid sampling artifacts
|
||||
atlas->TexUvLines[IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1 + n] = ImVec4(uv0.x, half_v, uv1.x, half_v);
|
||||
builder->TexUvLines[IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1 + n] = ImVec4(uv0.x, half_v, uv1.x, half_v);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5898,8 +5898,8 @@ void ImFontAtlasUpdateDrawListsSharedData(ImFontAtlas* atlas)
|
||||
if (shared_data->FontAtlas == atlas)
|
||||
{
|
||||
shared_data->TexUvWhitePixel = atlas->TexUvWhitePixel;
|
||||
shared_data->TexUvLines = atlas->TexUvLines;
|
||||
shared_data->TexUvCorners = atlas->TexUvCorners;
|
||||
shared_data->TexUvLines = atlas->Builder->TexUvLines;
|
||||
shared_data->TexUvCorners = atlas->Builder->TexUvCorners;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -915,11 +915,28 @@ IMGUI_API ImGuiStoragePair* ImLowerBound(ImGuiStoragePair* in_begin, ImGuiStorag
|
||||
#define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC_R(_N,_MAXERROR) ((_MAXERROR) / (1 - ImCos(IM_PI / ImMax((float)(_N), IM_PI))))
|
||||
#define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC_ERROR(_N,_RAD) ((1 - ImCos(IM_PI / ImMax((float)(_N), IM_PI))) / (_RAD))
|
||||
|
||||
// ImDrawList: Lookup table size for adaptive arc drawing, cover full circle.
|
||||
// ImDrawList: Lookup tables
|
||||
#ifndef IM_DRAWLIST_ARCFAST_TABLE_SIZE
|
||||
#define IM_DRAWLIST_ARCFAST_TABLE_SIZE 48 // Number of samples in lookup table.
|
||||
#define IM_DRAWLIST_ARCFAST_TABLE_SIZE (48) // Number of samples in adaptive arc drawing lookup table.
|
||||
#endif
|
||||
#define IM_DRAWLIST_ARCFAST_SAMPLE_MAX IM_DRAWLIST_ARCFAST_TABLE_SIZE // Sample index _PathArcToFastEx() for 360 angle.
|
||||
#define IM_DRAWLIST_ARCFAST_SAMPLE_MAX IM_DRAWLIST_ARCFAST_TABLE_SIZE // Sample index _PathArcToFastEx() for 360 angle.
|
||||
|
||||
#ifndef IM_DRAWLIST_TEX_LINES_WIDTH_MAX
|
||||
#define IM_DRAWLIST_TEX_LINES_WIDTH_MAX (32) // The maximum line width to bake anti-aliased textures for. Build atlas with ImFontAtlasFlags_NoBakedLines to disable baking.
|
||||
#endif
|
||||
#ifndef IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH
|
||||
#define IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH (4) // Calculate detailed textures for width [1..IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH]
|
||||
#endif
|
||||
#ifndef IM_DRAWLIST_TEX_LINES_SAMPLE_COUNT
|
||||
#define IM_DRAWLIST_TEX_LINES_SAMPLE_COUNT (4) // How many samples per integer thickness level.
|
||||
#endif
|
||||
#ifndef IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX
|
||||
#define IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX (16)
|
||||
#endif
|
||||
#ifndef IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX
|
||||
#define IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX (4) // 0: fill, 1-3: strokes thickness
|
||||
#endif
|
||||
#define IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH_MAX (IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH * IM_DRAWLIST_TEX_LINES_SAMPLE_COUNT)
|
||||
|
||||
// Data shared between all ImDrawList instances
|
||||
// Conceptually this could have been called e.g. ImDrawListSharedContext
|
||||
@@ -928,8 +945,8 @@ IMGUI_API ImGuiStoragePair* ImLowerBound(ImGuiStoragePair* in_begin, ImGuiStorag
|
||||
struct IMGUI_API ImDrawListSharedData
|
||||
{
|
||||
ImVec2 TexUvWhitePixel; // UV of white pixel in the atlas (== FontAtlas->TexUvWhitePixel)
|
||||
const ImVec4* TexUvLines; // UV of anti-aliased lines in the atlas (== FontAtlas->TexUvLines)
|
||||
const ImVec4* TexUvCorners; // UV of rounded corner (== FontAtlas->TexUvCorners)
|
||||
const ImVec4* TexUvLines; // UV of anti-aliased lines in the atlas (== FontAtlas->Builder->TexUvLines)
|
||||
const ImVec4* TexUvCorners; // UV of rounded corner (== FontAtlas->Builder->TexUvCorners)
|
||||
ImFontAtlas* FontAtlas; // Current font atlas
|
||||
ImFont* Font; // Current font (used for simplified AddText overload)
|
||||
float FontSize; // Current font size (used for for simplified AddText overload)
|
||||
@@ -4339,6 +4356,10 @@ struct ImFontAtlasBuilder
|
||||
ImFontAtlasRectId PackIdLineFractTexData;
|
||||
ImFontAtlasRectId PackIdCornersTexData;
|
||||
|
||||
// Cached UV coordinates
|
||||
ImVec4 TexUvLines[IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1 + IM_DRAWLIST_TEX_LINES_DETAILED_WIDTH_MAX + 1]; // UVs for baked anti-aliased lines
|
||||
ImVec4 TexUvCorners[IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX * IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX]; // UVs for baked anti-aliased corners (0= fill, 1> stroke thickness)
|
||||
|
||||
ImFontAtlasBuilder() { memset((void*)this, 0, sizeof(*this)); FrameCount = -1; RectsIndexFreeListStart = -1; PackIdMouseCursors = PackIdLinesTexData = PackIdLineFractTexData = PackIdCornersTexData = -1; }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user