chore: better name matching & add some definitions
fix: add asserts where they were missing
This commit is contained in:
@@ -10,8 +10,8 @@ D3D11_PRIMITIVE_TOPOLOGY *Renderer::m_Topologies = nullptr;
|
||||
void Renderer::DrawVertexBuffer(C4JRender::ePrimitiveType PrimitiveType, int count, ID3D11Buffer *buffer, C4JRender::eVertexType vType,
|
||||
C4JRender::ePixelShaderType psType)
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
ID3D11DeviceContext *d3d11 = context.m_pDeviceContext;
|
||||
Renderer::Context &c = this->getContext();
|
||||
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
|
||||
|
||||
int drawCount = count;
|
||||
bool indexed = false;
|
||||
@@ -35,11 +35,11 @@ void Renderer::DrawVertexBuffer(C4JRender::ePrimitiveType PrimitiveType, int cou
|
||||
void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType, C4JRender::ePrimitiveType PrimitiveType, int *count,
|
||||
bool *indexed)
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
ID3D11DeviceContext *d3d11 = context.m_pDeviceContext;
|
||||
Renderer::Context &c = this->getContext();
|
||||
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
|
||||
|
||||
C4JRender::eVertexType effectiveVertexType = vType;
|
||||
if (effectiveVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && context.lightingEnabled)
|
||||
if (effectiveVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && c.lightingEnabled)
|
||||
{
|
||||
effectiveVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
|
||||
}
|
||||
@@ -59,28 +59,28 @@ void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelSh
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
|
||||
if (context.matrixDirty[0])
|
||||
if (c.matrixDirty[MATRIX_MODE_MODELVIEW])
|
||||
{
|
||||
d3d11->Map(context.cbMatrix0, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, this->MatrixGet(0), sizeof(DirectX::XMMATRIX));
|
||||
d3d11->Unmap(context.cbMatrix0, 0);
|
||||
context.matrixDirty[0] = false;
|
||||
d3d11->Map(c.m_modelViewMatrix, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW), sizeof(DirectX::XMMATRIX));
|
||||
d3d11->Unmap(c.m_modelViewMatrix, 0);
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW] = false;
|
||||
}
|
||||
|
||||
if (context.matrixDirty[1])
|
||||
if (c.matrixDirty[MATRIX_MODE_MODELVIEW_UNK1])
|
||||
{
|
||||
d3d11->Map(context.cbMatrix2, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, this->MatrixGet(1), sizeof(DirectX::XMMATRIX));
|
||||
d3d11->Unmap(context.cbMatrix2, 0);
|
||||
context.matrixDirty[1] = false;
|
||||
d3d11->Map(c.cbMatrix2, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW_UNK1), sizeof(DirectX::XMMATRIX));
|
||||
d3d11->Unmap(c.cbMatrix2, 0);
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_UNK1] = false;
|
||||
}
|
||||
|
||||
if (context.matrixDirty[2])
|
||||
if (c.matrixDirty[MATRIX_MODE_MODELVIEW_UNK2])
|
||||
{
|
||||
d3d11->Map(context.cbMatrix3, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, this->MatrixGet(2), sizeof(DirectX::XMMATRIX));
|
||||
d3d11->Unmap(context.cbMatrix3, 0);
|
||||
context.matrixDirty[2] = false;
|
||||
d3d11->Map(c.cbMatrix3, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW_UNK2), sizeof(DirectX::XMMATRIX));
|
||||
d3d11->Unmap(c.cbMatrix3, 0);
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_UNK2] = false;
|
||||
}
|
||||
|
||||
this->UpdateFogState();
|
||||
@@ -113,22 +113,22 @@ void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelSh
|
||||
void Renderer::DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count, void *vertices, C4JRender::eVertexType vType,
|
||||
C4JRender::ePixelShaderType psType)
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
ID3D11DeviceContext *d3d11 = context.m_pDeviceContext;
|
||||
Renderer::CommandBuffer *commandBuffer = context.commandBuffer;
|
||||
Renderer::Context &c = this->getContext();
|
||||
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
|
||||
Renderer::CommandBuffer *commandBuffer = c.commandBuffer;
|
||||
|
||||
if (commandBuffer != nullptr)
|
||||
{
|
||||
C4JRender::eVertexType effectiveVertexType = vType;
|
||||
if (effectiveVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && context.lightingEnabled)
|
||||
if (effectiveVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && c.lightingEnabled)
|
||||
{
|
||||
effectiveVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
|
||||
}
|
||||
|
||||
context.recordingPrimitiveType = PrimitiveType;
|
||||
context.recordingVertexType = effectiveVertexType;
|
||||
c.recordingPrimitiveType = PrimitiveType;
|
||||
c.recordingVertexType = effectiveVertexType;
|
||||
const UINT stride = vertexStrideTable[effectiveVertexType];
|
||||
commandBuffer->AddVertices(stride, static_cast<UINT>(count), vertices, context);
|
||||
commandBuffer->AddVertices(stride, static_cast<UINT>(count), vertices, c);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -137,27 +137,30 @@ void Renderer::DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count,
|
||||
this->DrawVertexSetup(vType, psType, PrimitiveType, &drawCount, &indexed);
|
||||
|
||||
const UINT stride = vertexStrideTable[vType];
|
||||
const UINT copySize = stride * static_cast<UINT>(count);
|
||||
if (context.dynamicVertexOffset + copySize > 0x100000u)
|
||||
const UINT vertexBytes = stride * static_cast<UINT>(count);
|
||||
|
||||
assert(vertexBytes <= Context::VERTEX_BUFFER_SIZE);
|
||||
|
||||
if (c.dynamicVertexOffset + vertexBytes > Context::VERTEX_BUFFER_SIZE)
|
||||
{
|
||||
context.dynamicVertexOffset = 0;
|
||||
c.dynamicVertexOffset = 0;
|
||||
}
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
const D3D11_MAP mapType = context.dynamicVertexOffset == 0 ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
const HRESULT hr = d3d11->Map(context.dynamicVertexBuffer, 0, mapType, 0, &mapped);
|
||||
const D3D11_MAP mapType = c.dynamicVertexOffset == 0 ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||
const HRESULT hr = d3d11->Map(c.dynamicVertexBuffer, 0, mapType, 0, &mapped);
|
||||
if (hr != 0)
|
||||
{
|
||||
std::printf("ERROR: 0x%x\n", static_cast<unsigned int>(hr));
|
||||
}
|
||||
|
||||
std::memcpy(static_cast<std::uint8_t *>(mapped.pData) + context.dynamicVertexOffset, vertices, copySize);
|
||||
d3d11->Unmap(context.dynamicVertexBuffer, 0);
|
||||
std::memcpy(static_cast<std::uint8_t *>(mapped.pData) + c.dynamicVertexOffset, vertices, vertexBytes);
|
||||
d3d11->Unmap(c.dynamicVertexBuffer, 0);
|
||||
|
||||
this->StateUpdate();
|
||||
|
||||
ID3D11Buffer *dynamicBuffer = context.dynamicVertexBuffer;
|
||||
const UINT vertexOffset = context.dynamicVertexOffset;
|
||||
ID3D11Buffer *dynamicBuffer = c.dynamicVertexBuffer;
|
||||
const UINT vertexOffset = c.dynamicVertexOffset;
|
||||
d3d11->IASetVertexBuffers(0, 1, &dynamicBuffer, &stride, &vertexOffset);
|
||||
|
||||
if (indexed)
|
||||
@@ -169,5 +172,5 @@ void Renderer::DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count,
|
||||
d3d11->Draw(count, 0);
|
||||
}
|
||||
|
||||
context.dynamicVertexOffset += copySize;
|
||||
c.dynamicVertexOffset += vertexBytes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user