@@ -42,6 +42,10 @@ namespace {
42
42
DXGI_FORMAT_R16G16B16A16_FLOAT,
43
43
DXGI_FORMAT_R32G32B32A32_FLOAT
44
44
};
45
+
46
+ // Max texture size will be determined by D3D_FEATURE_LEVEL_, but D3D11 and D3D12 _REQ_TEXTURE2D_U_OR_V_DIMENSION should be the same.
47
+ template <typename T>
48
+ constexpr T MAX_TEX_UV{ D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION };
45
49
}
46
50
47
51
void Renderer::create (HWND hwnd)
@@ -127,11 +131,8 @@ void Renderer::create_image()
127
131
128
132
// Create texture.
129
133
const D3D11_TEXTURE2D_DESC texture2d_desc{
130
-
131
- // Max texture size will be determined by D3D_FEATURE_LEVEL_, but D3D11 and D3D12 _REQ_TEXTURE2D_U_OR_V_DIMENSION should be the same.
132
- .Width { std::clamp (image.get_width <UINT>(), 1u , static_cast <UINT>(D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) },
133
- .Height { std::clamp (image.get_height <UINT>(), 1u , static_cast <UINT>(D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) },
134
-
134
+ .Width { image.get_width <UINT>() },
135
+ .Height { image.get_height <UINT>() },
135
136
.MipLevels { 1 },
136
137
.ArraySize { 1 },
137
138
.Format { format },
@@ -721,11 +722,8 @@ void Renderer::draw_pass(UINT width, UINT height) noexcept
721
722
{
722
723
// Create texture.
723
724
const D3D11_TEXTURE2D_DESC texture2d_desc{
724
-
725
- // Max texture size will be determined by D3D_FEATURE_LEVEL_, but D3D11 and D3D12 _REQ_TEXTURE2D_U_OR_V_DIMENSION should be the same.
726
- .Width { std::clamp (width, 1u , static_cast <UINT>(D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) },
727
- .Height { std::clamp (height, 1u , static_cast <UINT>(D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) },
728
-
725
+ .Width { width },
726
+ .Height { height },
729
727
.MipLevels { 1 },
730
728
.ArraySize { 1 },
731
729
.Format { WIV_PASS_FORMATS[g_config.pass_format .val ] },
@@ -781,12 +779,8 @@ void Renderer::create_pixel_shader(const BYTE* shader, size_t shader_size) const
781
779
void Renderer::create_viewport (float width, float height, bool adjust) const noexcept
782
780
{
783
781
D3D11_VIEWPORT viewport{
784
-
785
- // Limit to maximum texture size, even it can go beyond.
786
- // Max texture size will be determined by D3D_FEATURE_LEVEL_, but D3D11 and D3D12 _REQ_TEXTURE2D_U_OR_V_DIMENSION should be the same.
787
- .Width { std::min (width, static_cast <float >(D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) },
788
- .Height { std::min (height, static_cast <float >(D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)) }
789
-
782
+ .Width { width },
783
+ .Height { height }
790
784
};
791
785
792
786
// Offset image in order to center it in the window + apply panning.
@@ -818,6 +812,15 @@ void Renderer::update_scale_and_dims_output() noexcept
818
812
auto_zoom = std::log2 (get_ratio<float >(dims_swap_chain.width , image_w));
819
813
820
814
scale = std::pow (2 .0f , auto_zoom + user_interface.image_zoom );
815
+
816
+ // Limit scale so we don't exceed min or max texture dims, or stretch image.
817
+ const auto ws{ image_w * scale };
818
+ const auto hs{ image_h * scale };
819
+ if (ws > MAX_TEX_UV<float > || hs > MAX_TEX_UV<float >)
820
+ scale = std::min (MAX_TEX_UV<float > / image_w, MAX_TEX_UV<float > / image_h);
821
+ else if (ws < 1 .0f || hs < 1 .0f )
822
+ scale = std::max (1 .0f / image_w, 1 .0f / image_h);
823
+
821
824
dims_output.width = static_cast <int >(std::ceil (image_w * scale));
822
825
dims_output.height = static_cast <int >(std::ceil (image_h * scale));
823
826
0 commit comments