Skip to content

Commit 189cd74

Browse files
committed
Add some more helper functions and use it.
1 parent 6b1a747 commit 189cd74

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

src/Layers/xrRender/r__dsgraph_render.cpp

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ ICF float calcLOD(float ssa /*fDistSq*/, float /*R*/)
1515
return _sqrt(clampr((ssa - r_ssaGLOD_end) / (r_ssaGLOD_start - r_ssaGLOD_end), 0.f, 1.f));
1616
}
1717

18-
// ALPHA
19-
void __fastcall sorted_L1(mapSorted_T::value_type &N)
20-
{
21-
dxRender_Visual* V = N.second.pVisual;
22-
VERIFY(V && V->shader._get());
23-
RCache.set_Element(N.second.se);
24-
RCache.set_xform_world(N.second.Matrix);
25-
RImplementation.apply_object(N.second.pObject);
26-
RImplementation.apply_lmaterial();
27-
V->Render(calcLOD(N.first, V->vis.sphere.R));
28-
}
29-
3018
template <class T> IC bool cmp_second_ssa(const T &lhs, const T &rhs) { return (lhs->second.ssa > rhs->second.ssa); }
3119
template <class T> IC bool cmp_ssa (const T &lhs, const T &rhs) { return (lhs.ssa > rhs.ssa ); }
3220

@@ -342,6 +330,9 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
342330
BasicStats.Primitives.End();
343331
}
344332

333+
//////////////////////////////////////////////////////////////////////////
334+
// Helper classes and functions
335+
345336
/*
346337
Предназначен для установки режима отрисовки HUD и возврата оригинального после отрисовки.
347338
*/
@@ -378,8 +369,39 @@ class hud_transform_helper
378369
}
379370
};
380371

372+
template<class T>
373+
IC void render_item(T &item)
374+
{
375+
dxRender_Visual* V = item.second.pVisual;
376+
VERIFY(V && V->shader._get());
377+
RCache.set_Element(item.second.se);
378+
RCache.set_xform_world(item.second.Matrix);
379+
RImplementation.apply_object(item.second.pObject);
380+
RImplementation.apply_lmaterial();
381+
V->Render(calcLOD(item.first, V->vis.sphere.R));
382+
}
383+
381384
template <class T> IC bool cmp_first_l(const T &lhs, const T &rhs) { return (lhs.first < rhs.first); }
382385
template <class T> IC bool cmp_first_h(const T &lhs, const T &rhs) { return (lhs.first > rhs.first); }
386+
387+
template<class T>
388+
IC void sort_front_to_back_render_and_clean(T &vec)
389+
{
390+
std::sort(vec.begin(), vec.end(), cmp_first_l<T::value_type>); // front-to-back
391+
for (auto &i : vec)
392+
render_item(i);
393+
vec.clear();
394+
}
395+
396+
template<class T>
397+
IC void sort_back_to_front_render_and_clean(T &vec)
398+
{
399+
std::sort(vec.begin(), vec.end(), cmp_first_h<T::value_type>); // back-to-front
400+
for (auto &i : vec)
401+
render_item(i);
402+
vec.clear();
403+
}
404+
383405
//////////////////////////////////////////////////////////////////////////
384406
// HUD render
385407
void D3DXRenderBase::r_dsgraph_render_hud()
@@ -388,10 +410,7 @@ void D3DXRenderBase::r_dsgraph_render_hud()
388410

389411
hud_transform_helper helper;
390412

391-
std::sort(mapHUD.begin(), mapHUD.end(), cmp_first_l<R_dsgraph::mapHUD_T::value_type>); // front-to-back
392-
for (auto &i : mapHUD)
393-
sorted_L1(i);
394-
mapHUD.clear();
413+
sort_front_to_back_render_and_clean(mapHUD);
395414

396415
#if RENDER == R_R1
397416
if (g_hud && g_hud->RenderActiveItemUIQuery())
@@ -432,17 +451,12 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()
432451
void D3DXRenderBase::r_dsgraph_render_sorted()
433452
{
434453
PIX_EVENT(r_dsgraph_render_sorted);
435-
std::sort(mapSorted.begin(), mapSorted.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
436-
for (auto &i : mapSorted)
437-
sorted_L1(i);
438-
mapSorted.clear();
454+
455+
sort_back_to_front_render_and_clean(mapSorted);
439456

440457
hud_transform_helper helper;
441458

442-
std::sort(mapHUDSorted.begin(), mapHUDSorted.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
443-
for (auto &i : mapHUDSorted)
444-
sorted_L1(i);
445-
mapHUDSorted.clear();
459+
sort_back_to_front_render_and_clean(mapHUDSorted);
446460
}
447461

448462
//////////////////////////////////////////////////////////////////////////
@@ -451,17 +465,12 @@ void D3DXRenderBase::r_dsgraph_render_emissive()
451465
{
452466
#if RENDER != R_R1
453467
PIX_EVENT(r_dsgraph_render_emissive);
454-
std::sort(mapEmissive.begin(), mapEmissive.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
455-
for (auto &i : mapEmissive)
456-
sorted_L1(i);
457-
mapEmissive.clear();
468+
469+
sort_front_to_back_render_and_clean(mapEmissive);
458470

459471
hud_transform_helper helper;
460472

461-
std::sort(mapHUDEmissive.begin(), mapHUDEmissive.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
462-
for (auto &i : mapHUDEmissive)
463-
sorted_L1(i);
464-
mapHUDEmissive.clear();
473+
sort_front_to_back_render_and_clean(mapHUDEmissive);
465474
#endif
466475
}
467476

@@ -471,10 +480,8 @@ void D3DXRenderBase::r_dsgraph_render_wmarks()
471480
{
472481
#if RENDER != R_R1
473482
PIX_EVENT(r_dsgraph_render_wmarks);
474-
std::sort(mapWmark.begin(), mapWmark.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
475-
for (auto &i : mapWmark)
476-
sorted_L1(i);
477-
mapWmark.clear();
483+
484+
sort_front_to_back_render_and_clean(mapWmark);
478485
#endif
479486
}
480487

@@ -483,10 +490,8 @@ void D3DXRenderBase::r_dsgraph_render_wmarks()
483490
void D3DXRenderBase::r_dsgraph_render_distort()
484491
{
485492
PIX_EVENT(r_dsgraph_render_distort);
486-
std::sort(mapDistort.begin(), mapDistort.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
487-
for (auto &i : mapDistort)
488-
sorted_L1(i);
489-
mapDistort.clear();
493+
494+
sort_back_to_front_render_and_clean(mapDistort);
490495
}
491496

492497
//////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)