52 void begin(
u32 entity,
bool sdf,
bool screen,
bool hasBox,
i32 layer,
f32 boxWidth,
f32 boxHeight,
bool autoKind =
false) {
54 changed_.push_back(entity);
60 text.autoKind = autoKind;
62 text.boxWidth = boxWidth;
63 text.boxHeight = boxHeight;
69 const auto found = entries_.find(entity);
70 if (found == entries_.end() || vertexCount <= 0 || indexCount <= 0 || vertexCount % 4 != 0 || indexCount != vertexCount / 4 * 6)
return false;
72 changed_.push_back(entity);
75 batch.
indices.assign(indices, indices + indexCount);
78 const u32 quads =
static_cast<u32>(vertexCount) / 4;
81 f32 left = INFINITY, bottom = INFINITY, right = -INFINITY, top = -INFINITY;
84 left = std::min(left, batch.
vertices[i]);
85 right = std::max(right, batch.
vertices[i]);
86 bottom = std::min(bottom, batch.
vertices[i + 1]);
87 top = std::max(top, batch.
vertices[i + 1]);
99 if (!entries_.erase(entity))
return;
101 changed_.push_back(entity);
110 template<
typename Visit>
112 const bool named = !all_changed_;
113 for (
const u32 entity : changed_) visit(entity);
115 all_changed_ =
false;
121 std::map<u32, RetainedText>&
entries() {
return entries_; }
124 std::map<u32, RetainedText> entries_;
126 std::vector<u32> changed_;
127 bool all_changed_ =
false;
133 constexpr double BITMAP_SCALE_EPSILON = 0.02;
134 const double scale = worldScaleX;
135 if (!std::isfinite(scale) || scale <= 0.0)
return false;
136 return std::abs(scale - 1.0) > BITMAP_SCALE_EPSILON;
146 constexpr double ROUNDING_MARGIN = 8.0 / 8388608.0;
147 for (
int i = 0; i < 16; ++i) {
148 if (!std::isfinite(view[i]) || !std::isfinite(model[i]))
return false;
150 for (
int plane = 0; plane < 6; ++plane) {
151 const int row = plane >> 1;
152 const double sign = plane % 2 == 0 ? 1.0 : -1.0;
153 for (
int slot = 0; slot < 3; ++slot) {
154 const int column = slot == 2 ? 12 : slot * 4;
155 double value = 0.0, error = 0.0;
156 for (
int k = 0; k < 4; ++k) {
157 const double a = view[k * 4 + 3], b = view[k * 4 + row];
158 value += (a + sign * b) * model[column + k];
159 error += (std::abs(a) + std::abs(b)) * std::abs(
static_cast<double>(model[column + k]));
161 out[plane * 6 + slot] = value;
162 out[plane * 6 + slot + 3] = error * ROUNDING_MARGIN;
170 if (!std::isfinite(left) || !std::isfinite(bottom) || !std::isfinite(right) || !std::isfinite(top))
return 1;
172 const double x = std::max(std::abs(left), std::abs(right)), y = std::max(std::abs(bottom), std::abs(top));
173 for (
int p = 0; p < 36; p += 6) {
174 const double a = planes[p], b = planes[p + 1], c = planes[p + 2];
175 const double margin = planes[p + 3] * x + planes[p + 4] * y + planes[p + 5];
176 const double lo = a * (a >= 0 ? left : right) + b * (b >= 0 ? bottom : top) + c;
177 const double hi = a * (a >= 0 ? right : left) + b * (b >= 0 ? top : bottom) + c;
178 if (hi < -margin)
return 0;
179 if (lo < margin) inside =
false;
181 return inside ? 1 : 2;
198 scratch.
visible.assign(count, 0);
200 u32 visibleCount = 0;
207 std::fill(scratch.
visible.begin() + start, scratch.
visible.begin() + end,
static_cast<u8>(status));
208 if (status == 1) visibleCount += end - start;
211 for (
u32 quad = start; quad < end; ++quad) {
215 const bool survives =
retainedTextClassify(planes, std::min(x0, x1), std::min(y0, y1), std::max(x0, x1), std::max(y0, y1)) != 0;
216 scratch.
visible[quad] = survives ? 1 : 0;
217 if (survives) ++visibleCount;
223 scratch.
indices.resize(
static_cast<usize>(visibleCount) * 6);
228 for (
u32 quad = start; quad < end; ++quad) {
229 if (!scratch.
visible[quad])
continue;
232 const u16 base =
static_cast<u16>(output * 4), sourceBase =
static_cast<u16>(quad * 4);
233 for (
u32 i = 0; i < 6; ++i) scratch.
indices[
static_cast<usize>(output) * 6 + i] =
static_cast<u16>(batch.
indices[
static_cast<usize>(quad) * 6 + i] - sourceBase + base);
Core type definitions and utilities for ESEngine.
The retained geometry of every label, by entity. Ordered: a frame submits in entity order,...
bool takeChanged(Visit &&visit)
Hands visit every label laid out, given glyphs or let go since the last call, and forgets them; false...
u64 revision() const
Moves with every label laid out, given glyphs or let go: what a pass drawn from the store was drawn f...
bool add(u32 entity, const f32 *vertices, i32 vertexCount, const u16 *indices, i32 indexCount, u32 pageId, TextGlyphMode mode=TextGlyphMode::Color)
One batch of an entity begun with begin(). False when it was not begun or the batch is not whole quad...
std::map< u32, RetainedText > & entries()
void begin(u32 entity, bool sdf, bool screen, bool hasBox, i32 layer, f32 boxWidth, f32 boxHeight, bool autoKind=false)
Replaces any geometry the entity held, with none yet: batches follow through add().
std::int32_t i32
Signed 32-bit integer.
constexpr u32 RETAINED_TEXT_BLOCK_QUADS
Quads in one bounds block: a view that misses the whole block does not look at its quads.
std::uint64_t u64
Unsigned 64-bit integer.
constexpr i32 TEXT_VERTEX_FLOATS
std::size_t usize
Size type for indexing and sizes.
RetainedTextKept
What a view keeps of a batch: nothing, all of it (read the batch itself), or a subset copied into scr...
RetainedTextKept retainedTextClip(const RetainedTextBatch &batch, const double *planes, RetainedTextClip &scratch)
constexpr u32 RETAINED_TEXT_QUAD_FLOATS
bool retainedTextAutoIsSdf(f32 worldScaleX)
std::uint32_t u32
Unsigned 32-bit integer.
bool retainedTextClipPlanes(double *out, const f32 *view, const f32 *model)
std::uint8_t u8
Unsigned 8-bit integer.
@ Color
The page's RGBA, tinted: a rasterized atlas that carries native-AA coverage in alpha,...
std::uint16_t u16
Unsigned 16-bit integer.
int retainedTextClassify(const double *planes, double left, double bottom, double right, double top)
0 outside, 1 inside, 2 crossing a clip plane. Non-finite bounds stay visible.
float f32
32-bit floating point
std::vector< f32 > blocks
left, bottom, right, top of each RETAINED_TEXT_BLOCK_QUADS quads.
std::vector< f32 > vertices
TEXT_VERTEX_FLOATS floats a vertex, four a quad.
TextGlyphMode mode
How the page's pixels become coverage. A label may mix them: an outline's ring, then its fill.
std::vector< u16 > indices
Six a quad, naming this batch's own vertices.
u32 pageId
The atlas page, which is the draw's texture.
Where the quads a view keeps are copied to, reused across batches and frames.
std::vector< f32 > vertices
std::vector< u8 > visible
std::vector< u8 > blockVisibility
std::vector< u16 > indices
f32 boxWidth
The box the layout used: a label whose box has since changed is stale.
bool hasBox
Laid out in a UINode box, so ordered by the UI tree rather than by layer.
std::vector< RetainedTextBatch > batches
bool screen
The domain the geometry was laid out for.
bool sdf
The pipeline the label's glyphs were chosen for, by world scale (autoKind). What each batch draws wit...
bool autoKind
The glyph pipeline was chosen from the entity's world scale, so a changed scale can change it.
i32 layer
Text.layer, for a label with no box.