Skip to content

Commit 24b0808

Browse files
committed
Merge remote-tracking branch 'intorr/intorr_dev' into xd_dev
2 parents 121fe21 + 189cd74 commit 24b0808

File tree

14 files changed

+117
-173
lines changed

14 files changed

+117
-173
lines changed

src/Layers/xrRender/D3DXRenderBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class D3DXRenderBase : public IRender, public pureFrame
4040
R_dsgraph::mapHUD_T mapHUD;
4141
R_dsgraph::mapLOD_T mapLOD;
4242
R_dsgraph::mapSorted_T mapDistort;
43+
R_dsgraph::mapHUD_T mapHUDSorted;
4344

4445
#if RENDER != R_R1
4546
R_dsgraph::mapSorted_T mapWmark; // sorted
@@ -142,10 +143,12 @@ class D3DXRenderBase : public IRender, public pureFrame
142143
mapHUD.clear();
143144
mapLOD.clear();
144145
mapDistort.clear();
146+
mapHUDSorted.clear();
145147

146148
#if RENDER != R_R1
147149
mapWmark.clear();
148150
mapEmissive.clear();
151+
mapHUDEmissive.clear();
149152
#endif
150153
}
151154

src/Layers/xrRender/Debug/dxPixEventWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define dxPixEventWrapper_included
33
#pragma once
44

5-
#if defined(DEBUG) && !defined(USE_OGL)
5+
#if !defined(MASTER_GOLD) && !defined(USE_OGL)
66

77
#define PIX_EVENT(Name) dxPixEventWrapper pixEvent##Name(L#Name)
88

src/Layers/xrRender/r__dsgraph_build.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,14 @@ void D3DXRenderBase::r_dsgraph_insert_dynamic(dxRender_Visual* pVisual, Fvector&
7474
if (RI.val_bHUD)
7575
{
7676
if (sh->flags.bStrictB2F)
77-
{
78-
mapSorted.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
79-
}
77+
mapHUDSorted.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
8078
else
81-
{
82-
mapHUD.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
79+
mapHUD .emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh })));
80+
8381
#if RENDER != R_R1
84-
if (sh->flags.bEmissive)
85-
mapHUDEmissive.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh_d }))); // sh_d -> L_special
86-
#endif // RENDER!=R_R1
87-
}
82+
if (sh->flags.bEmissive)
83+
mapHUDEmissive.emplace_back(std::make_pair(distSQ, _MatrixItemS({ SSA, RI.val_pObject, pVisual, *RI.val_pTransform, sh_d }))); // sh_d -> L_special
84+
#endif
8885
return;
8986
}
9087

src/Layers/xrRender/r__dsgraph_render.cpp

Lines changed: 104 additions & 146 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

@@ -107,7 +95,7 @@ template <class T> void sort_tlist(xr_vector<T::template value_type *>& lst, xr_
10795

10896
void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
10997
{
110-
// PIX_EVENT(r_dsgraph_render_graph);
98+
PIX_EVENT(r_dsgraph_render_graph);
11199
BasicStats.Primitives.Begin();
112100

113101
// **************************************************** NORMAL
@@ -342,178 +330,147 @@ void D3DXRenderBase::r_dsgraph_render_graph(u32 _priority)
342330
BasicStats.Primitives.End();
343331
}
344332

333+
//////////////////////////////////////////////////////////////////////////
334+
// Helper classes and functions
335+
336+
/*
337+
Предназначен для установки режима отрисовки HUD и возврата оригинального после отрисовки.
338+
*/
339+
class hud_transform_helper
340+
{
341+
Fmatrix Pold;
342+
Fmatrix FTold;
343+
344+
public:
345+
hud_transform_helper()
346+
{
347+
extern ENGINE_API float psHUD_FOV;
348+
349+
// Change projection
350+
Pold = Device.mProject;
351+
FTold = Device.mFullTransform;
352+
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
353+
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);
354+
355+
Device.mFullTransform.mul(Device.mProject, Device.mView);
356+
RCache.set_xform_project(Device.mProject);
357+
358+
RImplementation.rmNear();
359+
}
360+
361+
~hud_transform_helper()
362+
{
363+
RImplementation.rmNormal();
364+
365+
// Restore projection
366+
Device.mProject = Pold;
367+
Device.mFullTransform = FTold;
368+
RCache.set_xform_project(Device.mProject);
369+
}
370+
};
371+
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+
}
345383

346384
template <class T> IC bool cmp_first_l(const T &lhs, const T &rhs) { return (lhs.first < rhs.first); }
347385
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+
348405
//////////////////////////////////////////////////////////////////////////
349406
// HUD render
350407
void D3DXRenderBase::r_dsgraph_render_hud()
351408
{
352-
extern ENGINE_API float psHUD_FOV;
353-
354-
// PIX_EVENT(r_dsgraph_render_hud);
409+
PIX_EVENT(r_dsgraph_render_hud);
355410

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);
411+
hud_transform_helper helper;
361412

362-
Device.mFullTransform.mul(Device.mProject, Device.mView);
363-
RCache.set_xform_project(Device.mProject);
364-
365-
// Rendering
366-
rmNear();
367-
std::sort(mapHUD.begin(), mapHUD.end(), cmp_first_l<R_dsgraph::mapHUD_T::value_type>); // front-to-back
368-
for (auto &i : mapHUD)
369-
sorted_L1(i);
370-
mapHUD.clear();
413+
sort_front_to_back_render_and_clean(mapHUD);
371414

372415
#if RENDER == R_R1
373416
if (g_hud && g_hud->RenderActiveItemUIQuery())
374417
r_dsgraph_render_hud_ui(); // hud ui
375418
#endif
376-
/*
377-
if(g_hud && g_hud->RenderActiveItemUIQuery())
378-
{
379-
#if RENDER!=R_R1
380-
// Targets, use accumulator for temporary storage
381-
const ref_rt rt_null;
382-
// Reset all rt.
383-
//RCache.set_RT(0, 0);
384-
RCache.set_RT(0, 1);
385-
RCache.set_RT(0, 2);
386-
//if (RImplementation.o.albedo_wo) RCache.set_RT(RImplementation.Target->rt_Accumulator->pRT, 0);
387-
//else RCache.set_RT(RImplementation.Target->rt_Color->pRT, 0);
388-
if (RImplementation.o.albedo_wo) RImplementation.Target->u_setrt
389-
(RImplementation.Target->rt_Accumulator, rt_null, rt_null, HW.pBaseZB);
390-
else RImplementation.Target->u_setrt (RImplementation.Target->rt_Color,
391-
rt_null, rt_null, HW.pBaseZB);
392-
// View port is reset in DX9 when you change rt
393-
rmNear ();
394-
#endif
395-
g_hud->RenderActiveItemUI ();
396-
397-
#if RENDER!=R_R1
398-
//RCache.set_RT(0, 0);
399-
// Targets, use accumulator for temporary storage
400-
if (RImplementation.o.albedo_wo) RImplementation.Target->u_setrt (RImplementation.Target->rt_Position,
401-
RImplementation.Target->rt_Normal, RImplementation.Target->rt_Accumulator, HW.pBaseZB);
402-
else RImplementation.Target->u_setrt (RImplementation.Target->rt_Position,
403-
RImplementation.Target->rt_Normal, RImplementation.Target->rt_Color, HW.pBaseZB);
404-
#endif
405-
}
406-
*/
407-
408-
rmNormal();
409-
410-
// Restore projection
411-
Device.mProject = Pold;
412-
Device.mFullTransform = FTold;
413-
RCache.set_xform_project(Device.mProject);
414419
}
415420

416421
void D3DXRenderBase::r_dsgraph_render_hud_ui()
417422
{
418423
VERIFY(g_hud && g_hud->RenderActiveItemUIQuery());
419424

420-
extern ENGINE_API float psHUD_FOV;
421-
422-
// Change projection
423-
Fmatrix Pold = Device.mProject;
424-
Fmatrix FTold = Device.mFullTransform;
425-
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
426-
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);
425+
PIX_EVENT(r_dsgraph_render_hud_ui);
427426

428-
Device.mFullTransform.mul(Device.mProject, Device.mView);
429-
RCache.set_xform_project(Device.mProject);
427+
hud_transform_helper helper;
430428

431429
#if RENDER != R_R1
432430
// Targets, use accumulator for temporary storage
433431
const ref_rt rt_null;
434432
RCache.set_RT(0, 1);
435433
RCache.set_RT(0, 2);
434+
auto zb = HW.pBaseZB;
435+
436436
#if (RENDER == R_R3) || (RENDER == R_R4) || (RENDER==R_GL)
437-
if (!RImplementation.o.dx10_msaa)
438-
{
439-
if (RImplementation.o.albedo_wo)
440-
RImplementation.Target->u_setrt(RImplementation.Target->rt_Accumulator, rt_null, rt_null, HW.pBaseZB);
441-
else
442-
RImplementation.Target->u_setrt(RImplementation.Target->rt_Color, rt_null, rt_null, HW.pBaseZB);
443-
}
444-
else
445-
{
446-
if (RImplementation.o.albedo_wo)
447-
RImplementation.Target->u_setrt(
448-
RImplementation.Target->rt_Accumulator, rt_null, rt_null, RImplementation.Target->rt_MSAADepth->pZRT);
449-
else
450-
RImplementation.Target->u_setrt(
451-
RImplementation.Target->rt_Color, rt_null, rt_null, RImplementation.Target->rt_MSAADepth->pZRT);
452-
}
453-
#else // (RENDER==R_R3) || (RENDER==R_R4)
454-
if (RImplementation.o.albedo_wo)
455-
RImplementation.Target->u_setrt(RImplementation.Target->rt_Accumulator, rt_null, rt_null, HW.pBaseZB);
456-
else
457-
RImplementation.Target->u_setrt(RImplementation.Target->rt_Color, rt_null, rt_null, HW.pBaseZB);
458-
#endif // (RENDER==R_R3) || (RENDER==R_R4)
437+
if (RImplementation.o.dx10_msaa)
438+
zb = RImplementation.Target->rt_MSAADepth->pZRT;
439+
#endif
440+
441+
RImplementation.Target->u_setrt(
442+
RImplementation.o.albedo_wo ? RImplementation.Target->rt_Accumulator : RImplementation.Target->rt_Color,
443+
rt_null, rt_null, zb);
459444
#endif // RENDER!=R_R1
460445

461-
rmNear();
462446
g_hud->RenderActiveItemUI();
463-
rmNormal();
464-
465-
// Restore projection
466-
Device.mProject = Pold;
467-
Device.mFullTransform = FTold;
468-
RCache.set_xform_project(Device.mProject);
469447
}
470448

471449
//////////////////////////////////////////////////////////////////////////
472450
// strict-sorted render
473451
void D3DXRenderBase::r_dsgraph_render_sorted()
474452
{
475-
std::sort(mapSorted.begin(), mapSorted.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
476-
for (auto &i : mapSorted)
477-
sorted_L1(i);
478-
mapSorted.clear();
453+
PIX_EVENT(r_dsgraph_render_sorted);
454+
455+
sort_back_to_front_render_and_clean(mapSorted);
456+
457+
hud_transform_helper helper;
458+
459+
sort_back_to_front_render_and_clean(mapHUDSorted);
479460
}
480461

481462
//////////////////////////////////////////////////////////////////////////
482463
// strict-sorted render
483464
void D3DXRenderBase::r_dsgraph_render_emissive()
484465
{
485466
#if RENDER != R_R1
486-
std::sort(mapEmissive.begin(), mapEmissive.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
487-
for (auto &i : mapEmissive)
488-
sorted_L1(i);
489-
mapEmissive.clear();
467+
PIX_EVENT(r_dsgraph_render_emissive);
490468

491-
// HACK: Calculate this only once
469+
sort_front_to_back_render_and_clean(mapEmissive);
492470

493-
extern ENGINE_API float psHUD_FOV;
471+
hud_transform_helper helper;
494472

495-
// Change projection
496-
Fmatrix Pold = Device.mProject;
497-
Fmatrix FTold = Device.mFullTransform;
498-
Device.mProject.build_projection(deg2rad(psHUD_FOV * Device.fFOV /* *Device.fASPECT*/), Device.fASPECT,
499-
VIEWPORT_NEAR, g_pGamePersistent->Environment().CurrentEnv->far_plane);
500-
501-
Device.mFullTransform.mul(Device.mProject, Device.mView);
502-
RCache.set_xform_project(Device.mProject);
503-
504-
// Rendering
505-
rmNear();
506-
std::sort(mapHUDEmissive.begin(), mapHUDEmissive.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
507-
for (auto &i : mapHUDEmissive)
508-
sorted_L1(i);
509-
mapHUDEmissive.clear();
510-
511-
rmNormal();
512-
513-
// Restore projection
514-
Device.mProject = Pold;
515-
Device.mFullTransform = FTold;
516-
RCache.set_xform_project(Device.mProject);
473+
sort_front_to_back_render_and_clean(mapHUDEmissive);
517474
#endif
518475
}
519476

@@ -522,21 +479,19 @@ void D3DXRenderBase::r_dsgraph_render_emissive()
522479
void D3DXRenderBase::r_dsgraph_render_wmarks()
523480
{
524481
#if RENDER != R_R1
525-
std::sort(mapWmark.begin(), mapWmark.end(), cmp_first_l<R_dsgraph::mapSorted_T::value_type>); // front-to-back
526-
for (auto &i : mapWmark)
527-
sorted_L1(i);
528-
mapWmark.clear();
482+
PIX_EVENT(r_dsgraph_render_wmarks);
483+
484+
sort_front_to_back_render_and_clean(mapWmark);
529485
#endif
530486
}
531487

532488
//////////////////////////////////////////////////////////////////////////
533489
// strict-sorted render
534490
void D3DXRenderBase::r_dsgraph_render_distort()
535491
{
536-
std::sort(mapDistort.begin(), mapDistort.end(), cmp_first_h<R_dsgraph::mapSorted_T::value_type>); // back-to-front
537-
for (auto &i : mapDistort)
538-
sorted_L1(i);
539-
mapDistort.clear();
492+
PIX_EVENT(r_dsgraph_render_distort);
493+
494+
sort_back_to_front_render_and_clean(mapDistort);
540495
}
541496

542497
//////////////////////////////////////////////////////////////////////////
@@ -554,6 +509,7 @@ void D3DXRenderBase::r_dsgraph_render_subspace(IRender_Sector* _sector, CFrustum
554509
Fvector& _cop, BOOL _dynamic, BOOL _precise_portals)
555510
{
556511
VERIFY(_sector);
512+
PIX_EVENT(r_dsgraph_render_subspace);
557513
RImplementation.marker++; // !!! critical here
558514

559515
// Save and build new frustum, disable HOM
@@ -639,6 +595,8 @@ void D3DXRenderBase::r_dsgraph_render_subspace(IRender_Sector* _sector, CFrustum
639595

640596
void D3DXRenderBase::r_dsgraph_render_R1_box(IRender_Sector* S, Fbox& BB, int sh)
641597
{
598+
PIX_EVENT(r_dsgraph_render_R1_box);
599+
642600
lstVisuals.clear();
643601
lstVisuals.push_back(((CSector*)S)->root());
644602

0 commit comments

Comments
 (0)