chore: better name matching & add some definitions
fix: add asserts where they were missing
This commit is contained in:
@@ -22,7 +22,7 @@ void main(
|
||||
|
||||
*/
|
||||
|
||||
static unsigned char PS_ForceLOD_Data[] =
|
||||
static unsigned char g_main_PS_ForceLOD[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0x8A, 0x1E, 0x45, 0x87, 0xE0, 0xB2,
|
||||
0xDE, 0x2C, 0x00, 0x06, 0x9B, 0x08, 0x7F, 0x92, 0xEA, 0xE6,
|
||||
|
||||
@@ -11,7 +11,7 @@ void main(
|
||||
|
||||
*/
|
||||
|
||||
static unsigned char PS_ScreenClear_Data[] =
|
||||
static unsigned char g_main_PS_ScreenClear[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0xF5, 0xD0, 0x7D, 0x98, 0xF4, 0x78,
|
||||
0x62, 0xB1, 0x25, 0x1A, 0x74, 0x57, 0xF0, 0x48, 0x57, 0x90,
|
||||
|
||||
@@ -12,7 +12,7 @@ void main(
|
||||
|
||||
*/
|
||||
|
||||
static unsigned char PS_ScreenSpace_Data[] =
|
||||
static unsigned char g_main_PS_ScreenSpace[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0xB8, 0xC0, 0x6E, 0x7D, 0xDE, 0x9F,
|
||||
0x85, 0xBA, 0x86, 0xB9, 0x41, 0xAB, 0xCA, 0x09, 0x13, 0x95,
|
||||
|
||||
@@ -30,7 +30,7 @@ void main(
|
||||
|
||||
*/
|
||||
|
||||
static unsigned char PS_Standard_Data[] =
|
||||
static unsigned char g_main_PS_Standard[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0x3E, 0xD7, 0x47, 0x3D, 0x43, 0x30,
|
||||
0xB0, 0x7E, 0x8F, 0xF4, 0xBD, 0xA7, 0xCA, 0xCF, 0x70, 0x12,
|
||||
|
||||
@@ -23,7 +23,7 @@ void main(
|
||||
|
||||
*/
|
||||
|
||||
static unsigned char PS_TextureProjection_Data[] =
|
||||
static unsigned char g_main_PS_TextureProjection[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0x31, 0x2E, 0x38, 0xEB, 0x1E, 0x13,
|
||||
0x9F, 0xFA, 0xC3, 0x6B, 0xC2, 0x09, 0xD6, 0xCC, 0xBF, 0x4E,
|
||||
|
||||
@@ -4,6 +4,14 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#define MATRIX_MODE_MODELVIEW 0
|
||||
#define MATRIX_MODE_MODELVIEW_UNK1 1
|
||||
#define MATRIX_MODE_MODELVIEW_UNK2 2
|
||||
#define MATRIX_MODE_MODELVIEW_CBUFF 3
|
||||
#define MATRIX_MODE_MODELVIEW_MAX 4
|
||||
|
||||
#define STACK_TYPES 4
|
||||
#define STACK_SIZE 16
|
||||
#define MAX_MIP_LEVELS 5
|
||||
|
||||
class Renderer
|
||||
@@ -176,7 +184,7 @@ public:
|
||||
std::uint64_t GetAllocated();
|
||||
bool IsBusy();
|
||||
void AddMatrix(const float *matrix);
|
||||
void AddVertices(unsigned int stride, unsigned int count, void *dataIn, Renderer::Context &context);
|
||||
void AddVertices(unsigned int stride, unsigned int count, void *dataIn, Renderer::Context &c);
|
||||
void BindTexture(int idx);
|
||||
void SetColor(float r, float g, float b, float a);
|
||||
void SetDepthFunc(int func);
|
||||
@@ -191,7 +199,7 @@ public:
|
||||
void SetBlendFunc(int src, int dst);
|
||||
void SetBlendFactor(unsigned int factor);
|
||||
void SetFaceCull(bool enable);
|
||||
void Render(C4JRender::eVertexType vertexType, Renderer::Context &context, int primitiveType);
|
||||
void Render(C4JRender::eVertexType vType, Renderer::Context &c, int primitiveType);
|
||||
|
||||
struct Command
|
||||
{
|
||||
@@ -311,16 +319,19 @@ public:
|
||||
|
||||
struct Context
|
||||
{
|
||||
static const unsigned int VERTEX_BUFFER_SIZE = 0x100000;
|
||||
|
||||
Context(ID3D11Device *device, ID3D11DeviceContext *deviceContext);
|
||||
|
||||
ID3D11DeviceContext *m_pDeviceContext;
|
||||
ID3DUserDefinedAnnotation *userAnnotation;
|
||||
DWORD contextStateFlags;
|
||||
DWORD annotateDepth;
|
||||
BYTE paddingAfterFlags[12];
|
||||
DirectX::XMMATRIX matrixStacks[4][16];
|
||||
bool matrixDirty[4];
|
||||
DWORD matrixStackDepth[4];
|
||||
DWORD matrixModeType;
|
||||
DWORD boundTextureIndex;
|
||||
DirectX::XMMATRIX matrixStacks[MATRIX_MODE_MODELVIEW_MAX][STACK_SIZE];
|
||||
bool matrixDirty[MATRIX_MODE_MODELVIEW_MAX];
|
||||
DWORD stackPos[MATRIX_MODE_MODELVIEW_MAX];
|
||||
DWORD stackType;
|
||||
DWORD textureIdx;
|
||||
BYTE faceCullEnabled;
|
||||
BYTE depthTestEnabled;
|
||||
BYTE alphaTestEnabled;
|
||||
@@ -343,7 +354,7 @@ public:
|
||||
DirectX::XMFLOAT4 lightDirection[2];
|
||||
DirectX::XMFLOAT4 lightColour[2];
|
||||
DirectX::XMFLOAT4 lightAmbientColour;
|
||||
ID3D11Buffer *cbMatrix0;
|
||||
ID3D11Buffer *m_modelViewMatrix;
|
||||
ID3D11Buffer *cbMatrix1;
|
||||
ID3D11Buffer *cbMatrix2;
|
||||
ID3D11Buffer *cbMatrix3;
|
||||
|
||||
@@ -70,12 +70,12 @@ void Renderer::CommandBuffer::AddMatrix(const float *matrix)
|
||||
m_commands.push_back(command);
|
||||
}
|
||||
|
||||
void Renderer::CommandBuffer::AddVertices(unsigned int stride, unsigned int count, void *dataIn, Renderer::Context &context)
|
||||
void Renderer::CommandBuffer::AddVertices(unsigned int stride, unsigned int count, void *dataIn, Renderer::Context &c)
|
||||
{
|
||||
if (context.matrixDirty[3])
|
||||
if (c.matrixDirty[MATRIX_MODE_MODELVIEW_CBUFF])
|
||||
{
|
||||
this->AddMatrix(InternalRenderManager.MatrixGet(3));
|
||||
context.matrixDirty[3] = false;
|
||||
this->AddMatrix(InternalRenderManager.MatrixGet(MATRIX_MODE_MODELVIEW_CBUFF));
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_CBUFF] = false;
|
||||
}
|
||||
|
||||
const std::uint64_t vertexOffset = m_vertexDataLength;
|
||||
@@ -168,9 +168,9 @@ void Renderer::CommandBuffer::SetLightEnable(int light, bool enable)
|
||||
|
||||
void Renderer::CommandBuffer::SetLightDirection(int light, float x, float y, float z)
|
||||
{
|
||||
Renderer::Context &context = InternalRenderManager.getContext();
|
||||
const std::uint32_t depth = context.matrixStackDepth[3];
|
||||
const DirectX::XMMATRIX &matrix = context.matrixStacks[3][depth];
|
||||
Renderer::Context &c = InternalRenderManager.getContext();
|
||||
const std::uint32_t depth = c.stackPos[MATRIX_MODE_MODELVIEW_CBUFF];
|
||||
const DirectX::XMMATRIX &matrix = c.matrixStacks[MATRIX_MODE_MODELVIEW_CBUFF][depth];
|
||||
|
||||
DirectX::XMVECTOR direction = DirectX::XMVectorSet(x, y, z, 0.0f);
|
||||
direction = DirectX::XMVector3TransformNormal(direction, matrix);
|
||||
@@ -242,14 +242,14 @@ void Renderer::CommandBuffer::SetFaceCull(bool enable)
|
||||
m_commands.push_back(command);
|
||||
}
|
||||
|
||||
void Renderer::CommandBuffer::Render(C4JRender::eVertexType vertexType, Renderer::Context &context, int primitiveType)
|
||||
void Renderer::CommandBuffer::Render(C4JRender::eVertexType vType, Renderer::Context &c, int primitiveType)
|
||||
{
|
||||
if (!m_vertexBuffer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int drawVertexType = vertexType;
|
||||
int drawVertexType = vType;
|
||||
int shaderVertexType = drawVertexType;
|
||||
bool matrixOverride = false;
|
||||
|
||||
@@ -265,16 +265,16 @@ void Renderer::CommandBuffer::Render(C4JRender::eVertexType vertexType, Renderer
|
||||
const float row[4] = {command.add_matrix.m_matrix[12], command.add_matrix.m_matrix[13], command.add_matrix.m_matrix[14],
|
||||
command.add_matrix.m_matrix[15]};
|
||||
D3D11_MAPPED_SUBRESOURCE mappedAux0 = {};
|
||||
context.m_pDeviceContext->Map(context.cbAux0, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedAux0);
|
||||
c.m_pDeviceContext->Map(c.cbAux0, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedAux0);
|
||||
std::memcpy(mappedAux0.pData, row, sizeof(row));
|
||||
context.m_pDeviceContext->Unmap(context.cbAux0, 0);
|
||||
c.m_pDeviceContext->Unmap(c.cbAux0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE mappedMatrix1 = {};
|
||||
context.m_pDeviceContext->Map(context.cbMatrix1, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedMatrix1);
|
||||
c.m_pDeviceContext->Map(c.cbMatrix1, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedMatrix1);
|
||||
std::memcpy(mappedMatrix1.pData, command.add_matrix.m_matrix, sizeof(command.add_matrix.m_matrix));
|
||||
context.m_pDeviceContext->Unmap(context.cbMatrix1, 0);
|
||||
c.m_pDeviceContext->Unmap(c.cbMatrix1, 0);
|
||||
matrixOverride = true;
|
||||
}
|
||||
break;
|
||||
@@ -287,13 +287,13 @@ void Renderer::CommandBuffer::Render(C4JRender::eVertexType vertexType, Renderer
|
||||
|
||||
if (drawVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1)
|
||||
{
|
||||
if (context.lightingEnabled)
|
||||
if (c.lightingEnabled)
|
||||
{
|
||||
drawVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
|
||||
shaderVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT;
|
||||
}
|
||||
}
|
||||
else if (drawVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT && !context.lightingEnabled)
|
||||
else if (drawVertexType == C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT && !c.lightingEnabled)
|
||||
{
|
||||
drawVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1;
|
||||
shaderVertexType = C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1;
|
||||
@@ -301,8 +301,8 @@ void Renderer::CommandBuffer::Render(C4JRender::eVertexType vertexType, Renderer
|
||||
|
||||
if (static_cast<DWORD>(drawVertexType) != InternalRenderManager.activeVertexType)
|
||||
{
|
||||
context.m_pDeviceContext->VSSetShader(InternalRenderManager.vertexShaderTable[shaderVertexType], nullptr, 0);
|
||||
context.m_pDeviceContext->IASetInputLayout(InternalRenderManager.inputLayoutTable[shaderVertexType]);
|
||||
c.m_pDeviceContext->VSSetShader(InternalRenderManager.vertexShaderTable[shaderVertexType], nullptr, 0);
|
||||
c.m_pDeviceContext->IASetInputLayout(InternalRenderManager.inputLayoutTable[shaderVertexType]);
|
||||
InternalRenderManager.activeVertexType = drawVertexType;
|
||||
}
|
||||
}
|
||||
@@ -323,57 +323,57 @@ void Renderer::CommandBuffer::Render(C4JRender::eVertexType vertexType, Renderer
|
||||
ID3D11Buffer *buffer = m_vertexBuffer;
|
||||
const UINT stride = InternalRenderManager.vertexStrideTable[drawVertexType];
|
||||
const UINT offset = command.add_vertices.m_vertex_index_start;
|
||||
context.m_pDeviceContext->IASetVertexBuffers(0, 1, &buffer, &stride, &offset);
|
||||
c.m_pDeviceContext->IASetVertexBuffers(0, 1, &buffer, &stride, &offset);
|
||||
|
||||
if (drawIndexed)
|
||||
{
|
||||
context.m_pDeviceContext->DrawIndexed(drawCount, 0, 0);
|
||||
c.m_pDeviceContext->DrawIndexed(drawCount, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.m_pDeviceContext->Draw(drawCount, 0);
|
||||
c.m_pDeviceContext->Draw(drawCount, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case COMMAND_BIND_TEXTURE:
|
||||
{
|
||||
context.boundTextureIndex = command.bind_texture.m_texture_index;
|
||||
ID3D11ShaderResourceView *view = InternalRenderManager.m_textures[context.boundTextureIndex].view;
|
||||
context.m_pDeviceContext->PSSetShaderResources(0, 1, &view);
|
||||
c.textureIdx = command.bind_texture.m_texture_index;
|
||||
ID3D11ShaderResourceView *view = InternalRenderManager.m_textures[c.textureIdx].view;
|
||||
c.m_pDeviceContext->PSSetShaderResources(0, 1, &view);
|
||||
InternalRenderManager.UpdateTextureState(false);
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_COLOR:
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE mappedColour = {};
|
||||
context.m_pDeviceContext->Map(context.cbColour, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedColour);
|
||||
c.m_pDeviceContext->Map(c.cbColour, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedColour);
|
||||
std::memcpy(mappedColour.pData, command.set_color.m_color, sizeof(command.set_color.m_color));
|
||||
context.m_pDeviceContext->Unmap(context.cbColour, 0);
|
||||
c.m_pDeviceContext->Unmap(c.cbColour, 0);
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_DEPTH_FUNC:
|
||||
{
|
||||
context.depthStencilDesc.DepthFunc = static_cast<D3D11_COMPARISON_FUNC>(command.set_depth_func.m_depth_func);
|
||||
context.m_pDeviceContext->OMSetDepthStencilState(InternalRenderManager.GetManagedDepthStencilState(), 0);
|
||||
c.depthStencilDesc.DepthFunc = static_cast<D3D11_COMPARISON_FUNC>(command.set_depth_func.m_depth_func);
|
||||
c.m_pDeviceContext->OMSetDepthStencilState(InternalRenderManager.GetManagedDepthStencilState(), 0);
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_DEPTH_MASK:
|
||||
{
|
||||
context.depthWriteEnabled = command.set_depth_mask.m_enable ? 1 : 0;
|
||||
context.depthStencilDesc.DepthWriteMask = command.set_depth_mask.m_enable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
context.m_pDeviceContext->OMSetDepthStencilState(InternalRenderManager.GetManagedDepthStencilState(), 0);
|
||||
c.depthWriteEnabled = command.set_depth_mask.m_enable ? 1 : 0;
|
||||
c.depthStencilDesc.DepthWriteMask = command.set_depth_mask.m_enable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
c.m_pDeviceContext->OMSetDepthStencilState(InternalRenderManager.GetManagedDepthStencilState(), 0);
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_DEPTH_TEST:
|
||||
{
|
||||
context.depthTestEnabled = command.set_depth_test.m_enable ? 1 : 0;
|
||||
context.depthStencilDesc.DepthEnable = command.set_depth_test.m_enable ? TRUE : FALSE;
|
||||
context.m_pDeviceContext->OMSetDepthStencilState(InternalRenderManager.GetManagedDepthStencilState(), 0);
|
||||
c.depthTestEnabled = command.set_depth_test.m_enable ? 1 : 0;
|
||||
c.depthStencilDesc.DepthEnable = command.set_depth_test.m_enable ? TRUE : FALSE;
|
||||
c.m_pDeviceContext->OMSetDepthStencilState(InternalRenderManager.GetManagedDepthStencilState(), 0);
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_LIGHTING_ENABLE:
|
||||
{
|
||||
context.lightingEnabled = command.set_lighting_enable.m_enable ? 1 : 0;
|
||||
c.lightingEnabled = command.set_lighting_enable.m_enable ? 1 : 0;
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_LIGHT_ENABLE:
|
||||
@@ -381,8 +381,8 @@ void Renderer::CommandBuffer::Render(C4JRender::eVertexType vertexType, Renderer
|
||||
const int light = command.set_light_enable.m_light_index;
|
||||
if (light >= 0 && light < 2)
|
||||
{
|
||||
context.lightEnabled[light] = command.set_light_enable.m_enable ? 1 : 0;
|
||||
context.lightingDirty = 1;
|
||||
c.lightEnabled[light] = command.set_light_enable.m_enable ? 1 : 0;
|
||||
c.lightingDirty = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -391,11 +391,11 @@ void Renderer::CommandBuffer::Render(C4JRender::eVertexType vertexType, Renderer
|
||||
const int light = command.set_light_direction.m_light_index;
|
||||
if (light >= 0 && light < 2)
|
||||
{
|
||||
context.lightDirection[light].x = command.set_light_direction.m_direction[0];
|
||||
context.lightDirection[light].y = command.set_light_direction.m_direction[1];
|
||||
context.lightDirection[light].z = command.set_light_direction.m_direction[2];
|
||||
context.lightDirection[light].w = command.set_light_direction.m_direction[3];
|
||||
context.lightingDirty = 1;
|
||||
c.lightDirection[light].x = command.set_light_direction.m_direction[0];
|
||||
c.lightDirection[light].y = command.set_light_direction.m_direction[1];
|
||||
c.lightDirection[light].z = command.set_light_direction.m_direction[2];
|
||||
c.lightDirection[light].w = command.set_light_direction.m_direction[3];
|
||||
c.lightingDirty = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -404,50 +404,50 @@ void Renderer::CommandBuffer::Render(C4JRender::eVertexType vertexType, Renderer
|
||||
const int light = command.set_light_colour.m_light_index;
|
||||
if (light >= 0 && light < 2)
|
||||
{
|
||||
context.lightColour[light].x = command.set_light_colour.m_color[0];
|
||||
context.lightColour[light].y = command.set_light_colour.m_color[1];
|
||||
context.lightColour[light].z = command.set_light_colour.m_color[2];
|
||||
context.lightColour[light].w = 1.0f;
|
||||
context.lightingDirty = 1;
|
||||
c.lightColour[light].x = command.set_light_colour.m_color[0];
|
||||
c.lightColour[light].y = command.set_light_colour.m_color[1];
|
||||
c.lightColour[light].z = command.set_light_colour.m_color[2];
|
||||
c.lightColour[light].w = 1.0f;
|
||||
c.lightingDirty = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_LIGHT_AMBIENT_COLOUR:
|
||||
{
|
||||
context.lightAmbientColour.x = command.set_light_ambient_colour.m_color[0];
|
||||
context.lightAmbientColour.y = command.set_light_ambient_colour.m_color[1];
|
||||
context.lightAmbientColour.z = command.set_light_ambient_colour.m_color[2];
|
||||
context.lightAmbientColour.w = 1.0f;
|
||||
context.lightingDirty = 1;
|
||||
c.lightAmbientColour.x = command.set_light_ambient_colour.m_color[0];
|
||||
c.lightAmbientColour.y = command.set_light_ambient_colour.m_color[1];
|
||||
c.lightAmbientColour.z = command.set_light_ambient_colour.m_color[2];
|
||||
c.lightAmbientColour.w = 1.0f;
|
||||
c.lightingDirty = 1;
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_BLEND_ENABLE:
|
||||
{
|
||||
context.blendDesc.RenderTarget[0].BlendEnable = command.set_blend_enable.m_enable ? TRUE : FALSE;
|
||||
c.blendDesc.RenderTarget[0].BlendEnable = command.set_blend_enable.m_enable ? TRUE : FALSE;
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_BLEND_FUNC:
|
||||
{
|
||||
context.blendDesc.RenderTarget[0].SrcBlend = static_cast<D3D11_BLEND>(command.set_blend_func.m_src);
|
||||
context.blendDesc.RenderTarget[0].DestBlend = static_cast<D3D11_BLEND>(command.set_blend_func.m_dst);
|
||||
context.m_pDeviceContext->OMSetBlendState(InternalRenderManager.GetManagedBlendState(), context.blendFactor, 0xFFFFFFFFu);
|
||||
c.blendDesc.RenderTarget[0].SrcBlend = static_cast<D3D11_BLEND>(command.set_blend_func.m_src);
|
||||
c.blendDesc.RenderTarget[0].DestBlend = static_cast<D3D11_BLEND>(command.set_blend_func.m_dst);
|
||||
c.m_pDeviceContext->OMSetBlendState(InternalRenderManager.GetManagedBlendState(), c.blendFactor, 0xFFFFFFFFu);
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_BLEND_FACTOR:
|
||||
{
|
||||
const unsigned int factor = command.set_blend_factor.m_blend_factor;
|
||||
context.blendFactor[0] = float((factor >> 0) & 0xFFu) / 255.0f;
|
||||
context.blendFactor[1] = float((factor >> 8) & 0xFFu) / 255.0f;
|
||||
context.blendFactor[2] = float((factor >> 16) & 0xFFu) / 255.0f;
|
||||
context.blendFactor[3] = float((factor >> 24) & 0xFFu) / 255.0f;
|
||||
context.m_pDeviceContext->OMSetBlendState(InternalRenderManager.GetManagedBlendState(), context.blendFactor, 0xFFFFFFFFu);
|
||||
c.blendFactor[0] = float((factor >> 0) & 0xFFu) / 255.0f;
|
||||
c.blendFactor[1] = float((factor >> 8) & 0xFFu) / 255.0f;
|
||||
c.blendFactor[2] = float((factor >> 16) & 0xFFu) / 255.0f;
|
||||
c.blendFactor[3] = float((factor >> 24) & 0xFFu) / 255.0f;
|
||||
c.m_pDeviceContext->OMSetBlendState(InternalRenderManager.GetManagedBlendState(), c.blendFactor, 0xFFFFFFFFu);
|
||||
break;
|
||||
}
|
||||
case COMMAND_SET_FACE_CULL:
|
||||
{
|
||||
context.rasterizerDesc.CullMode = command.set_face_cull.m_enable ? D3D11_CULL_BACK : D3D11_CULL_NONE;
|
||||
context.m_pDeviceContext->RSSetState(InternalRenderManager.GetManagedRasterizerState());
|
||||
context.faceCullEnabled = command.set_face_cull.m_enable ? 1 : 0;
|
||||
c.rasterizerDesc.CullMode = command.set_face_cull.m_enable ? D3D11_CULL_BACK : D3D11_CULL_NONE;
|
||||
c.m_pDeviceContext->RSSetState(InternalRenderManager.GetManagedRasterizerState());
|
||||
c.faceCullEnabled = command.set_face_cull.m_enable ? 1 : 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -459,9 +459,9 @@ void Renderer::CommandBuffer::Render(C4JRender::eVertexType vertexType, Renderer
|
||||
{
|
||||
const DirectX::XMMATRIX identity = DirectX::XMMatrixIdentity();
|
||||
D3D11_MAPPED_SUBRESOURCE mappedIdentity = {};
|
||||
context.m_pDeviceContext->Map(context.cbMatrix1, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedIdentity);
|
||||
c.m_pDeviceContext->Map(c.cbMatrix1, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedIdentity);
|
||||
std::memcpy(mappedIdentity.pData, &identity, sizeof(identity));
|
||||
context.m_pDeviceContext->Unmap(context.cbMatrix1, 0);
|
||||
c.m_pDeviceContext->Unmap(c.cbMatrix1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,37 +474,37 @@ bool Renderer::CBuffCall(int index, bool full)
|
||||
const int internalIndex = externalToInternal[index];
|
||||
if (internalIndex >= 0)
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
Renderer::Context &c = this->getContext();
|
||||
const std::uint8_t vertexType = static_cast<std::uint8_t *>(reservedRendererPtr6)[internalIndex];
|
||||
const std::uint8_t primitiveType = reinterpret_cast<std::uint8_t *>(reservedRendererPtr1)[internalIndex];
|
||||
|
||||
if (full)
|
||||
{
|
||||
if (context.matrixDirty[0])
|
||||
if (c.matrixDirty[MATRIX_MODE_MODELVIEW])
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE mappedMatrix0 = {};
|
||||
context.m_pDeviceContext->Map(context.cbMatrix0, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedMatrix0);
|
||||
std::memcpy(mappedMatrix0.pData, this->MatrixGet(0), sizeof(DirectX::XMMATRIX));
|
||||
context.m_pDeviceContext->Unmap(context.cbMatrix0, 0);
|
||||
context.matrixDirty[0] = false;
|
||||
c.m_pDeviceContext->Map(c.m_modelViewMatrix, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedMatrix0);
|
||||
std::memcpy(mappedMatrix0.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW), sizeof(DirectX::XMMATRIX));
|
||||
c.m_pDeviceContext->Unmap(c.m_modelViewMatrix, 0);
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW] = false;
|
||||
}
|
||||
|
||||
if (context.matrixDirty[1])
|
||||
if (c.matrixDirty[MATRIX_MODE_MODELVIEW_UNK1])
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE mappedMatrix2 = {};
|
||||
context.m_pDeviceContext->Map(context.cbMatrix2, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedMatrix2);
|
||||
std::memcpy(mappedMatrix2.pData, this->MatrixGet(1), sizeof(DirectX::XMMATRIX));
|
||||
context.m_pDeviceContext->Unmap(context.cbMatrix2, 0);
|
||||
context.matrixDirty[1] = false;
|
||||
c.m_pDeviceContext->Map(c.cbMatrix2, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedMatrix2);
|
||||
std::memcpy(mappedMatrix2.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW_UNK1), sizeof(DirectX::XMMATRIX));
|
||||
c.m_pDeviceContext->Unmap(c.cbMatrix2, 0);
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_UNK1] = false;
|
||||
}
|
||||
|
||||
if (context.matrixDirty[2])
|
||||
if (c.matrixDirty[MATRIX_MODE_MODELVIEW_UNK2])
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE mappedMatrix3 = {};
|
||||
context.m_pDeviceContext->Map(context.cbMatrix3, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedMatrix3);
|
||||
std::memcpy(mappedMatrix3.pData, this->MatrixGet(2), sizeof(DirectX::XMMATRIX));
|
||||
context.m_pDeviceContext->Unmap(context.cbMatrix3, 0);
|
||||
context.matrixDirty[2] = false;
|
||||
c.m_pDeviceContext->Map(c.cbMatrix3, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedMatrix3);
|
||||
std::memcpy(mappedMatrix3.pData, this->MatrixGet(MATRIX_MODE_MODELVIEW_UNK2), sizeof(DirectX::XMMATRIX));
|
||||
c.m_pDeviceContext->Unmap(c.cbMatrix3, 0);
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_UNK2] = false;
|
||||
}
|
||||
|
||||
this->UpdateFogState();
|
||||
@@ -514,29 +514,29 @@ bool Renderer::CBuffCall(int index, bool full)
|
||||
|
||||
if (vertexType != activeVertexType)
|
||||
{
|
||||
context.m_pDeviceContext->VSSetShader(vertexShaderTable[vertexType], nullptr, 0);
|
||||
context.m_pDeviceContext->IASetInputLayout(inputLayoutTable[vertexType]);
|
||||
c.m_pDeviceContext->VSSetShader(vertexShaderTable[vertexType], nullptr, 0);
|
||||
c.m_pDeviceContext->IASetInputLayout(inputLayoutTable[vertexType]);
|
||||
activeVertexType = vertexType;
|
||||
}
|
||||
|
||||
int pixelType = 0;
|
||||
if (static_cast<int>(context.forcedLOD) > -1)
|
||||
if (static_cast<int>(c.forcedLOD) > -1)
|
||||
{
|
||||
const float forcedLod[4] = {static_cast<float>(static_cast<int>(context.forcedLOD)), 0.0f, 0.0f, 0.0f};
|
||||
const float forcedLod[4] = {static_cast<float>(static_cast<int>(c.forcedLOD)), 0.0f, 0.0f, 0.0f};
|
||||
D3D11_MAPPED_SUBRESOURCE mappedAux4 = {};
|
||||
context.m_pDeviceContext->Map(context.cbAux4, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedAux4);
|
||||
c.m_pDeviceContext->Map(c.cbAux4, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedAux4);
|
||||
std::memcpy(mappedAux4.pData, forcedLod, sizeof(forcedLod));
|
||||
context.m_pDeviceContext->Unmap(context.cbAux4, 0);
|
||||
c.m_pDeviceContext->Unmap(c.cbAux4, 0);
|
||||
pixelType = C4JRender::PIXEL_SHADER_TYPE_FORCELOD;
|
||||
}
|
||||
|
||||
if (static_cast<DWORD>(pixelType) != activePixelType)
|
||||
{
|
||||
context.m_pDeviceContext->PSSetShader(pixelShaderTable[pixelType], nullptr, 0);
|
||||
c.m_pDeviceContext->PSSetShader(pixelShaderTable[pixelType], nullptr, 0);
|
||||
activePixelType = pixelType;
|
||||
}
|
||||
|
||||
context.m_pDeviceContext->IASetPrimitiveTopology(m_Topologies[primitiveType]);
|
||||
c.m_pDeviceContext->IASetPrimitiveTopology(m_Topologies[primitiveType]);
|
||||
|
||||
ID3D11Buffer *indexBuffer = nullptr;
|
||||
if (primitiveType == C4JRender::PRIMITIVE_TYPE_QUAD_LIST)
|
||||
@@ -548,17 +548,17 @@ bool Renderer::CBuffCall(int index, bool full)
|
||||
indexBuffer = fanIndexBuffer;
|
||||
}
|
||||
|
||||
context.m_pDeviceContext->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
c.m_pDeviceContext->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R16_UINT, 0);
|
||||
}
|
||||
|
||||
Renderer::CommandBuffer *commandBuffer = static_cast<Renderer::CommandBuffer **>(reservedRendererPtr3)[internalIndex];
|
||||
commandBuffer->Render(static_cast<C4JRender::eVertexType>(vertexType), context, primitiveType);
|
||||
commandBuffer->Render(static_cast<C4JRender::eVertexType>(vertexType), c, primitiveType);
|
||||
|
||||
if (full)
|
||||
{
|
||||
this->MultWithStack(static_cast<DirectX::XMMATRIX *>(reservedRendererPtr4)[internalIndex]);
|
||||
context.matrixStacks[3][0] = DirectX::XMMatrixIdentity();
|
||||
context.matrixDirty[3] = true;
|
||||
c.matrixStacks[MATRIX_MODE_MODELVIEW_CBUFF][0] = DirectX::XMMatrixIdentity();
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_CBUFF] = true;
|
||||
}
|
||||
|
||||
result = true;
|
||||
@@ -598,6 +598,8 @@ int Renderer::CBuffCreate(int count)
|
||||
int end = first + count;
|
||||
while (true)
|
||||
{
|
||||
assert(first < kMaxExternalCBuffers);
|
||||
|
||||
int cursor = probe;
|
||||
while (cursor < end && cursor < kMaxExternalCBuffers && externalToInternal[cursor] == static_cast<std::int16_t>(-1))
|
||||
{
|
||||
@@ -644,14 +646,14 @@ int Renderer::CBuffCreate(int count)
|
||||
|
||||
void Renderer::CBuffDeferredModeEnd()
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
if (!context.deferredModeEnabled)
|
||||
Renderer::Context &c = this->getContext();
|
||||
if (!c.deferredModeEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EnterCriticalSection(&rtl_critical_section100);
|
||||
context.deferredModeEnabled = 0;
|
||||
c.deferredModeEnabled = 0;
|
||||
|
||||
std::int16_t *externalToInternal = static_cast<std::int16_t *>(reservedRendererPtr2);
|
||||
int *internalToExternal = static_cast<int *>(reservedRendererPtr5);
|
||||
@@ -660,7 +662,7 @@ void Renderer::CBuffDeferredModeEnd()
|
||||
Renderer::CommandBuffer **internalBuffers = static_cast<Renderer::CommandBuffer **>(reservedRendererPtr3);
|
||||
DirectX::XMMATRIX *internalMatrices = static_cast<DirectX::XMMATRIX *>(reservedRendererPtr4);
|
||||
|
||||
for (std::vector<Renderer::DeferredCBuff>::const_iterator it = context.deferredBuffers.begin(); it != context.deferredBuffers.end(); ++it)
|
||||
for (std::vector<Renderer::DeferredCBuff>::const_iterator it = c.deferredBuffers.begin(); it != c.deferredBuffers.end(); ++it)
|
||||
{
|
||||
const Renderer::DeferredCBuff &deferred = *it;
|
||||
const int existingIndex = externalToInternal[deferred.m_vertex_index];
|
||||
@@ -685,7 +687,7 @@ void Renderer::CBuffDeferredModeEnd()
|
||||
internalMatrices[internalSlot] = deferred.m_matrix;
|
||||
}
|
||||
|
||||
context.deferredBuffers.clear();
|
||||
c.deferredBuffers.clear();
|
||||
LeaveCriticalSection(&rtl_critical_section100);
|
||||
}
|
||||
|
||||
@@ -716,18 +718,22 @@ void Renderer::CBuffDelete(int first, int count)
|
||||
|
||||
void Renderer::CBuffEnd()
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
Renderer::Context &c = this->getContext();
|
||||
|
||||
assert(c.stackType == MATRIX_MODE_MODELVIEW_CBUFF);
|
||||
assert(c.stackPos[MATRIX_MODE_MODELVIEW_CBUFF] == 0);
|
||||
|
||||
EnterCriticalSection(&rtl_critical_section100);
|
||||
|
||||
if (context.deferredModeEnabled)
|
||||
if (c.deferredModeEnabled)
|
||||
{
|
||||
Renderer::DeferredCBuff deferred;
|
||||
deferred.m_command_buf = context.commandBuffer;
|
||||
deferred.m_vertex_index = context.recordingBufferIndex;
|
||||
deferred.m_vertex_type = context.recordingVertexType;
|
||||
deferred.m_primitive_type = context.recordingPrimitiveType;
|
||||
deferred.m_matrix = context.matrixStacks[3][0];
|
||||
context.deferredBuffers.push_back(deferred);
|
||||
deferred.m_command_buf = c.commandBuffer;
|
||||
deferred.m_vertex_index = c.recordingBufferIndex;
|
||||
deferred.m_vertex_type = c.recordingVertexType;
|
||||
deferred.m_primitive_type = c.recordingPrimitiveType;
|
||||
deferred.m_matrix = c.matrixStacks[MATRIX_MODE_MODELVIEW_CBUFF][0];
|
||||
c.deferredBuffers.push_back(deferred);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -738,7 +744,7 @@ void Renderer::CBuffEnd()
|
||||
Renderer::CommandBuffer **internalBuffers = static_cast<Renderer::CommandBuffer **>(reservedRendererPtr3);
|
||||
DirectX::XMMATRIX *internalMatrices = static_cast<DirectX::XMMATRIX *>(reservedRendererPtr4);
|
||||
|
||||
const int existingIndex = externalToInternal[context.recordingBufferIndex];
|
||||
const int existingIndex = externalToInternal[c.recordingBufferIndex];
|
||||
if (existingIndex >= 0)
|
||||
{
|
||||
this->DeleteInternalBuffer(existingIndex);
|
||||
@@ -752,17 +758,17 @@ void Renderer::CBuffEnd()
|
||||
const int internalSlot = reservedRendererDword2;
|
||||
++reservedRendererDword2;
|
||||
|
||||
externalToInternal[context.recordingBufferIndex] = static_cast<std::int16_t>(internalSlot);
|
||||
internalToExternal[internalSlot] = context.recordingBufferIndex;
|
||||
internalVertexTypes[internalSlot] = static_cast<std::uint8_t>(context.recordingVertexType);
|
||||
internalPrimitiveTypes[internalSlot] = static_cast<std::uint8_t>(context.recordingPrimitiveType);
|
||||
internalBuffers[internalSlot] = context.commandBuffer;
|
||||
internalMatrices[internalSlot] = context.matrixStacks[3][0];
|
||||
externalToInternal[c.recordingBufferIndex] = static_cast<std::int16_t>(internalSlot);
|
||||
internalToExternal[internalSlot] = c.recordingBufferIndex;
|
||||
internalVertexTypes[internalSlot] = static_cast<std::uint8_t>(c.recordingVertexType);
|
||||
internalPrimitiveTypes[internalSlot] = static_cast<std::uint8_t>(c.recordingPrimitiveType);
|
||||
internalBuffers[internalSlot] = c.commandBuffer;
|
||||
internalMatrices[internalSlot] = c.matrixStacks[MATRIX_MODE_MODELVIEW_CBUFF][0];
|
||||
}
|
||||
|
||||
context.matrixModeType = 0;
|
||||
context.commandBuffer->EndRecording(m_pDevice);
|
||||
context.commandBuffer = nullptr;
|
||||
c.stackType = MATRIX_MODE_MODELVIEW;
|
||||
c.commandBuffer->EndRecording(m_pDevice);
|
||||
c.commandBuffer = nullptr;
|
||||
|
||||
LeaveCriticalSection(&rtl_critical_section100);
|
||||
}
|
||||
@@ -792,13 +798,16 @@ int Renderer::CBuffSize(int index)
|
||||
|
||||
void Renderer::CBuffStart(int index, bool full)
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
context.commandBuffer = new (std::nothrow) Renderer::CommandBuffer(full);
|
||||
context.recordingBufferIndex = index;
|
||||
context.matrixModeType = 3;
|
||||
context.matrixStackDepth[3] = 0;
|
||||
context.matrixStacks[3][0] = DirectX::XMMatrixIdentity();
|
||||
context.matrixDirty[3] = true;
|
||||
Renderer::Context &c = this->getContext();
|
||||
c.commandBuffer = new (std::nothrow) Renderer::CommandBuffer(full);
|
||||
c.recordingBufferIndex = index;
|
||||
|
||||
assert(c.stackType == MATRIX_MODE_MODELVIEW);
|
||||
|
||||
c.stackType = MATRIX_MODE_MODELVIEW_CBUFF;
|
||||
c.stackPos[MATRIX_MODE_MODELVIEW_CBUFF] = 0;
|
||||
c.matrixStacks[MATRIX_MODE_MODELVIEW_CBUFF][0] = DirectX::XMMatrixIdentity();
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_CBUFF] = true;
|
||||
}
|
||||
|
||||
void Renderer::CBuffTick()
|
||||
|
||||
@@ -46,10 +46,10 @@ D3D11_PRIMITIVE_TOPOLOGY Renderer::g_topologies[C4JRender::PRIMITIVE_TYPE_COUNT]
|
||||
};
|
||||
|
||||
Renderer::Context::Context(ID3D11Device *device, ID3D11DeviceContext *deviceContext)
|
||||
: m_pDeviceContext(deviceContext), userAnnotation(nullptr), contextStateFlags(0), matrixModeType(0), boundTextureIndex(0), faceCullEnabled(1),
|
||||
: m_pDeviceContext(deviceContext), userAnnotation(nullptr), annotateDepth(0), stackType(0), textureIdx(0), faceCullEnabled(1),
|
||||
depthTestEnabled(1), alphaTestEnabled(0), alphaReference(1.0f), depthWriteEnabled(1), fogEnabled(0), fogNearDistance(0.0f),
|
||||
fogFarDistance(0.0f), fogDensity(0.0f), fogColourRed(0.0f), fogColourBlue(0.0f), fogColourGreen(0.0f), fogMode(0), lightingEnabled(0),
|
||||
lightingDirty(0), forcedLOD(0xFFFFFFFFu), cbMatrix0(nullptr), cbMatrix1(nullptr), cbMatrix2(nullptr), cbMatrix3(nullptr),
|
||||
lightingDirty(0), forcedLOD(0xFFFFFFFFu), m_modelViewMatrix(nullptr), cbMatrix1(nullptr), cbMatrix2(nullptr), cbMatrix3(nullptr),
|
||||
cbVertexTexcoord(nullptr), cbFogParams(nullptr), cbLighting(nullptr), cbTexGen(nullptr), cbAux0(nullptr), cbAux1(nullptr), cbColour(nullptr),
|
||||
cbFogColour(nullptr), cbAux2(nullptr), cbAlphaTest(nullptr), cbAux3(nullptr), cbAux4(nullptr), dynamicVertexBase(0), dynamicVertexOffset(0),
|
||||
dynamicVertexBuffer(nullptr), commandBuffer(nullptr), recordingBufferIndex(0), recordingVertexType(0), recordingPrimitiveType(0),
|
||||
@@ -58,7 +58,7 @@ Renderer::Context::Context(ID3D11Device *device, ID3D11DeviceContext *deviceCont
|
||||
deviceContext->QueryInterface(IID_PPV_ARGS(&userAnnotation));
|
||||
std::memset(matrixStacks, 0, sizeof(matrixStacks));
|
||||
std::memset(matrixDirty, 0, sizeof(matrixDirty));
|
||||
std::memset(matrixStackDepth, 0, sizeof(matrixStackDepth));
|
||||
std::memset(stackPos, 0, sizeof(stackPos));
|
||||
std::memset(lightEnabled, 0, sizeof(lightEnabled));
|
||||
std::memset(lightDirection, 0, sizeof(lightDirection));
|
||||
std::memset(lightColour, 0, sizeof(lightColour));
|
||||
@@ -73,10 +73,10 @@ Renderer::Context::Context(ID3D11Device *device, ID3D11DeviceContext *deviceCont
|
||||
blendFactor[3] = 0.0f;
|
||||
|
||||
const DirectX::XMMATRIX identity = DirectX::XMMatrixIdentity();
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
for (unsigned int i = 0; i < MATRIX_MODE_MODELVIEW_MAX; ++i)
|
||||
{
|
||||
matrixStacks[i][0] = identity;
|
||||
matrixStackDepth[i] = 0;
|
||||
stackPos[i] = 0;
|
||||
}
|
||||
|
||||
blendDesc.AlphaToCoverageEnable = FALSE;
|
||||
@@ -133,7 +133,7 @@ Renderer::Context::Context(ID3D11Device *device, ID3D11DeviceContext *deviceCont
|
||||
D3D11_SUBRESOURCE_DATA cbData = {};
|
||||
cbDesc.ByteWidth = sizeof(DirectX::XMMATRIX);
|
||||
cbData.pSysMem = &identity;
|
||||
device->CreateBuffer(&cbDesc, &cbData, &cbMatrix0);
|
||||
device->CreateBuffer(&cbDesc, &cbData, &m_modelViewMatrix);
|
||||
device->CreateBuffer(&cbDesc, &cbData, &cbMatrix1);
|
||||
device->CreateBuffer(&cbDesc, &cbData, &cbMatrix2);
|
||||
device->CreateBuffer(&cbDesc, &cbData, &cbMatrix3);
|
||||
@@ -172,7 +172,7 @@ Renderer::Context::Context(ID3D11Device *device, ID3D11DeviceContext *deviceCont
|
||||
device->CreateBuffer(&cbDesc, &cbData, &cbAux3);
|
||||
device->CreateBuffer(&cbDesc, &cbData, &cbAux4);
|
||||
|
||||
deviceContext->VSSetConstantBuffers(0, 10, &cbMatrix0);
|
||||
deviceContext->VSSetConstantBuffers(0, 10, &m_modelViewMatrix);
|
||||
deviceContext->PSSetConstantBuffers(0, 6, &cbColour);
|
||||
|
||||
{
|
||||
@@ -197,7 +197,7 @@ void Renderer::CaptureScreen(ImageFileBuffer *, XSOCIAL_PREVIEWIMAGE *) {}
|
||||
|
||||
void Renderer::Clear(int flags, D3D11_RECT *)
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
Renderer::Context &c = this->getContext();
|
||||
|
||||
ID3D11BlendState *blendState = nullptr;
|
||||
ID3D11DepthStencilState *depthState = nullptr;
|
||||
@@ -240,16 +240,16 @@ void Renderer::Clear(int flags, D3D11_RECT *)
|
||||
rasterDesc.MultisampleEnable = TRUE;
|
||||
m_pDevice->CreateRasterizerState(&rasterDesc, &rasterizerState);
|
||||
|
||||
context.m_pDeviceContext->VSSetShader(screenClearVertexShader, nullptr, 0);
|
||||
context.m_pDeviceContext->IASetInputLayout(nullptr);
|
||||
context.m_pDeviceContext->PSSetShader(screenClearPixelShader, nullptr, 0);
|
||||
context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
|
||||
context.m_pDeviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFFFu);
|
||||
context.m_pDeviceContext->OMSetDepthStencilState(depthState, 0);
|
||||
context.m_pDeviceContext->RSSetState(rasterizerState);
|
||||
context.m_pDeviceContext->PSSetShaderResources(0, 0, nullptr);
|
||||
context.m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
context.m_pDeviceContext->Draw(4, 0);
|
||||
c.m_pDeviceContext->VSSetShader(screenClearVertexShader, nullptr, 0);
|
||||
c.m_pDeviceContext->IASetInputLayout(nullptr);
|
||||
c.m_pDeviceContext->PSSetShader(screenClearPixelShader, nullptr, 0);
|
||||
c.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
|
||||
c.m_pDeviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFFFu);
|
||||
c.m_pDeviceContext->OMSetDepthStencilState(depthState, 0);
|
||||
c.m_pDeviceContext->RSSetState(rasterizerState);
|
||||
c.m_pDeviceContext->PSSetShaderResources(0, 0, nullptr);
|
||||
c.m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
c.m_pDeviceContext->Draw(4, 0);
|
||||
|
||||
if (blendState)
|
||||
{
|
||||
@@ -267,10 +267,10 @@ void Renderer::Clear(int flags, D3D11_RECT *)
|
||||
rasterizerState = nullptr;
|
||||
}
|
||||
|
||||
context.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), context.blendFactor, 0xFFFFFFFFu);
|
||||
context.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
|
||||
context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
|
||||
context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
|
||||
c.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), c.blendFactor, 0xFFFFFFFFu);
|
||||
c.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
|
||||
c.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
|
||||
c.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
|
||||
activeVertexType = 0xFFFFFFFFu;
|
||||
activePixelType = 0xFFFFFFFFu;
|
||||
}
|
||||
@@ -301,24 +301,23 @@ void Renderer::EndConditionalSurvey() {}
|
||||
|
||||
void Renderer::BeginEvent(LPCWSTR eventName)
|
||||
{
|
||||
Renderer::Context *context = static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx));
|
||||
if (context && context->m_pDeviceContext->GetType() != D3D11_DEVICE_CONTEXT_DEFERRED && context->userAnnotation)
|
||||
Renderer::Context &c = Renderer::getContext();
|
||||
if (c.m_pDeviceContext->GetType() != D3D11_DEVICE_CONTEXT_DEFERRED && c.userAnnotation)
|
||||
{
|
||||
context->userAnnotation->BeginEvent(eventName);
|
||||
++context->contextStateFlags;
|
||||
c.userAnnotation->BeginEvent(eventName);
|
||||
++c.annotateDepth;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::EndEvent()
|
||||
{
|
||||
Renderer::Context *context = static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx));
|
||||
if (context && context->m_pDeviceContext->GetType() != D3D11_DEVICE_CONTEXT_DEFERRED && context->userAnnotation)
|
||||
Renderer::Context &c = Renderer::getContext();
|
||||
if (c.m_pDeviceContext->GetType() != D3D11_DEVICE_CONTEXT_DEFERRED && c.userAnnotation)
|
||||
{
|
||||
context->userAnnotation->EndEvent();
|
||||
if (context->contextStateFlags > 0)
|
||||
{
|
||||
--context->contextStateFlags;
|
||||
}
|
||||
c.userAnnotation->EndEvent();
|
||||
|
||||
--c.annotateDepth;
|
||||
assert(c.annotateDepth >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,9 +411,15 @@ void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain)
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
|
||||
|
||||
m_pDevice->CreateTexture2D(&desc, nullptr, &renderTargetTextures[i]);
|
||||
m_pDevice->CreateRenderTargetView(renderTargetTextures[i], nullptr, &renderTargetViews[i]);
|
||||
m_pDevice->CreateShaderResourceView(renderTargetTextures[i], nullptr, &renderTargetShaderResourceViews[i]);
|
||||
HRESULT hr = 0;
|
||||
hr = m_pDevice->CreateTexture2D(&desc, nullptr, &renderTargetTextures[i]);
|
||||
assert(hr == S_OK);
|
||||
|
||||
hr = m_pDevice->CreateRenderTargetView(renderTargetTextures[i], nullptr, &renderTargetViews[i]);
|
||||
assert(hr == S_OK);
|
||||
|
||||
hr = m_pDevice->CreateShaderResourceView(renderTargetTextures[i], nullptr, &renderTargetShaderResourceViews[i]);
|
||||
assert(hr == S_OK);
|
||||
}
|
||||
|
||||
std::memset(m_textures, 0, sizeof(m_textures));
|
||||
@@ -457,7 +462,10 @@ void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain)
|
||||
quadIndexDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
D3D11_SUBRESOURCE_DATA quadIndexData = {};
|
||||
quadIndexData.pSysMem = quadIndices;
|
||||
m_pDevice->CreateBuffer(&quadIndexDesc, &quadIndexData, &quadIndexBuffer);
|
||||
|
||||
HRESULT hr = m_pDevice->CreateBuffer(&quadIndexDesc, &quadIndexData, &quadIndexBuffer);
|
||||
assert(hr >= 0);
|
||||
|
||||
delete[] quadIndices;
|
||||
|
||||
unsigned short *fanIndices = new unsigned short[0x2FFFAu];
|
||||
@@ -493,8 +501,8 @@ ID3D11DeviceContext *Renderer::InitialiseContext(bool fromPresent)
|
||||
m_pDevice->CreateDeferredContext(0, &deviceContext);
|
||||
}
|
||||
|
||||
Renderer::Context *context = new (std::nothrow) Renderer::Context(m_pDevice, deviceContext);
|
||||
TlsSetValue(Renderer::tlsIdx, context);
|
||||
Renderer::Context *c = new (std::nothrow) Renderer::Context(m_pDevice, deviceContext);
|
||||
TlsSetValue(Renderer::tlsIdx, c);
|
||||
return deviceContext;
|
||||
}
|
||||
|
||||
@@ -585,13 +593,13 @@ void Renderer::SetClearColour(const float colourRGBA[4])
|
||||
{
|
||||
std::memcpy(m_fClearColor, colourRGBA, sizeof(m_fClearColor));
|
||||
|
||||
Renderer::Context *context = static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx));
|
||||
if (context)
|
||||
Renderer::Context *c = static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx));
|
||||
if (c)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
context->m_pDeviceContext->Map(context->cbAux3, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
c->m_pDeviceContext->Map(c->cbAux3, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, colourRGBA, sizeof(float) * 4);
|
||||
context->m_pDeviceContext->Unmap(context->cbAux3, 0);
|
||||
c->m_pDeviceContext->Unmap(c->cbAux3, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,36 +627,36 @@ void Renderer::SetupShaders()
|
||||
screenSpacePixelShader = nullptr;
|
||||
screenClearPixelShader = nullptr;
|
||||
|
||||
m_pDevice->CreateVertexShader(VS_PF3_TF2_CB4_NB4_XW1_Data, sizeof(VS_PF3_TF2_CB4_NB4_XW1_Data), nullptr,
|
||||
m_pDevice->CreateVertexShader(g_main_VS_PF3_TF2_CB4_NB4_XW1, sizeof(g_main_VS_PF3_TF2_CB4_NB4_XW1), nullptr,
|
||||
&vertexShaderTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1]);
|
||||
m_pDevice->CreateVertexShader(VS_Compressed_Data, sizeof(VS_Compressed_Data), nullptr, &vertexShaderTable[C4JRender::VERTEX_TYPE_COMPRESSED]);
|
||||
m_pDevice->CreateVertexShader(VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data, sizeof(VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data), nullptr,
|
||||
m_pDevice->CreateVertexShader(g_main_VS_Compressed, sizeof(g_main_VS_Compressed), nullptr, &vertexShaderTable[C4JRender::VERTEX_TYPE_COMPRESSED]);
|
||||
m_pDevice->CreateVertexShader(g_main_VS_PF3_TF2_CB4_NB4_XW1_LIGHTING, sizeof(g_main_VS_PF3_TF2_CB4_NB4_XW1_LIGHTING), nullptr,
|
||||
&vertexShaderTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT]);
|
||||
m_pDevice->CreateVertexShader(VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data, sizeof(VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data), nullptr,
|
||||
m_pDevice->CreateVertexShader(g_main_VS_PF3_TF2_CB4_NB4_XW1_TEXGEN, sizeof(g_main_VS_PF3_TF2_CB4_NB4_XW1_TEXGEN), nullptr,
|
||||
&vertexShaderTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN]);
|
||||
m_pDevice->CreateVertexShader(VS_ScreenSpace_Data, sizeof(VS_ScreenSpace_Data), nullptr, &screenSpaceVertexShader);
|
||||
m_pDevice->CreateVertexShader(VS_ScreenClear_Data, sizeof(VS_ScreenClear_Data), nullptr, &screenClearVertexShader);
|
||||
m_pDevice->CreateVertexShader(g_main_VS_ScreenSpace, sizeof(g_main_VS_ScreenSpace), nullptr, &screenSpaceVertexShader);
|
||||
m_pDevice->CreateVertexShader(g_main_VS_ScreenClear, sizeof(g_main_VS_ScreenClear), nullptr, &screenClearVertexShader);
|
||||
|
||||
m_pDevice->CreatePixelShader(PS_Standard_Data, sizeof(PS_Standard_Data), nullptr, &pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_STANDARD]);
|
||||
m_pDevice->CreatePixelShader(PS_TextureProjection_Data, sizeof(PS_TextureProjection_Data), nullptr,
|
||||
m_pDevice->CreatePixelShader(g_main_PS_Standard, sizeof(g_main_PS_Standard), nullptr, &pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_STANDARD]);
|
||||
m_pDevice->CreatePixelShader(g_main_PS_TextureProjection, sizeof(g_main_PS_TextureProjection), nullptr,
|
||||
&pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_PROJECTION]);
|
||||
m_pDevice->CreatePixelShader(PS_ForceLOD_Data, sizeof(PS_ForceLOD_Data), nullptr, &pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_FORCELOD]);
|
||||
m_pDevice->CreatePixelShader(PS_ScreenSpace_Data, sizeof(PS_ScreenSpace_Data), nullptr, &screenSpacePixelShader);
|
||||
m_pDevice->CreatePixelShader(PS_ScreenClear_Data, sizeof(PS_ScreenClear_Data), nullptr, &screenClearPixelShader);
|
||||
m_pDevice->CreatePixelShader(g_main_PS_ForceLOD, sizeof(g_main_PS_ForceLOD), nullptr, &pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_FORCELOD]);
|
||||
m_pDevice->CreatePixelShader(g_main_PS_ScreenSpace, sizeof(g_main_PS_ScreenSpace), nullptr, &screenSpacePixelShader);
|
||||
m_pDevice->CreatePixelShader(g_main_PS_ScreenClear, sizeof(g_main_PS_ScreenClear), nullptr, &screenClearPixelShader);
|
||||
|
||||
m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, VS_PF3_TF2_CB4_NB4_XW1_Data, sizeof(VS_PF3_TF2_CB4_NB4_XW1_Data),
|
||||
m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, g_main_VS_PF3_TF2_CB4_NB4_XW1, sizeof(g_main_VS_PF3_TF2_CB4_NB4_XW1),
|
||||
&inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1]);
|
||||
m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_Compressed, 2, VS_Compressed_Data, sizeof(VS_Compressed_Data),
|
||||
m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_Compressed, 2, g_main_VS_Compressed, sizeof(g_main_VS_Compressed),
|
||||
&inputLayoutTable[C4JRender::VERTEX_TYPE_COMPRESSED]);
|
||||
m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data,
|
||||
sizeof(VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data), &inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT]);
|
||||
m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data,
|
||||
sizeof(VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data), &inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN]);
|
||||
m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, g_main_VS_PF3_TF2_CB4_NB4_XW1_LIGHTING,
|
||||
sizeof(g_main_VS_PF3_TF2_CB4_NB4_XW1_LIGHTING), &inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT]);
|
||||
m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, g_main_VS_PF3_TF2_CB4_NB4_XW1_TEXGEN,
|
||||
sizeof(g_main_VS_PF3_TF2_CB4_NB4_XW1_TEXGEN), &inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN]);
|
||||
}
|
||||
|
||||
void Renderer::StartFrame()
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
Renderer::Context &c = this->getContext();
|
||||
|
||||
activeVertexType = 0xFFFFFFFFu;
|
||||
activePixelType = 0xFFFFFFFFu;
|
||||
@@ -668,8 +676,8 @@ void Renderer::StartFrame()
|
||||
this->StateSetDepthTestEnable(false);
|
||||
this->StateSetAlphaTestEnable(true);
|
||||
|
||||
context.m_pDeviceContext->VSSetConstantBuffers(0, 10, &context.cbMatrix0);
|
||||
context.m_pDeviceContext->PSSetConstantBuffers(0, 6, &context.cbColour);
|
||||
c.m_pDeviceContext->VSSetConstantBuffers(0, 10, &c.m_modelViewMatrix);
|
||||
c.m_pDeviceContext->PSSetConstantBuffers(0, 6, &c.cbColour);
|
||||
|
||||
D3D11_VIEWPORT viewport = {};
|
||||
viewport.TopLeftX = 0.0f;
|
||||
@@ -678,8 +686,8 @@ void Renderer::StartFrame()
|
||||
viewport.Height = (float)backBufferHeight;
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
context.m_pDeviceContext->RSSetViewports(1, &viewport);
|
||||
context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
|
||||
c.m_pDeviceContext->RSSetViewports(1, &viewport);
|
||||
c.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
|
||||
}
|
||||
|
||||
void Renderer::Suspend()
|
||||
@@ -701,7 +709,7 @@ Renderer::Context &Renderer::getContext()
|
||||
|
||||
void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut)
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
Renderer::Context &c = this->getContext();
|
||||
|
||||
float left;
|
||||
float bottom;
|
||||
@@ -819,12 +827,12 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut)
|
||||
samplerDesc.MaxLOD = (std::numeric_limits<float>::max)();
|
||||
m_pDevice->CreateSamplerState(&samplerDesc, &samplerState);
|
||||
|
||||
context.m_pDeviceContext->VSSetShader(screenSpaceVertexShader, nullptr, 0);
|
||||
context.m_pDeviceContext->IASetInputLayout(nullptr);
|
||||
context.m_pDeviceContext->PSSetShader(screenSpacePixelShader, nullptr, 0);
|
||||
context.m_pDeviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFFFu);
|
||||
context.m_pDeviceContext->OMSetDepthStencilState(depthState, 0);
|
||||
context.m_pDeviceContext->RSSetState(rasterizerState);
|
||||
c.m_pDeviceContext->VSSetShader(screenSpaceVertexShader, nullptr, 0);
|
||||
c.m_pDeviceContext->IASetInputLayout(nullptr);
|
||||
c.m_pDeviceContext->PSSetShader(screenSpacePixelShader, nullptr, 0);
|
||||
c.m_pDeviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFFFu);
|
||||
c.m_pDeviceContext->OMSetDepthStencilState(depthState, 0);
|
||||
c.m_pDeviceContext->RSSetState(rasterizerState);
|
||||
|
||||
for (unsigned int i = 0; i < MAX_MIP_LEVELS - 1; ++i)
|
||||
{
|
||||
@@ -836,16 +844,16 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut)
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
|
||||
context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetViews[i], nullptr);
|
||||
context.m_pDeviceContext->RSSetViewports(1, &viewport);
|
||||
c.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetViews[i], nullptr);
|
||||
c.m_pDeviceContext->RSSetViewports(1, &viewport);
|
||||
|
||||
ID3D11ShaderResourceView *inputTexture = (i == 0) ? renderTargetShaderResourceView : renderTargetShaderResourceViews[i - 1];
|
||||
context.m_pDeviceContext->PSSetShaderResources(0, 1, &inputTexture);
|
||||
context.m_pDeviceContext->PSSetSamplers(0, 1, &samplerState);
|
||||
context.m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
c.m_pDeviceContext->PSSetShaderResources(0, 1, &inputTexture);
|
||||
c.m_pDeviceContext->PSSetSamplers(0, 1, &samplerState);
|
||||
c.m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
context.m_pDeviceContext->Map(context.cbAux1, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
c.m_pDeviceContext->Map(c.cbAux1, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
float *constants = static_cast<float *>(mapped.pData);
|
||||
if (i == 0)
|
||||
{
|
||||
@@ -861,8 +869,8 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut)
|
||||
constants[2] = 1.0f;
|
||||
constants[3] = 1.0f;
|
||||
}
|
||||
context.m_pDeviceContext->Unmap(context.cbAux1, 0);
|
||||
context.m_pDeviceContext->Draw(4, 0);
|
||||
c.m_pDeviceContext->Unmap(c.cbAux1, 0);
|
||||
c.m_pDeviceContext->Draw(4, 0);
|
||||
}
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc = {};
|
||||
@@ -876,9 +884,9 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut)
|
||||
unsigned char *linearData = new unsigned char[kThumbnailSize * kThumbnailSize * 4u];
|
||||
if (stagingTexture)
|
||||
{
|
||||
context.m_pDeviceContext->CopyResource(stagingTexture, renderTargetTextures[MAX_MIP_LEVELS - 2]);
|
||||
c.m_pDeviceContext->CopyResource(stagingTexture, renderTargetTextures[MAX_MIP_LEVELS - 2]);
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
if (SUCCEEDED(context.m_pDeviceContext->Map(stagingTexture, 0, D3D11_MAP_READ, 0, &mapped)))
|
||||
if (SUCCEEDED(c.m_pDeviceContext->Map(stagingTexture, 0, D3D11_MAP_READ, 0, &mapped)))
|
||||
{
|
||||
const unsigned char *src = static_cast<const unsigned char *>(mapped.pData);
|
||||
unsigned char *dst = linearData;
|
||||
@@ -892,7 +900,7 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut)
|
||||
src += mapped.RowPitch;
|
||||
dst += kThumbnailSize * 4u;
|
||||
}
|
||||
context.m_pDeviceContext->Unmap(stagingTexture, 0);
|
||||
c.m_pDeviceContext->Unmap(stagingTexture, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -925,9 +933,9 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut)
|
||||
blendState = nullptr;
|
||||
}
|
||||
|
||||
context.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), context.blendFactor, 0xFFFFFFFFu);
|
||||
context.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
|
||||
context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
|
||||
c.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), c.blendFactor, 0xFFFFFFFFu);
|
||||
c.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
|
||||
c.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
|
||||
|
||||
D3D11_VIEWPORT viewport = {};
|
||||
viewport.TopLeftX = 0.0f;
|
||||
@@ -936,8 +944,8 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut)
|
||||
viewport.Height = (float)backBufferHeight;
|
||||
viewport.MinDepth = 0.0f;
|
||||
viewport.MaxDepth = 1.0f;
|
||||
context.m_pDeviceContext->RSSetViewports(1, &viewport);
|
||||
context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
|
||||
c.m_pDeviceContext->RSSetViewports(1, &viewport);
|
||||
c.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
|
||||
activeVertexType = 0xFFFFFFFFu;
|
||||
activePixelType = 0xFFFFFFFFu;
|
||||
}
|
||||
|
||||
@@ -5,15 +5,17 @@
|
||||
|
||||
const float *Renderer::MatrixGet(int type)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
const int depth = context.matrixStackDepth[type];
|
||||
return reinterpret_cast<const float *>(&context.matrixStacks[type][depth]);
|
||||
Context &c = this->getContext();
|
||||
const int depth = c.stackPos[type];
|
||||
return reinterpret_cast<const float *>(&c.matrixStacks[type][depth]);
|
||||
}
|
||||
|
||||
void Renderer::MatrixMode(int type)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
context.matrixModeType = type;
|
||||
Context &c = this->getContext();
|
||||
assert(type >= 0);
|
||||
assert(type < STACK_TYPES);
|
||||
c.stackType = type;
|
||||
}
|
||||
|
||||
void Renderer::MatrixMult(float *mat)
|
||||
@@ -38,19 +40,25 @@ void Renderer::MatrixPerspective(float fovy, float aspect, float zNear, float zF
|
||||
|
||||
void Renderer::MatrixPop()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
const int mode = context.matrixModeType;
|
||||
--context.matrixStackDepth[mode];
|
||||
context.matrixDirty[mode] = true;
|
||||
Context &c = this->getContext();
|
||||
|
||||
assert(c.stackPos[c.stackType] > 0);
|
||||
|
||||
const int mode = c.stackType;
|
||||
--c.stackPos[mode];
|
||||
c.matrixDirty[mode] = true;
|
||||
}
|
||||
|
||||
void Renderer::MatrixPush()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
const int mode = context.matrixModeType;
|
||||
const int depth = context.matrixStackDepth[mode];
|
||||
context.matrixStacks[mode][depth + 1] = context.matrixStacks[mode][depth];
|
||||
++context.matrixStackDepth[mode];
|
||||
Context &c = this->getContext();
|
||||
|
||||
assert(c.stackPos[c.stackType] < (STACK_SIZE - 1));
|
||||
|
||||
const int mode = c.stackType;
|
||||
const int depth = c.stackPos[mode];
|
||||
c.matrixStacks[mode][depth + 1] = c.matrixStacks[mode][depth];
|
||||
++c.stackPos[mode];
|
||||
}
|
||||
|
||||
void Renderer::MatrixRotate(float angle, float x, float y, float z)
|
||||
@@ -68,11 +76,11 @@ void Renderer::MatrixScale(float x, float y, float z)
|
||||
|
||||
void Renderer::MatrixSetIdentity()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
const int mode = context.matrixModeType;
|
||||
const int depth = context.matrixStackDepth[mode];
|
||||
context.matrixStacks[mode][depth] = DirectX::XMMatrixIdentity();
|
||||
context.matrixDirty[mode] = true;
|
||||
Context &c = this->getContext();
|
||||
const int mode = c.stackType;
|
||||
const int depth = c.stackPos[mode];
|
||||
c.matrixStacks[mode][depth] = DirectX::XMMatrixIdentity();
|
||||
c.matrixDirty[mode] = true;
|
||||
}
|
||||
|
||||
void Renderer::MatrixTranslate(float x, float y, float z)
|
||||
@@ -83,28 +91,28 @@ void Renderer::MatrixTranslate(float x, float y, float z)
|
||||
|
||||
void Renderer::MultWithStack(DirectX::XMMATRIX matrix)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
const int mode = context.matrixModeType;
|
||||
const int depth = context.matrixStackDepth[mode];
|
||||
DirectX::XMMATRIX ¤t = context.matrixStacks[mode][depth];
|
||||
Context &c = this->getContext();
|
||||
const int mode = c.stackType;
|
||||
const int depth = c.stackPos[mode];
|
||||
DirectX::XMMATRIX ¤t = c.matrixStacks[mode][depth];
|
||||
current = DirectX::XMMatrixMultiply(matrix, current);
|
||||
context.matrixDirty[mode] = true;
|
||||
c.matrixDirty[mode] = true;
|
||||
}
|
||||
|
||||
void Renderer::Set_matrixDirty()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
Context &c = this->getContext();
|
||||
const DirectX::XMMATRIX identity = DirectX::XMMatrixIdentity();
|
||||
|
||||
context.matrixStacks[0][0] = identity;
|
||||
context.matrixStacks[1][0] = identity;
|
||||
context.matrixStacks[2][0] = identity;
|
||||
context.matrixStacks[3][0] = identity;
|
||||
c.matrixStacks[MATRIX_MODE_MODELVIEW][0] = identity;
|
||||
c.matrixStacks[MATRIX_MODE_MODELVIEW_UNK1][0] = identity;
|
||||
c.matrixStacks[MATRIX_MODE_MODELVIEW_UNK2][0] = identity;
|
||||
c.matrixStacks[MATRIX_MODE_MODELVIEW_CBUFF][0] = identity;
|
||||
|
||||
context.matrixDirty[0] = true;
|
||||
context.matrixDirty[1] = true;
|
||||
context.matrixDirty[2] = true;
|
||||
context.matrixDirty[3] = true;
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW] = true;
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_UNK1] = true;
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_UNK2] = true;
|
||||
c.matrixDirty[MATRIX_MODE_MODELVIEW_CBUFF] = true;
|
||||
|
||||
activeVertexType = 0xFFFFFFFFu;
|
||||
activePixelType = 0xFFFFFFFFu;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
ID3D11BlendState *Renderer::GetManagedBlendState()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
const D3D11_RENDER_TARGET_BLEND_DESC &rtBlend = context.blendDesc.RenderTarget[0];
|
||||
Context &c = this->getContext();
|
||||
const D3D11_RENDER_TARGET_BLEND_DESC &rtBlend = c.blendDesc.RenderTarget[0];
|
||||
|
||||
const int key = (rtBlend.BlendEnable ? 1 : 0) | ((static_cast<int>(rtBlend.SrcBlend) & 0x1F) << 1) |
|
||||
((static_cast<int>(rtBlend.DestBlend) & 0x1F) << 6) | ((static_cast<int>(rtBlend.RenderTargetWriteMask) & 0x0F) << 11);
|
||||
@@ -20,17 +20,17 @@ ID3D11BlendState *Renderer::GetManagedBlendState()
|
||||
}
|
||||
|
||||
ID3D11BlendState *state = nullptr;
|
||||
m_pDevice->CreateBlendState(&context.blendDesc, &state);
|
||||
m_pDevice->CreateBlendState(&c.blendDesc, &state);
|
||||
managedBlendStates.emplace(key, state);
|
||||
return state;
|
||||
}
|
||||
|
||||
ID3D11DepthStencilState *Renderer::GetManagedDepthStencilState()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
Context &c = this->getContext();
|
||||
|
||||
const int key = (context.depthStencilDesc.DepthEnable ? 2 : 0) | ((static_cast<int>(context.depthStencilDesc.DepthFunc) & 0x0F) << 2) |
|
||||
(context.depthStencilDesc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL ? 1 : 0);
|
||||
const int key = (c.depthStencilDesc.DepthEnable ? 2 : 0) | ((static_cast<int>(c.depthStencilDesc.DepthFunc) & 0x0F) << 2) |
|
||||
(c.depthStencilDesc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL ? 1 : 0);
|
||||
|
||||
auto it = managedDepthStencilStates.find(key);
|
||||
if (it != managedDepthStencilStates.end())
|
||||
@@ -39,18 +39,18 @@ ID3D11DepthStencilState *Renderer::GetManagedDepthStencilState()
|
||||
}
|
||||
|
||||
ID3D11DepthStencilState *state = nullptr;
|
||||
m_pDevice->CreateDepthStencilState(&context.depthStencilDesc, &state);
|
||||
m_pDevice->CreateDepthStencilState(&c.depthStencilDesc, &state);
|
||||
managedDepthStencilStates.emplace(key, state);
|
||||
return state;
|
||||
}
|
||||
|
||||
ID3D11RasterizerState *Renderer::GetManagedRasterizerState()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
Context &c = this->getContext();
|
||||
|
||||
const int key = (static_cast<std::uint8_t>(context.rasterizerDesc.DepthBias)) |
|
||||
(static_cast<std::uint8_t>(static_cast<int>(context.rasterizerDesc.SlopeScaledDepthBias)) << 8) |
|
||||
((static_cast<int>(context.rasterizerDesc.CullMode) & 0x03) << 16);
|
||||
const int key = (static_cast<std::uint8_t>(c.rasterizerDesc.DepthBias)) |
|
||||
(static_cast<std::uint8_t>(static_cast<int>(c.rasterizerDesc.SlopeScaledDepthBias)) << 8) |
|
||||
((static_cast<int>(c.rasterizerDesc.CullMode) & 0x03) << 16);
|
||||
|
||||
auto it = managedRasterizerStates.find(key);
|
||||
if (it != managedRasterizerStates.end())
|
||||
@@ -59,15 +59,15 @@ ID3D11RasterizerState *Renderer::GetManagedRasterizerState()
|
||||
}
|
||||
|
||||
ID3D11RasterizerState *state = nullptr;
|
||||
m_pDevice->CreateRasterizerState(&context.rasterizerDesc, &state);
|
||||
m_pDevice->CreateRasterizerState(&c.rasterizerDesc, &state);
|
||||
managedRasterizerStates.emplace(key, state);
|
||||
return state;
|
||||
}
|
||||
|
||||
ID3D11SamplerState *Renderer::GetManagedSamplerState()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
const int key = m_textures[context.boundTextureIndex].samplerParams;
|
||||
Context &c = this->getContext();
|
||||
const int key = m_textures[c.textureIdx].samplerParams;
|
||||
|
||||
auto it = managedSamplerStates.find(key);
|
||||
if (it != managedSamplerStates.end())
|
||||
@@ -104,54 +104,54 @@ ID3D11SamplerState *Renderer::GetManagedSamplerState()
|
||||
|
||||
void Renderer::StateSetFogEnable(bool enable)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
context.fogEnabled = enable ? 1 : 0;
|
||||
Context &c = this->getContext();
|
||||
c.fogEnabled = enable ? 1 : 0;
|
||||
}
|
||||
|
||||
void Renderer::StateSetFogMode(int mode)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
context.fogMode = mode;
|
||||
Context &c = this->getContext();
|
||||
c.fogMode = mode;
|
||||
}
|
||||
|
||||
void Renderer::StateSetFogNearDistance(float dist)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
context.fogNearDistance = dist;
|
||||
Context &c = this->getContext();
|
||||
c.fogNearDistance = dist;
|
||||
}
|
||||
|
||||
void Renderer::StateSetFogFarDistance(float dist)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
context.fogFarDistance = dist;
|
||||
Context &c = this->getContext();
|
||||
c.fogFarDistance = dist;
|
||||
}
|
||||
|
||||
void Renderer::StateSetFogDensity(float density)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
context.fogDensity = density;
|
||||
Context &c = this->getContext();
|
||||
c.fogDensity = density;
|
||||
}
|
||||
|
||||
void Renderer::StateSetFogColour(float red, float green, float blue)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
context.fogColourRed = red;
|
||||
context.fogColourBlue = blue;
|
||||
context.fogColourGreen = green;
|
||||
Context &c = this->getContext();
|
||||
c.fogColourRed = red;
|
||||
c.fogColourBlue = blue;
|
||||
c.fogColourGreen = green;
|
||||
}
|
||||
|
||||
void Renderer::UpdateViewportState() {}
|
||||
|
||||
void Renderer::StateSetLightingEnable(bool enable)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetLightingEnable(enable);
|
||||
c.commandBuffer->SetLightingEnable(enable);
|
||||
return;
|
||||
}
|
||||
|
||||
context.lightingEnabled = enable ? 1 : 0;
|
||||
c.lightingEnabled = enable ? 1 : 0;
|
||||
}
|
||||
|
||||
void Renderer::StateSetLightColour(int light, float red, float green, float blue)
|
||||
@@ -161,34 +161,34 @@ void Renderer::StateSetLightColour(int light, float red, float green, float blue
|
||||
return;
|
||||
}
|
||||
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetLightColour(light, red, green, blue);
|
||||
c.commandBuffer->SetLightColour(light, red, green, blue);
|
||||
return;
|
||||
}
|
||||
|
||||
context.lightColour[light].x = red;
|
||||
context.lightColour[light].y = green;
|
||||
context.lightColour[light].z = blue;
|
||||
context.lightColour[light].w = 1.0f;
|
||||
context.lightingDirty = 1;
|
||||
c.lightColour[light].x = red;
|
||||
c.lightColour[light].y = green;
|
||||
c.lightColour[light].z = blue;
|
||||
c.lightColour[light].w = 1.0f;
|
||||
c.lightingDirty = 1;
|
||||
}
|
||||
|
||||
void Renderer::StateSetLightAmbientColour(float red, float green, float blue)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetLightAmbientColour(red, green, blue);
|
||||
c.commandBuffer->SetLightAmbientColour(red, green, blue);
|
||||
return;
|
||||
}
|
||||
|
||||
context.lightAmbientColour.x = red;
|
||||
context.lightAmbientColour.y = green;
|
||||
context.lightAmbientColour.z = blue;
|
||||
context.lightAmbientColour.w = 1.0f;
|
||||
context.lightingDirty = 1;
|
||||
c.lightAmbientColour.x = red;
|
||||
c.lightAmbientColour.y = green;
|
||||
c.lightAmbientColour.z = blue;
|
||||
c.lightAmbientColour.w = 1.0f;
|
||||
c.lightingDirty = 1;
|
||||
}
|
||||
|
||||
void Renderer::StateSetLightEnable(int light, bool enable)
|
||||
@@ -198,152 +198,152 @@ void Renderer::StateSetLightEnable(int light, bool enable)
|
||||
return;
|
||||
}
|
||||
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetLightEnable(light, enable);
|
||||
c.commandBuffer->SetLightEnable(light, enable);
|
||||
return;
|
||||
}
|
||||
|
||||
context.lightEnabled[light] = enable ? 1 : 0;
|
||||
context.lightingDirty = 1;
|
||||
c.lightEnabled[light] = enable ? 1 : 0;
|
||||
c.lightingDirty = 1;
|
||||
}
|
||||
|
||||
void Renderer::StateSetColour(float r, float g, float b, float a)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetColor(r, g, b, a);
|
||||
c.commandBuffer->SetColor(r, g, b, a);
|
||||
return;
|
||||
}
|
||||
|
||||
ID3D11DeviceContext *d3d11 = context.m_pDeviceContext;
|
||||
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
|
||||
const float colour[4] = {r, g, b, a};
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
d3d11->Map(context.cbColour, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
d3d11->Map(c.cbColour, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, colour, sizeof(colour));
|
||||
d3d11->Unmap(context.cbColour, 0);
|
||||
d3d11->Unmap(c.cbColour, 0);
|
||||
}
|
||||
|
||||
void Renderer::StateSetDepthMask(bool enable)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetDepthMask(enable);
|
||||
c.commandBuffer->SetDepthMask(enable);
|
||||
return;
|
||||
}
|
||||
|
||||
context.depthStencilDesc.DepthWriteMask = enable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
context.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
|
||||
context.depthWriteEnabled = enable ? 1 : 0;
|
||||
c.depthStencilDesc.DepthWriteMask = enable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
c.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
|
||||
c.depthWriteEnabled = enable ? 1 : 0;
|
||||
}
|
||||
|
||||
void Renderer::StateSetBlendEnable(bool enable)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetBlendEnable(enable);
|
||||
c.commandBuffer->SetBlendEnable(enable);
|
||||
return;
|
||||
}
|
||||
|
||||
context.blendDesc.RenderTarget[0].BlendEnable = enable ? TRUE : FALSE;
|
||||
context.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), context.blendFactor, 0xFFFFFFFFu);
|
||||
c.blendDesc.RenderTarget[0].BlendEnable = enable ? TRUE : FALSE;
|
||||
c.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), c.blendFactor, 0xFFFFFFFFu);
|
||||
}
|
||||
|
||||
void Renderer::StateSetBlendFunc(int src, int dst)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetBlendFunc(src, dst);
|
||||
c.commandBuffer->SetBlendFunc(src, dst);
|
||||
return;
|
||||
}
|
||||
|
||||
context.blendDesc.RenderTarget[0].SrcBlend = static_cast<D3D11_BLEND>(src);
|
||||
context.blendDesc.RenderTarget[0].DestBlend = static_cast<D3D11_BLEND>(dst);
|
||||
context.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), context.blendFactor, 0xFFFFFFFFu);
|
||||
c.blendDesc.RenderTarget[0].SrcBlend = static_cast<D3D11_BLEND>(src);
|
||||
c.blendDesc.RenderTarget[0].DestBlend = static_cast<D3D11_BLEND>(dst);
|
||||
c.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), c.blendFactor, 0xFFFFFFFFu);
|
||||
}
|
||||
|
||||
void Renderer::StateSetBlendFactor(unsigned int colour)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetBlendFactor(colour);
|
||||
c.commandBuffer->SetBlendFactor(colour);
|
||||
return;
|
||||
}
|
||||
|
||||
const float scale = 255.0f;
|
||||
context.blendFactor[0] = static_cast<float>((colour >> 0) & 0xFFu) / scale;
|
||||
context.blendFactor[1] = static_cast<float>((colour >> 8) & 0xFFu) / scale;
|
||||
context.blendFactor[2] = static_cast<float>((colour >> 16) & 0xFFu) / scale;
|
||||
context.blendFactor[3] = static_cast<float>((colour >> 24) & 0xFFu) / scale;
|
||||
context.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), context.blendFactor, 0xFFFFFFFFu);
|
||||
c.blendFactor[0] = static_cast<float>((colour >> 0) & 0xFFu) / scale;
|
||||
c.blendFactor[1] = static_cast<float>((colour >> 8) & 0xFFu) / scale;
|
||||
c.blendFactor[2] = static_cast<float>((colour >> 16) & 0xFFu) / scale;
|
||||
c.blendFactor[3] = static_cast<float>((colour >> 24) & 0xFFu) / scale;
|
||||
c.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), c.blendFactor, 0xFFFFFFFFu);
|
||||
}
|
||||
|
||||
void Renderer::StateSetAlphaFunc(int, float param)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
context.alphaReference = param;
|
||||
Context &c = this->getContext();
|
||||
c.alphaReference = param;
|
||||
|
||||
const float alpha[4] = {0.0f, 0.0f, 0.0f, context.alphaTestEnabled ? context.alphaReference : 0.0f};
|
||||
const float alpha[4] = {0.0f, 0.0f, 0.0f, c.alphaTestEnabled ? c.alphaReference : 0.0f};
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
context.m_pDeviceContext->Map(context.cbAlphaTest, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
c.m_pDeviceContext->Map(c.cbAlphaTest, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, alpha, sizeof(alpha));
|
||||
context.m_pDeviceContext->Unmap(context.cbAlphaTest, 0);
|
||||
c.m_pDeviceContext->Unmap(c.cbAlphaTest, 0);
|
||||
}
|
||||
|
||||
void Renderer::StateSetDepthFunc(int func)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetDepthFunc(func);
|
||||
c.commandBuffer->SetDepthFunc(func);
|
||||
return;
|
||||
}
|
||||
|
||||
context.depthStencilDesc.DepthFunc = static_cast<D3D11_COMPARISON_FUNC>(func);
|
||||
context.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
|
||||
c.depthStencilDesc.DepthFunc = static_cast<D3D11_COMPARISON_FUNC>(func);
|
||||
c.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
|
||||
}
|
||||
|
||||
void Renderer::StateSetFaceCull(bool enable)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetFaceCull(enable);
|
||||
c.commandBuffer->SetFaceCull(enable);
|
||||
return;
|
||||
}
|
||||
|
||||
context.rasterizerDesc.CullMode = enable ? D3D11_CULL_BACK : D3D11_CULL_NONE;
|
||||
context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
|
||||
context.faceCullEnabled = enable ? 1 : 0;
|
||||
c.rasterizerDesc.CullMode = enable ? D3D11_CULL_BACK : D3D11_CULL_NONE;
|
||||
c.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
|
||||
c.faceCullEnabled = enable ? 1 : 0;
|
||||
}
|
||||
|
||||
void Renderer::StateSetFaceCullCW(bool enable)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.faceCullEnabled)
|
||||
Context &c = this->getContext();
|
||||
if (c.faceCullEnabled)
|
||||
{
|
||||
context.rasterizerDesc.CullMode = enable ? D3D11_CULL_BACK : D3D11_CULL_FRONT;
|
||||
c.rasterizerDesc.CullMode = enable ? D3D11_CULL_BACK : D3D11_CULL_FRONT;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.rasterizerDesc.CullMode = D3D11_CULL_NONE;
|
||||
c.rasterizerDesc.CullMode = D3D11_CULL_NONE;
|
||||
}
|
||||
|
||||
context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
|
||||
c.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
|
||||
}
|
||||
|
||||
void Renderer::StateSetLineWidth(float) {}
|
||||
|
||||
void Renderer::StateSetWriteEnable(bool red, bool green, bool blue, bool alpha)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
Context &c = this->getContext();
|
||||
|
||||
std::uint8_t mask = 0;
|
||||
mask |= red ? 0x1 : 0;
|
||||
@@ -351,127 +351,127 @@ void Renderer::StateSetWriteEnable(bool red, bool green, bool blue, bool alpha)
|
||||
mask |= blue ? 0x4 : 0;
|
||||
mask |= alpha ? 0x8 : 0;
|
||||
|
||||
context.blendDesc.RenderTarget[0].RenderTargetWriteMask = mask;
|
||||
context.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), context.blendFactor, 0xFFFFFFFFu);
|
||||
c.blendDesc.RenderTarget[0].RenderTargetWriteMask = mask;
|
||||
c.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), c.blendFactor, 0xFFFFFFFFu);
|
||||
}
|
||||
|
||||
void Renderer::StateSetDepthTestEnable(bool enable)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetDepthTestEnable(enable);
|
||||
c.commandBuffer->SetDepthTestEnable(enable);
|
||||
return;
|
||||
}
|
||||
|
||||
context.depthStencilDesc.DepthEnable = enable ? TRUE : FALSE;
|
||||
context.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
|
||||
context.depthTestEnabled = enable ? 1 : 0;
|
||||
c.depthStencilDesc.DepthEnable = enable ? TRUE : FALSE;
|
||||
c.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
|
||||
c.depthTestEnabled = enable ? 1 : 0;
|
||||
}
|
||||
|
||||
void Renderer::StateSetAlphaTestEnable(bool enable)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
context.alphaTestEnabled = enable ? 1 : 0;
|
||||
Context &c = this->getContext();
|
||||
c.alphaTestEnabled = enable ? 1 : 0;
|
||||
|
||||
const float alpha[4] = {0.0f, 0.0f, 0.0f, enable ? context.alphaReference : 0.0f};
|
||||
const float alpha[4] = {0.0f, 0.0f, 0.0f, enable ? c.alphaReference : 0.0f};
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
context.m_pDeviceContext->Map(context.cbAlphaTest, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
c.m_pDeviceContext->Map(c.cbAlphaTest, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, alpha, sizeof(alpha));
|
||||
context.m_pDeviceContext->Unmap(context.cbAlphaTest, 0);
|
||||
c.m_pDeviceContext->Unmap(c.cbAlphaTest, 0);
|
||||
}
|
||||
|
||||
void Renderer::StateSetDepthSlopeAndBias(float slope, float bias)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
Context &c = this->getContext();
|
||||
|
||||
const float scale = 65536.0f;
|
||||
context.rasterizerDesc.DepthBias = static_cast<int>(bias * scale);
|
||||
context.rasterizerDesc.SlopeScaledDepthBias = slope * scale;
|
||||
context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
|
||||
c.rasterizerDesc.DepthBias = static_cast<int>(bias * scale);
|
||||
c.rasterizerDesc.SlopeScaledDepthBias = slope * scale;
|
||||
c.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
|
||||
}
|
||||
|
||||
void Renderer::UpdateFogState()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
ID3D11DeviceContext *d3d11 = context.m_pDeviceContext;
|
||||
Context &c = this->getContext();
|
||||
ID3D11DeviceContext *d3d11 = c.m_pDeviceContext;
|
||||
|
||||
float fogParams[4] = {};
|
||||
if (context.fogEnabled)
|
||||
if (c.fogEnabled)
|
||||
{
|
||||
if (context.fogMode == 1)
|
||||
if (c.fogMode == 1)
|
||||
{
|
||||
fogParams[0] = context.fogFarDistance;
|
||||
fogParams[1] = 1.0f / (context.fogFarDistance - context.fogNearDistance);
|
||||
fogParams[0] = c.fogFarDistance;
|
||||
fogParams[1] = 1.0f / (c.fogFarDistance - c.fogNearDistance);
|
||||
fogParams[2] = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
fogParams[0] = context.fogDensity;
|
||||
fogParams[0] = c.fogDensity;
|
||||
fogParams[2] = 2.0f;
|
||||
}
|
||||
}
|
||||
|
||||
const float fogColour[4] = {context.fogColourRed, context.fogColourGreen, context.fogColourBlue, 1.0f};
|
||||
const float fogColour[4] = {c.fogColourRed, c.fogColourGreen, c.fogColourBlue, 1.0f};
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
d3d11->Map(context.cbFogParams, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
d3d11->Map(c.cbFogParams, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, fogParams, sizeof(fogParams));
|
||||
d3d11->Unmap(context.cbFogParams, 0);
|
||||
d3d11->Unmap(c.cbFogParams, 0);
|
||||
|
||||
d3d11->Map(context.cbFogColour, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
d3d11->Map(c.cbFogColour, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, fogColour, sizeof(fogColour));
|
||||
d3d11->Unmap(context.cbFogColour, 0);
|
||||
d3d11->Unmap(c.cbFogColour, 0);
|
||||
}
|
||||
|
||||
void Renderer::StateSetVertexTextureUV(float u, float v)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
Context &c = this->getContext();
|
||||
const float texgen[4] = {u - 1.0f, v - 1.0f, 0.0f, 0.0f};
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
context.m_pDeviceContext->Map(context.cbVertexTexcoord, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
c.m_pDeviceContext->Map(c.cbVertexTexcoord, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, texgen, sizeof(texgen));
|
||||
context.m_pDeviceContext->Unmap(context.cbVertexTexcoord, 0);
|
||||
c.m_pDeviceContext->Unmap(c.cbVertexTexcoord, 0);
|
||||
}
|
||||
|
||||
void Renderer::UpdateTexGenState()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
Context &c = this->getContext();
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
context.m_pDeviceContext->Map(context.cbTexGen, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, context.texGenMatrices, sizeof(context.texGenMatrices));
|
||||
context.m_pDeviceContext->Unmap(context.cbTexGen, 0);
|
||||
c.m_pDeviceContext->Map(c.cbTexGen, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, c.texGenMatrices, sizeof(c.texGenMatrices));
|
||||
c.m_pDeviceContext->Unmap(c.cbTexGen, 0);
|
||||
}
|
||||
|
||||
void Renderer::UpdateLightingState()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
if (!context.lightingDirty || !context.lightingEnabled)
|
||||
Context &c = this->getContext();
|
||||
if (!c.lightingDirty || !c.lightingEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.lightEnabled[0])
|
||||
if (!c.lightEnabled[0])
|
||||
{
|
||||
std::memset(&context.lightDirection[0], 0, sizeof(context.lightDirection[0]));
|
||||
std::memset(&context.lightColour[0], 0, sizeof(context.lightColour[0]));
|
||||
std::memset(&c.lightDirection[0], 0, sizeof(c.lightDirection[0]));
|
||||
std::memset(&c.lightColour[0], 0, sizeof(c.lightColour[0]));
|
||||
}
|
||||
|
||||
if (!context.lightEnabled[1])
|
||||
if (!c.lightEnabled[1])
|
||||
{
|
||||
std::memset(&context.lightDirection[1], 0, sizeof(context.lightDirection[1]));
|
||||
std::memset(&context.lightColour[1], 0, sizeof(context.lightColour[1]));
|
||||
std::memset(&c.lightDirection[1], 0, sizeof(c.lightDirection[1]));
|
||||
std::memset(&c.lightColour[1], 0, sizeof(c.lightColour[1]));
|
||||
}
|
||||
|
||||
const std::size_t lightingBytes = sizeof(context.lightDirection) + sizeof(context.lightColour) + sizeof(context.lightAmbientColour);
|
||||
const std::size_t lightingBytes = sizeof(c.lightDirection) + sizeof(c.lightColour) + sizeof(c.lightAmbientColour);
|
||||
D3D11_MAPPED_SUBRESOURCE mapped = {};
|
||||
context.m_pDeviceContext->Map(context.cbLighting, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, context.lightDirection, lightingBytes);
|
||||
context.m_pDeviceContext->Unmap(context.cbLighting, 0);
|
||||
c.m_pDeviceContext->Map(c.cbLighting, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
|
||||
std::memcpy(mapped.pData, c.lightDirection, lightingBytes);
|
||||
c.m_pDeviceContext->Unmap(c.cbLighting, 0);
|
||||
|
||||
context.lightingDirty = 0;
|
||||
c.lightingDirty = 0;
|
||||
}
|
||||
|
||||
void Renderer::StateSetLightDirection(int light, float x, float y, float z)
|
||||
@@ -481,21 +481,21 @@ void Renderer::StateSetLightDirection(int light, float x, float y, float z)
|
||||
return;
|
||||
}
|
||||
|
||||
Context &context = this->getContext();
|
||||
if (context.commandBuffer != nullptr && context.commandBuffer->isActive != 0)
|
||||
Context &c = this->getContext();
|
||||
if (c.commandBuffer != nullptr && c.commandBuffer->isActive != 0)
|
||||
{
|
||||
context.commandBuffer->SetLightDirection(light, x, y, z);
|
||||
c.commandBuffer->SetLightDirection(light, x, y, z);
|
||||
return;
|
||||
}
|
||||
|
||||
const std::uint32_t stackIndex = context.matrixStackDepth[0];
|
||||
const DirectX::XMMATRIX &modelView = context.matrixStacks[0][stackIndex];
|
||||
const std::uint32_t stackIndex = c.stackPos[MATRIX_MODE_MODELVIEW];
|
||||
const DirectX::XMMATRIX &modelView = c.matrixStacks[MATRIX_MODE_MODELVIEW][stackIndex];
|
||||
const DirectX::XMVECTOR direction = DirectX::XMVectorSet(x, y, z, 0.0f);
|
||||
const DirectX::XMVECTOR transformed = DirectX::XMVector3TransformNormal(direction, modelView);
|
||||
const DirectX::XMVECTOR normalized = DirectX::XMVector3Normalize(transformed);
|
||||
|
||||
DirectX::XMStoreFloat4(&context.lightDirection[light], normalized);
|
||||
context.lightingDirty = 1;
|
||||
DirectX::XMStoreFloat4(&c.lightDirection[light], normalized);
|
||||
c.lightingDirty = 1;
|
||||
}
|
||||
|
||||
void Renderer::StateSetViewport(C4JRender::eViewportType viewportType)
|
||||
@@ -569,14 +569,14 @@ void Renderer::StateSetEnableViewportClipPlanes(bool) {}
|
||||
|
||||
void Renderer::StateSetTexGenCol(int col, float x, float y, float z, float w, bool eyeSpace)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
Context &c = this->getContext();
|
||||
|
||||
DirectX::XMVECTOR plane = DirectX::XMVectorSet(x, y, z, w);
|
||||
if (eyeSpace)
|
||||
{
|
||||
DirectX::XMFLOAT4X4 modelView;
|
||||
std::memset(&modelView, 0, sizeof(modelView));
|
||||
std::memcpy(&modelView, this->MatrixGet(0), sizeof(modelView));
|
||||
std::memcpy(&modelView, this->MatrixGet(MATRIX_MODE_MODELVIEW), sizeof(modelView));
|
||||
|
||||
DirectX::XMVECTOR determinant = DirectX::XMVectorZero();
|
||||
const DirectX::XMMATRIX inverse = DirectX::XMMatrixInverse(&determinant, DirectX::XMLoadFloat4x4(&modelView));
|
||||
@@ -589,13 +589,13 @@ void Renderer::StateSetTexGenCol(int col, float x, float y, float z, float w, bo
|
||||
const int activeSet = eyeSpace ? 0 : 1;
|
||||
const int inactiveSet = eyeSpace ? 1 : 0;
|
||||
|
||||
float *active = reinterpret_cast<float *>(&context.texGenMatrices[activeSet]);
|
||||
float *active = reinterpret_cast<float *>(&c.texGenMatrices[activeSet]);
|
||||
active[col + 0] = transformed.x;
|
||||
active[col + 4] = transformed.y;
|
||||
active[col + 8] = transformed.z;
|
||||
active[col + 12] = transformed.w;
|
||||
|
||||
float *inactive = reinterpret_cast<float *>(&context.texGenMatrices[inactiveSet]);
|
||||
float *inactive = reinterpret_cast<float *>(&c.texGenMatrices[inactiveSet]);
|
||||
inactive[col + 0] = 0.0f;
|
||||
inactive[col + 4] = 0.0f;
|
||||
inactive[col + 8] = 0.0f;
|
||||
@@ -604,9 +604,9 @@ void Renderer::StateSetTexGenCol(int col, float x, float y, float z, float w, bo
|
||||
|
||||
void Renderer::StateSetStencil(D3D11_COMPARISON_FUNC function, uint8_t stencil_ref, uint8_t stencil_func_mask, uint8_t stencil_write_mask)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
Context &c = this->getContext();
|
||||
|
||||
D3D11_DEPTH_STENCIL_DESC desc = context.depthStencilDesc;
|
||||
D3D11_DEPTH_STENCIL_DESC desc = c.depthStencilDesc;
|
||||
desc.StencilEnable = TRUE;
|
||||
desc.StencilReadMask = stencil_func_mask;
|
||||
desc.StencilWriteMask = stencil_write_mask;
|
||||
@@ -624,15 +624,15 @@ void Renderer::StateSetStencil(D3D11_COMPARISON_FUNC function, uint8_t stencil_r
|
||||
|
||||
void Renderer::StateSetForceLOD(int LOD)
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
context.forcedLOD = LOD;
|
||||
Context &c = this->getContext();
|
||||
c.forcedLOD = LOD;
|
||||
}
|
||||
|
||||
void Renderer::StateUpdate()
|
||||
{
|
||||
Context &context = this->getContext();
|
||||
this->StateSetFaceCull(context.faceCullEnabled != 0);
|
||||
this->StateSetDepthMask(context.depthWriteEnabled != 0);
|
||||
this->StateSetDepthTestEnable(context.depthTestEnabled != 0);
|
||||
this->StateSetAlphaTestEnable(context.alphaTestEnabled != 0);
|
||||
Context &c = this->getContext();
|
||||
this->StateSetFaceCull(c.faceCullEnabled != 0);
|
||||
this->StateSetDepthMask(c.depthWriteEnabled != 0);
|
||||
this->StateSetDepthTestEnable(c.depthTestEnabled != 0);
|
||||
this->StateSetAlphaTestEnable(c.alphaTestEnabled != 0);
|
||||
}
|
||||
|
||||
@@ -13,37 +13,42 @@ DXGI_FORMAT Renderer::textureFormats[C4JRender::MAX_TEXTURE_FORMATS] = {
|
||||
|
||||
int Renderer::TextureCreate()
|
||||
{
|
||||
for (int i = 0; i < 512; ++i)
|
||||
int i = 0;
|
||||
for (; ; i++)
|
||||
{
|
||||
Texture &texture = m_textures[i];
|
||||
if (!texture.allocated)
|
||||
assert(i < 512);
|
||||
|
||||
if (!m_textures[i].allocated)
|
||||
{
|
||||
texture.texture = nullptr;
|
||||
texture.allocated = true;
|
||||
texture.mipLevels = 1;
|
||||
texture.samplerParams = 0;
|
||||
return i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
m_textures[i].texture = nullptr;
|
||||
m_textures[i].allocated = true;
|
||||
m_textures[i].mipLevels = 1;
|
||||
m_textures[i].samplerParams = 0;
|
||||
return i;
|
||||
}
|
||||
|
||||
void Renderer::TextureSetTextureLevels(int levels)
|
||||
{
|
||||
const int boundTextureIndex = this->getContext().boundTextureIndex;
|
||||
m_textures[boundTextureIndex].mipLevels = levels;
|
||||
const int textureIdx = this->getContext().textureIdx;
|
||||
|
||||
assert(levels <= MAX_MIP_LEVELS);
|
||||
|
||||
m_textures[textureIdx].mipLevels = levels;
|
||||
}
|
||||
|
||||
int Renderer::TextureGetTextureLevels()
|
||||
{
|
||||
const int boundTextureIndex = this->getContext().boundTextureIndex;
|
||||
return m_textures[boundTextureIndex].mipLevels;
|
||||
const int textureIdx = this->getContext().textureIdx;
|
||||
return m_textures[textureIdx].mipLevels;
|
||||
}
|
||||
|
||||
void Renderer::TextureSetParam(int param, int value)
|
||||
{
|
||||
Texture &texture = m_textures[this->getContext().boundTextureIndex];
|
||||
Texture &texture = m_textures[this->getContext().textureIdx];
|
||||
|
||||
switch (param)
|
||||
{
|
||||
@@ -87,8 +92,12 @@ void Renderer::TextureDynamicUpdateEnd() {}
|
||||
|
||||
void Renderer::TextureData(int width, int height, void *data, int level, C4JRender::eTextureFormat format)
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
Texture &texture = m_textures[context.boundTextureIndex];
|
||||
Renderer::Context &c = this->getContext();
|
||||
|
||||
assert(m_textures[c.textureIdx].allocated);
|
||||
assert((level > 0) || (m_textures[c.textureIdx].texture == NULL));
|
||||
|
||||
Texture &texture = m_textures[c.textureIdx];
|
||||
texture.textureFormat = format;
|
||||
|
||||
if (level == 0)
|
||||
@@ -102,19 +111,24 @@ void Renderer::TextureData(int width, int height, void *data, int level, C4JRend
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
m_pDevice->CreateTexture2D(&desc, nullptr, &texture.texture);
|
||||
m_pDevice->CreateShaderResourceView(texture.texture, nullptr, &texture.view);
|
||||
|
||||
HRESULT hr = 0;
|
||||
hr = m_pDevice->CreateTexture2D(&desc, nullptr, &texture.texture);
|
||||
assert(hr >= 0);
|
||||
|
||||
hr = m_pDevice->CreateShaderResourceView(texture.texture, nullptr, &texture.view);
|
||||
assert(hr >= 0);
|
||||
}
|
||||
|
||||
const UINT rowPitch = width * 4u;
|
||||
const UINT depthPitch = width * height * 4u;
|
||||
context.m_pDeviceContext->UpdateSubresource(texture.texture, level, nullptr, data, rowPitch, depthPitch);
|
||||
c.m_pDeviceContext->UpdateSubresource(texture.texture, level, nullptr, data, rowPitch, depthPitch);
|
||||
}
|
||||
|
||||
void Renderer::TextureDataUpdate(int xoffset, int yoffset, int width, int height, void *data, int level)
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
Texture &texture = m_textures[context.boundTextureIndex];
|
||||
Renderer::Context &c = this->getContext();
|
||||
Texture &texture = m_textures[c.textureIdx];
|
||||
|
||||
D3D11_BOX box = {};
|
||||
box.left = xoffset;
|
||||
@@ -129,7 +143,7 @@ void Renderer::TextureDataUpdate(int xoffset, int yoffset, int width, int height
|
||||
|
||||
const UINT rowPitch = width * 4u;
|
||||
const UINT depthPitch = width * height * 4u;
|
||||
context.m_pDeviceContext->UpdateSubresource(texture.texture, level, &box, data, rowPitch, depthPitch);
|
||||
c.m_pDeviceContext->UpdateSubresource(texture.texture, level, &box, data, rowPitch, depthPitch);
|
||||
}
|
||||
|
||||
void Renderer::TextureFree(int idx)
|
||||
@@ -168,16 +182,16 @@ void Renderer::TextureBind(int idx)
|
||||
textureIndex = defaultTextureIndex;
|
||||
}
|
||||
|
||||
Renderer::Context &context = this->getContext();
|
||||
Renderer::Context &c = this->getContext();
|
||||
|
||||
if (context.commandBuffer && context.commandBuffer->isActive)
|
||||
if (c.commandBuffer && c.commandBuffer->isActive)
|
||||
{
|
||||
context.commandBuffer->BindTexture(textureIndex);
|
||||
c.commandBuffer->BindTexture(textureIndex);
|
||||
}
|
||||
|
||||
context.boundTextureIndex = textureIndex;
|
||||
c.textureIdx = textureIndex;
|
||||
ID3D11ShaderResourceView *const view = m_textures[textureIndex].view;
|
||||
context.m_pDeviceContext->PSSetShaderResources(0, 1, &view);
|
||||
c.m_pDeviceContext->PSSetShaderResources(0, 1, &view);
|
||||
this->UpdateTextureState(false);
|
||||
}
|
||||
|
||||
@@ -189,26 +203,26 @@ void Renderer::TextureBindVertex(int idx)
|
||||
textureIndex = defaultTextureIndex;
|
||||
}
|
||||
|
||||
Renderer::Context &context = this->getContext();
|
||||
context.boundTextureIndex = textureIndex;
|
||||
Renderer::Context &c = this->getContext();
|
||||
c.textureIdx = textureIndex;
|
||||
|
||||
ID3D11ShaderResourceView *const view = m_textures[textureIndex].view;
|
||||
context.m_pDeviceContext->VSSetShaderResources(0, 1, &view);
|
||||
c.m_pDeviceContext->VSSetShaderResources(0, 1, &view);
|
||||
this->UpdateTextureState(true);
|
||||
}
|
||||
|
||||
void Renderer::UpdateTextureState(bool vertexSampler)
|
||||
{
|
||||
Renderer::Context &context = this->getContext();
|
||||
Renderer::Context &c = this->getContext();
|
||||
ID3D11SamplerState *sampler = this->GetManagedSamplerState();
|
||||
|
||||
if (vertexSampler)
|
||||
{
|
||||
context.m_pDeviceContext->VSSetSamplers(0, 1, &sampler);
|
||||
c.m_pDeviceContext->VSSetSamplers(0, 1, &sampler);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.m_pDeviceContext->PSSetSamplers(0, 1, &sampler);
|
||||
c.m_pDeviceContext->PSSetSamplers(0, 1, &sampler);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ void main(
|
||||
|
||||
*/
|
||||
|
||||
static unsigned char VS_Compressed_Data[] =
|
||||
static unsigned char g_main_VS_Compressed[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0x1F, 0x76, 0x17, 0xC2, 0xF2, 0x5A,
|
||||
0x47, 0x81, 0x55, 0xD3, 0x6E, 0xD1, 0x0A, 0xB0, 0xBF, 0x4A,
|
||||
|
||||
@@ -35,7 +35,7 @@ void main(
|
||||
|
||||
*/
|
||||
|
||||
static unsigned char VS_PF3_TF2_CB4_NB4_XW1_Data[] =
|
||||
static unsigned char g_main_VS_PF3_TF2_CB4_NB4_XW1[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0x83, 0x66, 0x28, 0xAB, 0x3F, 0xFA,
|
||||
0xEB, 0x49, 0x6F, 0xE0, 0x81, 0x37, 0x2A, 0x0E, 0x62, 0x6E,
|
||||
|
||||
@@ -43,7 +43,7 @@ void main(
|
||||
|
||||
*/
|
||||
|
||||
static unsigned char VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data[] =
|
||||
static unsigned char g_main_VS_PF3_TF2_CB4_NB4_XW1_LIGHTING[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0x94, 0x85, 0x62, 0xA8, 0x82, 0x54,
|
||||
0xB8, 0xE6, 0x16, 0x24, 0x6D, 0x3A, 0xB4, 0x0D, 0x4A, 0x7C,
|
||||
|
||||
@@ -36,7 +36,7 @@ void main(
|
||||
|
||||
*/
|
||||
|
||||
static unsigned char VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data[] =
|
||||
static unsigned char g_main_VS_PF3_TF2_CB4_NB4_XW1_TEXGEN[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0xD7, 0x13, 0x1B, 0xCA, 0xDF, 0xE8,
|
||||
0xA9, 0xCC, 0xDA, 0x19, 0x1B, 0x6D, 0x0C, 0x53, 0xED, 0xEE,
|
||||
|
||||
@@ -13,7 +13,7 @@ void main(
|
||||
}
|
||||
|
||||
*/
|
||||
static unsigned char VS_ScreenClear_Data[] =
|
||||
static unsigned char g_main_VS_ScreenClear[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0xFB, 0x82, 0xC7, 0xF7, 0x5E, 0x97,
|
||||
0x42, 0x30, 0xDA, 0xAE, 0x62, 0x79, 0x54, 0x21, 0x37, 0xA2,
|
||||
|
||||
@@ -21,7 +21,7 @@ void main(
|
||||
|
||||
*/
|
||||
|
||||
static unsigned char VS_ScreenSpace_Data[] =
|
||||
static unsigned char g_main_VS_ScreenSpace[] =
|
||||
{
|
||||
0x44, 0x58, 0x42, 0x43, 0xB6, 0x90, 0x0F, 0x5D, 0x1E, 0x08,
|
||||
0xBC, 0x0E, 0xCD, 0x1F, 0xED, 0xD0, 0xAE, 0x45, 0x7E, 0xDA,
|
||||
|
||||
Reference in New Issue
Block a user