Skip to content

Commit 901ed44

Browse files
CrosRoad95patrikjuvonen
authored andcommitted
Add dxDrawPrimitive3D and dxDrawMaterialPrimitive3D (#760)
* dxDrawPrimitive3d and dxDrawMaterialPrimitive3d * a bit clean up * comment update * fix along Botder tips * fixed along Qaisjp tips * fixed * Fix formatting, update errors and clear vectors
1 parent bdb8013 commit 901ed44

File tree

10 files changed

+703
-46
lines changed

10 files changed

+703
-46
lines changed

Client/core/CCore.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,10 @@ void CCore::OnDeviceRestore()
18581858
void CCore::OnPreFxRender()
18591859
{
18601860
// Don't do nothing if nothing won't be drawn
1861+
1862+
if (CGraphics::GetSingleton().HasPrimitive3DPreGUIQueueItems())
1863+
CGraphics::GetSingleton().DrawPrimitive3DPreGUIQueue();
1864+
18611865
if (!CGraphics::GetSingleton().HasLine3DPreGUIQueueItems())
18621866
return;
18631867

Client/core/Graphics/CGraphics.cpp

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "CMaterialLine3DBatcher.h"
1616
#include "CPrimitiveBatcher.h"
1717
#include "CPrimitiveMaterialBatcher.h"
18+
#include "CPrimitive3DBatcher.h"
19+
#include "CMaterialPrimitive3DBatcher.h"
1820
#include "CAspectRatioConverter.h"
1921
extern CCore* g_pCore;
2022
extern bool g_bInGTAScene;
@@ -58,6 +60,10 @@ CGraphics::CGraphics(CLocalGUI* pGUI)
5860
m_pLine3DBatcherPostGUI = new CLine3DBatcher(false);
5961
m_pMaterialLine3DBatcherPreGUI = new CMaterialLine3DBatcher(true);
6062
m_pMaterialLine3DBatcherPostGUI = new CMaterialLine3DBatcher(false);
63+
m_pPrimitive3DBatcherPreGUI = new CPrimitive3DBatcher(true);
64+
m_pPrimitive3DBatcherPostGUI = new CPrimitive3DBatcher(false);
65+
m_pMaterialPrimitive3DBatcherPreGUI = new CMaterialPrimitive3DBatcher(true, this);
66+
m_pMaterialPrimitive3DBatcherPostGUI = new CMaterialPrimitive3DBatcher(false, this);
6167
m_pPrimitiveBatcher = new CPrimitiveBatcher();
6268
m_pPrimitiveMaterialBatcher = new CPrimitiveMaterialBatcher(this);
6369

@@ -84,6 +90,10 @@ CGraphics::~CGraphics()
8490
SAFE_DELETE(m_pMaterialLine3DBatcherPostGUI);
8591
SAFE_DELETE(m_pPrimitiveBatcher);
8692
SAFE_DELETE(m_pPrimitiveMaterialBatcher);
93+
SAFE_DELETE(m_pPrimitive3DBatcherPreGUI);
94+
SAFE_DELETE(m_pPrimitive3DBatcherPostGUI);
95+
SAFE_DELETE(m_pMaterialPrimitive3DBatcherPreGUI);
96+
SAFE_DELETE(m_pMaterialPrimitive3DBatcherPostGUI);
8797
SAFE_DELETE(m_pScreenGrabber);
8898
SAFE_DELETE(m_pPixelsManager);
8999
SAFE_DELETE(m_pAspectRatioConverter);
@@ -898,6 +908,44 @@ void CGraphics::DrawPrimitiveQueued(std::vector<PrimitiveVertice>* pVecVertices,
898908
AddQueueItem(Item, bPostGUI);
899909
}
900910

911+
void CGraphics::DrawPrimitive3DQueued(std::vector<PrimitiveVertice>* pVecVertices, D3DPRIMITIVETYPE eType, bool bPostGUI)
912+
{
913+
// Prevent queuing when minimized
914+
if (g_pCore->IsWindowMinimized())
915+
{
916+
delete pVecVertices;
917+
return;
918+
}
919+
920+
// Add it to the queue
921+
if (bPostGUI && !CCore::GetSingleton().IsMenuVisible())
922+
m_pPrimitive3DBatcherPostGUI->AddPrimitive(eType, pVecVertices);
923+
else
924+
m_pPrimitive3DBatcherPreGUI->AddPrimitive(eType, pVecVertices);
925+
}
926+
927+
void CGraphics::DrawMaterialPrimitive3DQueued(std::vector<PrimitiveMaterialVertice>* pVecVertices, D3DPRIMITIVETYPE eType, CMaterialItem* pMaterial, bool bPostGUI)
928+
{
929+
// Prevent queuing when minimized
930+
if (g_pCore->IsWindowMinimized())
931+
{
932+
delete pVecVertices;
933+
return;
934+
}
935+
936+
if (CShaderItem* pShaderItem = DynamicCast<CShaderItem>(pMaterial))
937+
{
938+
// If material is a shader, use its current instance
939+
pMaterial = pShaderItem->m_pShaderInstance;
940+
}
941+
942+
// Add it to the queue
943+
if (bPostGUI && !CCore::GetSingleton().IsMenuVisible())
944+
m_pMaterialPrimitive3DBatcherPostGUI->AddPrimitive(eType, pMaterial, pVecVertices);
945+
else
946+
m_pMaterialPrimitive3DBatcherPreGUI->AddPrimitive(eType, pMaterial, pVecVertices);
947+
}
948+
901949
void CGraphics::DrawMaterialPrimitiveQueued(std::vector<PrimitiveMaterialVertice>* pVecVertices, D3DPRIMITIVETYPE eType, CMaterialItem* pMaterial,
902950
bool bPostGUI)
903951
{
@@ -1437,7 +1485,10 @@ void CGraphics::OnDeviceCreate(IDirect3DDevice9* pDevice)
14371485
m_pMaterialLine3DBatcherPreGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
14381486
m_pMaterialLine3DBatcherPostGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
14391487
m_pPrimitiveBatcher->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
1440-
m_pPrimitiveMaterialBatcher->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
1488+
m_pPrimitive3DBatcherPreGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
1489+
m_pPrimitive3DBatcherPostGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
1490+
m_pMaterialPrimitive3DBatcherPreGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
1491+
m_pMaterialPrimitive3DBatcherPostGUI->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
14411492
m_pRenderItemManager->OnDeviceCreate(pDevice, GetViewportWidth(), GetViewportHeight());
14421493
m_pScreenGrabber->OnDeviceCreate(pDevice);
14431494
m_pPixelsManager->OnDeviceCreate(pDevice);
@@ -1513,6 +1564,8 @@ void CGraphics::DrawPostGUIQueue()
15131564
DrawQueue(m_PostGUIQueue);
15141565
m_pLine3DBatcherPostGUI->Flush();
15151566
m_pMaterialLine3DBatcherPostGUI->Flush();
1567+
m_pPrimitive3DBatcherPostGUI->Flush();
1568+
m_pMaterialPrimitive3DBatcherPostGUI->Flush();
15161569

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

1527-
bool CGraphics::HasLine3DPreGUIQueueItems()
1580+
void CGraphics::DrawPrimitive3DPreGUIQueue(void)
1581+
{
1582+
m_pPrimitive3DBatcherPreGUI->Flush();
1583+
m_pMaterialPrimitive3DBatcherPreGUI->Flush();
1584+
}
1585+
1586+
bool CGraphics::HasLine3DPreGUIQueueItems(void)
15281587
{
15291588
return m_pLine3DBatcherPreGUI->HasItems() || m_pMaterialLine3DBatcherPreGUI->HasItems();
15301589
}
15311590

1591+
bool CGraphics::HasPrimitive3DPreGUIQueueItems(void)
1592+
{
1593+
return m_pMaterialPrimitive3DBatcherPreGUI->HasItems() || m_pPrimitive3DBatcherPreGUI->HasItems();
1594+
}
1595+
15321596
void CGraphics::DrawQueue(std::vector<sDrawQueueItem>& Queue)
15331597
{
15341598
BeginDrawBatch();

Client/core/Graphics/CGraphics.h

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class CLine3DBatcher;
2828
class CMaterialLine3DBatcher;
2929
class CPrimitiveBatcher;
3030
class CPrimitiveMaterialBatcher;
31+
class CPrimitive3DBatcher;
32+
class CMaterialPrimitive3DBatcher;
3133
class CAspectRatioConverter;
3234
struct IDirect3DDevice9;
3335
struct IDirect3DSurface9;
@@ -65,6 +67,7 @@ class CGraphics : public CGraphicsInterface, public CSingleton<CGraphics>
6567
{
6668
friend class CDirect3DEvents9;
6769
friend CPrimitiveMaterialBatcher;
70+
friend CMaterialPrimitive3DBatcher;
6871

6972
public:
7073
ZERO_ON_NEW
@@ -147,6 +150,10 @@ class CGraphics : public CGraphicsInterface, public CSingleton<CGraphics>
147150

148151
void DrawPrimitiveQueued(std::vector<PrimitiveVertice>* pVecVertices, D3DPRIMITIVETYPE eType, bool bPostGUI = false);
149152
void DrawMaterialPrimitiveQueued(std::vector<PrimitiveMaterialVertice>* vertices, D3DPRIMITIVETYPE type, CMaterialItem* pMaterial, bool bPostGUI);
153+
154+
void DrawPrimitive3DQueued(std::vector<PrimitiveVertice>* pVecVertices, D3DPRIMITIVETYPE eType, bool bPostGUI);
155+
void DrawMaterialPrimitive3DQueued(std::vector<PrimitiveMaterialVertice>* pVecVertices, D3DPRIMITIVETYPE eType, CMaterialItem* pMaterial, bool bPostGUI);
156+
150157
void DrawCircleQueued(float fX, float fY, float fRadius, float fStartAngle, float fStopAngle, unsigned long ulColor, unsigned long ulColorCenter,
151158
short siSegments, float fRatio, bool bPostGUI);
152159

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

176183
// To draw queued up drawings
177-
void DrawPreGUIQueue();
178-
void DrawPostGUIQueue();
179-
void DrawLine3DPreGUIQueue();
180-
bool HasLine3DPreGUIQueueItems();
184+
void DrawPreGUIQueue(void);
185+
void DrawPostGUIQueue(void);
186+
void DrawLine3DPreGUIQueue(void);
187+
bool HasLine3DPreGUIQueueItems(void);
188+
void DrawPrimitive3DPreGUIQueue(void);
189+
bool HasPrimitive3DPreGUIQueueItems(void);
181190

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

208217
IDirect3DDevice9* m_pDevice;
209218

210-
CRenderItemManager* m_pRenderItemManager;
211-
CScreenGrabberInterface* m_pScreenGrabber;
212-
CPixelsManagerInterface* m_pPixelsManager;
213-
CTileBatcher* m_pTileBatcher;
214-
CLine3DBatcher* m_pLine3DBatcherPreGUI;
215-
CLine3DBatcher* m_pLine3DBatcherPostGUI;
216-
CMaterialLine3DBatcher* m_pMaterialLine3DBatcherPreGUI;
217-
CMaterialLine3DBatcher* m_pMaterialLine3DBatcherPostGUI;
218-
CPrimitiveBatcher* m_pPrimitiveBatcher;
219-
CPrimitiveMaterialBatcher* m_pPrimitiveMaterialBatcher;
220-
CAspectRatioConverter* m_pAspectRatioConverter;
219+
CRenderItemManager* m_pRenderItemManager;
220+
CScreenGrabberInterface* m_pScreenGrabber;
221+
CPixelsManagerInterface* m_pPixelsManager;
222+
CTileBatcher* m_pTileBatcher;
223+
CLine3DBatcher* m_pLine3DBatcherPreGUI;
224+
CLine3DBatcher* m_pLine3DBatcherPostGUI;
225+
CMaterialLine3DBatcher* m_pMaterialLine3DBatcherPreGUI;
226+
CMaterialLine3DBatcher* m_pMaterialLine3DBatcherPostGUI;
227+
CPrimitiveBatcher* m_pPrimitiveBatcher;
228+
CPrimitiveMaterialBatcher* m_pPrimitiveMaterialBatcher;
229+
CPrimitive3DBatcher* m_pPrimitive3DBatcherPreGUI;
230+
CPrimitive3DBatcher* m_pPrimitive3DBatcherPostGUI;
231+
CMaterialPrimitive3DBatcher* m_pMaterialPrimitive3DBatcherPreGUI;
232+
CMaterialPrimitive3DBatcher* m_pMaterialPrimitive3DBatcherPostGUI;
233+
CAspectRatioConverter* m_pAspectRatioConverter;
221234

222235
// Fonts
223236
ID3DXFont* m_pDXFonts[NUM_FONTS];

0 commit comments

Comments
 (0)