@@ -67,7 +67,7 @@ bool TextContents::Render(const ContentContext& renderer,
67
67
68
68
// Information shared by all glyph draw calls.
69
69
Command cmd;
70
- cmd.label = " Glyph " ;
70
+ cmd.label = " TextRun " ;
71
71
cmd.primitive_type = PrimitiveType::kTriangle ;
72
72
cmd.pipeline =
73
73
renderer.GetGlyphAtlasPipeline (OptionsFromPassAndEntity (pass, entity));
@@ -121,8 +121,20 @@ bool TextContents::Render(const ContentContext& renderer,
121
121
cmd.BindVertices (std::move (vertex_buffer));
122
122
}
123
123
124
+ size_t instance_count = 0u ;
125
+ std::vector<Matrix> glyph_positions;
126
+ std::vector<Point > glyph_sizes;
127
+ std::vector<Point > atlas_positions;
128
+ std::vector<Point > atlas_glyph_sizes;
129
+
124
130
// Iterate through all the runs in the blob.
125
131
for (const auto & run : frame_.GetRuns ()) {
132
+ instance_count = 0u ;
133
+ glyph_positions.clear ();
134
+ glyph_sizes.clear ();
135
+ atlas_positions.clear ();
136
+ atlas_glyph_sizes.clear ();
137
+
126
138
auto font = run.GetFont ();
127
139
auto glyph_size = ISize::Ceil (font.GetMetrics ().GetBoundingBox ().size );
128
140
// Draw each glyph individually. This should probably be batched.
@@ -133,21 +145,29 @@ bool TextContents::Render(const ContentContext& renderer,
133
145
VALIDATION_LOG << " Could not find glyph position in the atlas." ;
134
146
return false ;
135
147
}
148
+ instance_count++;
149
+ glyph_positions.emplace_back (glyph_position.position .Translate (
150
+ {font.GetMetrics ().min_extent .x , font.GetMetrics ().ascent , 0.0 }));
151
+ glyph_sizes.emplace_back (Point {static_cast <Scalar>(glyph_size.width ),
152
+ static_cast <Scalar>(glyph_size.height )});
153
+ atlas_positions.emplace_back (atlas_glyph_pos->origin );
154
+ atlas_glyph_sizes.emplace_back (
155
+ Point {atlas_glyph_pos->size .width , atlas_glyph_pos->size .height });
156
+ }
136
157
137
- VS::GlyphInfo glyph_info;
138
- glyph_info.position = glyph_position.position .Translate (
139
- {font.GetMetrics ().min_extent .x , font.GetMetrics ().ascent , 0.0 });
140
- glyph_info.glyph_size = {static_cast <Scalar>(glyph_size.width ),
141
- static_cast <Scalar>(glyph_size.height )};
142
- glyph_info.atlas_position = atlas_glyph_pos->origin ;
143
- glyph_info.atlas_glyph_size = {atlas_glyph_pos->size .width ,
144
- atlas_glyph_pos->size .height };
145
- VS::BindGlyphInfo (cmd,
146
- pass.GetTransientsBuffer ().EmplaceUniform (glyph_info));
147
-
148
- if (!pass.AddCommand (cmd)) {
149
- return false ;
150
- }
158
+ cmd.instance_count = instance_count;
159
+ VS::BindGlyphPositions (
160
+ cmd, pass.GetTransientsBuffer ().EmplaceStorageBuffer (glyph_positions));
161
+ VS::BindGlyphSizes (
162
+ cmd, pass.GetTransientsBuffer ().EmplaceStorageBuffer (glyph_sizes));
163
+ VS::BindAtlasPositions (
164
+ cmd, pass.GetTransientsBuffer ().EmplaceStorageBuffer (atlas_positions));
165
+ VS::BindAtlasGlyphSizes (
166
+ cmd,
167
+ pass.GetTransientsBuffer ().EmplaceStorageBuffer (atlas_glyph_sizes));
168
+
169
+ if (!pass.AddCommand (cmd)) {
170
+ return false ;
151
171
}
152
172
}
153
173
0 commit comments