@@ -354,13 +354,10 @@ void CanvasRenderer::CreatePermanentResources()
354
354
355
355
void CanvasRenderer::UpdatePanelVertices (ECS::Components::Transform2D& transform, ECS::Components::UI::Panel& panel, ECS::Components::UI::PanelTemplate& panelTemplate)
356
356
{
357
- std::vector<vec4>& vertices = _vertices.Get ();
358
-
359
357
// Add vertices if necessary
360
358
if (panel.gpuVertexIndex == -1 )
361
359
{
362
- panel.gpuVertexIndex = static_cast <i32>(vertices.size ());
363
- vertices.resize (vertices.size () + 6 ); // TODO: Indexing?
360
+ panel.gpuVertexIndex = _vertices.AddCount (6 );
364
361
}
365
362
366
363
const vec2 min = panelTemplate.texCoords .min ;
@@ -380,19 +377,19 @@ void CanvasRenderer::UpdatePanelVertices(ECS::Components::Transform2D& transform
380
377
vec2 size = PixelSizeToNDC (transform.GetSize ());
381
378
382
379
// Triangle 1
383
- vertices [panel.gpuVertexIndex + 0 ] = vec4 (position, panelUVs[0 ]);
384
- vertices [panel.gpuVertexIndex + 1 ] = vec4 (position + vec2 (size.x , size.y ), panelUVs[1 ]);
385
- vertices [panel.gpuVertexIndex + 2 ] = vec4 (position + vec2 (size.x , 0 ), panelUVs[2 ]);
380
+ _vertices [panel.gpuVertexIndex + 0 ] = vec4 (position, panelUVs[0 ]);
381
+ _vertices [panel.gpuVertexIndex + 1 ] = vec4 (position + vec2 (size.x , size.y ), panelUVs[1 ]);
382
+ _vertices [panel.gpuVertexIndex + 2 ] = vec4 (position + vec2 (size.x , 0 ), panelUVs[2 ]);
386
383
387
384
// Triangle 2
388
- vertices [panel.gpuVertexIndex + 3 ] = vec4 (position + vec2 (0 , size.y ), panelUVs[3 ]);
389
- vertices [panel.gpuVertexIndex + 4 ] = vec4 (position + vec2 (size.x , size.y ), panelUVs[4 ]);
390
- vertices [panel.gpuVertexIndex + 5 ] = vec4 (position, panelUVs[5 ]);
385
+ _vertices [panel.gpuVertexIndex + 3 ] = vec4 (position + vec2 (0 , size.y ), panelUVs[3 ]);
386
+ _vertices [panel.gpuVertexIndex + 4 ] = vec4 (position + vec2 (size.x , size.y ), panelUVs[4 ]);
387
+ _vertices [panel.gpuVertexIndex + 5 ] = vec4 (position, panelUVs[5 ]);
391
388
392
389
_vertices.SetDirtyElements (panel.gpuVertexIndex , 6 );
393
390
}
394
391
395
- void CalculateVertices (const vec4& pos, const vec4& uv, std::vector <vec4>& vertices, u32 vertexIndex)
392
+ void CalculateVertices (const vec4& pos, const vec4& uv, Renderer::GPUVector <vec4>& vertices, u32 vertexIndex)
396
393
{
397
394
const f32& posLeft = pos.x ;
398
395
const f32& posBottom = pos.y ;
@@ -415,8 +412,6 @@ void CalculateVertices(const vec4& pos, const vec4& uv, std::vector<vec4>& verti
415
412
416
413
void CanvasRenderer::UpdateTextVertices (ECS::Components::Transform2D& transform, ECS::Components::UI::Text& text, ECS::Components::UI::TextTemplate& textTemplate)
417
414
{
418
- std::vector<vec4>& vertices = _vertices.Get ();
419
-
420
415
if (text.text .size () == 0 )
421
416
{
422
417
return ;
@@ -452,9 +447,7 @@ void CanvasRenderer::UpdateTextVertices(ECS::Components::Transform2D& transform,
452
447
if (text.gpuVertexIndex == -1 || text.hasGrown )
453
448
{
454
449
u32 numVertices = text.numCharsNonWhitespace * 6 ;
455
-
456
- text.gpuVertexIndex = static_cast <i32>(vertices.size ());
457
- vertices.resize (vertices.size () + numVertices);
450
+ text.gpuVertexIndex = _vertices.AddCount (numVertices);
458
451
}
459
452
460
453
vec2 worldPos = transform.GetWorldPosition ();
@@ -531,7 +524,7 @@ void CanvasRenderer::UpdateTextVertices(ECS::Components::Transform2D& transform,
531
524
atlasTop *= texelSize.y ;
532
525
533
526
// Add vertices
534
- CalculateVertices (vec4 (planeMin, planeMax), vec4 (atlasLeft, atlasBottom, atlasRight, atlasTop), vertices , vertexIndex);
527
+ CalculateVertices (vec4 (planeMin, planeMax), vec4 (atlasLeft, atlasBottom, atlasRight, atlasTop), _vertices , vertexIndex);
535
528
vertexIndex += 6 ;
536
529
}
537
530
@@ -546,19 +539,16 @@ void CanvasRenderer::UpdateTextVertices(ECS::Components::Transform2D& transform,
546
539
547
540
void CanvasRenderer::UpdatePanelData (ECS::Components::Transform2D& transform, Panel& panel, ECS::Components::UI::PanelTemplate& panelTemplate)
548
541
{
549
- std::vector<PanelDrawData>& panelDrawDatas = _panelDrawDatas.Get ();
550
-
551
542
// Add draw data if necessary
552
543
if (panel.gpuDataIndex == -1 )
553
544
{
554
- panel.gpuDataIndex = static_cast <i32>(panelDrawDatas.size ());
555
- panelDrawDatas.resize (panelDrawDatas.size () + 1 );
545
+ panel.gpuDataIndex = _panelDrawDatas.Add ();
556
546
}
557
547
vec2 size = transform.GetSize ();
558
548
vec2 cornerRadius = vec2 (panelTemplate.cornerRadius / size.x , panelTemplate.cornerRadius /size.y );
559
549
560
550
// Update draw data
561
- auto & drawData = panelDrawDatas [panel.gpuDataIndex ];
551
+ auto & drawData = _panelDrawDatas [panel.gpuDataIndex ];
562
552
drawData.packed .z = panelTemplate.color .ToRGBA32 ();
563
553
drawData.cornerRadiusAndBorder = vec4 (cornerRadius, 0 .0f , 0 .0f );
564
554
@@ -635,8 +625,6 @@ void CanvasRenderer::UpdatePanelData(ECS::Components::Transform2D& transform, Pa
635
625
636
626
void CanvasRenderer::UpdateTextData (Text& text, ECS::Components::UI::TextTemplate& textTemplate)
637
627
{
638
- std::vector<CharDrawData>& charDrawDatas = _charDrawDatas.Get ();
639
-
640
628
if (text.sizeChanged )
641
629
{
642
630
// Count how many non whitspace characters there are
@@ -665,8 +653,7 @@ void CanvasRenderer::UpdateTextData(Text& text, ECS::Components::UI::TextTemplat
665
653
// Add or update draw data if necessary
666
654
if (text.gpuDataIndex == -1 || text.hasGrown )
667
655
{
668
- text.gpuDataIndex = static_cast <i32>(charDrawDatas.size ());
669
- charDrawDatas.resize (charDrawDatas.size () + text.numCharsNonWhitespace );
656
+ text.gpuDataIndex = _charDrawDatas.AddCount (text.numCharsNonWhitespace );
670
657
}
671
658
672
659
// Update CharDrawData
@@ -702,7 +689,7 @@ void CanvasRenderer::UpdateTextData(Text& text, ECS::Components::UI::TextTemplat
702
689
continue ;
703
690
}
704
691
705
- auto & drawData = charDrawDatas [text.gpuDataIndex + charIndex];
692
+ auto & drawData = _charDrawDatas [text.gpuDataIndex + charIndex];
706
693
drawData.packed0 .x = fontTextureIndex;
707
694
drawData.packed0 .y = charIndex;
708
695
drawData.packed0 .z = textTemplate.color .ToRGBA32 ();
0 commit comments