Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/setElementModel_Vehicles_Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX authored Aug 9, 2023
2 parents fbd36fb + e1717d0 commit 3641ef5
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Client/core/CChat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void CChat::Draw(bool bUseCacheTexture, bool bAllowOutline)
// Make sure render target size is reasonable
int iRenderTargetSizeX = Clamp<int>(8, chatSize.fX, pGraphics->GetViewportWidth());
int iRenderTargetSizeY = Clamp<int>(8, chatSize.fY, pGraphics->GetViewportHeight());
m_pCacheTexture = pGraphics->GetRenderItemManager()->CreateRenderTarget(iRenderTargetSizeX, iRenderTargetSizeY, true, true);
m_pCacheTexture = pGraphics->GetRenderItemManager()->CreateRenderTarget(iRenderTargetSizeX, iRenderTargetSizeY, false, true, 0, true);
if (m_pCacheTexture)
m_RenderTargetChatSize = chatSize;
else
Expand Down
2 changes: 1 addition & 1 deletion Client/core/CScreenGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ bool CScreenGrabber::GetBackBufferPixels(uint uiSizeX, uint uiSizeY, CBuffer& bu

// Try to create new one if needed
if (uiSizeX > 0)
m_pScreenShotTemp = CGraphics::GetSingleton().GetRenderItemManager()->CreateRenderTarget(uiSizeX, uiSizeY, false, true);
m_pScreenShotTemp = CGraphics::GetSingleton().GetRenderItemManager()->CreateRenderTarget(uiSizeX, uiSizeY, false, false, 0, true);
}

if (!m_pScreenShotTemp)
Expand Down
2 changes: 1 addition & 1 deletion Client/core/Graphics/CGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2154,7 +2154,7 @@ void CGraphics::DrawProgressMessage(bool bPreserveBackbuffer)
// Save backbuffer pixels
if (!m_pTempBackBufferData)
m_pTempBackBufferData =
CGraphics::GetSingleton().GetRenderItemManager()->CreateRenderTarget(BackBufferDesc.Width, BackBufferDesc.Height, true, true);
CGraphics::GetSingleton().GetRenderItemManager()->CreateRenderTarget(BackBufferDesc.Width, BackBufferDesc.Height, false, true, 0, true);
if (!m_pTempBackBufferData)
break;
hr = m_pDevice->StretchRect(pD3DBackBufferSurface, NULL, m_pTempBackBufferData->m_pD3DRenderTargetSurface, NULL, D3DTEXF_POINT);
Expand Down
17 changes: 13 additions & 4 deletions Client/core/Graphics/CRenderItem.RenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
//
//
////////////////////////////////////////////////////////////////
void CRenderTargetItem::PostConstruct(CRenderItemManager* pManager, uint uiSizeX, uint uiSizeY, bool bWithAlphaChannel, bool bIncludeInMemoryStats)
void CRenderTargetItem::PostConstruct(CRenderItemManager* pManager, uint uiSizeX, uint uiSizeY, bool bHasSurfaceFormat, bool bWithAlphaChannel,
int surfaceFormat, bool bIncludeInMemoryStats)
{
Super::PostConstruct(pManager, bIncludeInMemoryStats);
m_uiSizeX = uiSizeX;
m_uiSizeY = uiSizeY;
m_uiSurfaceSizeX = uiSizeX;
m_uiSurfaceSizeY = uiSizeY;
m_bHasSurfaceFormat = bHasSurfaceFormat;
m_bWithAlphaChannel = bWithAlphaChannel;
m_eSurfaceFormat = surfaceFormat;

// Initial creation of d3d data
CreateUnderlyingData();
Expand Down Expand Up @@ -98,9 +101,15 @@ void CRenderTargetItem::CreateUnderlyingData()
// i == 1 - EvictManagedResources
// 3rd try - i == 2 - 32 bit target
// 4th try - i == 3 - 16 bit target
D3DFORMAT Format = i & 1 ? D3DFMT_R5G6B5 : D3DFMT_X8R8G8B8;
if (m_bWithAlphaChannel)
Format = D3DFMT_A8R8G8B8;
D3DFORMAT Format;
if (m_bHasSurfaceFormat)
Format = (D3DFORMAT)m_eSurfaceFormat;
else
{
Format = i & 1 ? D3DFMT_R5G6B5 : D3DFMT_X8R8G8B8;
if (m_bWithAlphaChannel)
Format = D3DFMT_A8R8G8B8;
}
if (SUCCEEDED(
m_pDevice->CreateTexture(m_uiSizeX, m_uiSizeY, 1, D3DUSAGE_RENDERTARGET, Format, D3DPOOL_DEFAULT, (IDirect3DTexture9**)&m_pD3DTexture, NULL)))
break;
Expand Down
7 changes: 4 additions & 3 deletions Client/core/Graphics/CRenderItemManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ CVectorGraphicItem* CRenderItemManager::CreateVectorGraphic(uint width, uint hei
//
//
////////////////////////////////////////////////////////////////
CRenderTargetItem* CRenderItemManager::CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bWithAlphaChannel, bool bForce)
CRenderTargetItem* CRenderItemManager::CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bHasSurfaceFormat, bool bWithAlphaChannel, int surfaceFormat,
bool bForce)
{
if (!bForce && !CanCreateRenderItem(CRenderTargetItem::GetClassId()))
return NULL;
Expand All @@ -187,7 +188,7 @@ CRenderTargetItem* CRenderItemManager::CreateRenderTarget(uint uiSizeX, uint uiS
bool bIncludeInMemoryStats = (bForce == false);

CRenderTargetItem* pRenderTargetItem = new CRenderTargetItem();
pRenderTargetItem->PostConstruct(this, uiSizeX, uiSizeY, bWithAlphaChannel, bIncludeInMemoryStats);
pRenderTargetItem->PostConstruct(this, uiSizeX, uiSizeY, bHasSurfaceFormat, bWithAlphaChannel, surfaceFormat, bIncludeInMemoryStats);

if (!pRenderTargetItem->IsValid())
{
Expand Down Expand Up @@ -498,7 +499,7 @@ void CRenderItemManager::UpdateBackBufferCopySize()

// Try to create new one if needed
if (uiSizeX > 0)
m_pBackBufferCopy = CreateRenderTarget(uiSizeX, uiSizeY, false, true);
m_pBackBufferCopy = CreateRenderTarget(uiSizeX, uiSizeY, false, false, (_D3DFORMAT)0, true);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Client/core/Graphics/CRenderItemManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class CRenderItemManager : public CRenderItemManagerInterface
ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1);
virtual CShaderItem* CreateShader(const SString& strFile, const SString& strRootPath, bool bIsRawData, SString& strOutStatus, float fPriority,
float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask, const EffectMacroList& macros);
virtual CRenderTargetItem* CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bWithAlphaChannel, bool bForce = false);
virtual CRenderTargetItem* CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bHasSurfaceFormat, bool bWithAlphaChannel, int surfaceFormat,
bool bForce = false);
virtual CScreenSourceItem* CreateScreenSource(uint uiSizeX, uint uiSizeY);
virtual CVectorGraphicItem* CreateVectorGraphic(uint width, uint height);
virtual CWebBrowserItem* CreateWebBrowser(uint uiSizeX, uint uiSizeY);
Expand Down
5 changes: 3 additions & 2 deletions Client/mods/deathmatch/logic/CClientRenderElementManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ CClientShader* CClientRenderElementManager::CreateShader(const SString& strFile,
//
//
////////////////////////////////////////////////////////////////
CClientRenderTarget* CClientRenderElementManager::CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bWithAlphaChannel)
CClientRenderTarget* CClientRenderElementManager::CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bHasSurfaceFormat, bool bWithAlphaChannel,
_D3DFORMAT surfaceFormat)
{
// Create the item
CRenderTargetItem* pRenderTargetItem = m_pRenderItemManager->CreateRenderTarget(uiSizeX, uiSizeY, bWithAlphaChannel);
CRenderTargetItem* pRenderTargetItem = m_pRenderItemManager->CreateRenderTarget(uiSizeX, uiSizeY, bHasSurfaceFormat, bWithAlphaChannel, surfaceFormat);

// Check create worked
if (!pRenderTargetItem)
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientRenderElementManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CClientRenderElementManager
ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1);
CClientShader* CreateShader(const SString& strFile, const SString& strRootPath, bool bIsRawData, SString& strOutStatus, float fPriority, float fMaxDistance,
bool bLayered, bool bDebug, int iTypeMask, const EffectMacroList& macros);
CClientRenderTarget* CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bWithAlphaChannel);
CClientRenderTarget* CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bHasSurfaceFormat, bool bWithAlphaChannel, _D3DFORMAT surfaceFormat);
CClientScreenSource* CreateScreenSource(uint uiSizeX, uint uiSizeY);
CClientWebBrowser* CreateWebBrowser(uint uiSizeX, uint uiSizeY, bool bIsLocal, bool bTransparent);
CClientVectorGraphic* CreateVectorGraphic(uint width, uint height);
Expand Down
33 changes: 33 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,39 @@ ADD_ENUM(eModelIdeFlag::IS_BREAKABLE_STATUE, "is_breakable_statue")
ADD_ENUM(eModelIdeFlag::IS_CRANE, "is_crane")
IMPLEMENT_ENUM_CLASS_END("model-ide-flag")

// https://learn.microsoft.com/en-us/windows/win32/direct3d9/d3dformat
IMPLEMENT_ENUM_CLASS_BEGIN(_D3DFORMAT)
ADD_ENUM(_D3DFORMAT::D3DFMT_R8G8B8, "r8g8b8")
ADD_ENUM(_D3DFORMAT::D3DFMT_A8R8G8B8, "a8r8g8b8")
ADD_ENUM(_D3DFORMAT::D3DFMT_X8R8G8B8, "x8r8g8b8")
ADD_ENUM(_D3DFORMAT::D3DFMT_R5G6B5, "r5g6b5")
ADD_ENUM(_D3DFORMAT::D3DFMT_X1R5G5B5, "x1r5g5b5")
ADD_ENUM(_D3DFORMAT::D3DFMT_A1R5G5B5, "a1r5g5b5")
ADD_ENUM(_D3DFORMAT::D3DFMT_A4R4G4B4, "a4r4g4b4")
ADD_ENUM(_D3DFORMAT::D3DFMT_R3G3B2, "r3g3b2")
ADD_ENUM(_D3DFORMAT::D3DFMT_A8, "a8")
ADD_ENUM(_D3DFORMAT::D3DFMT_A8R3G3B2, "a8r3g3b2")
ADD_ENUM(_D3DFORMAT::D3DFMT_X4R4G4B4, "x4r4g4b4")
ADD_ENUM(_D3DFORMAT::D3DFMT_A2B10G10R10, "a2b10g10r10")
ADD_ENUM(_D3DFORMAT::D3DFMT_A8B8G8R8, "a8b8g8r8")
ADD_ENUM(_D3DFORMAT::D3DFMT_X8B8G8R8, "x8b8g8r8")
ADD_ENUM(_D3DFORMAT::D3DFMT_G16R16, "g16r16")
ADD_ENUM(_D3DFORMAT::D3DFMT_A2R10G10B10, "a2r10g10b10")
ADD_ENUM(_D3DFORMAT::D3DFMT_A16B16G16R16, "a16b16g16r16")
ADD_ENUM(_D3DFORMAT::D3DFMT_A8P8, "a8p8")
ADD_ENUM(_D3DFORMAT::D3DFMT_P8, "p8")
ADD_ENUM(_D3DFORMAT::D3DFMT_L8, "l8")
ADD_ENUM(_D3DFORMAT::D3DFMT_L16, "l16")
ADD_ENUM(_D3DFORMAT::D3DFMT_A8L8, "a8l8")
ADD_ENUM(_D3DFORMAT::D3DFMT_A4L4, "a4l4")
ADD_ENUM(_D3DFORMAT::D3DFMT_R16F, "r16f")
ADD_ENUM(_D3DFORMAT::D3DFMT_G16R16F, "g16r16f")
ADD_ENUM(_D3DFORMAT::D3DFMT_A16B16G16R16F, "a16b16g16r16f")
ADD_ENUM(_D3DFORMAT::D3DFMT_R32F, "r32f")
ADD_ENUM(_D3DFORMAT::D3DFMT_G32R32F, "g32r32f")
ADD_ENUM(_D3DFORMAT::D3DFMT_A32B32G32R32F, "a32b32g32r32f")
IMPLEMENT_ENUM_CLASS_END("surface-format")

//
// CResource from userdata
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ DECLARE_ENUM_CLASS(eSoundEffectParams::I3DL2Reverb);
DECLARE_ENUM_CLASS(eSoundEffectParams::ParamEq);
DECLARE_ENUM_CLASS(eSoundEffectParams::Reverb);
DECLARE_ENUM_CLASS(eModelIdeFlag);
DECLARE_ENUM_CLASS(_D3DFORMAT);

class CRemoteCall;

Expand Down
17 changes: 13 additions & 4 deletions Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,21 +1187,30 @@ int CLuaDrawingDefs::DxCreateShader(lua_State* luaVM)
int CLuaDrawingDefs::DxCreateRenderTarget(lua_State* luaVM)
{
// element dxCreateRenderTarget( int sizeX, int sizeY [, int withAlphaChannel = false ] )
// element dxCreateRenderTarget( int sizeX, int sizeY, SurfaceFormat surfaceFormat )
CVector2D vecSize;
bool bWithAlphaChannel;
bool bWithAlphaChannel = false;
bool bHasSurfaceFormat = false;
_D3DFORMAT surfaceFormat;

CScriptArgReader argStream(luaVM);
argStream.ReadVector2D(vecSize);
argStream.ReadBool(bWithAlphaChannel, false);
if (argStream.NextIsString())
{
argStream.ReadEnumString(surfaceFormat);
bHasSurfaceFormat = true;
}
else
argStream.ReadBool(bWithAlphaChannel, false);

if (!argStream.HasErrors())
{
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaVM);
CResource* pParentResource = pLuaMain ? pLuaMain->GetResource() : NULL;
if (pParentResource)
{
CClientRenderTarget* pRenderTarget =
g_pClientGame->GetManager()->GetRenderElementManager()->CreateRenderTarget((uint)vecSize.fX, (uint)vecSize.fY, bWithAlphaChannel);
CClientRenderTarget* pRenderTarget = g_pClientGame->GetManager()->GetRenderElementManager()->CreateRenderTarget(
(uint)vecSize.fX, (uint)vecSize.fY, bHasSurfaceFormat, bWithAlphaChannel, surfaceFormat);
if (pRenderTarget)
{
// Make it a child of the resource's file root ** CHECK Should parent be pFileResource, and element added to pParentResource's ElementGroup? **
Expand Down
8 changes: 6 additions & 2 deletions Client/sdk/core/CRenderItemManagerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class CRenderItemManagerInterface
ETextureType textureType = TTYPE_TEXTURE, uint uiVolumeDepth = 1) = 0;
virtual CShaderItem* CreateShader(const SString& strFile, const SString& strRootPath, bool bIsRawData, SString& strOutStatus, float fPriority,
float fMaxDistance, bool bLayered, bool bDebug, int iTypeMask, const EffectMacroList& macros) = 0;
virtual CRenderTargetItem* CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bWithAlphaChannel, bool bForce = false) = 0;
virtual CRenderTargetItem* CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bHasSurfaceFormat, bool bWithAlphaChannel,
int surfaceFormat, bool bForce = false) = 0;
virtual CScreenSourceItem* CreateScreenSource(uint uiSizeX, uint uiSizeY) = 0;
virtual CWebBrowserItem* CreateWebBrowser(uint uiSizeX, uint uiSizeY) = 0;
virtual CVectorGraphicItem* CreateVectorGraphic(uint uiSizeX, uint uiSizeY) = 0;
Expand Down Expand Up @@ -500,7 +501,8 @@ class CRenderTargetItem : public CTextureItem
{
DECLARE_CLASS(CRenderTargetItem, CTextureItem)
CRenderTargetItem() : ClassInit(this) {}
virtual void PostConstruct(CRenderItemManager* pManager, uint uiSizeX, uint uiSizeY, bool bWithAlphaChannel, bool bIncludeInMemoryStats);
virtual void PostConstruct(CRenderItemManager* pManager, uint uiSizeX, uint uiSizeY, bool bHasSurfaceFormat, bool bWithAlphaChannel,
int surfaceFormat, bool bIncludeInMemoryStats);
virtual void PreDestruct();
virtual bool IsValid();
virtual void OnLostDevice();
Expand All @@ -510,6 +512,8 @@ class CRenderTargetItem : public CTextureItem
bool ReadPixels(CBuffer& outBuffer, SString& strOutError);

bool m_bWithAlphaChannel;
bool m_bHasSurfaceFormat;
int m_eSurfaceFormat;
IDirect3DSurface9* m_pD3DRenderTargetSurface;
IDirect3DSurface9* m_pD3DZStencilSurface;
IDirect3DSurface9* m_pD3DReadSurface;
Expand Down

0 comments on commit 3641ef5

Please sign in to comment.