@@ -342,28 +342,52 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
342
342
BasicStats.Primitives .End ();
343
343
}
344
344
345
+ /*
346
+ Предназначен для установки режима отрисовки HUD и возврата оригинального после отрисовки.
347
+ */
348
+ class hud_transform_helper
349
+ {
350
+ Fmatrix Pold;
351
+ Fmatrix FTold;
352
+
353
+ public:
354
+ hud_transform_helper ()
355
+ {
356
+ extern ENGINE_API float psHUD_FOV;
357
+
358
+ // Change projection
359
+ Pold = Device.mProject ;
360
+ FTold = Device.mFullTransform ;
361
+ Device.mProject .build_projection (deg2rad (psHUD_FOV * Device.fFOV /* *Device.fASPECT*/ ), Device.fASPECT ,
362
+ VIEWPORT_NEAR, g_pGamePersistent->Environment ().CurrentEnv ->far_plane );
363
+
364
+ Device.mFullTransform .mul (Device.mProject , Device.mView );
365
+ RCache.set_xform_project (Device.mProject );
366
+
367
+ RImplementation.rmNear ();
368
+ }
369
+
370
+ ~hud_transform_helper ()
371
+ {
372
+ RImplementation.rmNormal ();
373
+
374
+ // Restore projection
375
+ Device.mProject = Pold;
376
+ Device.mFullTransform = FTold;
377
+ RCache.set_xform_project (Device.mProject );
378
+ }
379
+ };
345
380
346
381
template <class T > IC bool cmp_first_l (const T &lhs, const T &rhs) { return (lhs.first < rhs.first ); }
347
382
template <class T > IC bool cmp_first_h (const T &lhs, const T &rhs) { return (lhs.first > rhs.first ); }
348
383
// ////////////////////////////////////////////////////////////////////////
349
384
// HUD render
350
385
void D3DXRenderBase::r_dsgraph_render_hud ()
351
386
{
352
- extern ENGINE_API float psHUD_FOV;
353
-
354
387
PIX_EVENT (r_dsgraph_render_hud);
355
388
356
- // Change projection
357
- Fmatrix Pold = Device.mProject ;
358
- Fmatrix FTold = Device.mFullTransform ;
359
- Device.mProject .build_projection (deg2rad (psHUD_FOV * Device.fFOV /* *Device.fASPECT*/ ), Device.fASPECT ,
360
- VIEWPORT_NEAR, g_pGamePersistent->Environment ().CurrentEnv ->far_plane );
361
-
362
- Device.mFullTransform .mul (Device.mProject , Device.mView );
363
- RCache.set_xform_project (Device.mProject );
389
+ hud_transform_helper helper;
364
390
365
- // Rendering
366
- rmNear ();
367
391
std::sort (mapHUD.begin (), mapHUD.end (), cmp_first_l<R_dsgraph::mapHUD_T::value_type>); // front-to-back
368
392
for (auto &i : mapHUD)
369
393
sorted_L1 (i);
@@ -373,13 +397,6 @@ void D3DXRenderBase::r_dsgraph_render_hud()
373
397
if (g_hud && g_hud->RenderActiveItemUIQuery ())
374
398
r_dsgraph_render_hud_ui (); // hud ui
375
399
#endif
376
-
377
- rmNormal ();
378
-
379
- // Restore projection
380
- Device.mProject = Pold;
381
- Device.mFullTransform = FTold;
382
- RCache.set_xform_project (Device.mProject );
383
400
}
384
401
385
402
void D3DXRenderBase::r_dsgraph_render_hud_ui ()
@@ -388,16 +405,7 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()
388
405
389
406
PIX_EVENT (r_dsgraph_render_hud_ui);
390
407
391
- extern ENGINE_API float psHUD_FOV;
392
-
393
- // Change projection
394
- Fmatrix Pold = Device.mProject ;
395
- Fmatrix FTold = Device.mFullTransform ;
396
- Device.mProject .build_projection (deg2rad (psHUD_FOV * Device.fFOV /* *Device.fASPECT*/ ), Device.fASPECT ,
397
- VIEWPORT_NEAR, g_pGamePersistent->Environment ().CurrentEnv ->far_plane );
398
-
399
- Device.mFullTransform .mul (Device.mProject , Device.mView );
400
- RCache.set_xform_project (Device.mProject );
408
+ hud_transform_helper helper;
401
409
402
410
#if RENDER != R_R1
403
411
// Targets, use accumulator for temporary storage
@@ -416,14 +424,7 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()
416
424
rt_null, rt_null, zb);
417
425
#endif // RENDER!=R_R1
418
426
419
- rmNear ();
420
427
g_hud->RenderActiveItemUI ();
421
- rmNormal ();
422
-
423
- // Restore projection
424
- Device.mProject = Pold;
425
- Device.mFullTransform = FTold;
426
- RCache.set_xform_project (Device.mProject );
427
428
}
428
429
429
430
// ////////////////////////////////////////////////////////////////////////
@@ -436,28 +437,12 @@ void D3DXRenderBase::r_dsgraph_render_sorted()
436
437
sorted_L1 (i);
437
438
mapSorted.clear ();
438
439
439
- extern ENGINE_API float psHUD_FOV;
440
-
441
- // Change projection
442
- Fmatrix Pold = Device.mProject ;
443
- Fmatrix FTold = Device.mFullTransform ;
444
- Device.mProject .build_projection (deg2rad (psHUD_FOV * Device.fFOV /* *Device.fASPECT*/ ), Device.fASPECT ,
445
- VIEWPORT_NEAR, g_pGamePersistent->Environment ().CurrentEnv ->far_plane );
440
+ hud_transform_helper helper;
446
441
447
- Device.mFullTransform .mul (Device.mProject , Device.mView );
448
- RCache.set_xform_project (Device.mProject );
449
-
450
- // Rendering
451
- rmNear ();
452
442
std::sort (mapHUDSorted.begin (), mapHUDSorted.end (), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
453
443
for (auto &i : mapHUDSorted)
454
444
sorted_L1 (i);
455
- rmNormal ();
456
-
457
- // Restore projection
458
- Device.mProject = Pold;
459
- Device.mFullTransform = FTold;
460
- RCache.set_xform_project (Device.mProject );
445
+ mapHUDSorted.clear ();
461
446
}
462
447
463
448
// ////////////////////////////////////////////////////////////////////////
@@ -471,31 +456,12 @@ void D3DXRenderBase::r_dsgraph_render_emissive()
471
456
sorted_L1 (i);
472
457
mapEmissive.clear ();
473
458
474
- // HACK: Calculate this only once
475
-
476
- extern ENGINE_API float psHUD_FOV;
459
+ hud_transform_helper helper;
477
460
478
- // Change projection
479
- Fmatrix Pold = Device.mProject ;
480
- Fmatrix FTold = Device.mFullTransform ;
481
- Device.mProject .build_projection (deg2rad (psHUD_FOV * Device.fFOV /* *Device.fASPECT*/ ), Device.fASPECT ,
482
- VIEWPORT_NEAR, g_pGamePersistent->Environment ().CurrentEnv ->far_plane );
483
-
484
- Device.mFullTransform .mul (Device.mProject , Device.mView );
485
- RCache.set_xform_project (Device.mProject );
486
-
487
- // Rendering
488
- rmNear ();
489
461
std::sort (mapHUDEmissive.begin (), mapHUDEmissive.end (), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
490
462
for (auto &i : mapHUDEmissive)
491
463
sorted_L1 (i);
492
464
mapHUDEmissive.clear ();
493
- rmNormal ();
494
-
495
- // Restore projection
496
- Device.mProject = Pold;
497
- Device.mFullTransform = FTold;
498
- RCache.set_xform_project (Device.mProject );
499
465
#endif
500
466
}
501
467
0 commit comments