@@ -250,9 +250,8 @@ void DeviceResources::CreateDeviceResources()
250
250
}
251
251
}
252
252
253
- void DeviceResources::UpdateOffscreenResources (int width, int height) {
253
+ void DeviceResources::UpdateOffscreenResources (int width, int height, float aspecRatio ) {
254
254
m_d3dOffscreenRenderTargetView.Reset ();
255
- // m_offscreenRenderTarget.Reset();
256
255
m_d3dOffscreenDepthStencilView.Reset ();
257
256
m_offscreenDepthStencil.Reset ();
258
257
m_d3dContext->Flush ();
@@ -271,29 +270,41 @@ void DeviceResources::UpdateOffscreenResources(int width, int height) {
271
270
m_d3dDevice->CheckMultisampleQualityLevels (backBufferFormat, count, &qualityLevels);
272
271
if (qualityLevels > 0 ) {
273
272
msaaLevel = count;
274
- msaaQuality = qualityLevels - 1 ; // Highest quality level
273
+ msaaQuality = qualityLevels - 1 ;
275
274
break ;
276
275
}
277
276
}
278
277
279
- const int maxWidth = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // Dx11 maximum texture dimension
280
- const int maxHeight = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // Dx11 maximum texture dimension
281
- width = std::min (width, maxWidth);
282
- height = std::min (height, maxHeight);
278
+ // Determine max texture dimension based on MSAA
279
+ const int maxTextureDimension = (msaaLevel > 1 ) ? 8192 : D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
283
280
281
+ if (aspecRatio > 1 .0f ) {
282
+ width = std::min (width, maxTextureDimension);
283
+ height = width / aspecRatio;
284
+ }
285
+ else {
286
+ height = std::min (height, maxTextureDimension);
287
+ width = height * aspecRatio;
288
+ }
289
+
290
+ width = std::min (width, maxTextureDimension);
291
+ height = std::min (height, maxTextureDimension);
292
+
293
+
294
+ // --- Rest of the code remains unchanged ---
284
295
// Create the offscreen render target texture
285
296
CD3D11_TEXTURE2D_DESC offscreenTextureDesc (
286
- backBufferFormat, // This format should match your requirements
287
- width, // Texture width
288
- height, // Texture height
289
- 1 , // Mip levels
290
- 1 , // Array size
291
- D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, // Bind flags
297
+ backBufferFormat,
298
+ width,
299
+ height,
300
+ 1 ,
301
+ 1 ,
302
+ D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE,
292
303
D3D11_USAGE_DEFAULT,
293
304
0 ,
294
- msaaLevel, // MSAA sample count
295
- msaaQuality, // MSAA quality
296
- 0 // Misc flags
305
+ msaaLevel,
306
+ msaaQuality,
307
+ 0
297
308
);
298
309
ThrowIfFailed (m_d3dDevice->CreateTexture2D (&offscreenTextureDesc, nullptr , &m_offscreenRenderTarget));
299
310
@@ -305,7 +316,7 @@ void DeviceResources::UpdateOffscreenResources(int width, int height) {
305
316
1 ,
306
317
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE
307
318
);
308
-
319
+
309
320
ThrowIfFailed (m_d3dDevice->CreateTexture2D (&nonMsaaDesc, nullptr , &m_offscreenNonMsaaTexture));
310
321
311
322
// Create a render target view for the offscreen render target
@@ -316,13 +327,13 @@ void DeviceResources::UpdateOffscreenResources(int width, int height) {
316
327
m_depthBufferFormat,
317
328
width,
318
329
height,
319
- 1 , // This depth stencil view has only one texture.
320
- 1 , // Use a single mipmap level.
330
+ 1 ,
331
+ 1 ,
321
332
D3D11_BIND_DEPTH_STENCIL,
322
333
D3D11_USAGE_DEFAULT,
323
334
0 ,
324
- msaaLevel, // MSAA sample count
325
- msaaQuality, // MSAA quality
335
+ msaaLevel,
336
+ msaaQuality,
326
337
0
327
338
);
328
339
@@ -332,8 +343,7 @@ void DeviceResources::UpdateOffscreenResources(int width, int height) {
332
343
CD3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc (D3D11_DSV_DIMENSION_TEXTURE2DMS);
333
344
ThrowIfFailed (m_d3dDevice->CreateDepthStencilView (m_offscreenDepthStencil.Get (), &dsvDesc, &m_d3dOffscreenDepthStencilView));
334
345
335
- m_offscreenViewport = { 0 .0f , 0 .0f , static_cast <float >(offscreenTextureDesc.Width ), static_cast <float >(offscreenTextureDesc.Height ),
336
- 0 .f , 1 .f };
346
+ m_offscreenViewport = { 0 .0f , 0 .0f , static_cast <float >(width), static_cast <float >(height), 0 .f , 1 .f };
337
347
}
338
348
339
349
0 commit comments