Skip to content

Commit

Permalink
Merge branch 'master' into TheNormalnij/new_txd_allocating
Browse files Browse the repository at this point in the history
  • Loading branch information
Pirulax authored Aug 30, 2023
2 parents a8d0172 + da113b9 commit dc7a378
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 30 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/sync-master-to-maetro.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ jobs:
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout release/maetro
if ! git merge master --ff --no-edit
then
# Discard locale conflicts
git checkout --ours -- Shared/installer/locale "Shared/data/MTA San Andreas/MTA/locale"
git add --verbose Shared/installer/locale "Shared/data/MTA San Andreas/MTA/locale"
# Discard install_cef.lua conflicts
git checkout --ours -- utils/buildactions/install_cef.lua
git add --verbose utils/buildactions/install_cef.lua
# We should be done with the merge now
git commit --no-edit
fi
git merge master --no-ff --no-edit --no-commit
# Discard locale conflicts
git checkout --ours -- Shared/installer/locale "Shared/data/MTA San Andreas/MTA/locale"
git add --verbose Shared/installer/locale "Shared/data/MTA San Andreas/MTA/locale"
# Discard install_cef.lua conflicts
git checkout --ours -- utils/buildactions/install_cef.lua
git add --verbose utils/buildactions/install_cef.lua
# We should be done with the merge now
printf "Synchronize changes from 1.6 master branch [ci skip]\n\n" > commit.txt
git log --expand-tabs=4 --pretty=format:'%h %s' release/maetro..master >> commit.txt
git commit --no-edit --allow-empty -F commit.txt
git push origin release/maetro
91 changes: 90 additions & 1 deletion Client/core/Graphics/CPixelsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ void CPixelsManager::OnDeviceCreate(IDirect3DDevice9* pDevice)
// Copy pixels from texture
//
////////////////////////////////////////////////////////////////
bool CPixelsManager::GetTexturePixels(IDirect3DBaseTexture9* pD3DBaseTexture, CPixels& outPixels, const RECT* pRect, uint uiSurfaceIndex)
bool CPixelsManager::GetTexturePixels(IDirect3DBaseTexture9* pD3DBaseTexture, CPixels& outPixels, EPixelsFormatType pixelsFormat, ERenderFormat renderFormat,
bool bMipMaps, const RECT* pRect, uint uiSurfaceIndex)
{
if (!pD3DBaseTexture)
return false;
Expand All @@ -73,6 +74,9 @@ bool CPixelsManager::GetTexturePixels(IDirect3DBaseTexture9* pD3DBaseTexture, CP
D3DRESOURCETYPE resourceType = pD3DBaseTexture->GetType();
if (resourceType == D3DRTYPE_VOLUMETEXTURE)
{
if (pixelsFormat != EPixelsFormat::PLAIN)
return D3DXGetVolumePixels((IDirect3DVolumeTexture9*)pD3DBaseTexture, outPixels, pixelsFormat, renderFormat, bMipMaps, pRect, uiSurfaceIndex);

return GetVolumeTexturePixels((IDirect3DVolumeTexture9*)pD3DBaseTexture, outPixels, pRect, uiSurfaceIndex);
}
else if (resourceType == D3DRTYPE_CUBETEXTURE)
Expand Down Expand Up @@ -100,6 +104,9 @@ bool CPixelsManager::GetTexturePixels(IDirect3DBaseTexture9* pD3DBaseTexture, CP
CVARS_GET("allow_screen_upload", bAllowScreenUpload);
if (bAllowScreenUpload)
{
if (pixelsFormat != EPixelsFormat::PLAIN)
return D3DXGetSurfacePixels(pD3DSurface, outPixels, pixelsFormat, renderFormat, bMipMaps, pRect);

// Get pixels onto offscreen surface
IDirect3DSurface9* pLockableSurface = GetRTLockableSurface(pD3DSurface);

Expand All @@ -118,6 +125,9 @@ bool CPixelsManager::GetTexturePixels(IDirect3DBaseTexture9* pD3DBaseTexture, CP
}
else if (Desc.Usage == 0)
{
if (pixelsFormat != EPixelsFormat::PLAIN)
return D3DXGetSurfacePixels(pD3DSurface, outPixels, pixelsFormat, renderFormat, bMipMaps, pRect);

if (Desc.Format == D3DFMT_A8R8G8B8 || Desc.Format == D3DFMT_X8R8G8B8 || Desc.Format == D3DFMT_R5G6B5)
{
// Direct reading will work here
Expand Down Expand Up @@ -467,6 +477,85 @@ bool CPixelsManager::SetSurfacePixels(IDirect3DSurface9* pD3DSurface, const CPix
return true;
}

////////////////////////////////////////////////////////////////
//
// CPixelsManager::D3DXGetSurfacePixels
//
// Returns D3DXIMAGE_FILEFORMAT pixels
//
////////////////////////////////////////////////////////////////
bool CPixelsManager::D3DXGetSurfacePixels(IDirect3DSurface9* pD3DSurface, CPixels& outPixels, EPixelsFormatType pixelsFormat, ERenderFormat renderFormat,
bool bMipMaps, const RECT* pRect)
{
if (!pD3DSurface)
return false;

ID3DXBuffer* dxBuffer;
CAutoReleaseMe<ID3DXBuffer> Thanks1(dxBuffer);

D3DXIMAGE_FILEFORMAT dxFileFormat = D3DXIFF_DDS;
switch (pixelsFormat)
{
case EPixelsFormat::PNG:
dxFileFormat = D3DXIFF_PNG;
break;
case EPixelsFormat::JPEG:
dxFileFormat = D3DXIFF_JPG;
break;
}

if (dxFileFormat != D3DXIFF_DDS)
{
if (!FAILED(D3DXSaveSurfaceToFileInMemory(&dxBuffer, dxFileFormat, pD3DSurface, NULL, pRect)))
{
outPixels.SetSize(dxBuffer->GetBufferSize());
char* pPixelsData = outPixels.GetData();
memcpy(pPixelsData, dxBuffer->GetBufferPointer(), outPixels.GetSize());
return true;
}
return false;
}

// Convert surface to DDS texture of requested format

IDirect3DTexture9* pD3DTempTexture = NULL;
IDirect3DSurface9* pD3DTempSurface = NULL;
CAutoReleaseMe<IDirect3DTexture9> Thanks2(pD3DTempTexture);
CAutoReleaseMe<IDirect3DSurface9> Thanks3(pD3DTempSurface);

D3DSURFACE_DESC Desc;
pD3DSurface->GetDesc(&Desc);

D3DFORMAT dxFormat = (D3DFORMAT)renderFormat;
if (dxFormat == D3DFMT_UNKNOWN)
dxFormat = Desc.Format;

if (pRect)
{
Desc.Width = pRect->right - pRect->left;
Desc.Height = pRect->bottom - pRect->top;
}

if (FAILED(m_pDevice->CreateTexture(Desc.Width, Desc.Height, !bMipMaps, NULL, dxFormat, D3DPOOL_SYSTEMMEM, &pD3DTempTexture, NULL)))
return false;

if (FAILED(pD3DTempTexture->GetSurfaceLevel(0, &pD3DTempSurface)))
return false;

if (FAILED(D3DXLoadSurfaceFromSurface(pD3DTempSurface, NULL, NULL, pD3DSurface, NULL, pRect, D3DX_FILTER_NONE, 0)))
return false;

// Extract pixels from converted texture
if (!FAILED(D3DXSaveTextureToFileInMemory(&dxBuffer, dxFileFormat, pD3DTempTexture, NULL)))
{
outPixels.SetSize(dxBuffer->GetBufferSize());
char* pPixelsData = outPixels.GetData();
memcpy(pPixelsData, dxBuffer->GetBufferPointer(), outPixels.GetSize());
return true;
}
return false;
}

////////////////////////////////////////////////////////////////
//
// CPixelsManager::GetRTLockableSurface
Expand Down
8 changes: 7 additions & 1 deletion Client/core/Graphics/CPixelsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class CPixelsManager : public CPixelsManagerInterface
// CPixelsManagerInterface
virtual void OnDeviceCreate(IDirect3DDevice9* pDevice);
virtual bool IsPixels(const CPixels& pixels);
virtual bool GetTexturePixels(IDirect3DBaseTexture9* pD3DBaseTexture, CPixels& outPixels, const RECT* pRect = NULL, uint uiSurfaceIndex = 0);
virtual bool GetTexturePixels(IDirect3DBaseTexture9* pD3DBaseTexture, CPixels& outPixels, EPixelsFormatType pixelsFormat = EPixelsFormat::PLAIN,
ERenderFormat renderFormat = RFORMAT_UNKNOWN, bool bMipMaps = true, const RECT* pRect = NULL, uint uiSurfaceIndex = 0);
virtual bool SetTexturePixels(IDirect3DBaseTexture9* pD3DBaseTexture, const CPixels& pixels, const RECT* pRect = NULL, uint uiSurfaceIndex = 0);
virtual bool GetPixelsSize(const CPixels& pixels, uint& uiOutWidth, uint& uiOutHeight);
virtual EPixelsFormatType GetPixelsFormat(const CPixels& pixels);
Expand All @@ -62,6 +63,11 @@ class CPixelsManager : public CPixelsManagerInterface
bool GetVolumePixels(IDirect3DVolume9* pD3DVolume, CPixels& outPixels, const RECT* pRect, uint uiSlice);
bool SetVolumePixels(IDirect3DVolume9* pD3DVolume, const CPixels& pixels, const RECT* pRect, uint uiSlice);

bool D3DXGetSurfacePixels(IDirect3DSurface9* pD3DSurface, CPixels& outPixels, EPixelsFormatType pixelsFormat, ERenderFormat renderFormat, bool bMipMaps,
const RECT* pRect);
bool D3DXGetVolumePixels(IDirect3DVolumeTexture9* pD3DVolumeTexture, CPixels& outPixels, EPixelsFormatType pixelsFormat, ERenderFormat renderFormat,
bool bMipMaps, const RECT* pRect, uint uiSlice);

// Util
static int GetRectWidth(const RECT& rc);
static int GetRectHeight(const RECT& rc);
Expand Down
106 changes: 106 additions & 0 deletions Client/core/Graphics/CPixelsManager_VolumeTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,112 @@ bool CPixelsManager::SetVolumePixels(IDirect3DVolume9* pD3DSurface, const CPixel
return true;
}

////////////////////////////////////////////////////////////////
//
// CPixelsManager::D3DXGetVolumePixels
//
// Returns D3DXIMAGE_FILEFORMAT pixels
//
////////////////////////////////////////////////////////////////
bool CPixelsManager::D3DXGetVolumePixels(IDirect3DVolumeTexture9* pD3DVolumeTexture, CPixels& outPixels, EPixelsFormatType pixelsFormat,
ERenderFormat renderFormat, bool bMipMaps, const RECT* pRect, uint uiSlice)
{
if (!pD3DVolumeTexture)
return false;

IDirect3DVolume9* pVolume = NULL;
CAutoReleaseMe<IDirect3DVolume9> Thanks1(pVolume);

pD3DVolumeTexture->GetVolumeLevel(0, &pVolume);
if (!pVolume)
return false;

D3DVOLUME_DESC Desc;
pVolume->GetDesc(&Desc);

D3DBOX box;
if (pRect)
{
assert(pRect->left >= 0 && pRect->top >= 0 && pRect->right <= (int)Desc.Width && pRect->bottom <= (int)Desc.Height);
box.Left = pRect->left;
box.Top = pRect->top;
box.Right = pRect->right;
box.Bottom = pRect->bottom;
Desc.Width = pRect->right - pRect->left;
Desc.Height = pRect->bottom - pRect->top;
}
else
{
box.Left = 0;
box.Top = 0;
box.Right = Desc.Width;
box.Bottom = Desc.Height;
}
box.Front = uiSlice;
box.Back = uiSlice + 1;

D3DXIMAGE_FILEFORMAT dxFileFormat = D3DXIFF_DDS;
switch (pixelsFormat)
{
case EPixelsFormat::PNG:
dxFileFormat = D3DXIFF_PNG;
break;
case EPixelsFormat::JPEG:
dxFileFormat = D3DXIFF_JPG;
break;
}

D3DFORMAT dxFormat = (D3DFORMAT)renderFormat;
if (dxFormat == D3DFMT_UNKNOWN)
dxFormat = Desc.Format;

bool bNeedToConvert = dxFileFormat == D3DXIFF_DDS;
if (bNeedToConvert && Desc.Format == dxFormat && !bMipMaps)
bNeedToConvert = false; // No need to convert DDS if compression is the same and no mipmaps required

ID3DXBuffer* dxBuffer;
CAutoReleaseMe<ID3DXBuffer> Thanks2(dxBuffer);
if (!FAILED(D3DXSaveVolumeToFileInMemory(&dxBuffer, bNeedToConvert ? D3DXIFF_DDS : dxFileFormat, pVolume, NULL, &box)))
{
if (bNeedToConvert)
{
// Convert volume slice to DDS texture of requested format
IDirect3DTexture9* pD3DTempTexture = NULL;
IDirect3DSurface9* pD3DTempSurface = NULL;
CAutoReleaseMe<IDirect3DTexture9> Thanks3(pD3DTempTexture);
CAutoReleaseMe<IDirect3DSurface9> Thanks4(pD3DTempSurface);

if (FAILED(m_pDevice->CreateTexture(Desc.Width, Desc.Height, !bMipMaps, NULL, dxFormat, D3DPOOL_SYSTEMMEM, &pD3DTempTexture, NULL)))
return false;

if (FAILED(pD3DTempTexture->GetSurfaceLevel(0, &pD3DTempSurface)))
return false;

if (FAILED(D3DXLoadSurfaceFromFileInMemory(pD3DTempSurface, NULL, NULL, dxBuffer->GetBufferPointer(), dxBuffer->GetBufferSize(), NULL,
D3DX_FILTER_NONE, 0, NULL)))
return false;

// Extract pixels from converted texture
if (!FAILED(D3DXSaveTextureToFileInMemory(&dxBuffer, dxFileFormat, pD3DTempTexture, NULL)))
{
outPixels.SetSize(dxBuffer->GetBufferSize());
char* pPixelsData = outPixels.GetData();
memcpy(pPixelsData, dxBuffer->GetBufferPointer(), outPixels.GetSize());
return true;
}
}
else
{
// Use source pixels buffer
outPixels.SetSize(dxBuffer->GetBufferSize());
char* pPixelsData = outPixels.GetData();
memcpy(pPixelsData, dxBuffer->GetBufferPointer(), outPixels.GetSize());
return true;
}
}
return false;
}

////////////////////////////////////////////////////////////////
//
// CPixelsManager::LockVolumeRect
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ IMPLEMENT_ENUM_END("weapon-skill")
IMPLEMENT_ENUM_BEGIN(ERenderFormat)
ADD_ENUM(RFORMAT_UNKNOWN, "unknown")
ADD_ENUM(RFORMAT_ARGB, "argb")
ADD_ENUM(RFORMAT_XRGB, "xrgb")
ADD_ENUM(RFORMAT_RGB, "rgb")
ADD_ENUM(RFORMAT_DXT1, "dxt1")
ADD_ENUM(RFORMAT_DXT2, "dxt2")
ADD_ENUM(RFORMAT_DXT3, "dxt3")
Expand Down Expand Up @@ -314,6 +316,7 @@ ADD_ENUM(EPixelsFormat::UNKNOWN, "unknown")
ADD_ENUM(EPixelsFormat::PLAIN, "plain")
ADD_ENUM(EPixelsFormat::JPEG, "jpeg")
ADD_ENUM(EPixelsFormat::PNG, "png")
ADD_ENUM(EPixelsFormat::DDS, "dds")
IMPLEMENT_ENUM_END("pixel-format")

IMPLEMENT_ENUM_BEGIN(EBlendModeType)
Expand Down
25 changes: 18 additions & 7 deletions Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1773,17 +1773,28 @@ int CLuaDrawingDefs::DxGetStatus(lua_State* luaVM)

int CLuaDrawingDefs::DxGetTexturePixels(lua_State* luaVM)
{
// string dxGetTexturePixels( [ int surfaceIndex, ] element texture [, int x, int y, int width, int height ] )
CClientTexture* pTexture;
CVector2D vecPosition;
CVector2D vecSize;
int surfaceIndex = 0;
// string dxGetTexturePixels( [ int surfaceIndex, ] element texture [, string pixelsFormat = "plain" [, string textureFormat = "argb"] [, bool mipmaps = true]]
// [, int x, int y, int width, int height ] )
CClientTexture* pTexture;
CVector2D vecPosition;
CVector2D vecSize;
int surfaceIndex = 0;
EPixelsFormatType pixelsFormat = EPixelsFormat::PLAIN;
ERenderFormat textureFormat = RFORMAT_UNKNOWN;
bool bMipMaps = true;

CScriptArgReader argStream(luaVM);
if (argStream.NextIsNumber())
argStream.ReadNumber(surfaceIndex);
argStream.ReadUserData(pTexture);

if (argStream.NextIsEnumString(pixelsFormat))
{
argStream.ReadEnumString(pixelsFormat, EPixelsFormat::PLAIN);
argStream.ReadIfNextIsEnumString(textureFormat, RFORMAT_UNKNOWN);
argStream.ReadIfNextIsBool(bMipMaps, true);
}

argStream.ReadVector2D(vecPosition, CVector2D());
argStream.ReadVector2D(vecSize, CVector2D());

Expand All @@ -1794,8 +1805,8 @@ int CLuaDrawingDefs::DxGetTexturePixels(lua_State* luaVM)
CPixels pixels;

// TODO: "height ? &rc : NULL" - height will always be set to 0 or another number! Why does this exist?
if (g_pCore->GetGraphics()->GetPixelsManager()->GetTexturePixels(pTexture->GetTextureItem()->m_pD3DTexture, pixels, vecSize.fY == 0 ? NULL : &rc,
surfaceIndex))
if (g_pCore->GetGraphics()->GetPixelsManager()->GetTexturePixels(pTexture->GetTextureItem()->m_pD3DTexture, pixels, pixelsFormat, textureFormat,
bMipMaps, vecSize.fY == 0 ? NULL : &rc, surfaceIndex))
{
lua_pushlstring(luaVM, pixels.GetData(), pixels.GetSize());
return 1;
Expand Down
12 changes: 12 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void CLuaWorldDefs::LoadFunctions()
{
constexpr static const std::pair<const char*, lua_CFunction> functions[]{// World get functions
{"getTime", GetTime},
{"getColorFilter", ArgumentParser<GetColorFilter>},
{"getRoofPosition", GetRoofPosition},
{"getGroundPosition", GetGroundPosition},
{"processLineOfSight", ProcessLineOfSight},
Expand Down Expand Up @@ -2024,6 +2025,17 @@ bool CLuaWorldDefs::SetColorFilter(uchar ucPass0Red, uchar ucPass0Green, uchar u
return true;
}

CLuaMultiReturn<uchar, uchar, uchar, uchar, uchar, uchar, uchar, uchar> CLuaWorldDefs::GetColorFilter(bool isOriginal)
{
SColor uColor0 = 0;
SColor uColor1 = 0;
g_pMultiplayer->GetColorFilter(uColor0.ulARGB, uColor1.ulARGB, isOriginal);
return {
uColor0.R, uColor0.G, uColor0.B, uColor0.A,
uColor1.R, uColor1.G, uColor1.B, uColor1.A,
};
}

bool CLuaWorldDefs::SetGrainMultiplier(eGrainMultiplierType type, float fMultiplier)
{
g_pMultiplayer->SetGrainMultiplier(type, fMultiplier);
Expand Down
7 changes: 4 additions & 3 deletions Client/mods/deathmatch/logic/luadefs/CLuaWorldDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ class CLuaWorldDefs : public CLuaDefs

LUA_DECLARE(CreateExplosion);

static bool ResetColorFilter();
static bool SetColorFilter(uchar ucPass0Red, uchar ucPass0Green, uchar ucPass0Blue, uchar ucPass0Alpha, uchar ucPass1Red, uchar ucPass1Green,
uchar ucPass1Blue, uchar ucPass1Alpha);
static bool ResetColorFilter();
static bool SetColorFilter(uchar ucPass0Red, uchar ucPass0Green, uchar ucPass0Blue, uchar ucPass0Alpha,
uchar ucPass1Red, uchar ucPass1Green, uchar ucPass1Blue, uchar ucPass1Alpha);
static CLuaMultiReturn<uchar, uchar, uchar, uchar, uchar, uchar, uchar, uchar> GetColorFilter(bool isOriginal = false);

static bool SetGrainMultiplier(eGrainMultiplierType type, float fMultiplier);
static bool SetGrainLevel(uchar ucLevel);
Expand Down
Loading

0 comments on commit dc7a378

Please sign in to comment.