Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 201de35

Browse files
authored
Add SVG support (lunasvg) (#2026)
1 parent bdf3e3e commit 201de35

File tree

82 files changed

+18199
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+18199
-62
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
*
6+
* Multi Theft Auto is available from https://www.multitheftauto.com/
7+
*
8+
*****************************************************************************/
9+
10+
#include "StdInc.h"
11+
12+
////////////////////////////////////////////////////////////////
13+
//
14+
// CVectorGraphicItem::PostConstruct
15+
//
16+
//
17+
//
18+
////////////////////////////////////////////////////////////////
19+
void CVectorGraphicItem::PostConstruct(CRenderItemManager* pManager, uint width, uint height)
20+
{
21+
Super::PostConstruct(pManager);
22+
23+
m_uiSizeX = width;
24+
m_uiSizeY = height;
25+
m_uiSurfaceSizeX = width;
26+
m_uiSurfaceSizeY = height;
27+
28+
m_TextureAddress = TADDRESS_CLAMP;
29+
30+
CreateUnderlyingData();
31+
}
32+
33+
////////////////////////////////////////////////////////////////
34+
//
35+
// CVectorGraphicItem::PreDestruct
36+
//
37+
//
38+
//
39+
////////////////////////////////////////////////////////////////
40+
void CVectorGraphicItem::PreDestruct()
41+
{
42+
ReleaseUnderlyingData();
43+
Super::PreDestruct();
44+
}
45+
46+
////////////////////////////////////////////////////////////////
47+
//
48+
// CVectorGraphicItem::IsValid
49+
//
50+
// Check underlying data is present
51+
//
52+
////////////////////////////////////////////////////////////////
53+
bool CVectorGraphicItem::IsValid()
54+
{
55+
return m_pD3DTexture != nullptr;
56+
}
57+
58+
////////////////////////////////////////////////////////////////
59+
//
60+
// CVectorGraphicItem::OnLostDevice
61+
//
62+
// Release device stuff
63+
//
64+
////////////////////////////////////////////////////////////////
65+
void CVectorGraphicItem::OnLostDevice()
66+
{
67+
// Nothing required for CVectorGraphicItem
68+
}
69+
70+
////////////////////////////////////////////////////////////////
71+
//
72+
// CVectorGraphicItem::OnResetDevice
73+
//
74+
// Recreate device stuff
75+
//
76+
////////////////////////////////////////////////////////////////
77+
void CVectorGraphicItem::OnResetDevice()
78+
{
79+
// Nothing required for CVectorGraphicItem
80+
}
81+
82+
////////////////////////////////////////////////////////////////
83+
//
84+
// CVectorGraphicItem::CreateUnderlyingData
85+
//
86+
// From file
87+
//
88+
////////////////////////////////////////////////////////////////
89+
void CVectorGraphicItem::CreateUnderlyingData()
90+
{
91+
assert(!m_pD3DRenderTargetSurface);
92+
assert(!m_pD3DTexture);
93+
94+
D3DXCreateTexture(m_pDevice, m_uiSizeX, m_uiSizeY, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, (IDirect3DTexture9**)&m_pD3DTexture);
95+
96+
// Check texture created
97+
if (!m_pD3DTexture)
98+
return;
99+
100+
// D3DXCreateTexture sets width and height to 1 if the argument value was 0
101+
// See: https://docs.microsoft.com/en-us/windows/desktop/direct3d9/d3dxcreatetexture
102+
if (m_uiSizeX == 0)
103+
m_uiSizeX = 1;
104+
105+
if (m_uiSizeY == 0)
106+
m_uiSizeY = 1;
107+
108+
// Get the render target surface here for convenience
109+
((IDirect3DTexture9*)m_pD3DTexture)->GetSurfaceLevel(0, &m_pD3DRenderTargetSurface);
110+
111+
// Update surface size, although it probably will be unchanged | Todo: Remove this
112+
D3DSURFACE_DESC desc;
113+
m_pD3DRenderTargetSurface->GetDesc(&desc);
114+
m_uiSurfaceSizeX = desc.Width;
115+
m_uiSurfaceSizeY = desc.Height;
116+
117+
m_iMemoryKBUsed = CRenderItemManager::CalcD3DResourceMemoryKBUsage(m_pD3DRenderTargetSurface);
118+
}
119+
120+
////////////////////////////////////////////////////////////////
121+
//
122+
// CVectorGraphicItem::ReleaseUnderlyingData
123+
//
124+
//
125+
//
126+
////////////////////////////////////////////////////////////////
127+
void CVectorGraphicItem::ReleaseUnderlyingData()
128+
{
129+
SAFE_RELEASE(m_pD3DRenderTargetSurface);
130+
SAFE_RELEASE(m_pD3DTexture);
131+
}
132+
133+
void CVectorGraphicItem::Resize(const CVector2D& size)
134+
{
135+
// Update size
136+
m_uiSizeX = static_cast<uint>(size.fX);
137+
m_uiSizeY = static_cast<uint>(size.fY);
138+
139+
// Recreate texture
140+
ReleaseUnderlyingData();
141+
CreateUnderlyingData();
142+
}

‎Client/core/Graphics/CRenderItemManager.cpp‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,40 @@ CTextureItem* CRenderItemManager::CreateTexture(const SString& strFullFilePath,
135135
if (!pTextureItem->IsValid())
136136
{
137137
SAFE_RELEASE(pTextureItem);
138-
return NULL;
138+
return nullptr;
139139
}
140140

141141
UpdateMemoryUsage();
142142

143143
return pTextureItem;
144144
}
145145

146+
////////////////////////////////////////////////////////////////
147+
//
148+
// CRenderItemManager::CreateVectorGraphic
149+
//
150+
//
151+
//
152+
////////////////////////////////////////////////////////////////
153+
CVectorGraphicItem* CRenderItemManager::CreateVectorGraphic(uint width, uint height)
154+
{
155+
if (!CanCreateRenderItem(CVectorGraphicItem::GetClassId()))
156+
return nullptr;
157+
158+
CVectorGraphicItem* pVectorItem = new CVectorGraphicItem;
159+
pVectorItem->PostConstruct(this, width, height);
160+
161+
if (!pVectorItem->IsValid())
162+
{
163+
SAFE_RELEASE(pVectorItem);
164+
return nullptr;
165+
}
166+
167+
UpdateMemoryUsage();
168+
169+
return pVectorItem;
170+
}
171+
146172
////////////////////////////////////////////////////////////////
147173
//
148174
// CRenderItemManager::CreateRenderTarget

‎Client/core/Graphics/CRenderItemManager.h‎

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,41 @@ class CRenderItemManager : public CRenderItemManagerInterface
2222
~CRenderItemManager();
2323

2424
// CRenderItemManagerInterface
25-
virtual void DoPulse();
26-
virtual CDxFontItem* CreateDxFont(const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY);
27-
virtual CGuiFontItem* CreateGuiFont(const SString& strFullFilePath, const SString& strFontName, uint uiSize);
28-
virtual CTextureItem* CreateTexture(const SString& strFullFilePath, const CPixels* pPixels, bool bMipMaps = true, uint uiSizeX = RDEFAULT,
29-
uint uiSizeY = RDEFAULT, ERenderFormat format = RFORMAT_UNKNOWN, ETextureAddress textureAddress = TADDRESS_WRAP,
30-
ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1);
31-
virtual CShaderItem* CreateShader(const SString& strFile, const SString& strRootPath, bool bIsRawData, SString& strOutStatus, float fPriority,
32-
float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask, const EffectMacroList& macros);
33-
virtual CRenderTargetItem* CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bWithAlphaChannel, bool bForce = false);
34-
virtual CScreenSourceItem* CreateScreenSource(uint uiSizeX, uint uiSizeY);
35-
virtual CWebBrowserItem* CreateWebBrowser(uint uiSizeX, uint uiSizeY);
36-
virtual bool SetRenderTarget(CRenderTargetItem* pItem, bool bClear);
37-
virtual void EnableSetRenderTargetOldVer(bool bEnable);
38-
virtual bool IsSetRenderTargetEnabledOldVer();
39-
virtual bool RestoreDefaultRenderTarget();
40-
virtual void UpdateBackBufferCopy();
41-
virtual void UpdateScreenSource(CScreenSourceItem* pScreenSourceItem, bool bResampleNow);
42-
virtual SShaderItemLayers* GetAppliedShaderForD3DData(CD3DDUMMY* pD3DData);
43-
virtual bool ApplyShaderItemToWorldTexture(CShaderItem* pShaderItem, const SString& strTextureNameMatch, CClientEntityBase* pClientEntity,
44-
bool bAppendLayers);
45-
virtual bool RemoveShaderItemFromWorldTexture(CShaderItem* pShaderItem, const SString& strTextureNameMatch, CClientEntityBase* pClientEntity);
46-
virtual void RemoveClientEntityRefs(CClientEntityBase* pClientEntity);
47-
virtual void GetVisibleTextureNames(std::vector<SString>& outNameList, const SString& strTextureNameMatch, ushort usModelID);
48-
virtual eDxTestMode GetTestMode() { return m_TestMode; }
49-
virtual void SetTestMode(eDxTestMode testMode);
50-
virtual void GetDxStatus(SDxStatus& outStatus);
51-
virtual CEffectCloner* GetEffectCloner() { return m_pEffectCloner; }
52-
virtual void PreDrawWorld();
53-
virtual void SetDepthBufferFormat(ERenderFormat depthBufferFormat) { m_depthBufferFormat = depthBufferFormat; }
54-
virtual ERenderFormat GetDepthBufferFormat() { return m_depthBufferFormat; }
55-
virtual void SaveReadableDepthBuffer();
56-
virtual void FlushNonAARenderTarget();
57-
virtual void HandleStretchRect(IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect,
58-
int Filter);
25+
virtual void DoPulse();
26+
virtual CDxFontItem* CreateDxFont(const SString& strFullFilePath, uint uiSize, bool bBold, DWORD ulQuality = DEFAULT_QUALITY);
27+
virtual CGuiFontItem* CreateGuiFont(const SString& strFullFilePath, const SString& strFontName, uint uiSize);
28+
virtual CTextureItem* CreateTexture(const SString& strFullFilePath, const CPixels* pPixels, bool bMipMaps = true, uint uiSizeX = RDEFAULT,
29+
uint uiSizeY = RDEFAULT, ERenderFormat format = RFORMAT_UNKNOWN, ETextureAddress textureAddress = TADDRESS_WRAP,
30+
ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1);
31+
virtual CShaderItem* CreateShader(const SString& strFile, const SString& strRootPath, bool bIsRawData, SString& strOutStatus, float fPriority,
32+
float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask, const EffectMacroList& macros);
33+
virtual CRenderTargetItem* CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bWithAlphaChannel, bool bForce = false);
34+
virtual CScreenSourceItem* CreateScreenSource(uint uiSizeX, uint uiSizeY);
35+
virtual CVectorGraphicItem* CreateVectorGraphic(uint width, uint height);
36+
virtual CWebBrowserItem* CreateWebBrowser(uint uiSizeX, uint uiSizeY);
37+
virtual bool SetRenderTarget(CRenderTargetItem* pItem, bool bClear);
38+
virtual void EnableSetRenderTargetOldVer(bool bEnable);
39+
virtual bool IsSetRenderTargetEnabledOldVer();
40+
virtual bool RestoreDefaultRenderTarget();
41+
virtual void UpdateBackBufferCopy();
42+
virtual void UpdateScreenSource(CScreenSourceItem* pScreenSourceItem, bool bResampleNow);
43+
virtual SShaderItemLayers* GetAppliedShaderForD3DData(CD3DDUMMY* pD3DData);
44+
virtual bool ApplyShaderItemToWorldTexture(CShaderItem* pShaderItem, const SString& strTextureNameMatch, CClientEntityBase* pClientEntity,
45+
bool bAppendLayers);
46+
virtual bool RemoveShaderItemFromWorldTexture(CShaderItem* pShaderItem, const SString& strTextureNameMatch, CClientEntityBase* pClientEntity);
47+
virtual void RemoveClientEntityRefs(CClientEntityBase* pClientEntity);
48+
virtual void GetVisibleTextureNames(std::vector<SString>& outNameList, const SString& strTextureNameMatch, ushort usModelID);
49+
virtual eDxTestMode GetTestMode() { return m_TestMode; }
50+
virtual void SetTestMode(eDxTestMode testMode);
51+
virtual void GetDxStatus(SDxStatus& outStatus);
52+
virtual CEffectCloner* GetEffectCloner() { return m_pEffectCloner; }
53+
virtual void PreDrawWorld();
54+
virtual void SetDepthBufferFormat(ERenderFormat depthBufferFormat) { m_depthBufferFormat = depthBufferFormat; }
55+
virtual ERenderFormat GetDepthBufferFormat() { return m_depthBufferFormat; }
56+
virtual void SaveReadableDepthBuffer();
57+
virtual void FlushNonAARenderTarget();
58+
virtual void HandleStretchRect(IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect,
59+
int Filter);
5960

6061
// CRenderItemManager
6162
void NotifyContructRenderItem(CRenderItem* pItem);

‎Client/mods/deathmatch/logic/CClientDisplay.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class CClientDisplay;
1717
enum eDisplayType
1818
{
1919
DISPLAY_TEXT,
20+
DISPLAY_VECTORGRAPHIC,
2021
};
2122

2223
class CClientDisplay

‎Client/mods/deathmatch/logic/CClientEntity.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,8 @@ unsigned int CClientEntity::GetTypeID(const char* szTypeName)
12131213
return CCLIENTSOUND;
12141214
else if (strcmp(szTypeName, "light") == 0)
12151215
return CCLIENTPOINTLIGHTS;
1216+
else if (strcmp(szTypeName, "svg") == 0)
1217+
return CCLIENTVECTORGRAPHIC;
12161218
else
12171219
return CCLIENTUNKNOWN;
12181220
}

‎Client/mods/deathmatch/logic/CClientEntity.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ enum eClientEntityType
7777
CCLIENTBROWSER,
7878
CCLIENTSEARCHLIGHT,
7979
CCLIENTIFP,
80+
CCLIENTVECTORGRAPHIC,
8081
CCLIENTUNKNOWN,
8182
};
8283

@@ -138,6 +139,7 @@ enum eCClientEntityClassTypes
138139
CLASS_CClientRenderTarget,
139140
CLASS_CClientScreenSource,
140141
CLASS_CClientWebBrowser,
142+
CLASS_CClientVectorGraphic,
141143
CLASS_CClientWeapon,
142144
CLASS_CClientEffect,
143145
CLASS_CClientPointLights,

‎Client/mods/deathmatch/logic/CClientPerfStat.LuaMemory.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ void CClientPerfStatLuaMemoryImpl::GetLuaMemoryStats(CClientPerfStatResult* pRes
294294
int RenderTargetCount = g_pClientGame->GetManager()->GetRenderElementManager()->GetRenderTargetCount();
295295
int ScreenSourceCount = g_pClientGame->GetManager()->GetRenderElementManager()->GetScreenSourceCount();
296296
int WebBrowserCount = g_pClientGame->GetManager()->GetRenderElementManager()->GetWebBrowserCount();
297+
int VectorGraphicCount = g_pClientGame->GetManager()->GetRenderElementManager()->GetVectorGraphicCount();
297298
TextItemCount = std::max(TextItemCount - 4, 0); // Remove count for radar items
298299
row[c++] = !TextItemCount ? "-" : SString("%d", TextItemCount);
299300
row[c++] = !DxFontCount ? "-" : SString("%d", DxFontCount);
@@ -303,6 +304,7 @@ void CClientPerfStatLuaMemoryImpl::GetLuaMemoryStats(CClientPerfStatResult* pRes
303304
row[c++] = !RenderTargetCount ? "-" : SString("%d", RenderTargetCount);
304305
row[c++] = !ScreenSourceCount ? "-" : SString("%d", ScreenSourceCount);
305306
row[c++] = !WebBrowserCount ? "-" : SString("%d", WebBrowserCount);
307+
row[c++] = !VectorGraphicCount ? "-" : SString("%d", VectorGraphicCount);
306308
}
307309

308310
// For each VM

‎Client/mods/deathmatch/logic/CClientRenderElementManager.cpp‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*****************************************************************************/
1010

1111
#include "StdInc.h"
12+
#include "CClientVectorGraphic.h"
1213

1314
////////////////////////////////////////////////////////////////
1415
//
@@ -27,6 +28,7 @@ CClientRenderElementManager::CClientRenderElementManager(CClientManager* pClient
2728
m_uiStatsRenderTargetCount = 0;
2829
m_uiStatsScreenSourceCount = 0;
2930
m_uiStatsWebBrowserCount = 0;
31+
m_uiStatsVectorGraphicCount = 0;
3032
}
3133

3234
////////////////////////////////////////////////////////////////
@@ -243,6 +245,33 @@ CClientWebBrowser* CClientRenderElementManager::CreateWebBrowser(uint uiSizeX, u
243245
return pWebBrowserElement;
244246
}
245247

248+
////////////////////////////////////////////////////////////////
249+
//
250+
// CClientRenderElementManager::CreateVectorGraphic
251+
//
252+
//
253+
//
254+
////////////////////////////////////////////////////////////////
255+
CClientVectorGraphic* CClientRenderElementManager::CreateVectorGraphic(uint width, uint height)
256+
{
257+
// Create the item
258+
CVectorGraphicItem* pVectorGraphicItem = m_pRenderItemManager->CreateVectorGraphic(width, height);
259+
260+
// Check create worked
261+
if (!pVectorGraphicItem)
262+
return nullptr;
263+
264+
// Create the element
265+
CClientVectorGraphic* pVectorGraphicElement = new CClientVectorGraphic(m_pClientManager, INVALID_ELEMENT_ID, pVectorGraphicItem);
266+
267+
// Add to this manager's list
268+
MapSet(m_ItemElementMap, pVectorGraphicElement->GetRenderItem(), pVectorGraphicElement);
269+
270+
m_uiStatsVectorGraphicCount++;
271+
272+
return pVectorGraphicElement;
273+
}
274+
246275
////////////////////////////////////////////////////////////////
247276
//
248277
// CClientRenderElementManager::FindAutoTexture
@@ -311,6 +340,8 @@ void CClientRenderElementManager::Remove(CClientRenderElement* pElement)
311340
m_uiStatsScreenSourceCount--;
312341
else if (pElement->IsA(CClientWebBrowser::GetClassId()))
313342
m_uiStatsWebBrowserCount--;
343+
else if (pElement->IsA(CClientVectorGraphic::GetClassId()))
344+
m_uiStatsVectorGraphicCount--;
314345
else if (pElement->IsA(CClientTexture::GetClassId()))
315346
m_uiStatsTextureCount--;
316347

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /