10#include <glm/gtc/type_ptr.hpp>
16#include <glm/gtc/type_ptr.hpp>
23 const glm::vec2& position,
const glm::vec2& size,
24 const glm::vec2& uvOffset,
const glm::vec2& uvScale,
25 const glm::vec4& color,
u32 textureId,
28 f32 hw = size.x * 0.5f;
29 f32 hh = size.y * 0.5f;
33 { {position.x - hw, position.y - hh, depth}, pc, uvOffset },
34 { {position.x + hw, position.y - hh, depth}, pc, {uvOffset.x + uvScale.x, uvOffset.y} },
35 { {position.x + hw, position.y + hh, depth}, pc, {uvOffset.x + uvScale.x, uvOffset.y + uvScale.y} },
36 { {position.x - hw, position.y + hh, depth}, pc, {uvOffset.x, uvOffset.y + uvScale.y} },
40 .stage = current_stage_,
42 .shaderId = batch_shader_id_,
44 .textureId = textureId,
54 static std::vector<f32> faded;
57 for (
auto& [raw,
text] : retained_text_.entries()) {
58 if (
text.screen != screen)
continue;
59 if (onlyRoot != 0 && screenRootAt(raw) != onlyRoot)
continue;
61 if (!registry.
valid(entity))
continue;
63 if (node && node->hidden_in_tree_)
continue;
64 const f32 opacity = (node ? node->alpha_in_tree_ : 1.0f) * groupOpacity.
of(entity);
65 if (opacity <= 0.0f)
continue;
71 const i32 order = visual ? visual->uiOrder : -1;
78 transform->ensureDecomposed();
79 depth = transform->worldPosition.z;
82 const u32 cullBit = visual ? visual->uiCullBit : 0u;
83 const f32* model = glm::value_ptr(matrix);
91 if (opacity != 1.0f) {
94 vertices = faded.data();
96 submitTextBatch(vertices,
static_cast<i32>(vertexCount), indices,
static_cast<i32>(vertexCount / 4 * 6),
97 batch.
pageId, model, entity, layer, depth, batch.
mode, cullBit);
103 const f32* vertices,
i32 vertexCount,
104 const u16* indices,
i32 indexCount,
105 u32 textureId,
const f32* transform16,
108 if (vertexCount <= 0 || indexCount <= 0
111 glm::mat4 model = glm::make_mat4(transform16);
118 for (
i32 i = 0; i < vertexCount; ++i) {
120 glm::vec4 worldPos = model * glm::vec4(v[0], v[1], 0.0f, 1.0f);
122 dst[i] = { {worldPos.x, worldPos.y, worldPos.z}, pc, {v[2], v[3]}, glyphMode, v[8] };
125 pushBatchCommand(pool_, draw_list_, clip_state_, vOff,
static_cast<u32>(vertexCount), indices,
127 .stage = current_stage_,
129 .shaderId = batch_shader_id_,
131 .textureId = textureId,
140 const f32* vertices,
i32 vertexCount,
141 const u16* indices,
i32 indexCount,
142 u32 textureId,
i32 blendMode,
143 const f32* transform16,
144 Entity entity,
i32 layer,
f32 depth,
u32 materialId,
bool premultipliedColor,
145 f32 treeAlpha,
u32 cullBit
150 const bool screen = screen_domain_ && screen_domain_->count(entity.
id()) != 0;
151 if (screen != overlay_active_)
return;
152 if (layer == 0 && ui_tree_layers_) {
153 if (
const auto it = ui_tree_layers_->find(entity.
id()); it != ui_tree_layers_->end()) layer = it->second;
155 if (vertexCount <= 0 || indexCount <= 0 || treeAlpha <= 0.0f
158 constexpr i32 FLOATS_PER_VERTEX = 8;
159 glm::mat4 model = glm::make_mat4(transform16);
162 const MaterialRecord* material = materialId != 0 ? context_.materials().find(materialId) :
nullptr;
163 const bool builtinColor = !material || material->
shader == 0;
171 for (
i32 i = 0; i < vertexCount; ++i) {
172 const f32* v = vertices + i * FLOATS_PER_VERTEX;
173 glm::vec4 worldPos = model * glm::vec4(v[0], v[1], 0.0f, 1.0f);
175 glm::vec4 color = glm::vec4(v[4], v[5], v[6], v[7]) * (premultipliedColor ? glm::vec4(treeAlpha) : glm::vec4(1.0f, 1.0f, 1.0f, treeAlpha));
176 if (premultipliedColor && builtinColor) {
178 color = color.a > 0.0f ? glm::vec4(glm::vec3(color) / color.a, color.a)
182 dst[i] = { {worldPos.x, worldPos.y, worldPos.z}, pc, {v[2], v[3]} };
185 const u32 defaultShader = !builtinColor ? material->
shader
188 .stage = current_stage_,
190 .shaderId = defaultShader,
192 .textureId = textureId,
201 if (materialId != 0) {
203 key.
shaderId = (m->shader != 0) ? m->shader : defaultShader;
204 key.
blend = m->blend;
208 key.
cull =
static_cast<u8>(m->cull);
212 pushBatchCommand(pool_, draw_list_, clip_state_, vOff,
static_cast<u32>(vertexCount), indices,
213 static_cast<u32>(indexCount), key);
The single submission face: the ONLY place a DrawCommand is assembled.
Rendering context containing all renderer state.
Frame resources and the shared scene rendering contract.
void submitTileQuad(const glm::vec2 &position, const glm::vec2 &size, const glm::vec2 &uvOffset, const glm::vec2 &uvScale, const glm::vec4 &color, u32 textureId, Entity entity, i32 layer, f32 depth)
void submitRetainedText(ecs::Registry ®istry, bool screen, const f32 *projection, u32 onlyRoot=0)
Every retained label laid out for one domain into the open list, culled against projection (world,...
void submitSkeletalBatch(const f32 *vertices, i32 vertexCount, const u16 *indices, i32 indexCount, u32 textureId, i32 blendMode, const f32 *transform16, Entity entity, i32 layer, f32 depth, u32 materialId=0, bool premultipliedColor=false, f32 treeAlpha=1.0f, u32 cullBit=0)
Batch vertices posed by a skeletal runtime, drawn as one entity's geometry.
u32 batchProgram(BatchVariant variant)
void submitTextBatch(const f32 *vertices, i32 vertexCount, const u16 *indices, i32 indexCount, u32 textureId, const f32 *transform16, Entity entity, i32 layer, f32 depth, TextGlyphMode mode, u32 cullBit=0)
static constexpr i32 UI_BASE_LAYER
The opacity a draw inherits from the GroupOpacity above it.
f32 of(Entity entity) const
1 when no enabled group encloses entity (itself included).
Central container for all entities and components.
bool valid(Entity entity) const
Checks if an entity is currently valid.
T * tryGet(Entity entity)
Tries to get a component from an entity.
bool copyFlatRenderMatrix(Registry ®istry, Entity entity, glm::mat4 &output)
void appendQuad(TransientBufferPool &pool, DrawList &drawList, const ClipState &clips, const BatchVertex quad[4], const BatchDrawKey &key)
std::int32_t i32
Signed 32-bit integer.
i32 batchGlyphModeBits(TextGlyphMode mode)
constexpr i32 TEXT_VERTEX_FLOATS
std::size_t usize
Size type for indexing and sizes.
u32 packColor(f32 r, f32 g, f32 b, f32 a)
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)
std::uint32_t u32
Unsigned 32-bit integer.
bool retainedTextClipPlanes(double *out, const f32 *view, const f32 *model)
BlendMode
Predefined blend modes for rendering.
std::uint8_t u8
Unsigned 8-bit integer.
std::uint16_t u16
Unsigned 16-bit integer.
void pushBatchCommand(TransientBufferPool &pool, DrawList &drawList, const ClipState &clips, u32 vertexByteOffset, u32 vertexCount, const u32 *localIndices, u32 indexCount, const BatchDrawKey &key)
Pushes a DrawCommand for vertices ALREADY resident in the Batch stream at vertexByteOffset.
bool batchEntityVisible(const DrawList &drawList, const ClipState &clips, Entity entity, i32 layer, u32 cullBit)
float f32
32-bit floating point
Non-geometry attributes of a batch draw — everything needed to build the sort key + DrawCommand.
u8 cull
CullMode: 0 = none, 1 = back, 2 = front.
One vertex of the shared batch stream.
Entity identifier with packed index + generation.
constexpr u32 id() const
Returns the raw packed value for FFI serialization.
static constexpr Entity fromRaw(u32 v)
Reconstructs an Entity from a raw packed value.
A material's resolved render state (P0) plus its packed std140 constants (P1).
u32 shader
Program id; 0 means "use the path's default batch shader".
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< u16 > indices
UINode — the CSS box-model layout input (the CSS/Flex primary layout model).
UIVisual — the single UI visual component, merging the former low-level UIRenderer (what the renderer...