chore: make all code conventions consistent, slightly clean up some things and fix bugs where some stuff would visually look messed up
This commit is contained in:
@@ -1,59 +1,47 @@
|
||||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
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 &c = this->getContext();
|
||||
Renderer::Context &c = getContext();
|
||||
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
|
||||
|
||||
int drawCount = count;
|
||||
bool indexed = false;
|
||||
this->DrawVertexSetup(vType, psType, PrimitiveType, &drawCount, &indexed);
|
||||
this->StateUpdate();
|
||||
DrawVertexSetup(vType, psType, PrimitiveType, &drawCount, &indexed);
|
||||
StateUpdate();
|
||||
|
||||
const UINT stride = vertexStrideTable[vType];
|
||||
const UINT offset = 0;
|
||||
d3d11->IASetVertexBuffers(0, 1, &buffer, &stride, &offset);
|
||||
|
||||
if (indexed)
|
||||
{
|
||||
d3d11->DrawIndexed(drawCount, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
d3d11->Draw(count, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType, C4JRender::ePrimitiveType PrimitiveType, int *count,
|
||||
bool *indexed)
|
||||
{
|
||||
Renderer::Context &c = this->getContext();
|
||||
Renderer::Context &c = getContext();
|
||||
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
|
||||
|
||||
C4JRender::eVertexType effectiveVertexType = vType;
|
||||
if (effectiveVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && c.lightingEnabled)
|
||||
{
|
||||
effectiveVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
|
||||
}
|
||||
|
||||
if (effectiveVertexType != activeVertexType)
|
||||
{
|
||||
d3d11->VSSetShader(vertexShaderTable[effectiveVertexType], nullptr, 0);
|
||||
d3d11->VSSetShader(vertexShaderTable[effectiveVertexType], NULL, 0);
|
||||
d3d11->IASetInputLayout(inputLayoutTable[effectiveVertexType]);
|
||||
activeVertexType = effectiveVertexType;
|
||||
}
|
||||
|
||||
if (psType != activePixelType)
|
||||
{
|
||||
d3d11->PSSetShader(pixelShaderTable[psType], nullptr, 0);
|
||||
d3d11->PSSetShader(pixelShaderTable[psType], NULL, 0);
|
||||
activePixelType = psType;
|
||||
}
|
||||
|
||||
@@ -62,7 +50,7 @@ void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelSh
|
||||
if (c.matrixDirty[MATRIX_MODE_MODELVIEW])
|
||||
{
|
||||
d3d11->Map(c.m_modelViewMatrix, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW), sizeof(DirectX::XMMATRIX));
|
||||
memcpy(mapped.pData, MatrixGet(MATRIX_MODE_MODELVIEW), sizeof(DirectX::XMMATRIX));
|
||||
d3d11->Unmap(c.m_modelViewMatrix, 0);
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW] = false;
|
||||
}
|
||||
@@ -70,7 +58,7 @@ void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelSh
|
||||
if (c.matrixDirty[MATRIX_MODE_MODELVIEW_PROJECTION])
|
||||
{
|
||||
d3d11->Map(c.m_projectionMatrix, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW_PROJECTION), sizeof(DirectX::XMMATRIX));
|
||||
memcpy(mapped.pData, MatrixGet(MATRIX_MODE_MODELVIEW_PROJECTION), sizeof(DirectX::XMMATRIX));
|
||||
d3d11->Unmap(c.m_projectionMatrix, 0);
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_PROJECTION] = false;
|
||||
}
|
||||
@@ -78,17 +66,17 @@ void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelSh
|
||||
if (c.matrixDirty[MATRIX_MODE_MODELVIEW_TEXTURE])
|
||||
{
|
||||
d3d11->Map(c.m_textureMatrix, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW_TEXTURE), sizeof(DirectX::XMMATRIX));
|
||||
memcpy(mapped.pData, MatrixGet(MATRIX_MODE_MODELVIEW_TEXTURE), sizeof(DirectX::XMMATRIX));
|
||||
d3d11->Unmap(c.m_textureMatrix, 0);
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_TEXTURE] = false;
|
||||
}
|
||||
|
||||
this->UpdateFogState();
|
||||
this->UpdateViewportState();
|
||||
this->UpdateLightingState();
|
||||
this->UpdateTexGenState();
|
||||
UpdateFogState();
|
||||
UpdateViewportState();
|
||||
UpdateLightingState();
|
||||
UpdateTexGenState();
|
||||
|
||||
d3d11->IASetPrimitiveTopology(m_Topologies[PrimitiveType]);
|
||||
d3d11->IASetPrimitiveTopology(g_topologies[PrimitiveType]);
|
||||
|
||||
if (PrimitiveType == C4JRender::PRIMITIVE_TYPE_QUAD_LIST)
|
||||
{
|
||||
@@ -106,24 +94,22 @@ void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelSh
|
||||
return;
|
||||
}
|
||||
|
||||
d3d11->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0);
|
||||
d3d11->IASetIndexBuffer(NULL, DXGI_FORMAT_R16_UINT, 0);
|
||||
*indexed = false;
|
||||
}
|
||||
|
||||
void Renderer::DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count, void *vertices, C4JRender::eVertexType vType,
|
||||
C4JRender::ePixelShaderType psType)
|
||||
{
|
||||
Renderer::Context &c = this->getContext();
|
||||
Renderer::Context &c = getContext();
|
||||
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
|
||||
Renderer::CommandBuffer *commandBuffer = c.commandBuffer;
|
||||
|
||||
if (commandBuffer != nullptr)
|
||||
if (commandBuffer != NULL)
|
||||
{
|
||||
C4JRender::eVertexType effectiveVertexType = vType;
|
||||
if (effectiveVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1 && c.lightingEnabled)
|
||||
{
|
||||
effectiveVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
|
||||
}
|
||||
|
||||
c.recordingPrimitiveType = PrimitiveType;
|
||||
c.recordingVertexType = effectiveVertexType;
|
||||
@@ -134,7 +120,7 @@ void Renderer::DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count,
|
||||
|
||||
int drawCount = count;
|
||||
bool indexed = false;
|
||||
this->DrawVertexSetup(vType, psType, PrimitiveType, &drawCount, &indexed);
|
||||
DrawVertexSetup(vType, psType, PrimitiveType, &drawCount, &indexed);
|
||||
|
||||
const UINT stride = vertexStrideTable[vType];
|
||||
const UINT vertexBytes = stride * static_cast<UINT>(count);
|
||||
@@ -142,35 +128,27 @@ void Renderer::DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count,
|
||||
assert(vertexBytes <= Context::VERTEX_BUFFER_SIZE);
|
||||
|
||||
if (c.dynamicVertexOffset + vertexBytes > Context::VERTEX_BUFFER_SIZE)
|
||||
{
|
||||
c.dynamicVertexOffset = 0;
|
||||
}
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE 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));
|
||||
}
|
||||
if (FAILED(hr))
|
||||
printf("ERROR: 0x%x\n", static_cast<unsigned int>(hr));
|
||||
|
||||
std::memcpy(static_cast<std::uint8_t *>(mapped.pData) + c.dynamicVertexOffset, vertices, vertexBytes);
|
||||
memcpy(reinterpret_cast<std::uint8_t *>(mapped.pData) + c.dynamicVertexOffset, vertices, vertexBytes);
|
||||
d3d11->Unmap(c.dynamicVertexBuffer, 0);
|
||||
|
||||
this->StateUpdate();
|
||||
StateUpdate();
|
||||
|
||||
ID3D11Buffer *dynamicBuffer = c.dynamicVertexBuffer;
|
||||
const UINT vertexOffset = c.dynamicVertexOffset;
|
||||
d3d11->IASetVertexBuffers(0, 1, &dynamicBuffer, &stride, &vertexOffset);
|
||||
|
||||
if (indexed)
|
||||
{
|
||||
d3d11->DrawIndexed(drawCount, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
d3d11->Draw(count, 0);
|
||||
}
|
||||
|
||||
c.dynamicVertexOffset += vertexBytes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user