@@ -67,7 +67,7 @@ bool TextContents::Render(const ContentContext& renderer,
6767
6868 // Information shared by all glyph draw calls.
6969 Command cmd;
70- cmd.label = " Glyph " ;
70+ cmd.label = " TextRun " ;
7171 cmd.primitive_type = PrimitiveType::kTriangle ;
7272 cmd.pipeline =
7373 renderer.GetGlyphAtlasPipeline (OptionsFromPassAndEntity (pass, entity));
@@ -121,8 +121,20 @@ bool TextContents::Render(const ContentContext& renderer,
121121 cmd.BindVertices (std::move (vertex_buffer));
122122 }
123123
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+
124130 // Iterate through all the runs in the blob.
125131 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+
126138 auto font = run.GetFont ();
127139 auto glyph_size = ISize::Ceil (font.GetMetrics ().GetBoundingBox ().size );
128140 // Draw each glyph individually. This should probably be batched.
@@ -133,21 +145,29 @@ bool TextContents::Render(const ContentContext& renderer,
133145 VALIDATION_LOG << " Could not find glyph position in the atlas." ;
134146 return false ;
135147 }
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+ }
136157
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 ;
151171 }
152172 }
153173
0 commit comments