| 411 | } |
| 412 | |
| 413 | void Renderer::DrawFullScreenQuad(ID3D11ShaderResourceView* texture, Vector3 color, bool fit, float customAspect) |
| 414 | { |
| 415 | constexpr auto VERTEX_COUNT = 4; |
| 416 | constexpr auto UV_RANGE = std::pair<Vector2, Vector2>(Vector2(0.0f), Vector2(1.0f)); |
| 417 | |
| 418 | auto uvStart = Vector2::Zero; |
| 419 | auto uvEnd = Vector2::One; |
| 420 | |
| 421 | if (fit) |
| 422 | { |
| 423 | ID3D11Texture2D* texture2DPtr; |
| 424 | texture->GetResource(reinterpret_cast<ID3D11Resource**>(&texture2DPtr)); |
| 425 | |
| 426 | auto desc = D3D11_TEXTURE2D_DESC(); |
| 427 | texture2DPtr->GetDesc(&desc); |
| 428 | |
| 429 | float screenAspect = float(_screenWidth) / float(_screenHeight); |
| 430 | float imageAspect = customAspect == 0.0f ? float(desc.Width) / float(desc.Height) : customAspect; |
| 431 | |
| 432 | if (screenAspect > imageAspect) |
| 433 | { |
| 434 | float diff = ((screenAspect - imageAspect) / screenAspect) / 2; |
| 435 | uvStart.y += diff; |
| 436 | uvEnd.y -= diff; |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | float diff = ((imageAspect - screenAspect) / imageAspect) / 2; |
| 441 | uvStart.x += diff; |
| 442 | uvEnd.x -= diff; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | auto vertices = std::array<Vertex, VERTEX_COUNT>{}; |
| 447 | auto colorVec4 = Vector4(color.x, color.y, color.z, 1.0f); |
| 448 | |
| 449 | vertices[0].Position = Vector3(-1.0f, 1.0f, 0.0f); |
| 450 | vertices[0].UV.x = uvStart.x; |
| 451 | vertices[0].UV.y = uvStart.y; |
| 452 | vertices[0].Color = VectorColorToRGBA_TempToVector4(colorVec4); |
| 453 | |
| 454 | vertices[1].Position = Vector3(1.0f, 1.0f, 0.0f); |
| 455 | vertices[1].UV.x = uvEnd.x; |
| 456 | vertices[1].UV.y = uvStart.y; |
| 457 | vertices[1].Color = VectorColorToRGBA_TempToVector4(colorVec4); |
| 458 | |
| 459 | vertices[2].Position = Vector3(1.0f, -1.0f, 0.0f); |
| 460 | vertices[2].UV.x = uvEnd.x; |
| 461 | vertices[2].UV.y = uvEnd.y; |
| 462 | vertices[2].Color = VectorColorToRGBA_TempToVector4(colorVec4); |
| 463 | |
| 464 | vertices[3].Position = Vector3(-1.0f, -1.0f, 0.0f); |
| 465 | vertices[3].UV.x = uvStart.x; |
| 466 | vertices[3].UV.y = uvEnd.y; |
| 467 | vertices[3].Color = VectorColorToRGBA_TempToVector4(colorVec4); |
| 468 | |
| 469 | _shaders.Bind(Shader::FullScreenQuad); |
| 470 | |