2020-05-27 09:21:20 +02:00
|
|
|
#include "framework.h"
|
2019-01-13 21:57:16 +01:00
|
|
|
#include "Renderer11.h"
|
2020-05-27 09:21:20 +02:00
|
|
|
#include "input.h"
|
|
|
|
#include "winmain.h"
|
|
|
|
#include "level.h"
|
|
|
|
#include "configuration.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "health.h"
|
|
|
|
#include "pickup.h"
|
|
|
|
#include "inventory.h"
|
|
|
|
#include "gameflow.h"
|
|
|
|
#include "Lara.h"
|
|
|
|
#include "effect2.h"
|
|
|
|
#include "rope.h"
|
|
|
|
#include "camera.h"
|
|
|
|
#include "tomb4fx.h"
|
|
|
|
#include "trmath.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "footprint.h"
|
2020-05-30 15:55:23 +02:00
|
|
|
#include "setup.h"
|
2020-06-16 15:11:30 +02:00
|
|
|
#include "Utils.h"
|
|
|
|
#include "VertexBuffer.h"
|
2020-06-21 14:27:12 +02:00
|
|
|
namespace T5M::Renderer {
|
|
|
|
using namespace T5M::Renderer::Utils;
|
|
|
|
using std::array;
|
|
|
|
Renderer11 g_Renderer;
|
|
|
|
Renderer11::Renderer11() {
|
|
|
|
initialiseHairRemaps();
|
|
|
|
|
|
|
|
m_blinkColorDirection = 1;
|
|
|
|
}
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
Renderer11::~Renderer11() {
|
|
|
|
FreeRendererData();
|
|
|
|
|
|
|
|
DX11_RELEASE(m_backBufferRTV);
|
|
|
|
DX11_RELEASE(m_backBufferTexture);
|
|
|
|
DX11_RELEASE(m_depthStencilState);
|
|
|
|
DX11_RELEASE(m_depthStencilTexture);
|
|
|
|
DX11_RELEASE(m_depthStencilView);
|
|
|
|
|
|
|
|
DX11_DELETE(m_primitiveBatch);
|
|
|
|
DX11_DELETE(m_spriteBatch);
|
|
|
|
DX11_DELETE(m_gameFont);
|
|
|
|
DX11_DELETE(m_states);
|
|
|
|
|
|
|
|
DX11_RELEASE(m_vsRooms);
|
|
|
|
DX11_RELEASE(m_psRooms);
|
|
|
|
DX11_RELEASE(m_vsItems);
|
|
|
|
DX11_RELEASE(m_psItems);
|
|
|
|
DX11_RELEASE(m_vsStatics);
|
|
|
|
DX11_RELEASE(m_psStatics);
|
|
|
|
DX11_RELEASE(m_vsHairs);
|
|
|
|
DX11_RELEASE(m_psHairs);
|
|
|
|
DX11_RELEASE(m_vsSky);
|
|
|
|
DX11_RELEASE(m_psSky);
|
|
|
|
DX11_RELEASE(m_vsSprites);
|
|
|
|
DX11_RELEASE(m_psSprites);
|
|
|
|
DX11_RELEASE(m_vsSolid);
|
|
|
|
DX11_RELEASE(m_psSolid);
|
|
|
|
DX11_RELEASE(m_vsInventory);
|
|
|
|
DX11_RELEASE(m_psInventory);
|
|
|
|
DX11_RELEASE(m_vsFullScreenQuad);
|
|
|
|
DX11_RELEASE(m_psFullScreenQuad);
|
|
|
|
DX11_RELEASE(m_cbCameraMatrices);
|
|
|
|
DX11_RELEASE(m_cbItem);
|
|
|
|
DX11_RELEASE(m_cbStatic);
|
|
|
|
DX11_RELEASE(m_cbLights);
|
|
|
|
DX11_RELEASE(m_cbMisc);
|
|
|
|
|
|
|
|
DX11_RELEASE(m_swapChain);
|
|
|
|
DX11_RELEASE(m_context);
|
|
|
|
DX11_RELEASE(m_device);
|
|
|
|
}
|
2019-03-24 10:08:54 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
void Renderer11::FreeRendererData() {
|
|
|
|
m_meshPointersToMesh.clear();
|
2019-03-15 23:03:54 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
for (int i = 0; i < ID_NUMBER_OBJECTS; i++)
|
|
|
|
DX11_DELETE(m_moveableObjects[i]);
|
|
|
|
free(m_moveableObjects);
|
2019-03-24 10:08:54 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
for (int i = 0; i < g_NumSprites; i++)
|
|
|
|
DX11_DELETE(m_sprites[i]);
|
|
|
|
free(m_sprites);
|
2019-03-15 23:03:54 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
for (int i = 0; i < MAX_STATICS; i++)
|
|
|
|
DX11_DELETE(m_staticObjects[i]);
|
|
|
|
free(m_staticObjects);
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
m_rooms.clear();
|
|
|
|
m_roomTextures.clear();
|
|
|
|
m_moveablesTextures.clear();
|
|
|
|
m_staticsTextures.clear();
|
|
|
|
m_spritesTextures.clear();
|
|
|
|
}
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
void Renderer11::clearSceneItems() {
|
|
|
|
m_roomsToDraw.clear();
|
|
|
|
m_itemsToDraw.clear();
|
|
|
|
m_effectsToDraw.clear();
|
|
|
|
m_lightsToDraw.clear();
|
|
|
|
m_staticsToDraw.clear();
|
|
|
|
m_spritesToDraw.clear();
|
|
|
|
m_lines3DToDraw.clear();
|
|
|
|
m_lines2DToDraw.clear();
|
2019-02-10 09:15:02 +01:00
|
|
|
}
|
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
int Renderer11::SyncRenderer() {
|
|
|
|
// Sync the renderer
|
|
|
|
int nf = Sync();
|
|
|
|
if (nf < 2) {
|
|
|
|
int i = 2 - nf;
|
|
|
|
nf = 2;
|
|
|
|
do {
|
|
|
|
while (!Sync());
|
|
|
|
i--;
|
|
|
|
} while (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
GnFrameCounter++;
|
|
|
|
return nf;
|
|
|
|
}
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3D11VertexShader* Renderer11::compileVertexShader(const wchar_t* fileName, const char* function, const char* model, ID3D10Blob** bytecode) {
|
|
|
|
HRESULT res;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
*bytecode = NULL;
|
|
|
|
ID3DBlob* errors = NULL;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
printf("Compiling vertex shader: %s\n", fileName);
|
|
|
|
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
|
|
|
|
res = D3DCompileFromFile(fileName, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, function, model, flags, 0, bytecode, &errors);
|
|
|
|
throwIfFailed(res);
|
2020-06-16 15:11:30 +02:00
|
|
|
|
2019-05-02 21:19:24 +02:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3D11VertexShader* shader = NULL;
|
|
|
|
res = m_device->CreateVertexShader((*bytecode)->GetBufferPointer(), (*bytecode)->GetBufferSize(), NULL, &shader);
|
|
|
|
throwIfFailed(res);
|
2020-01-03 06:48:15 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
return shader;
|
|
|
|
}
|
2020-01-03 06:48:15 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3D11PixelShader* Renderer11::compilePixelShader(const wchar_t* fileName, const char* function, const char* model, ID3D10Blob** bytecode) {
|
|
|
|
HRESULT res;
|
2020-01-03 06:48:15 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
*bytecode = NULL;
|
|
|
|
ID3DBlob* errors = NULL;
|
2020-01-03 06:48:15 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
printf("Compiling pixel shader: %s\n", fileName);
|
|
|
|
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
|
|
|
|
throwIfFailed(D3DCompileFromFile(fileName, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, function, model, flags, 0, bytecode, &errors));
|
2019-05-03 20:58:36 +02:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3D11PixelShader* shader = NULL;
|
|
|
|
throwIfFailed(m_device->CreatePixelShader((*bytecode)->GetBufferPointer(), (*bytecode)->GetBufferSize(), NULL, &shader));
|
|
|
|
return shader;
|
|
|
|
}
|
2019-05-02 21:19:24 +02:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3D11GeometryShader* Renderer11::compileGeometryShader(const wchar_t* fileName) {
|
|
|
|
HRESULT res;
|
2019-05-02 21:19:24 +02:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3DBlob* bytecode = NULL;
|
|
|
|
ID3DBlob* errors = NULL;
|
2019-01-23 07:31:56 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
res = D3DCompileFromFile(fileName, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, NULL, "gs_4_0", D3D10_SHADER_OPTIMIZATION_LEVEL3, 0, &bytecode, &errors);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3D11GeometryShader* shader = NULL;
|
|
|
|
res = m_device->CreateGeometryShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), NULL, &shader);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
2019-03-15 23:03:54 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
return shader;
|
|
|
|
}
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3D11ComputeShader* Renderer11::compileComputeShader(const wchar_t* fileName) {
|
|
|
|
HRESULT res;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3DBlob* bytecode = NULL;
|
|
|
|
ID3DBlob* errors = NULL;
|
2019-05-31 21:45:13 +02:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
res = D3DCompileFromFile(fileName, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, NULL, "gs_4_0", D3D10_SHADER_OPTIMIZATION_LEVEL3, 0, &bytecode, &errors);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3D11ComputeShader* shader = NULL;
|
|
|
|
res = m_device->CreateComputeShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), NULL, &shader);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
2019-01-28 21:51:51 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
return shader;
|
|
|
|
}
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
void Renderer11::UpdateProgress(float value) {
|
|
|
|
m_progress = value;
|
|
|
|
}
|
2019-01-16 20:54:45 +01:00
|
|
|
|
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
ID3D11Buffer* Renderer11::createConstantBuffer(size_t size) {
|
|
|
|
ID3D11Buffer* buffer;
|
2019-02-02 07:59:44 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
D3D11_BUFFER_DESC desc;
|
|
|
|
ZeroMemory(&desc, sizeof(D3D11_BUFFER_DESC));
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
desc.ByteWidth = size; // Constant buffer must have a size multiple of 16 bytes
|
|
|
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
|
|
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
2019-02-09 09:35:20 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
HRESULT res = m_device->CreateBuffer(&desc, NULL, &buffer);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2020-06-21 14:27:12 +02:00
|
|
|
return buffer;
|
2020-01-12 23:10:38 +01:00
|
|
|
}
|
2020-06-21 14:27:12 +02:00
|
|
|
|
|
|
|
RendererHUDBar::RendererHUDBar(ID3D11Device* m_device, int x, int y, int w, int h, int borderSize, array<Vector4, 9> colors) {
|
|
|
|
array<Vector3, 9> barVertices = {
|
|
|
|
Vector3(x, HUD_ZERO_Y + y, 0.5),
|
|
|
|
Vector3(x + (w / 2.0f), HUD_ZERO_Y + y, 0.5),
|
|
|
|
Vector3(x + w, HUD_ZERO_Y + y, 0.5),
|
|
|
|
Vector3(x, HUD_ZERO_Y + (y + h / 2.0f), 0.5),
|
|
|
|
Vector3(x + (w / 2.0f), HUD_ZERO_Y + (y + h / 2.0f), 0.5),
|
|
|
|
Vector3(x + w, HUD_ZERO_Y + (y + h / 2.0f), 0.5),
|
|
|
|
Vector3(x, HUD_ZERO_Y + y + h, 0.5),
|
|
|
|
Vector3(x + (w / 2.0f), HUD_ZERO_Y + y + h, 0.5),
|
|
|
|
Vector3(x + w, HUD_ZERO_Y + y + h, 0.5),
|
|
|
|
|
|
|
|
};
|
|
|
|
const float HUD_BORDER_WIDTH = borderSize * (REFERENCE_RES_WIDTH / REFERENCE_RES_HEIGHT);
|
|
|
|
const float HUD_BORDER_HEIGT = borderSize;
|
|
|
|
array<Vector3, 16> barBorderVertices = {
|
|
|
|
//top left
|
|
|
|
Vector3(x - HUD_BORDER_WIDTH ,HUD_ZERO_Y + y - HUD_BORDER_HEIGT,0),
|
|
|
|
Vector3(x ,HUD_ZERO_Y + y - HUD_BORDER_HEIGT,0),
|
|
|
|
Vector3(x ,HUD_ZERO_Y + y,0),
|
|
|
|
Vector3(x - HUD_BORDER_WIDTH ,HUD_ZERO_Y + y,0),
|
|
|
|
//top right
|
|
|
|
Vector3(x + w ,HUD_ZERO_Y + y - HUD_BORDER_HEIGT,0),
|
|
|
|
Vector3(x + w + HUD_BORDER_WIDTH,HUD_ZERO_Y + y - HUD_BORDER_HEIGT,0),
|
|
|
|
Vector3(x + w + HUD_BORDER_WIDTH,HUD_ZERO_Y + y,0),
|
|
|
|
Vector3(x + w ,HUD_ZERO_Y + y,0),
|
|
|
|
//bottom right
|
|
|
|
Vector3(x + w ,HUD_ZERO_Y + y + h,0),
|
|
|
|
Vector3(x + w + HUD_BORDER_WIDTH,HUD_ZERO_Y + y + h,0),
|
|
|
|
Vector3(x + w + HUD_BORDER_WIDTH,HUD_ZERO_Y + y + h + HUD_BORDER_HEIGT,0),
|
|
|
|
Vector3(x + w ,HUD_ZERO_Y + y + h + HUD_BORDER_HEIGT,0),
|
|
|
|
//bottom left
|
|
|
|
Vector3(x - HUD_BORDER_WIDTH ,HUD_ZERO_Y + y + h,0),
|
|
|
|
Vector3(x ,HUD_ZERO_Y + y + h,0),
|
|
|
|
Vector3(x ,HUD_ZERO_Y + y + h + HUD_BORDER_HEIGT,0),
|
|
|
|
Vector3(x - HUD_BORDER_WIDTH ,HUD_ZERO_Y + y + h + HUD_BORDER_HEIGT,0)
|
|
|
|
};
|
|
|
|
|
|
|
|
array<Vector2, 9> barUVs = {
|
|
|
|
Vector2(0,0),
|
|
|
|
Vector2(0.5,0),
|
|
|
|
Vector2(1,0),
|
|
|
|
Vector2(0,0.5),
|
|
|
|
Vector2(0.5,0.5),
|
|
|
|
Vector2(1,0.5),
|
|
|
|
Vector2(0,1),
|
|
|
|
Vector2(0.5,1),
|
|
|
|
Vector2(1,1),
|
|
|
|
};
|
|
|
|
array<Vector2, 16> barBorderUVs = {
|
|
|
|
//top left
|
|
|
|
Vector2(0,0),
|
|
|
|
Vector2(0.25,0),
|
|
|
|
Vector2(0.25,0.25),
|
|
|
|
Vector2(0,0.25),
|
|
|
|
//top right
|
|
|
|
Vector2(0.75,0),
|
|
|
|
Vector2(1,0),
|
|
|
|
Vector2(1,0.25),
|
|
|
|
Vector2(0.75,0.25),
|
|
|
|
//bottom right
|
|
|
|
Vector2(0.75,0.75),
|
|
|
|
Vector2(1,0.75),
|
|
|
|
Vector2(1,1),
|
|
|
|
Vector2(0.75,1),
|
|
|
|
//bottom left
|
|
|
|
Vector2(0,0.75),
|
|
|
|
Vector2(0.25,0.75),
|
|
|
|
Vector2(0.25,1),
|
|
|
|
Vector2(0,1),
|
|
|
|
};
|
|
|
|
|
|
|
|
array<int, 24> barIndices = {
|
|
|
|
0,1,3,1,4,3,
|
|
|
|
//
|
|
|
|
1,2,4,2,5,4,
|
|
|
|
//
|
|
|
|
3,4,6,4,7,6,
|
|
|
|
//
|
|
|
|
4,5,7,5,8,7
|
|
|
|
};
|
|
|
|
array<int, 56> barBorderIndices = {
|
|
|
|
//top left
|
|
|
|
0,1,3,1,2,3,
|
|
|
|
//top center
|
|
|
|
1,4,2,4,7,2,
|
|
|
|
//top right
|
|
|
|
4,5,7,5,6,7,
|
|
|
|
//right
|
|
|
|
7,6,8,6,9,8,
|
|
|
|
//bottom right
|
|
|
|
8,9,11,9,10,11,
|
|
|
|
//bottom
|
|
|
|
13,8,14,8,11,14,
|
|
|
|
//bottom left
|
|
|
|
12,13,15,13,14,15,
|
|
|
|
//left
|
|
|
|
3,2,12,2,13,12,
|
|
|
|
//center
|
|
|
|
2,7,13,7,8,13
|
|
|
|
};
|
|
|
|
array<RendererVertex, 9> vertices;
|
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
|
|
|
|
vertices[i].Position = barVertices[i];
|
|
|
|
vertices[i].Color = colors[i];
|
|
|
|
vertices[i].UV = barUVs[i];
|
|
|
|
vertices[i].Normal = Vector3(0, 0, 0);
|
|
|
|
vertices[i].Bone = 0.0f;
|
|
|
|
}
|
|
|
|
vertexBuffer = VertexBuffer(m_device, vertices.size(), vertices.data());
|
|
|
|
indexBuffer = IndexBuffer(m_device, barIndices.size(), barIndices.data());
|
|
|
|
|
|
|
|
array<RendererVertex, barBorderVertices.size()> verticesBorder;
|
|
|
|
for (int i = 0; i < barBorderVertices.size(); i++) {
|
|
|
|
verticesBorder[i].Position = barBorderVertices[i];
|
|
|
|
verticesBorder[i].Color = Vector4(1, 1, 1, 1);
|
|
|
|
verticesBorder[i].UV = barBorderUVs[i];
|
|
|
|
verticesBorder[i].Normal = Vector3(0, 0, 0);
|
|
|
|
verticesBorder[i].Bone = 0.0f;
|
|
|
|
}
|
|
|
|
vertexBufferBorder = VertexBuffer(m_device, verticesBorder.size(), verticesBorder.data());
|
|
|
|
indexBufferBorder = IndexBuffer(m_device, barBorderIndices.size(), barBorderIndices.data());
|
|
|
|
|
2020-01-12 17:28:04 +01:00
|
|
|
}
|
2020-06-21 14:27:12 +02:00
|
|
|
|
2020-01-12 17:28:04 +01:00
|
|
|
}
|