| 668 | } |
| 669 | |
| 670 | void Texture::generateMips(RenderContext* pContext, bool minMaxMips) |
| 671 | { |
| 672 | if (mType != Type::Texture2D) |
| 673 | { |
| 674 | logWarning("Texture::generateMips() was only tested with Texture2Ds"); |
| 675 | } |
| 676 | |
| 677 | // #OPTME: should blit support arrays? |
| 678 | for (uint32_t m = 0; m < mMipLevels - 1; m++) |
| 679 | { |
| 680 | for (uint32_t a = 0; a < mArraySize; a++) |
| 681 | { |
| 682 | auto srv = getSRV(m, 1, a, 1); |
| 683 | auto rtv = getRTV(m + 1, a, 1); |
| 684 | if (!minMaxMips) |
| 685 | { |
| 686 | pContext->blit(srv, rtv, RenderContext::kMaxRect, RenderContext::kMaxRect, TextureFilteringMode::Linear); |
| 687 | } |
| 688 | else |
| 689 | { |
| 690 | const TextureReductionMode redModes[] = { |
| 691 | TextureReductionMode::Standard, |
| 692 | TextureReductionMode::Min, |
| 693 | TextureReductionMode::Max, |
| 694 | TextureReductionMode::Standard, |
| 695 | }; |
| 696 | const float4 componentsTransform[] = { |
| 697 | float4(1.0f, 0.0f, 0.0f, 0.0f), |
| 698 | float4(0.0f, 1.0f, 0.0f, 0.0f), |
| 699 | float4(0.0f, 0.0f, 1.0f, 0.0f), |
| 700 | float4(0.0f, 0.0f, 0.0f, 1.0f), |
| 701 | }; |
| 702 | pContext->blit( |
| 703 | srv, rtv, RenderContext::kMaxRect, RenderContext::kMaxRect, TextureFilteringMode::Linear, redModes, componentsTransform |
| 704 | ); |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | if (mReleaseRtvsAfterGenMips) |
| 710 | { |
| 711 | // Releasing RTVs to free space on the heap. |
| 712 | // We only do it once to handle the case that generateMips() was called during load. |
| 713 | // If it was called more then once, the texture is probably dynamic and it's better to keep the RTVs around |
| 714 | mRtvs.clear(); |
| 715 | mReleaseRtvsAfterGenMips = false; |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | uint64_t Texture::getTexelCount() const |
| 720 | { |