Skip to content

Commit f8c93f9

Browse files
committed
RendererVertex
1 parent 0bed151 commit f8c93f9

File tree

2 files changed

+157
-10
lines changed

2 files changed

+157
-10
lines changed

Windows_Libs/Dev/Render/Renderer.h

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
class Renderer
77
{
88
public:
9-
109
struct Texture
1110
{
1211
bool allocated;
@@ -44,6 +43,8 @@ class Renderer
4443
COMMAND_SET_FACE_CULL,
4544
};
4645

46+
struct Context;
47+
4748
struct CommandBuffer
4849
{
4950
struct Command
@@ -144,7 +145,7 @@ class Renderer
144145
};
145146
};
146147

147-
148+
void AddVertices(uint32_t param_1,uint32_t param_2,void *param_3,Context *param_4);
148149
};
149150

150151
struct DeferredCBuff
@@ -205,15 +206,15 @@ class Renderer
205206
ID3D11Buffer* pid3d11buffer1130;
206207
ID3D11Buffer* pid3d11buffer1138;
207208
uint64_t qword1140;
208-
DWORD dword1148;
209+
UINT dword1148;
209210
BYTE gap114C[4];
210211
ID3D11Buffer* pid3d11buffer1150;
211212
BYTE gap1158[8];
212213
DirectX::XMMATRIX arraymatrix1160[2];
213214
Renderer::CommandBuffer* qword11E0;
214215
DWORD dword11E8;
215-
DWORD dword11EC;
216-
DWORD dword11F0;
216+
C4JRender::eVertexType dword11EC;
217+
C4JRender::ePixelShaderType dword11F0;
217218
BYTE byte11F4;
218219
BYTE gap11F5[3];
219220
std::vector<DeferredCBuff> std__vector11F8;
@@ -273,9 +274,9 @@ class Renderer
273274
ID3D11DepthStencilView* qword98;
274275
ID3D11VertexShader** qwordA0;
275276
BYTE gapA8[16];
276-
uint64_t qwordB8;
277+
ID3D11PixelShader** qwordB8;
277278
BYTE gapC0[16];
278-
uint64_t qwordD0;
279+
uint32_t* qwordD0;
279280
ID3D11InputLayout** qwordD8;
280281
ID3D11Buffer* qwordE0;
281282
ID3D11Buffer* qwordE8;
@@ -286,8 +287,8 @@ class Renderer
286287
BYTE byteFC;
287288
BYTE gapFD[3];
288289
_RTL_CRITICAL_SECTION rtl_critical_section100;
289-
DWORD dword128;
290-
DWORD dword12C;
290+
C4JRender::eVertexType m_VertexType;
291+
C4JRender::ePixelShaderType m_PixelShaderType;
291292
C4JRender::eViewportType m_ViewportType;
292293
BYTE byte134;
293294
BYTE gap135[3];
@@ -307,6 +308,25 @@ class Renderer
307308
DWORD dword517C;
308309
BYTE gap5180[328];
309310
BYTE m_bShouldScreenGrabNextFrame;
311+
312+
// RendererVertex.cpp
313+
public:
314+
void DrawVertexBuffer(C4JRender::ePrimitiveType PrimitiveType, int count, ID3D11Buffer *buffer, C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType);
315+
private:
316+
void DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType, C4JRender::ePrimitiveType PrimitiveType, int *count, bool *indexed);
317+
static enum D3D_PRIMITIVE_TOPOLOGY* m_Topologies;
318+
public:
319+
void DrawVertices(C4JRender::ePrimitiveType PrimitiveType,int count,void *vertices,C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType);
320+
321+
// idk
322+
void StateUpdate();
323+
Context* getContext();
324+
float* MatrixGet(int param_1);
325+
326+
void UpdateFogState();
327+
void UpdateViewportState();
328+
void UpdateLightingState();
329+
void UpdateTexGenState();
310330
};
311331

312332
// Singleton
Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,128 @@
1-
#pragma once
1+
#include "Renderer.h"
2+
3+
void Renderer::DrawVertexBuffer(C4JRender::ePrimitiveType PrimitiveType, int count, ID3D11Buffer *buffer, C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType) {
4+
auto context = this->getContext();
5+
auto d3d11 = context->m_pDeviceContext;
6+
7+
bool indexed;
8+
this->DrawVertexSetup(vType, psType, PrimitiveType, &count, &indexed);
9+
this->StateUpdate();
10+
11+
d3d11->IASetVertexBuffers(0, 1, &buffer, &qwordD0[vType], nullptr);
12+
if (indexed) {
13+
d3d11->DrawIndexed(count, 0, 0);
14+
} else {
15+
d3d11->Draw(count, 0);
16+
}
17+
18+
}
19+
20+
void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType, C4JRender::ePrimitiveType PrimitiveType, int *count, bool *indexed) {
21+
auto context = this->getContext();
22+
auto d3d11 = context->m_pDeviceContext;
23+
24+
if (vType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && context->byte1064) {
25+
vType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
26+
}
27+
28+
if (vType != m_VertexType) {
29+
d3d11->VSSetShader(qwordA0[vType], nullptr, 0);
30+
d3d11->IASetInputLayout(qwordD8[vType]);
31+
m_VertexType = vType;
32+
}
33+
34+
if (psType != m_PixelShaderType) {
35+
d3d11->PSSetShader(qwordB8[psType], nullptr, 0);
36+
m_PixelShaderType = psType;
37+
}
38+
39+
if (context->bool1020) {
40+
D3D11_MAPPED_SUBRESOURCE mappedResource;
41+
d3d11->Map(context->pid3d11buffer10C0, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
42+
auto pfVar5 = this->MatrixGet(0);
43+
std::memcpy(mappedResource.pData, pfVar5, 64);
44+
d3d11->Unmap(context->pid3d11buffer10C0, 0);
45+
context->bool1020 = false;
46+
}
47+
if (context->bool1021) {
48+
D3D11_MAPPED_SUBRESOURCE mappedResource;
49+
d3d11->Map(context->pid3d11buffer10D0, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
50+
auto pfVar5 = this->MatrixGet(1);
51+
std::memcpy(mappedResource.pData, pfVar5, 64);
52+
d3d11->Unmap(context->pid3d11buffer10D0, 0);
53+
context->bool1021 = false;
54+
}
55+
if (context->bool1022) {
56+
D3D11_MAPPED_SUBRESOURCE mappedResource;
57+
d3d11->Map(context->pid3d11buffer10D8, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
58+
auto pfVar5 = this->MatrixGet(2);
59+
std::memcpy(mappedResource.pData, pfVar5, 64);
60+
d3d11->Unmap(context->pid3d11buffer10D8, 0);
61+
context->bool1022 = false;
62+
}
63+
64+
this->UpdateFogState();
65+
this->UpdateViewportState();
66+
this->UpdateLightingState();
67+
this->UpdateTexGenState();
68+
69+
d3d11->IASetPrimitiveTopology(m_Topologies[PrimitiveType]);
70+
71+
if (PrimitiveType == C4JRender::PRIMITIVE_TYPE_QUAD_LIST) {
72+
d3d11->IASetIndexBuffer(qwordE0, DXGI_FORMAT_R16_UINT, 0);
73+
*count = (*count * 6 + 3) / 4; // ceil
74+
*indexed = true;
75+
return;
76+
}
77+
else if (PrimitiveType == C4JRender::PRIMITIVE_TYPE_TRIANGLE_FAN) {
78+
d3d11->IASetIndexBuffer(qwordE8, DXGI_FORMAT_R16_UINT, 0);
79+
*count = (*count - 2) * 3;
80+
*indexed = true;
81+
return;
82+
}
83+
else {
84+
d3d11->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0);
85+
*count = *count;
86+
*indexed = false;
87+
return;
88+
}
89+
}
90+
91+
void Renderer::DrawVertices(C4JRender::ePrimitiveType PrimitiveType,int count,void *vertices,C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType) {
92+
auto context = this->getContext();
93+
auto d3d11 = context->m_pDeviceContext;
94+
auto commandBuffer = context->qword11E0;
95+
96+
if (commandBuffer != nullptr) {
97+
if (vType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && context->byte1064) {
98+
vType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
99+
}
100+
101+
context->dword11EC = vType;
102+
context->dword11F0 = psType;
103+
104+
commandBuffer->AddVertices(qwordD0[vType], count, vertices, context);
105+
} else {
106+
bool indexed;
107+
this->DrawVertexSetup(vType, psType, PrimitiveType, &count, &indexed);
108+
109+
if (0x100000 < context->dword1148 + qwordD0[vType] * count) {
110+
context->dword1148 = 0;
111+
}
112+
113+
D3D11_MAPPED_SUBRESOURCE mappedResource;
114+
d3d11->Map(context->pid3d11buffer1150, 0, context->dword1148 == 0 ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource);
115+
std::memcpy((uint8_t*)mappedResource.pData + context->dword1148, vertices, qwordD0[vType] * count);
116+
d3d11->Unmap(context->pid3d11buffer1150, 0);
117+
this->StateUpdate();
118+
119+
d3d11->IASetVertexBuffers(0, 1, &context->pid3d11buffer1150, &qwordD0[vType], &context->dword1148);
120+
if (indexed) {
121+
d3d11->DrawIndexed(count, 0, 0);
122+
} else {
123+
d3d11->Draw(count, 0);
124+
}
125+
126+
context->dword1148 += qwordD0[vType] * count;
127+
}
128+
}

0 commit comments

Comments
 (0)