1212extern float r_ssaLOD_A;
1313extern float r_ssaLOD_B;
1414
15+ template <class T > IC bool cmp_first_l (const T &lhs, const T &rhs) { return (lhs.first < rhs.first ); }
16+ template <class T > IC bool cmp_first_h (const T &lhs, const T &rhs) { return (lhs.first > rhs.first ); }
17+
1518ICF bool pred_dot (const std::pair<float , u32 >& _1, const std::pair<float , u32 >& _2) { return _1.first < _2.first ; }
19+
1620void D3DXRenderBase::r_dsgraph_render_lods (bool _setup_zb, bool _clear)
1721{
22+ if (mapLOD.empty ())
23+ return ;
24+
1825 if (_setup_zb)
19- mapLOD.getLR (lstLODs ); // front-to-back
26+ std::sort ( mapLOD.begin (), mapLOD. end (), cmp_first_l<R_dsgraph::mapLOD_T::value_type> ); // front-to-back
2027 else
21- mapLOD.getRL (lstLODs); // back-to-front
22- if (lstLODs.empty ())
23- return ;
28+ std::sort (mapLOD.begin (), mapLOD.end (), cmp_first_h<R_dsgraph::mapLOD_T::value_type>); // back-to-front
2429
2530 // *** Fill VB and generate groups
2631 u32 shid = _setup_zb ? SE_R1_LMODELS : SE_R1_NORMAL_LQ;
27- FLOD* firstV = (FLOD*)lstLODs [0 ].pVisual ;
32+ FLOD* firstV = (FLOD*)mapLOD [0 ]. second .pVisual ;
2833 ref_selement cur_S = firstV->shader ->E [shid];
2934 float ssaRange = r_ssaLOD_A - r_ssaLOD_B;
3035 if (ssaRange < EPS_S)
@@ -37,9 +42,9 @@ void D3DXRenderBase::r_dsgraph_render_lods(bool _setup_zb, bool _clear)
3742 // Msg("dbg_lods: shader[%X]",u32((void*)firstV->shader._get()));
3843 // Msg("dbg_lods: shader_E[%X]",u32((void*)cur_S._get()));
3944
40- for (u32 i = 0 ; i < lstLODs .size (); i++)
45+ for (u32 i = 0 ; i < mapLOD .size (); i++)
4146 {
42- const u32 iBatchSize = std::min (lstLODs .size () - i, (size_t )uiImpostersFit);
47+ const u32 iBatchSize = std::min (mapLOD .size () - i, (size_t )uiImpostersFit);
4348 int cur_count = 0 ;
4449 u32 vOffset;
4550 FLOD::_hw* V =
@@ -48,7 +53,7 @@ void D3DXRenderBase::r_dsgraph_render_lods(bool _setup_zb, bool _clear)
4853 for (u32 j = 0 ; j < iBatchSize; ++j, ++i)
4954 {
5055 // sort out redundancy
51- R_dsgraph::_LodItem& P = lstLODs [i];
56+ R_dsgraph::_LodItem& P = mapLOD [i]. second ;
5257 if (P.pVisual ->shader ->E [shid] == cur_S)
5358 cur_count++;
5459 else
@@ -121,10 +126,10 @@ void D3DXRenderBase::r_dsgraph_render_lods(bool _setup_zb, bool _clear)
121126 for (u32 g = 0 ; g < lstLODgroups.size (); g++)
122127 {
123128 int p_count = lstLODgroups[g];
124- u32 uiNumPasses = lstLODs [current].pVisual ->shader ->E [shid]->passes .size ();
129+ u32 uiNumPasses = mapLOD [current]. second .pVisual ->shader ->E [shid]->passes .size ();
125130 if (uiPass < uiNumPasses)
126131 {
127- RCache.set_Element (lstLODs [current].pVisual ->shader ->E [shid], uiPass);
132+ RCache.set_Element (mapLOD [current]. second .pVisual ->shader ->E [shid], uiPass);
128133 RCache.set_Geometry (firstV->geom );
129134 RCache.Render (D3DPT_TRIANGLELIST, vCurOffset, 0 , 4 * p_count, 0 , 2 * p_count);
130135 }
@@ -137,8 +142,6 @@ void D3DXRenderBase::r_dsgraph_render_lods(bool _setup_zb, bool _clear)
137142 lstLODgroups.clear ();
138143 }
139144
140- lstLODs.clear ();
141-
142145 if (_clear)
143146 mapLOD.clear ();
144147}
0 commit comments