Skip to content
4 changes: 4 additions & 0 deletions Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,10 @@ void CCore::OnDeviceRestore()
void CCore::OnPreFxRender()
{
// Don't do nothing if nothing won't be drawn

if (CGraphics::GetSingleton().HasPrimitive3DPreGUIQueueItems())
CGraphics::GetSingleton().DrawPrimitive3DPreGUIQueue();

if (!CGraphics::GetSingleton().HasLine3DPreGUIQueueItems())
return;

Expand Down
68 changes: 66 additions & 2 deletions Client/core/Graphics/CGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "CMaterialLine3DBatcher.h"
#include "CPrimitiveBatcher.h"
#include "CPrimitiveMaterialBatcher.h"
#include "CPrimitive3DBatcher.h"
#include "CMaterialPrimitive3DBatcher.h"
#include "CAspectRatioConverter.h"
extern CCore* g_pCore;
extern bool g_bInGTAScene;
Expand Down Expand Up @@ -58,6 +60,10 @@ CGraphics::CGraphics(CLocalGUI* pGUI)
m_pLine3DBatcherPostGUI = new CLine3DBatcher(false);
m_pMaterialLine3DBatcherPreGUI = new CMaterialLine3DBatcher(true);
m_pMaterialLine3DBatcherPostGUI = new CMaterialLine3DBatcher(false);
m_pPrimitive3DBatcherPreGUI = new CPrimitive3DBatcher(true);
m_pPrimitive3DBatcherPostGUI = new CPrimitive3DBatcher(false);
m_pMaterialPrimitive3DBatcherPreGUI = new CMaterialPrimitive3DBatcher(true, this);
m_pMaterialPrimitive3DBatcherPostGUI = new CMaterialPrimitive3DBatcher(false, this);
m_pPrimitiveBatcher = new CPrimitiveBatcher();
m_pPrimitiveMaterialBatcher = new CPrimitiveMaterialBatcher(this);

Expand All @@ -84,6 +90,10 @@ CGraphics::~CGraphics()
SAFE_DELETE(m_pMaterialLine3DBatcherPostGUI);
SAFE_DELETE(m_pPrimitiveBatcher);
SAFE_DELETE(m_pPrimitiveMaterialBatcher);
SAFE_DELETE(m_pPrimitive3DBatcherPreGUI);
SAFE_DELETE(m_pPrimitive3DBatcherPostGUI);
SAFE_DELETE(m_pMaterialPrimitive3DBatcherPreGUI);
SAFE_DELETE(m_pMaterialPrimitive3DBatcherPostGUI);
SAFE_DELETE(m_pScreenGrabber);
SAFE_DELETE(m_pPixelsManager);
SAFE_DELETE(m_pAspectRatioConverter);
Expand Down Expand Up @@ -898,6 +908,44 @@ void CGraphics::DrawPrimitiveQueued(std::vector<PrimitiveVertice>* pVecVertices,
AddQueueItem(Item, bPostGUI);
}

void CGraphics::DrawPrimitive3DQueued(std::vector<PrimitiveVertice>* pVecVertices, D3DPRIMITIVETYPE eType, bool bPostGUI)
{
// Prevent queuing when minimized
if (g_pCore->IsWindowMinimized())
{
delete pVecVertices;
return;
}

// Add it to the queue
if (bPostGUI && !CCore::GetSingleton().IsMenuVisible())
m_pPrimitive3DBatcherPostGUI->AddPrimitive(eType, pVecVertices);
else
m_pPrimitive3DBatcherPreGUI->AddPrimitive(eType, pVecVertices);
}

void CGraphics::DrawMaterialPrimitive3DQueued(std::vector<PrimitiveMaterialVertice>* pVecVertices, D3DPRIMITIVETYPE eType, CMaterialItem* pMaterial, bool bPostGUI)
{
// Prevent queuing when minimized
if (g_pCore->IsWindowMinimized())
{
delete pVecVertices;
return;
}

if (CShaderItem* pShaderItem = DynamicCast<CShaderItem>(pMaterial))
{
// If material is a shader, use its current instance
pMaterial = pShaderItem->m_pShaderInstance;
}

// Add it to the queue
if (bPostGUI && !CCore::GetSingleton().IsMenuVisible())
m_pMaterialPrimitive3DBatcherPostGUI->AddPrimitive(eType, pMaterial, pVecVertices);
else
m_pMaterialPrimitive3DBatcherPreGUI->AddPrimitive(eType, pMaterial, pVecVertices);
}

void CGraphics::DrawMaterialPrimitiveQueued(std::vector<PrimitiveMaterialVertice>* pVecVertices, D3DPRIMITIVETYPE eType, CMaterialItem* pMaterial,
bool bPostGUI)
{
Expand Down Expand Up @@ -1437,7 +1485,10 @@ void CGraphics::OnDeviceCreate(IDirect3DDevice9* pDevice)
m_pMaterialLine3DBatcherPreGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
m_pMaterialLine3DBatcherPostGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
m_pPrimitiveBatcher->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
m_pPrimitiveMaterialBatcher->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
m_pPrimitive3DBatcherPreGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
m_pPrimitive3DBatcherPostGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
m_pMaterialPrimitive3DBatcherPreGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
m_pMaterialPrimitive3DBatcherPostGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
m_pRenderItemManager->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
m_pScreenGrabber->OnDeviceCreate(pDevice);
m_pPixelsManager->OnDeviceCreate(pDevice);
Expand Down Expand Up @@ -1513,6 +1564,8 @@ void CGraphics::DrawPostGUIQueue()
DrawQueue(m_PostGUIQueue);
m_pLine3DBatcherPostGUI->Flush();
m_pMaterialLine3DBatcherPostGUI->Flush();
m_pPrimitive3DBatcherPostGUI->Flush();
m_pMaterialPrimitive3DBatcherPostGUI->Flush();

// Both queues should be empty now, and there should be no outstanding refs
assert(m_PreGUIQueue.empty() && m_iDebugQueueRefs == 0);
Expand All @@ -1524,11 +1577,22 @@ void CGraphics::DrawLine3DPreGUIQueue()
m_pMaterialLine3DBatcherPreGUI->Flush();
}

bool CGraphics::HasLine3DPreGUIQueueItems()
void CGraphics::DrawPrimitive3DPreGUIQueue(void)
{
m_pPrimitive3DBatcherPreGUI->Flush();
m_pMaterialPrimitive3DBatcherPreGUI->Flush();
}

bool CGraphics::HasLine3DPreGUIQueueItems(void)
{
return m_pLine3DBatcherPreGUI->HasItems() || m_pMaterialLine3DBatcherPreGUI->HasItems();
}

bool CGraphics::HasPrimitive3DPreGUIQueueItems(void)
{
return m_pMaterialPrimitive3DBatcherPreGUI->HasItems() || m_pPrimitive3DBatcherPreGUI->HasItems();
}

void CGraphics::DrawQueue(std::vector<sDrawQueueItem>& Queue)
{
BeginDrawBatch();
Expand Down
43 changes: 28 additions & 15 deletions Client/core/Graphics/CGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CLine3DBatcher;
class CMaterialLine3DBatcher;
class CPrimitiveBatcher;
class CPrimitiveMaterialBatcher;
class CPrimitive3DBatcher;
class CMaterialPrimitive3DBatcher;
class CAspectRatioConverter;
struct IDirect3DDevice9;
struct IDirect3DSurface9;
Expand Down Expand Up @@ -65,6 +67,7 @@ class CGraphics : public CGraphicsInterface, public CSingleton<CGraphics>
{
friend class CDirect3DEvents9;
friend CPrimitiveMaterialBatcher;
friend CMaterialPrimitive3DBatcher;

public:
ZERO_ON_NEW
Expand Down Expand Up @@ -147,6 +150,10 @@ class CGraphics : public CGraphicsInterface, public CSingleton<CGraphics>

void DrawPrimitiveQueued(std::vector<PrimitiveVertice>* pVecVertices, D3DPRIMITIVETYPE eType, bool bPostGUI = false);
void DrawMaterialPrimitiveQueued(std::vector<PrimitiveMaterialVertice>* vertices, D3DPRIMITIVETYPE type, CMaterialItem* pMaterial, bool bPostGUI);

void DrawPrimitive3DQueued(std::vector<PrimitiveVertice>* pVecVertices, D3DPRIMITIVETYPE eType, bool bPostGUI);
void DrawMaterialPrimitive3DQueued(std::vector<PrimitiveMaterialVertice>* pVecVertices, D3DPRIMITIVETYPE eType, CMaterialItem* pMaterial, bool bPostGUI);

void DrawCircleQueued(float fX, float fY, float fRadius, float fStartAngle, float fStopAngle, unsigned long ulColor, unsigned long ulColorCenter,
short siSegments, float fRatio, bool bPostGUI);

Expand Down Expand Up @@ -174,10 +181,12 @@ class CGraphics : public CGraphicsInterface, public CSingleton<CGraphics>
bool CopyDataFromSurface(IDirect3DSurface9* pSurface, CBuffer& outBuffer);

// To draw queued up drawings
void DrawPreGUIQueue();
void DrawPostGUIQueue();
void DrawLine3DPreGUIQueue();
bool HasLine3DPreGUIQueueItems();
void DrawPreGUIQueue(void);
void DrawPostGUIQueue(void);
void DrawLine3DPreGUIQueue(void);
bool HasLine3DPreGUIQueueItems(void);
void DrawPrimitive3DPreGUIQueue(void);
bool HasPrimitive3DPreGUIQueueItems(void);

void DidRenderScene();
void SetProgressMessage(const SString& strMessage);
Expand Down Expand Up @@ -207,17 +216,21 @@ class CGraphics : public CGraphicsInterface, public CSingleton<CGraphics>

IDirect3DDevice9* m_pDevice;

CRenderItemManager* m_pRenderItemManager;
CScreenGrabberInterface* m_pScreenGrabber;
CPixelsManagerInterface* m_pPixelsManager;
CTileBatcher* m_pTileBatcher;
CLine3DBatcher* m_pLine3DBatcherPreGUI;
CLine3DBatcher* m_pLine3DBatcherPostGUI;
CMaterialLine3DBatcher* m_pMaterialLine3DBatcherPreGUI;
CMaterialLine3DBatcher* m_pMaterialLine3DBatcherPostGUI;
CPrimitiveBatcher* m_pPrimitiveBatcher;
CPrimitiveMaterialBatcher* m_pPrimitiveMaterialBatcher;
CAspectRatioConverter* m_pAspectRatioConverter;
CRenderItemManager* m_pRenderItemManager;
CScreenGrabberInterface* m_pScreenGrabber;
CPixelsManagerInterface* m_pPixelsManager;
CTileBatcher* m_pTileBatcher;
CLine3DBatcher* m_pLine3DBatcherPreGUI;
CLine3DBatcher* m_pLine3DBatcherPostGUI;
CMaterialLine3DBatcher* m_pMaterialLine3DBatcherPreGUI;
CMaterialLine3DBatcher* m_pMaterialLine3DBatcherPostGUI;
CPrimitiveBatcher* m_pPrimitiveBatcher;
CPrimitiveMaterialBatcher* m_pPrimitiveMaterialBatcher;
CPrimitive3DBatcher* m_pPrimitive3DBatcherPreGUI;
CPrimitive3DBatcher* m_pPrimitive3DBatcherPostGUI;
CMaterialPrimitive3DBatcher* m_pMaterialPrimitive3DBatcherPreGUI;
CMaterialPrimitive3DBatcher* m_pMaterialPrimitive3DBatcherPostGUI;
CAspectRatioConverter* m_pAspectRatioConverter;

// Fonts
ID3DXFont* m_pDXFonts[NUM_FONTS];
Expand Down
Loading