Skip to content

Commit 42ce4f8

Browse files
committed
Port changes from OGSR to fix OpenXRay#1748
1 parent fdf1ea9 commit 42ce4f8

File tree

11 files changed

+49
-24
lines changed

11 files changed

+49
-24
lines changed

src/Include/xrRender/UIShader.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class IUIShader
77
public:
88
virtual ~IUIShader() { ; }
99
virtual void Copy(IUIShader& _in) = 0;
10-
virtual void create(LPCSTR sh, LPCSTR tex = nullptr) = 0;
10+
virtual void create(LPCSTR sh, LPCSTR tex = nullptr, bool no_cache = false) = 0;
1111
virtual bool inited() = 0;
12-
virtual void destroy() = 0;
12+
//virtual void destroy() = 0;
1313
};
1414

1515
#endif // UIShader_included

src/Layers/xrRender/dxUIRender.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ void dxUIRender::CreateUIGeom()
1313

1414
void dxUIRender::DestroyUIGeom()
1515
{
16+
for (auto& it : g_UIShadersCache)
17+
it.second.destroy();
18+
g_UIShadersCache.clear();
19+
1620
hGeom_TL = NULL;
1721
hGeom_LIT = NULL;
1822
}

src/Layers/xrRender/dxUIRender.h

-12
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,9 @@ class dxUIRender : public IUIRender
1313

1414
virtual void SetShader(IUIShader& shader);
1515
virtual void SetAlphaRef(int aref);
16-
//. virtual void StartTriList(u32 iMaxVerts);
17-
//. virtual void FlushTriList();
18-
//. virtual void StartTriFan(u32 iMaxVerts);
19-
//. virtual void FlushTriFan();
20-
// virtual void StartTriStrip(u32 iMaxVerts);
21-
// virtual void FlushTriStrip();
22-
//. virtual void StartLineStrip(u32 iMaxVerts);
23-
//. virtual void FlushLineStrip();
24-
//. virtual void StartLineList(u32 iMaxVerts);
25-
//. virtual void FlushLineList();
2616
virtual void SetScissor(Irect* rect = nullptr);
2717
virtual void GetActiveTextureResolution(Fvector2& res);
2818

29-
//. virtual void PushPoint(float x, float y, u32 c, float u, float v);
30-
// virtual void PushPoint(int x, int y, u32 c, float u, float v);
3119
virtual void PushPoint(float x, float y, float z, u32 C, float u, float v);
3220

3321
virtual void StartPrimitive(u32 iMaxVerts, ePrimitiveType primType, ePointType pointType);

src/Layers/xrRender/dxUIShader.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
#include "stdafx.h"
22
#include "dxUIShader.h"
33

4+
xr_unordered_map<std::string, ref_shader> g_UIShadersCache;
5+
6+
static ref_shader& GetCachedUIShader(const char* sh, const char* tex)
7+
{
8+
std::string key{ tex ? tex : "" };
9+
key += "_";
10+
key += sh;
11+
12+
if (const auto it = g_UIShadersCache.find(key); it != g_UIShadersCache.end())
13+
{
14+
return it->second;
15+
}
16+
else
17+
{
18+
auto& shader = g_UIShadersCache[key];
19+
shader.create(sh, tex);
20+
return shader;
21+
}
22+
}
23+
424
void dxUIShader::Copy(IUIShader& _in) { *this = *((dxUIShader*)&_in); }
5-
void dxUIShader::create(LPCSTR sh, LPCSTR tex) { hShader.create(sh, tex); }
6-
void dxUIShader::destroy() { hShader.destroy(); }
25+
void dxUIShader::create(LPCSTR sh, LPCSTR tex, bool no_cache) { hShader = GetCachedUIShader(sh, tex); }
26+
//void dxUIShader::destroy() { hShader.destroy(); }

src/Layers/xrRender/dxUIShader.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "Include/xrRender/UIShader.h"
66

7+
extern xr_unordered_map<std::string, ref_shader> g_UIShadersCache;
8+
79
class dxUIShader : public IUIShader
810
{
911
friend class dxUIRender;
@@ -14,9 +16,9 @@ class dxUIShader : public IUIShader
1416
public:
1517
virtual ~dxUIShader() { ; }
1618
virtual void Copy(IUIShader& _in);
17-
virtual void create(LPCSTR sh, LPCSTR tex = nullptr);
19+
virtual void create(LPCSTR sh, LPCSTR tex = nullptr, bool no_cache = false);
1820
virtual bool inited() { return hShader; }
19-
virtual void destroy();
21+
//virtual void destroy();
2022

2123
private:
2224
ref_shader hShader;

src/xrGame/ui/UICellItem.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ CUICellItem::~CUICellItem()
4848

4949
void CUICellItem::init()
5050
{
51-
CUIXml uiXml;
52-
if (!uiXml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, "actor_menu_item.xml", false))
53-
return;
51+
static CUIXml uiXml;
52+
static bool isXmlReady = false;
53+
if (!isXmlReady)
54+
{
55+
uiXml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, "actor_menu_item.xml", false);
56+
isXmlReady = true;
57+
}
5458

5559
m_text = xr_new<CUIStatic>("Text");
5660
m_text->SetAutoDelete(true);

src/xrGame/ui/UILoadingScreen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void UILoadingScreen::Show(bool show)
135135
CUIWindow::Show(show);
136136
if (!show)
137137
{
138-
loadingLogo->GetStaticItem()->GetShader()->destroy();
138+
// loadingLogo->GetStaticItem()->GetShader()->destroy();
139139
if (loadingStage)
140140
loadingStage->SetText(nullptr);
141141
SetStageTip(nullptr, nullptr, nullptr);

src/xrGame/ui/UIStatsIcon.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void CUIStatsIcon::InitTexInfo()
5757
void CUIStatsIcon::FreeTexInfo()
5858
{
5959
// ranks
60+
/*
6061
for (int i = RANK_0; i <= RANK_4; i++)
6162
{
6263
(*m_tex_info)[i][0].sh->destroy();
@@ -66,6 +67,7 @@ void CUIStatsIcon::FreeTexInfo()
6667
(*m_tex_info)[ARTEFACT][1].sh->destroy();
6768
(*m_tex_info)[DEATH][0].sh->destroy();
6869
(*m_tex_info)[DEATH][1].sh->destroy();
70+
*/
6971

7072
xr_delete(m_tex_info);
7173
}

src/xrUICore/Static/UIStatic.h

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class XRUICORE_API CUIStatic : public CUIWindow, public ITextureOwner, public CU
109109
pcstr GetDebugType() override { return "CUIStatic"; }
110110
void FillDebugInfo() override;
111111

112+
void SetNoShaderCache(bool v) { m_UIStaticItem.SetNoShaderCache(v); }
113+
112114
protected:
113115
CUILines* m_pTextControl{};
114116

src/xrUICore/Static/UIStaticItem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ void CUIStaticItem::Render(float angle)
208208

209209
void CUIStaticItem::CreateShader(LPCSTR tex, LPCSTR sh)
210210
{
211-
hShader->create(sh, tex);
211+
hShader->create(sh, tex, !!uFlags.test(flNoShaderCache));
212212

213213
#ifdef DEBUG
214214
dbg_tex_name = tex;

src/xrUICore/Static/UIStaticItem.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class XRUICORE_API CUIStaticItem
2424
flValidTextureRect = (1 << 1),
2525
flValidHeadingPivot = (1 << 2),
2626
flFixedLTWhileHeading = (1 << 3),
27+
flNoShaderCache = (1 << 4),
2728
};
2829

2930
Frect TextureRect;
@@ -76,7 +77,9 @@ class XRUICORE_API CUIStaticItem
7677
Fvector2 GetHeadingPivot() { return vHeadingPivot; }
7778
IC void SetMirrorMode(EUIMirroring m) { eMirrorMode = m; }
7879
IC EUIMirroring GetMirrorMode() { return eMirrorMode; }
79-
80+
void SetNoShaderCache(const bool v) {
81+
uFlags.set(flNoShaderCache, v);
82+
}
8083
private:
8184
void RenderInternal(const Fvector2& pos);
8285
void RenderInternal(float angle);

0 commit comments

Comments
 (0)