Skip to content

Commit

Permalink
Port changes from OGSR to fix OpenXRay#1748
Browse files Browse the repository at this point in the history
  • Loading branch information
yohjimane committed Dec 18, 2024
1 parent fdf1ea9 commit 5b70411
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Include/xrRender/UIShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class IUIShader
public:
virtual ~IUIShader() { ; }
virtual void Copy(IUIShader& _in) = 0;
virtual void create(LPCSTR sh, LPCSTR tex = nullptr) = 0;
virtual void create(LPCSTR sh, LPCSTR tex = nullptr, bool no_cache = false) = 0;
virtual bool inited() = 0;
virtual void destroy() = 0;
//virtual void destroy() = 0;
};

#endif // UIShader_included
4 changes: 4 additions & 0 deletions src/Layers/xrRender/dxUIRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ void dxUIRender::CreateUIGeom()

void dxUIRender::DestroyUIGeom()
{
for (auto& it : g_UIShadersCache)
it.second.destroy();
g_UIShadersCache.clear();

hGeom_TL = NULL;
hGeom_LIT = NULL;
}
Expand Down
12 changes: 0 additions & 12 deletions src/Layers/xrRender/dxUIRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,9 @@ class dxUIRender : public IUIRender

virtual void SetShader(IUIShader& shader);
virtual void SetAlphaRef(int aref);
//. virtual void StartTriList(u32 iMaxVerts);
//. virtual void FlushTriList();
//. virtual void StartTriFan(u32 iMaxVerts);
//. virtual void FlushTriFan();
// virtual void StartTriStrip(u32 iMaxVerts);
// virtual void FlushTriStrip();
//. virtual void StartLineStrip(u32 iMaxVerts);
//. virtual void FlushLineStrip();
//. virtual void StartLineList(u32 iMaxVerts);
//. virtual void FlushLineList();
virtual void SetScissor(Irect* rect = nullptr);
virtual void GetActiveTextureResolution(Fvector2& res);

//. virtual void PushPoint(float x, float y, u32 c, float u, float v);
// virtual void PushPoint(int x, int y, u32 c, float u, float v);
virtual void PushPoint(float x, float y, float z, u32 C, float u, float v);

virtual void StartPrimitive(u32 iMaxVerts, ePrimitiveType primType, ePointType pointType);
Expand Down
34 changes: 32 additions & 2 deletions src/Layers/xrRender/dxUIShader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
#include "stdafx.h"
#include "dxUIShader.h"

xr_unordered_map<std::string, ref_shader> g_UIShadersCache;

static ref_shader& GetCachedUIShader(const char* sh, const char* tex)
{
std::string key{ tex ? tex : "" };
key += "_";
key += sh;

if (const auto it = g_UIShadersCache.find(key); it != g_UIShadersCache.end())
{
return it->second;
}
else
{
auto& shader = g_UIShadersCache[key];
shader.create(sh, tex);
return shader;
}
}

void dxUIShader::Copy(IUIShader& _in) { *this = *((dxUIShader*)&_in); }
void dxUIShader::create(LPCSTR sh, LPCSTR tex) { hShader.create(sh, tex); }
void dxUIShader::destroy() { hShader.destroy(); }
void dxUIShader::create(LPCSTR sh, LPCSTR tex, bool no_cache)
{
if (no_cache)
{
hShader.create(sh, tex);
}
else
{
hShader = GetCachedUIShader(sh, tex);
}
}
//void dxUIShader::destroy() { hShader.destroy(); }
6 changes: 4 additions & 2 deletions src/Layers/xrRender/dxUIShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "Include/xrRender/UIShader.h"

extern xr_unordered_map<std::string, ref_shader> g_UIShadersCache;

class dxUIShader : public IUIShader
{
friend class dxUIRender;
Expand All @@ -14,9 +16,9 @@ class dxUIShader : public IUIShader
public:
virtual ~dxUIShader() { ; }
virtual void Copy(IUIShader& _in);
virtual void create(LPCSTR sh, LPCSTR tex = nullptr);
virtual void create(LPCSTR sh, LPCSTR tex = nullptr, bool no_cache = false);
virtual bool inited() { return hShader; }
virtual void destroy();
//virtual void destroy();

private:
ref_shader hShader;
Expand Down
10 changes: 7 additions & 3 deletions src/xrGame/ui/UICellItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ CUICellItem::~CUICellItem()

void CUICellItem::init()
{
CUIXml uiXml;
if (!uiXml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, "actor_menu_item.xml", false))
return;
static CUIXml uiXml;
static bool isXmlReady = false;
if (!isXmlReady)
{
uiXml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, "actor_menu_item.xml", false);
isXmlReady = true;
}

m_text = xr_new<CUIStatic>("Text");
m_text->SetAutoDelete(true);
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/ui/UILoadingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void UILoadingScreen::Show(bool show)
CUIWindow::Show(show);
if (!show)
{
loadingLogo->GetStaticItem()->GetShader()->destroy();
// loadingLogo->GetStaticItem()->GetShader()->destroy();
if (loadingStage)
loadingStage->SetText(nullptr);
SetStageTip(nullptr, nullptr, nullptr);
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/ui/UIStatsIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void CUIStatsIcon::InitTexInfo()
void CUIStatsIcon::FreeTexInfo()
{
// ranks
/*
for (int i = RANK_0; i <= RANK_4; i++)
{
(*m_tex_info)[i][0].sh->destroy();
Expand All @@ -66,6 +67,7 @@ void CUIStatsIcon::FreeTexInfo()
(*m_tex_info)[ARTEFACT][1].sh->destroy();
(*m_tex_info)[DEATH][0].sh->destroy();
(*m_tex_info)[DEATH][1].sh->destroy();
*/

xr_delete(m_tex_info);
}
Expand Down
2 changes: 2 additions & 0 deletions src/xrUICore/Static/UIStatic.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class XRUICORE_API CUIStatic : public CUIWindow, public ITextureOwner, public CU
pcstr GetDebugType() override { return "CUIStatic"; }
void FillDebugInfo() override;

void SetNoShaderCache(bool v) { m_UIStaticItem.SetNoShaderCache(v); }

protected:
CUILines* m_pTextControl{};

Expand Down
2 changes: 1 addition & 1 deletion src/xrUICore/Static/UIStaticItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void CUIStaticItem::Render(float angle)

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

#ifdef DEBUG
dbg_tex_name = tex;
Expand Down
5 changes: 4 additions & 1 deletion src/xrUICore/Static/UIStaticItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class XRUICORE_API CUIStaticItem
flValidTextureRect = (1 << 1),
flValidHeadingPivot = (1 << 2),
flFixedLTWhileHeading = (1 << 3),
flNoShaderCache = (1 << 4),
};

Frect TextureRect;
Expand Down Expand Up @@ -76,7 +77,9 @@ class XRUICORE_API CUIStaticItem
Fvector2 GetHeadingPivot() { return vHeadingPivot; }
IC void SetMirrorMode(EUIMirroring m) { eMirrorMode = m; }
IC EUIMirroring GetMirrorMode() { return eMirrorMode; }

void SetNoShaderCache(const bool v) {
uFlags.set(flNoShaderCache, v);
}
private:
void RenderInternal(const Fvector2& pos);
void RenderInternal(float angle);
Expand Down

0 comments on commit 5b70411

Please sign in to comment.