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