MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / DrawFullScreenSprite

Method DrawFullScreenSprite

TombEngine/Renderer/RendererDraw2D.cpp:484–558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

482 }
483
484 void Renderer::DrawFullScreenSprite(RendererSprite* sprite, DirectX::SimpleMath::Vector3 color, bool fit)
485 {
486 Vector2 uvStart = { 0.0f, 0.0f };
487 Vector2 uvEnd = { 1.0f, 1.0f };
488
489 ID3D11ShaderResourceView* texture = sprite->Texture->ShaderResourceView.Get();
490
491 if (fit)
492 {
493 float screenAspect = float(_screenWidth) / float(_screenHeight);
494 float imageAspect = float(sprite->Width) / float(sprite->Height);
495
496 if (screenAspect > imageAspect)
497 {
498 float diff = (screenAspect - imageAspect) / screenAspect / 2;
499 uvStart.y += diff;
500 uvEnd.y -= diff;
501 }
502 else
503 {
504 float diff = (imageAspect - screenAspect) / imageAspect / 2;
505 uvStart.x += diff;
506 uvEnd.x -= diff;
507 }
508 }
509
510 auto scale = Vector2(sprite->Width / (float)sprite->Texture->Width, sprite->Height / (float)sprite->Texture->Height);
511 uvStart.x = uvStart.x * scale.x + sprite->UV[0].x;
512 uvStart.y = uvStart.y * scale.y + sprite->UV[0].y;
513 uvEnd.x = uvEnd.x * scale.x + sprite->UV[0].x;
514 uvEnd.y = uvEnd.y * scale.y + sprite->UV[0].y;
515
516 Vertex vertices[4];
517
518 vertices[0].Position.x = -1.0f;
519 vertices[0].Position.y = 1.0f;
520 vertices[0].Position.z = 0.0f;
521 vertices[0].UV.x = uvStart.x;
522 vertices[0].UV.y = uvStart.y;
523 vertices[0].Color = VectorColorToRGBA_TempToVector4(Vector4(color.x, color.y, color.z, 1.0f));
524
525 vertices[1].Position.x = 1.0f;
526 vertices[1].Position.y = 1.0f;
527 vertices[1].Position.z = 0.0f;
528 vertices[1].UV.x = uvEnd.x;
529 vertices[1].UV.y = uvStart.y;
530 vertices[1].Color = VectorColorToRGBA_TempToVector4(Vector4(color.x, color.y, color.z, 1.0f));
531
532 vertices[2].Position.x = 1.0f;
533 vertices[2].Position.y = -1.0f;
534 vertices[2].Position.z = 0.0f;
535 vertices[2].UV.x = uvEnd.x;
536 vertices[2].UV.y = uvEnd.y;
537 vertices[2].Color = VectorColorToRGBA_TempToVector4(Vector4(color.x, color.y, color.z, 1.0f));
538
539 vertices[3].Position.x = -1.0f;
540 vertices[3].Position.y = -1.0f;
541 vertices[3].Position.z = 0.0f;

Callers

nothing calls this directly

Calls 5

BindMethod · 0.80
Vector2Function · 0.50
Vector4Function · 0.50
GetMethod · 0.45

Tested by

no test coverage detected