@@ -106,65 +106,41 @@ bool TextContents::Render(const ContentContext& renderer,
106106 // and the vertex shader uses this to size the glyph correctly. The
107107 // interpolated vertex information is also used in the fragment shader to
108108 // sample from the glyph atlas.
109- {
110- VertexBufferBuilder<VS::PerVertexData> vertex_builder;
111- if (!Tessellator{}.Tessellate (
112- FillType::kPositive ,
113- PathBuilder{}
114- .AddRect (Rect::MakeXYWH (0.0 , 0.0 , 1.0 , 1.0 ))
115- .TakePath ()
116- .CreatePolyline (),
117- [&vertex_builder](Point point) {
118- VS::PerVertexData vtx;
119- vtx.unit_vertex = point;
120- vertex_builder.AppendVertex (std::move (vtx));
121- })) {
122- return false ;
123- }
124- auto dummy = vertex_builder.CreateVertexBuffer (pass.GetTransientsBuffer ());
125- auto vertex_buffer = dummy;
126- if (!vertex_buffer) {
127- return false ;
128- }
129- cmd.BindVertices (std::move (vertex_buffer));
130- }
131109
132- size_t instance_count = 0u ;
133- std::vector<Matrix> glyph_positions;
134- std::vector<Point> glyph_sizes;
135- std::vector<Point> atlas_positions;
136- std::vector<Point> atlas_glyph_sizes;
110+ const std::vector<Point> unit_vertex_points = {
111+ {0 , 0 }, {1 , 0 }, {0 , 1 }, {1 , 0 }, {0 , 1 }, {1 , 1 },
112+ };
137113
114+ VertexBufferBuilder<VS::PerVertexData> vertex_builder;
138115 for (const auto & run : frame_.GetRuns ()) {
139116 auto font = run.GetFont ();
140117 auto glyph_size = ISize::Ceil (font.GetMetrics ().GetBoundingBox ().size );
141118 for (const auto & glyph_position : run.GetGlyphPositions ()) {
142- FontGlyphPair font_glyph_pair{font, glyph_position.glyph };
143- auto atlas_glyph_pos = atlas->FindFontGlyphPosition (font_glyph_pair);
144- if (!atlas_glyph_pos.has_value ()) {
145- VALIDATION_LOG << " Could not find glyph position in the atlas." ;
146- return false ;
119+ for (const auto & point : unit_vertex_points) {
120+ VS::PerVertexData vtx;
121+ vtx.unit_vertex = point;
122+
123+ FontGlyphPair font_glyph_pair{font, glyph_position.glyph };
124+ auto atlas_glyph_pos = atlas->FindFontGlyphPosition (font_glyph_pair);
125+ if (!atlas_glyph_pos.has_value ()) {
126+ VALIDATION_LOG << " Could not find glyph position in the atlas." ;
127+ return false ;
128+ }
129+ vtx.glyph_position =
130+ glyph_position.position +
131+ Point{font.GetMetrics ().min_extent .x , font.GetMetrics ().ascent };
132+ vtx.glyph_size = Point{static_cast <Scalar>(glyph_size.width ),
133+ static_cast <Scalar>(glyph_size.height )};
134+ vtx.atlas_position = atlas_glyph_pos->origin ;
135+ vtx.atlas_glyph_size =
136+ Point{atlas_glyph_pos->size .width , atlas_glyph_pos->size .height };
137+ vertex_builder.AppendVertex (std::move (vtx));
147138 }
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 });
156139 }
157140 }
158-
159- cmd.instance_count = instance_count;
160- VS::BindGlyphPositions (
161- cmd, pass.GetTransientsBuffer ().EmplaceStorageBuffer (glyph_positions));
162- VS::BindGlyphSizes (
163- cmd, pass.GetTransientsBuffer ().EmplaceStorageBuffer (glyph_sizes));
164- VS::BindAtlasPositions (
165- cmd, pass.GetTransientsBuffer ().EmplaceStorageBuffer (atlas_positions));
166- VS::BindAtlasGlyphSizes (
167- cmd, pass.GetTransientsBuffer ().EmplaceStorageBuffer (atlas_glyph_sizes));
141+ auto vertex_buffer =
142+ vertex_builder.CreateVertexBuffer (pass.GetTransientsBuffer ());
143+ cmd.BindVertices (std::move (vertex_buffer));
168144
169145 if (!pass.AddCommand (cmd)) {
170146 return false ;
0 commit comments