@@ -342,28 +342,52 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
342342 BasicStats.Primitives .End ();
343343}
344344
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+ };
345380
346381template <class T > IC bool cmp_first_l (const T &lhs, const T &rhs) { return (lhs.first < rhs.first ); }
347382template <class T > IC bool cmp_first_h (const T &lhs, const T &rhs) { return (lhs.first > rhs.first ); }
348383// ////////////////////////////////////////////////////////////////////////
349384// HUD render
350385void D3DXRenderBase::r_dsgraph_render_hud ()
351386{
352- extern ENGINE_API float psHUD_FOV;
353-
354387 PIX_EVENT (r_dsgraph_render_hud);
355388
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;
364390
365- // Rendering
366- rmNear ();
367391 std::sort (mapHUD.begin (), mapHUD.end (), cmp_first_l<R_dsgraph::mapHUD_T::value_type>); // front-to-back
368392 for (auto &i : mapHUD)
369393 sorted_L1 (i);
@@ -373,13 +397,6 @@ void D3DXRenderBase::r_dsgraph_render_hud()
373397 if (g_hud && g_hud->RenderActiveItemUIQuery ())
374398 r_dsgraph_render_hud_ui (); // hud ui
375399#endif
376-
377- rmNormal ();
378-
379- // Restore projection
380- Device.mProject = Pold;
381- Device.mFullTransform = FTold;
382- RCache.set_xform_project (Device.mProject );
383400}
384401
385402void D3DXRenderBase::r_dsgraph_render_hud_ui ()
@@ -388,16 +405,7 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()
388405
389406 PIX_EVENT (r_dsgraph_render_hud_ui);
390407
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;
401409
402410#if RENDER != R_R1
403411 // Targets, use accumulator for temporary storage
@@ -416,14 +424,7 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()
416424 rt_null, rt_null, zb);
417425#endif // RENDER!=R_R1
418426
419- rmNear ();
420427 g_hud->RenderActiveItemUI ();
421- rmNormal ();
422-
423- // Restore projection
424- Device.mProject = Pold;
425- Device.mFullTransform = FTold;
426- RCache.set_xform_project (Device.mProject );
427428}
428429
429430// ////////////////////////////////////////////////////////////////////////
@@ -436,28 +437,12 @@ void D3DXRenderBase::r_dsgraph_render_sorted()
436437 sorted_L1 (i);
437438 mapSorted.clear ();
438439
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;
446441
447- Device.mFullTransform .mul (Device.mProject , Device.mView );
448- RCache.set_xform_project (Device.mProject );
449-
450- // Rendering
451- rmNear ();
452442 std::sort (mapHUDSorted.begin (), mapHUDSorted.end (), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
453443 for (auto &i : mapHUDSorted)
454444 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 ();
461446}
462447
463448// ////////////////////////////////////////////////////////////////////////
@@ -471,31 +456,12 @@ void D3DXRenderBase::r_dsgraph_render_emissive()
471456 sorted_L1 (i);
472457 mapEmissive.clear ();
473458
474- // HACK: Calculate this only once
475-
476- extern ENGINE_API float psHUD_FOV;
459+ hud_transform_helper helper;
477460
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 ();
489461 std::sort (mapHUDEmissive.begin (), mapHUDEmissive.end (), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
490462 for (auto &i : mapHUDEmissive)
491463 sorted_L1 (i);
492464 mapHUDEmissive.clear ();
493- rmNormal ();
494-
495- // Restore projection
496- Device.mProject = Pold;
497- Device.mFullTransform = FTold;
498- RCache.set_xform_project (Device.mProject );
499465#endif
500466}
501467
0 commit comments