2019-01-13 21:57:16 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2019-01-16 20:54:45 +01:00
|
|
|
#include <array>
|
2019-01-13 21:57:16 +01:00
|
|
|
#include "Enums.h"
|
|
|
|
|
|
|
|
#include <D3D11.h>
|
|
|
|
|
|
|
|
#include <SimpleMath.h>
|
|
|
|
#include <CommonStates.h>
|
|
|
|
#include <DirectXHelpers.h>
|
|
|
|
#include <Effects.h>
|
|
|
|
#include <GeometricPrimitive.h>
|
|
|
|
#include <PostProcess.h>
|
|
|
|
#include <PrimitiveBatch.h>
|
|
|
|
#include <ScreenGrab.h>
|
|
|
|
#include <SpriteBatch.h>
|
|
|
|
#include <SpriteFont.h>
|
|
|
|
#include <VertexTypes.h>
|
|
|
|
#include <WICTextureLoader.h>
|
|
|
|
|
|
|
|
#include "..\Global\global.h"
|
|
|
|
|
|
|
|
#define PI 3.14159265358979323846f
|
|
|
|
#define RADIAN 0.01745329252f
|
|
|
|
|
|
|
|
#define DX11_RELEASE(x) if (x != NULL) x->Release()
|
2019-03-15 23:03:54 +01:00
|
|
|
#define DX11_DELETE(x) if (x != NULL) { delete x; x = NULL; }
|
2019-01-13 21:57:16 +01:00
|
|
|
|
|
|
|
using namespace DirectX;
|
|
|
|
using namespace DirectX::SimpleMath;
|
|
|
|
using namespace std;
|
|
|
|
|
2019-01-16 20:54:45 +01:00
|
|
|
template <class T>
|
|
|
|
class PreallocatedVector
|
|
|
|
{
|
|
|
|
private:
|
2019-01-21 22:23:32 +01:00
|
|
|
T** m_objects;
|
2019-12-02 09:11:21 +01:00
|
|
|
int m_maxItems;
|
|
|
|
int m_numItems;
|
|
|
|
int m_startSize;
|
2019-01-16 20:54:45 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
PreallocatedVector()
|
|
|
|
{
|
|
|
|
m_objects = NULL;
|
2019-01-21 22:23:32 +01:00
|
|
|
m_maxItems = 0;
|
2019-01-16 20:54:45 +01:00
|
|
|
m_startSize = 0;
|
|
|
|
m_numItems = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
~PreallocatedVector()
|
|
|
|
{
|
2019-03-24 10:08:54 +01:00
|
|
|
free(m_objects);
|
2019-01-16 20:54:45 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
inline void Reserve(int numItems)
|
2019-01-16 20:54:45 +01:00
|
|
|
{
|
2019-01-21 22:23:32 +01:00
|
|
|
m_objects = (T**)malloc(sizeof(T*) * numItems);
|
|
|
|
ZeroMemory(m_objects, sizeof(T*) * m_maxItems);
|
2019-01-16 20:54:45 +01:00
|
|
|
m_maxItems = numItems;
|
|
|
|
m_numItems = 0;
|
|
|
|
m_startSize = numItems;
|
|
|
|
}
|
|
|
|
|
2019-01-21 22:23:32 +01:00
|
|
|
inline void Clear()
|
2019-01-16 20:54:45 +01:00
|
|
|
{
|
|
|
|
m_numItems = 0;
|
2019-01-21 22:23:32 +01:00
|
|
|
ZeroMemory(m_objects, sizeof(T*) * m_maxItems);
|
2019-01-16 20:54:45 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
inline int Size()
|
2019-01-16 20:54:45 +01:00
|
|
|
{
|
2019-01-21 22:23:32 +01:00
|
|
|
return m_numItems;
|
2019-01-16 20:54:45 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
inline void Sort(int(*compareFunc)(T*, T*))
|
2019-01-16 20:54:45 +01:00
|
|
|
{
|
2019-01-21 22:23:32 +01:00
|
|
|
qsort(m_objects, m_numItems, sizeof(T), compareFunc);
|
2019-01-16 20:54:45 +01:00
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
inline T*& operator[] (int x) {
|
2019-06-10 21:42:42 +02:00
|
|
|
if (x >= m_maxItems)
|
|
|
|
return m_objects[0];
|
2019-01-21 22:23:32 +01:00
|
|
|
return m_objects[x];
|
2019-01-16 20:54:45 +01:00
|
|
|
}
|
|
|
|
|
2019-01-21 22:23:32 +01:00
|
|
|
inline void Add(T* value)
|
2019-01-16 20:54:45 +01:00
|
|
|
{
|
2019-06-10 21:42:42 +02:00
|
|
|
if (m_numItems >= m_maxItems)
|
|
|
|
return;
|
2019-01-21 22:23:32 +01:00
|
|
|
m_objects[m_numItems++] = value;
|
2019-01-16 20:54:45 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-24 10:08:54 +01:00
|
|
|
template <class T, class U>
|
|
|
|
class PreallocatedDictionary
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
T** m_keys;
|
|
|
|
U** m_objects;
|
2019-12-02 09:11:21 +01:00
|
|
|
int m_maxItems;
|
|
|
|
int m_numItems;
|
|
|
|
int m_startSize;
|
2019-03-24 10:08:54 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
PreallocatedDictionary()
|
|
|
|
{
|
|
|
|
m_keys = NULL;
|
|
|
|
m_objects = NULL;
|
|
|
|
m_maxItems = 0;
|
|
|
|
m_startSize = 0;
|
|
|
|
m_numItems = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
~PreallocatedDictionary()
|
|
|
|
{
|
|
|
|
free(m_keys);
|
|
|
|
free(m_objects);
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
inline void Reserve(int numItems)
|
2019-03-24 10:08:54 +01:00
|
|
|
{
|
|
|
|
m_keys = (T**)malloc(sizeof(T*) * numItems);
|
|
|
|
m_objects = (U**)malloc(sizeof(U*) * numItems);
|
|
|
|
ZeroMemory(m_keys, sizeof(T*) * m_maxItems);
|
|
|
|
ZeroMemory(m_objects, sizeof(U*) * m_maxItems);
|
|
|
|
m_maxItems = numItems;
|
|
|
|
m_numItems = 0;
|
|
|
|
m_startSize = numItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Clear()
|
|
|
|
{
|
|
|
|
m_numItems = 0;
|
|
|
|
ZeroMemory(m_keys, sizeof(T*) * m_maxItems);
|
|
|
|
ZeroMemory(m_objects, sizeof(T*) * m_maxItems);
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
inline int Size()
|
2019-03-24 10:08:54 +01:00
|
|
|
{
|
|
|
|
return m_numItems;
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
inline T*& operator[] (int x) {
|
2019-03-24 10:08:54 +01:00
|
|
|
return m_objects[x];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool KeyExists(T* key)
|
|
|
|
{
|
2019-12-02 09:11:21 +01:00
|
|
|
for (int i = 0; i < m_numItems; i++)
|
2019-03-24 10:08:54 +01:00
|
|
|
if (m_keys[i] == key)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline U* Get(T* key)
|
|
|
|
{
|
2019-12-02 09:11:21 +01:00
|
|
|
for (int i = 0; i < m_numItems; i++)
|
2019-03-24 10:08:54 +01:00
|
|
|
if (m_keys[i] == key)
|
|
|
|
return m_objects[i];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Add(T* key, U* value)
|
|
|
|
{
|
|
|
|
m_keys[m_numItems] = key;
|
|
|
|
m_objects[m_numItems++] = value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-10 09:15:02 +01:00
|
|
|
struct RendererDisplayMode {
|
2019-12-02 09:11:21 +01:00
|
|
|
int Width;
|
|
|
|
int Height;
|
|
|
|
int RefreshRate;
|
2019-02-10 09:15:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererVideoAdapter {
|
|
|
|
string Name;
|
2019-12-02 09:11:21 +01:00
|
|
|
int Index;
|
2019-02-10 09:15:02 +01:00
|
|
|
vector<RendererDisplayMode> DisplayModes;
|
|
|
|
};
|
|
|
|
|
2019-01-13 21:57:16 +01:00
|
|
|
struct RendererVertex {
|
|
|
|
Vector3 Position;
|
|
|
|
Vector3 Normal;
|
|
|
|
Vector2 UV;
|
|
|
|
Vector4 Color;
|
|
|
|
float Bone;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RenderTarget2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ID3D11RenderTargetView* RenderTargetView;
|
|
|
|
ID3D11ShaderResourceView* ShaderResourceView;
|
|
|
|
ID3D11Texture2D* Texture;
|
2019-01-28 21:51:51 +01:00
|
|
|
ID3D11DepthStencilView* DepthStencilView;
|
|
|
|
ID3D11Texture2D* DepthStencilTexture;
|
2019-01-13 21:57:16 +01:00
|
|
|
bool IsValid = false;
|
|
|
|
|
|
|
|
RenderTarget2D()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
static RenderTarget2D* Create(ID3D11Device* device, int w, int h, DXGI_FORMAT format)
|
2019-01-13 21:57:16 +01:00
|
|
|
{
|
|
|
|
RenderTarget2D* rt = new RenderTarget2D();
|
|
|
|
|
|
|
|
D3D11_TEXTURE2D_DESC desc;
|
|
|
|
desc.Width = w;
|
|
|
|
desc.Height = h;
|
|
|
|
desc.MipLevels = 1;
|
|
|
|
desc.ArraySize = 1;
|
|
|
|
desc.Format = format;
|
|
|
|
desc.SampleDesc.Count = 1;
|
2019-01-28 21:51:51 +01:00
|
|
|
desc.SampleDesc.Quality = 0;
|
2019-01-13 21:57:16 +01:00
|
|
|
desc.Usage = D3D11_USAGE_DEFAULT;
|
|
|
|
desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
|
|
|
|
desc.CPUAccessFlags = 0;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
|
|
|
|
rt->Texture = NULL;
|
|
|
|
HRESULT res = device->CreateTexture2D(&desc, NULL, &rt->Texture);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
D3D11_RENDER_TARGET_VIEW_DESC viewDesc;
|
|
|
|
viewDesc.Format = desc.Format;
|
|
|
|
viewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
|
|
|
viewDesc.Texture2D.MipSlice = 0;
|
|
|
|
|
|
|
|
res = device->CreateRenderTargetView(rt->Texture, &viewDesc, &rt->RenderTargetView);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Setup the description of the shader resource view.
|
|
|
|
D3D11_SHADER_RESOURCE_VIEW_DESC shaderDesc;
|
|
|
|
shaderDesc.Format = desc.Format;
|
|
|
|
shaderDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
|
|
|
shaderDesc.Texture2D.MostDetailedMip = 0;
|
|
|
|
shaderDesc.Texture2D.MipLevels = 1;
|
|
|
|
|
|
|
|
res = device->CreateShaderResourceView(rt->Texture, &shaderDesc, &rt->ShaderResourceView);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
|
|
|
|
2019-01-28 21:51:51 +01:00
|
|
|
D3D11_TEXTURE2D_DESC depthTexDesc;
|
|
|
|
ZeroMemory(&depthTexDesc, sizeof(D3D11_TEXTURE2D_DESC));
|
|
|
|
depthTexDesc.Width = w;
|
|
|
|
depthTexDesc.Height = h;
|
|
|
|
depthTexDesc.MipLevels = 1;
|
|
|
|
depthTexDesc.ArraySize = 1;
|
|
|
|
depthTexDesc.SampleDesc.Count = 1;
|
|
|
|
depthTexDesc.SampleDesc.Quality = 0;
|
|
|
|
depthTexDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
|
|
|
depthTexDesc.Usage = D3D11_USAGE_DEFAULT;
|
|
|
|
depthTexDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
|
|
|
depthTexDesc.CPUAccessFlags = 0;
|
|
|
|
depthTexDesc.MiscFlags = 0;
|
|
|
|
|
|
|
|
rt->DepthStencilTexture = NULL;
|
|
|
|
res = device->CreateTexture2D(&depthTexDesc, NULL, &rt->DepthStencilTexture);
|
|
|
|
if (FAILED(res))
|
2019-12-14 22:41:38 +01:00
|
|
|
return NULL;
|
2019-01-28 21:51:51 +01:00
|
|
|
|
|
|
|
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
|
|
|
|
ZeroMemory(&dsvDesc, sizeof(D3D11_DEPTH_STENCIL_VIEW_DESC));
|
|
|
|
dsvDesc.Format = depthTexDesc.Format;
|
|
|
|
dsvDesc.Flags = 0;
|
|
|
|
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
|
|
|
dsvDesc.Texture2D.MipSlice = 0;
|
|
|
|
|
|
|
|
rt->DepthStencilView = NULL;
|
|
|
|
res = device->CreateDepthStencilView(rt->DepthStencilTexture, &dsvDesc, &rt->DepthStencilView);
|
|
|
|
if (FAILED(res))
|
2019-12-14 22:41:38 +01:00
|
|
|
return NULL;
|
2019-01-28 21:51:51 +01:00
|
|
|
|
2019-01-13 21:57:16 +01:00
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
|
|
|
|
~RenderTarget2D()
|
|
|
|
{
|
|
|
|
DX11_RELEASE(RenderTargetView);
|
|
|
|
DX11_RELEASE(ShaderResourceView);
|
|
|
|
DX11_RELEASE(Texture);
|
2019-01-28 21:51:51 +01:00
|
|
|
DX11_RELEASE(DepthStencilView);
|
|
|
|
DX11_RELEASE(DepthStencilTexture);
|
2019-01-13 21:57:16 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Texture2D
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ID3D11ShaderResourceView* ShaderResourceView;
|
|
|
|
ID3D11Texture2D* Texture;
|
|
|
|
|
|
|
|
Texture2D()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~Texture2D()
|
|
|
|
{
|
|
|
|
DX11_RELEASE(ShaderResourceView);
|
|
|
|
DX11_RELEASE(Texture);
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
static Texture2D* LoadFromByteArray(ID3D11Device* device, int w, int h, byte* data)
|
2019-01-13 21:57:16 +01:00
|
|
|
{
|
|
|
|
Texture2D* texture = new Texture2D();
|
|
|
|
|
|
|
|
D3D11_TEXTURE2D_DESC desc;
|
|
|
|
desc.Width = w;
|
|
|
|
desc.Height = h;
|
|
|
|
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
desc.MipLevels = 1;
|
|
|
|
desc.ArraySize = 1;
|
|
|
|
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
|
desc.SampleDesc.Quality = 0;
|
|
|
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
|
|
|
|
|
|
D3D11_SUBRESOURCE_DATA subresourceData;
|
|
|
|
subresourceData.pSysMem = data;
|
|
|
|
subresourceData.SysMemPitch = w * 4;
|
|
|
|
subresourceData.SysMemSlicePitch = 0;
|
|
|
|
|
|
|
|
HRESULT res = device->CreateTexture2D(&desc, &subresourceData, &texture->Texture);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
D3D11_SHADER_RESOURCE_VIEW_DESC shaderDesc;
|
|
|
|
shaderDesc.Format = desc.Format;
|
|
|
|
shaderDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
|
|
|
shaderDesc.Texture2D.MostDetailedMip = 0;
|
|
|
|
shaderDesc.Texture2D.MipLevels = 1;
|
|
|
|
|
|
|
|
res = device->CreateShaderResourceView(texture->Texture, &shaderDesc, &texture->ShaderResourceView);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2019-12-14 22:41:38 +01:00
|
|
|
static Texture2D* LoadFromFile(ID3D11Device* device, const char* fileName)
|
2019-01-13 21:57:16 +01:00
|
|
|
{
|
|
|
|
Texture2D* texture = new Texture2D();
|
|
|
|
|
|
|
|
wchar_t buffer[255];
|
|
|
|
size_t converted = 0;
|
|
|
|
mbstowcs_s(&converted, buffer, fileName, strlen(fileName));
|
|
|
|
|
|
|
|
ID3D11Resource* resource = NULL;
|
|
|
|
ID3D11DeviceContext* context = NULL;
|
|
|
|
device->GetImmediateContext(&context);
|
|
|
|
|
2019-01-16 20:54:45 +01:00
|
|
|
HRESULT res = CreateWICTextureFromFile(device, context, &buffer[0], &resource, &texture->ShaderResourceView, (size_t)0);
|
2019-01-13 21:57:16 +01:00
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
resource->QueryInterface(IID_ID3D11Texture2D, (void **)&texture->Texture);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class VertexBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ID3D11Buffer* Buffer;
|
|
|
|
|
|
|
|
VertexBuffer()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~VertexBuffer()
|
|
|
|
{
|
|
|
|
DX11_RELEASE(Buffer);
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
static VertexBuffer* Create(ID3D11Device* device, int numVertices, RendererVertex* vertices)
|
2019-01-13 21:57:16 +01:00
|
|
|
{
|
|
|
|
HRESULT res;
|
|
|
|
|
|
|
|
VertexBuffer* vb = new VertexBuffer();
|
|
|
|
|
|
|
|
D3D11_BUFFER_DESC desc;
|
|
|
|
ZeroMemory(&desc, sizeof(desc));
|
|
|
|
|
|
|
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
|
|
|
desc.ByteWidth = sizeof(RendererVertex) * numVertices;
|
|
|
|
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
|
|
|
|
|
|
res = device->CreateBuffer(&desc, NULL, &vb->Buffer);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (vertices != NULL)
|
|
|
|
{
|
|
|
|
ID3D11DeviceContext* context = NULL;
|
|
|
|
device->GetImmediateContext(&context);
|
|
|
|
|
|
|
|
D3D11_MAPPED_SUBRESOURCE ms;
|
|
|
|
|
|
|
|
res = context->Map(vb->Buffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memcpy(ms.pData, vertices, sizeof(RendererVertex) * numVertices);
|
|
|
|
|
|
|
|
context->Unmap(vb->Buffer, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return vb;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class IndexBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ID3D11Buffer* Buffer;
|
|
|
|
|
|
|
|
IndexBuffer()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~IndexBuffer()
|
|
|
|
{
|
|
|
|
DX11_RELEASE(Buffer);
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
static IndexBuffer* Create(ID3D11Device* device, int numIndices, int* indices)
|
2019-01-13 21:57:16 +01:00
|
|
|
{
|
|
|
|
HRESULT res;
|
|
|
|
|
|
|
|
IndexBuffer* ib = new IndexBuffer();
|
|
|
|
|
|
|
|
D3D11_BUFFER_DESC desc;
|
|
|
|
ZeroMemory(&desc, sizeof(desc));
|
|
|
|
|
|
|
|
desc.Usage = D3D11_USAGE_DYNAMIC;
|
2019-12-02 09:11:21 +01:00
|
|
|
desc.ByteWidth = sizeof(int) * numIndices;
|
2019-01-13 21:57:16 +01:00
|
|
|
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
|
|
|
|
|
|
|
res = device->CreateBuffer(&desc, NULL, &ib->Buffer);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (indices != NULL)
|
|
|
|
{
|
|
|
|
ID3D11DeviceContext* context = NULL;
|
|
|
|
device->GetImmediateContext(&context);
|
|
|
|
|
|
|
|
D3D11_MAPPED_SUBRESOURCE ms;
|
|
|
|
|
|
|
|
res = context->Map(ib->Buffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);
|
|
|
|
if (FAILED(res))
|
|
|
|
return NULL;
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
memcpy(ms.pData, indices, sizeof(int) * numIndices);
|
2019-01-13 21:57:16 +01:00
|
|
|
|
|
|
|
context->Unmap(ib->Buffer, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ib;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererStringToDraw
|
|
|
|
{
|
|
|
|
float X;
|
|
|
|
float Y;
|
2019-12-02 09:11:21 +01:00
|
|
|
int Flags;
|
2019-01-13 21:57:16 +01:00
|
|
|
wstring String;
|
|
|
|
Vector3 Color;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererPolygon
|
|
|
|
{
|
|
|
|
byte Shape;
|
2019-12-02 09:11:21 +01:00
|
|
|
int AnimatedSet;
|
|
|
|
int TextureId;
|
|
|
|
int Distance;
|
|
|
|
int Indices[4];
|
2019-01-13 21:57:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererBone
|
|
|
|
{
|
|
|
|
Vector3 Translation;
|
|
|
|
Matrix GlobalTransform;
|
|
|
|
Matrix Transform;
|
|
|
|
Vector3 GlobalTranslation;
|
|
|
|
vector<RendererBone*> Children;
|
|
|
|
RendererBone* Parent;
|
2019-12-02 09:11:21 +01:00
|
|
|
int Index;
|
2019-01-13 21:57:16 +01:00
|
|
|
Vector3 ExtraRotation;
|
|
|
|
byte ExtraRotationFlags;
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
RendererBone(int index)
|
2019-01-13 21:57:16 +01:00
|
|
|
{
|
|
|
|
Index = index;
|
|
|
|
ExtraRotationFlags = 0;
|
|
|
|
Translation = Vector3(0, 0, 0);
|
|
|
|
ExtraRotation = Vector3(0, 0, 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-01 17:31:49 +01:00
|
|
|
struct RendererLight {
|
2019-02-03 11:58:15 +01:00
|
|
|
Vector3 Position;
|
|
|
|
float Type;
|
|
|
|
Vector3 Color;
|
|
|
|
float Dynamic;
|
2019-02-01 17:31:49 +01:00
|
|
|
Vector4 Direction;
|
|
|
|
float Intensity;
|
|
|
|
float In;
|
|
|
|
float Out;
|
|
|
|
float Range;
|
|
|
|
|
|
|
|
RendererLight()
|
|
|
|
{
|
|
|
|
Dynamic = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ShaderLight {
|
|
|
|
Vector4 Position;
|
|
|
|
Vector4 Color;
|
|
|
|
Vector4 Direction;
|
|
|
|
float Intensity;
|
|
|
|
float In;
|
|
|
|
float Out;
|
|
|
|
float Range;
|
|
|
|
};
|
|
|
|
|
2019-01-28 21:51:51 +01:00
|
|
|
struct CCameraMatrixBuffer
|
2019-01-13 21:57:16 +01:00
|
|
|
{
|
|
|
|
Matrix View;
|
|
|
|
Matrix Projection;
|
2019-01-28 21:51:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CItemBuffer
|
|
|
|
{
|
|
|
|
Matrix World;
|
2019-01-23 07:31:56 +01:00
|
|
|
Matrix BonesMatrices[32];
|
2019-01-28 21:51:51 +01:00
|
|
|
Vector4 Position;
|
|
|
|
Vector4 AmbientLight;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CStaticBuffer
|
|
|
|
{
|
|
|
|
Matrix World;
|
|
|
|
Vector4 Position;
|
2019-02-01 17:31:49 +01:00
|
|
|
Vector4 Color;
|
|
|
|
};
|
|
|
|
|
2019-04-26 15:10:32 +02:00
|
|
|
struct CShadowLightBuffer {
|
|
|
|
ShaderLight Light;
|
|
|
|
Matrix LightViewProjection;
|
2019-12-02 09:11:21 +01:00
|
|
|
int CastShadows;
|
2019-04-26 15:10:32 +02:00
|
|
|
float Padding[15];
|
|
|
|
};
|
|
|
|
|
2019-02-01 17:31:49 +01:00
|
|
|
struct CLightBuffer {
|
|
|
|
ShaderLight Lights[NUM_LIGHTS_PER_BUFFER];
|
2019-12-02 09:11:21 +01:00
|
|
|
int NumLights;
|
2019-02-09 09:35:20 +01:00
|
|
|
Vector3 CameraPosition;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CMiscBuffer {
|
2019-12-02 09:11:21 +01:00
|
|
|
int AlphaTest;
|
|
|
|
int Caustics;
|
2019-03-18 23:30:41 +01:00
|
|
|
float Padding[14];
|
2019-01-13 21:57:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererAnimatedTexture
|
|
|
|
{
|
2019-12-02 09:11:21 +01:00
|
|
|
int Id;
|
2019-01-13 21:57:16 +01:00
|
|
|
Vector2 UV[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererAnimatedTextureSet
|
|
|
|
{
|
2019-12-02 09:11:21 +01:00
|
|
|
int NumTextures;
|
2019-02-02 07:59:44 +01:00
|
|
|
RendererAnimatedTexture** Textures;
|
2019-03-16 20:55:27 +01:00
|
|
|
|
|
|
|
~RendererAnimatedTextureSet()
|
|
|
|
{
|
2019-12-02 09:11:21 +01:00
|
|
|
for (int i = 0; i < NumTextures; i++)
|
2019-03-16 20:55:27 +01:00
|
|
|
delete Textures[i];
|
2019-03-24 10:08:54 +01:00
|
|
|
free(Textures);
|
2019-03-16 20:55:27 +01:00
|
|
|
}
|
2019-01-13 21:57:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererBucket
|
|
|
|
{
|
|
|
|
vector<RendererVertex> Vertices;
|
2019-12-02 09:11:21 +01:00
|
|
|
vector<int> Indices;
|
2019-01-13 21:57:16 +01:00
|
|
|
vector<RendererPolygon> Polygons;
|
|
|
|
vector<RendererPolygon> AnimatedPolygons;
|
2019-12-02 09:11:21 +01:00
|
|
|
int StartVertex;
|
|
|
|
int StartIndex;
|
|
|
|
int NumTriangles;
|
|
|
|
int NumVertices;
|
|
|
|
int NumIndices;
|
2019-01-13 21:57:16 +01:00
|
|
|
};
|
|
|
|
|
2019-01-16 20:54:45 +01:00
|
|
|
struct RendererStatic {
|
2019-12-02 09:11:21 +01:00
|
|
|
int Id;
|
|
|
|
short RoomIndex;
|
2019-01-16 20:54:45 +01:00
|
|
|
MESH_INFO* Mesh;
|
|
|
|
Matrix World;
|
|
|
|
};
|
|
|
|
|
2019-01-13 21:57:16 +01:00
|
|
|
struct RendererRoom
|
|
|
|
{
|
|
|
|
ROOM_INFO* Room;
|
|
|
|
Vector4 AmbientLight;
|
|
|
|
RendererBucket Buckets[NUM_BUCKETS];
|
|
|
|
RendererBucket AnimatedBuckets[NUM_BUCKETS];
|
2019-01-16 20:54:45 +01:00
|
|
|
vector<RendererLight> Lights;
|
|
|
|
vector<RendererStatic> Statics;
|
2019-01-13 21:57:16 +01:00
|
|
|
bool Visited;
|
2019-01-16 20:54:45 +01:00
|
|
|
float Distance;
|
2019-12-02 09:11:21 +01:00
|
|
|
int RoomNumber;
|
2019-02-01 17:31:49 +01:00
|
|
|
PreallocatedVector<RendererLight> LightsToDraw;
|
2019-01-13 21:57:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererRoomNode {
|
2019-12-02 09:11:21 +01:00
|
|
|
short From;
|
|
|
|
short To;
|
2019-01-13 21:57:16 +01:00
|
|
|
Vector4 ClipPort;
|
|
|
|
};
|
|
|
|
|
2019-01-16 20:54:45 +01:00
|
|
|
struct RendererItem {
|
2019-12-02 09:11:21 +01:00
|
|
|
int Id;
|
2019-01-13 21:57:16 +01:00
|
|
|
ITEM_INFO* Item;
|
|
|
|
Matrix World;
|
2019-01-21 22:23:32 +01:00
|
|
|
Matrix AnimationTransforms[32];
|
2019-12-02 09:11:21 +01:00
|
|
|
int NumMeshes;
|
2019-02-03 11:58:15 +01:00
|
|
|
PreallocatedVector<RendererLight> Lights;
|
2019-01-13 21:57:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererMesh
|
|
|
|
{
|
|
|
|
RendererBucket Buckets[NUM_BUCKETS];
|
|
|
|
RendererBucket AnimatedBuckets[NUM_BUCKETS];
|
|
|
|
vector<Vector3> Positions;
|
|
|
|
};
|
|
|
|
|
2019-09-22 21:14:43 +02:00
|
|
|
struct RendererEffect {
|
2019-12-02 09:11:21 +01:00
|
|
|
int Id;
|
2019-09-22 21:14:43 +02:00
|
|
|
FX_INFO* Effect;
|
|
|
|
Matrix World;
|
|
|
|
RendererMesh* Mesh;
|
|
|
|
PreallocatedVector<RendererLight> Lights;
|
|
|
|
};
|
|
|
|
|
2019-01-13 21:57:16 +01:00
|
|
|
struct RendererObject
|
|
|
|
{
|
2019-12-02 09:11:21 +01:00
|
|
|
int Id;
|
2019-01-13 21:57:16 +01:00
|
|
|
vector<RendererMesh*> ObjectMeshes;
|
|
|
|
RendererBone* Skeleton;
|
|
|
|
vector<Matrix> AnimationTransforms;
|
|
|
|
vector<Matrix> BindPoseTransforms;
|
|
|
|
vector<RendererBone*> LinearizedBones;
|
|
|
|
bool DoNotDraw;
|
|
|
|
bool HasDataInBucket[NUM_BUCKETS];
|
|
|
|
bool HasDataInAnimatedBucket[NUM_BUCKETS];
|
2019-03-16 20:55:27 +01:00
|
|
|
|
|
|
|
~RendererObject()
|
|
|
|
{
|
2019-12-02 09:11:21 +01:00
|
|
|
/*for (int i = 0; i < ObjectMeshes.size(); i++)
|
2019-03-24 10:08:54 +01:00
|
|
|
delete ObjectMeshes[i];*/
|
2019-12-02 09:11:21 +01:00
|
|
|
for (int i = 0; i < LinearizedBones.size(); i++)
|
2019-03-24 10:08:54 +01:00
|
|
|
delete LinearizedBones[i];
|
2019-03-16 20:55:27 +01:00
|
|
|
}
|
2019-01-13 21:57:16 +01:00
|
|
|
};
|
|
|
|
|
2019-02-01 17:31:49 +01:00
|
|
|
struct RendererSprite {
|
2019-12-02 09:11:21 +01:00
|
|
|
int Width;
|
|
|
|
int Height;
|
2019-02-01 17:31:49 +01:00
|
|
|
Vector2 UV[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererSpriteSequence {
|
2019-12-02 09:11:21 +01:00
|
|
|
int Id;
|
2019-02-01 17:31:49 +01:00
|
|
|
RendererSprite** SpritesList;
|
2019-12-02 09:11:21 +01:00
|
|
|
int NumSprites;
|
2019-02-01 17:31:49 +01:00
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
RendererSpriteSequence(int id, int num)
|
2019-02-01 17:31:49 +01:00
|
|
|
{
|
|
|
|
Id = id;
|
2019-03-16 20:55:27 +01:00
|
|
|
NumSprites = num;
|
2019-02-01 17:31:49 +01:00
|
|
|
SpritesList = (RendererSprite**)malloc(sizeof(RendererSprite*) * num);
|
|
|
|
}
|
2019-03-16 20:55:27 +01:00
|
|
|
|
|
|
|
~RendererSpriteSequence()
|
|
|
|
{
|
2019-12-02 09:11:21 +01:00
|
|
|
/*for (int i = 0; i < NumSprites; i++)
|
2019-03-16 20:55:27 +01:00
|
|
|
delete SpritesList[i];
|
|
|
|
free(SpritesList);*/
|
|
|
|
}
|
2019-02-01 17:31:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererSpriteToDraw {
|
|
|
|
RENDERER_SPRITE_TYPE Type;
|
|
|
|
RendererSprite* Sprite;
|
|
|
|
float Distance;
|
|
|
|
float Scale;
|
|
|
|
float X, Y, Z;
|
|
|
|
float X1, Y1, Z1;
|
|
|
|
float X2, Y2, Z2;
|
|
|
|
float X3, Y3, Z3;
|
|
|
|
float X4, Y4, Z4;
|
|
|
|
byte R;
|
|
|
|
byte G;
|
|
|
|
byte B;
|
|
|
|
float Rotation;
|
|
|
|
float Width;
|
|
|
|
float Height;
|
|
|
|
BLEND_MODES BlendMode;
|
|
|
|
};
|
|
|
|
|
2019-02-02 15:40:44 +01:00
|
|
|
struct RendererLine3D {
|
2019-02-01 17:31:49 +01:00
|
|
|
float X1;
|
|
|
|
float Y1;
|
|
|
|
float Z1;
|
|
|
|
float X2;
|
|
|
|
float Y2;
|
|
|
|
float Z2;
|
|
|
|
byte R;
|
|
|
|
byte G;
|
|
|
|
byte B;
|
|
|
|
};
|
|
|
|
|
2019-02-02 08:23:54 +01:00
|
|
|
struct RendererWeatherParticle {
|
|
|
|
float X, Y, Z;
|
|
|
|
float AngleH;
|
|
|
|
float AngleV;
|
|
|
|
float Size;
|
2019-12-02 09:11:21 +01:00
|
|
|
short Room;
|
2019-02-02 08:23:54 +01:00
|
|
|
bool Reset;
|
2019-03-29 00:27:16 +01:00
|
|
|
bool Draw;
|
2019-02-02 08:23:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RendererUnderwaterDustParticle {
|
|
|
|
float X, Y, Z;
|
2019-12-02 09:11:21 +01:00
|
|
|
short Life;
|
|
|
|
short Room;
|
2019-02-02 08:23:54 +01:00
|
|
|
bool Reset;
|
|
|
|
};
|
|
|
|
|
2019-02-02 15:40:44 +01:00
|
|
|
struct RendererLine2D {
|
|
|
|
Vector2 Vertices[2];
|
|
|
|
Vector4 Color;
|
|
|
|
};
|
|
|
|
|
2019-01-13 21:57:16 +01:00
|
|
|
class Renderer11
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// Core DX11 objects
|
2019-04-29 13:10:58 +02:00
|
|
|
ID3D11Device* m_device = NULL;
|
|
|
|
ID3D11DeviceContext* m_context = NULL;
|
|
|
|
IDXGISwapChain* m_swapChain = NULL;
|
|
|
|
IDXGIDevice* m_dxgiDevice = NULL;
|
|
|
|
CommonStates* m_states = NULL;
|
|
|
|
ID3D11InputLayout* m_inputLayout = NULL;
|
|
|
|
D3D11_VIEWPORT m_viewport;
|
|
|
|
D3D11_VIEWPORT m_shadowMapViewport;
|
|
|
|
Viewport* m_viewportToolkit;
|
|
|
|
vector<RendererVideoAdapter> m_adapters;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
|
|
|
// Main back buffer
|
2019-04-29 13:10:58 +02:00
|
|
|
ID3D11RenderTargetView* m_backBufferRTV;
|
|
|
|
ID3D11Texture2D* m_backBufferTexture;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2019-04-29 13:10:58 +02:00
|
|
|
ID3D11DepthStencilState* m_depthStencilState;
|
|
|
|
ID3D11DepthStencilView* m_depthStencilView;
|
|
|
|
ID3D11Texture2D* m_depthStencilTexture;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2019-04-29 13:10:58 +02:00
|
|
|
RenderTarget2D* m_dumpScreenRenderTarget;
|
|
|
|
RenderTarget2D* m_renderTarget;
|
|
|
|
RenderTarget2D* m_currentRenderTarget;
|
|
|
|
RenderTarget2D* m_shadowMap;
|
2019-01-28 21:51:51 +01:00
|
|
|
|
2019-01-13 21:57:16 +01:00
|
|
|
// Shaders
|
2019-04-29 13:10:58 +02:00
|
|
|
ID3D11VertexShader* m_vsRooms;
|
|
|
|
ID3D11PixelShader* m_psRooms;
|
|
|
|
ID3D11VertexShader* m_vsItems;
|
|
|
|
ID3D11PixelShader* m_psItems;
|
|
|
|
ID3D11VertexShader* m_vsHairs;
|
|
|
|
ID3D11PixelShader* m_psHairs;
|
|
|
|
ID3D11VertexShader* m_vsStatics;
|
|
|
|
ID3D11PixelShader* m_psStatics;
|
|
|
|
ID3D11VertexShader* m_vsSky;
|
|
|
|
ID3D11PixelShader* m_psSky;
|
|
|
|
ID3D11VertexShader* m_vsSprites;
|
|
|
|
ID3D11PixelShader* m_psSprites;
|
|
|
|
ID3D11VertexShader* m_vsSolid;
|
|
|
|
ID3D11PixelShader* m_psSolid;
|
|
|
|
ID3D11VertexShader* m_vsInventory;
|
|
|
|
ID3D11PixelShader* m_psInventory;
|
|
|
|
ID3D11VertexShader* m_vsFullScreenQuad;
|
|
|
|
ID3D11PixelShader* m_psFullScreenQuad;
|
|
|
|
ID3D11VertexShader* m_vsShadowMap;
|
|
|
|
ID3D11PixelShader* m_psShadowMap;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
|
|
|
// Constant buffers
|
2019-04-29 13:10:58 +02:00
|
|
|
CCameraMatrixBuffer m_stCameraMatrices;
|
|
|
|
ID3D11Buffer* m_cbCameraMatrices;
|
|
|
|
CItemBuffer m_stItem;
|
|
|
|
ID3D11Buffer* m_cbItem;
|
|
|
|
CStaticBuffer m_stStatic;
|
|
|
|
ID3D11Buffer* m_cbStatic;
|
|
|
|
CLightBuffer m_stLights;
|
|
|
|
ID3D11Buffer* m_cbLights;
|
|
|
|
CMiscBuffer m_stMisc;
|
|
|
|
ID3D11Buffer* m_cbMisc;
|
|
|
|
CShadowLightBuffer m_stShadowMap;
|
|
|
|
ID3D11Buffer* m_cbShadowMap;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
|
|
|
// Text and sprites
|
2019-04-29 13:10:58 +02:00
|
|
|
SpriteFont* m_gameFont;
|
|
|
|
SpriteBatch* m_spriteBatch;
|
|
|
|
vector<RendererStringToDraw> m_strings;
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_blinkColorValue;
|
|
|
|
int m_blinkColorDirection;
|
2019-04-29 13:10:58 +02:00
|
|
|
PrimitiveBatch<RendererVertex>* m_primitiveBatch;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
|
|
|
// System resources
|
2019-04-29 13:10:58 +02:00
|
|
|
Texture2D* m_caustics[NUM_CAUSTICS_TEXTURES];
|
|
|
|
Texture2D* m_binocularsTexture;
|
|
|
|
Texture2D* m_whiteTexture;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
|
|
|
// Level data
|
2019-03-15 23:03:54 +01:00
|
|
|
Texture2D* m_titleScreen;
|
|
|
|
Texture2D* m_loadScreen;
|
2019-01-16 20:54:45 +01:00
|
|
|
Texture2D* m_textureAtlas;
|
2019-02-01 17:31:49 +01:00
|
|
|
Texture2D* m_skyTexture;
|
2019-06-01 09:32:42 +02:00
|
|
|
Texture2D* m_logo;
|
2019-01-16 20:54:45 +01:00
|
|
|
VertexBuffer* m_roomsVertexBuffer;
|
|
|
|
IndexBuffer* m_roomsIndexBuffer;
|
|
|
|
VertexBuffer* m_moveablesVertexBuffer;
|
|
|
|
IndexBuffer* m_moveablesIndexBuffer;
|
|
|
|
VertexBuffer* m_staticsVertexBuffer;
|
|
|
|
IndexBuffer* m_staticsIndexBuffer;
|
2019-01-21 22:23:32 +01:00
|
|
|
RendererRoom** m_rooms;
|
2019-01-16 20:54:45 +01:00
|
|
|
Matrix m_hairsMatrices[12];
|
2019-12-02 09:11:21 +01:00
|
|
|
short m_normalLaraSkinJointRemap[15][32];
|
|
|
|
short m_youngLaraSkinJointRemap[15][32];
|
|
|
|
short m_laraSkinJointRemap[15][32];
|
|
|
|
short m_numHairVertices;
|
|
|
|
short m_numHairIndices;
|
2019-01-16 20:54:45 +01:00
|
|
|
vector<RendererVertex> m_hairVertices;
|
2019-12-02 09:11:21 +01:00
|
|
|
vector<short> m_hairIndices;
|
2019-01-21 22:23:32 +01:00
|
|
|
PreallocatedVector<RendererRoom> m_roomsToDraw;
|
|
|
|
PreallocatedVector<RendererItem> m_itemsToDraw;
|
|
|
|
PreallocatedVector<RendererEffect> m_effectsToDraw;
|
|
|
|
PreallocatedVector<RendererStatic> m_staticsToDraw;
|
|
|
|
PreallocatedVector<RendererLight> m_lightsToDraw;
|
|
|
|
PreallocatedVector<RendererLight> m_dynamicLights;
|
2019-02-01 17:31:49 +01:00
|
|
|
PreallocatedVector<RendererSpriteToDraw> m_spritesToDraw;
|
2019-02-02 15:40:44 +01:00
|
|
|
PreallocatedVector<RendererLine3D> m_lines3DToDraw;
|
|
|
|
PreallocatedVector<RendererLine2D> m_lines2DToDraw;
|
2019-02-03 11:58:15 +01:00
|
|
|
PreallocatedVector<RendererLight> m_tempItemLights;
|
2019-02-01 17:31:49 +01:00
|
|
|
RendererSpriteToDraw* m_spritesBuffer;
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_nextSprite;
|
2019-02-02 15:40:44 +01:00
|
|
|
RendererLine3D* m_lines3DBuffer;
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_nextLine3D;
|
2019-02-02 15:40:44 +01:00
|
|
|
RendererLine2D* m_lines2DBuffer;
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_nextLine2D;
|
2019-01-16 20:54:45 +01:00
|
|
|
RendererLight* m_shadowLight;
|
2019-01-21 22:23:32 +01:00
|
|
|
RendererObject** m_moveableObjects;
|
|
|
|
RendererObject** m_staticObjects;
|
2019-02-01 17:31:49 +01:00
|
|
|
RendererSprite** m_sprites;
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_numMoveables;
|
|
|
|
int m_numStatics;
|
|
|
|
int m_numSprites;
|
|
|
|
int m_numSpritesSequences;
|
2019-02-01 17:31:49 +01:00
|
|
|
RendererSpriteSequence** m_spriteSequences;
|
2019-03-24 10:08:54 +01:00
|
|
|
unordered_map<unsigned int, RendererMesh*> m_meshPointersToMesh;
|
2019-01-21 22:23:32 +01:00
|
|
|
Matrix m_LaraWorldMatrix;
|
2019-02-02 07:59:44 +01:00
|
|
|
RendererAnimatedTextureSet** m_animatedTextureSets;
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_numAnimatedTextureSets;
|
|
|
|
int m_currentCausticsFrame;
|
2019-03-18 23:30:41 +01:00
|
|
|
RendererUnderwaterDustParticle m_underwaterDustParticles[NUM_UNDERWATER_DUST_PARTICLES];
|
|
|
|
bool m_firstUnderwaterDustParticles = true;
|
2019-03-24 10:08:54 +01:00
|
|
|
vector<RendererMesh*> m_meshes;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
2019-01-28 21:51:51 +01:00
|
|
|
// Debug variables
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_numDrawCalls = 0;
|
2019-01-28 21:51:51 +01:00
|
|
|
|
2019-01-16 21:21:14 +01:00
|
|
|
// Preallocated pools of objects for avoiding new/delete
|
|
|
|
// Items and effects are safe (can't be more than 1024 items in TR),
|
|
|
|
// lights should be oversized (eventually ignore lights more than MAX_LIGHTS)
|
|
|
|
RendererItem m_items[NUM_ITEMS];
|
|
|
|
RendererEffect m_effects[NUM_ITEMS];
|
|
|
|
RendererLight m_lights[MAX_LIGHTS];
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_nextLight;
|
|
|
|
int m_currentY;
|
2019-01-16 21:21:14 +01:00
|
|
|
|
2019-01-21 22:23:32 +01:00
|
|
|
// Times for debug
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_timeUpdate;
|
|
|
|
int m_timeDraw;
|
|
|
|
int m_timeFrame;
|
2019-01-21 22:23:32 +01:00
|
|
|
|
2019-02-02 08:23:54 +01:00
|
|
|
// Others
|
|
|
|
bool m_firstWeather;
|
|
|
|
RendererWeatherParticle m_rain[NUM_RAIN_DROPS];
|
|
|
|
RendererWeatherParticle m_snow[NUM_SNOW_PARTICLES];
|
2019-03-15 23:03:54 +01:00
|
|
|
RENDERER_FADE_STATUS m_fadeStatus;
|
|
|
|
float m_fadeFactor;
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_progress;
|
2019-03-20 00:05:00 +01:00
|
|
|
bool m_enableCinematicBars = false;
|
2019-12-14 22:41:38 +01:00
|
|
|
int m_pickupRotation;
|
2019-02-02 08:23:54 +01:00
|
|
|
|
2019-01-13 21:57:16 +01:00
|
|
|
// Private functions
|
2019-04-29 13:10:58 +02:00
|
|
|
bool drawScene(bool dump);
|
|
|
|
bool drawAllStrings();
|
2019-12-14 22:41:38 +01:00
|
|
|
ID3D11VertexShader* compileVertexShader(const char* fileName, const char* function, const char* model, ID3D10Blob** bytecode);
|
|
|
|
ID3D11GeometryShader* compileGeometryShader(const char* fileName);
|
|
|
|
ID3D11PixelShader* compilePixelShader(const char* fileName, const char* function, const char* model, ID3D10Blob** bytecode);
|
|
|
|
ID3D11ComputeShader* compileComputeShader(const char* fileName);
|
2019-12-02 09:11:21 +01:00
|
|
|
ID3D11Buffer* createConstantBuffer(int size);
|
2019-12-14 22:41:38 +01:00
|
|
|
int getAnimatedTextureInfo(short textureId);
|
2019-04-29 13:10:58 +02:00
|
|
|
void initialiseHairRemaps();
|
2019-12-02 09:11:21 +01:00
|
|
|
RendererMesh* getRendererMeshFromTrMesh(RendererObject* obj, short* meshPtr, short* refMeshPtr, short boneIndex, int isJoints, int isHairs);
|
|
|
|
void fromTrAngle(Matrix* matrix, short* frameptr, int index);
|
2019-04-29 13:10:58 +02:00
|
|
|
void buildHierarchy(RendererObject* obj);
|
|
|
|
void buildHierarchyRecursive(RendererObject* obj, RendererBone* node, RendererBone* parentNode);
|
2019-12-02 09:11:21 +01:00
|
|
|
void updateAnimation(RendererItem* item, RendererObject* obj, short** frmptr, short frac, short rate, int mask);
|
|
|
|
bool printDebugMessage(int x, int y, int alpha, byte r, byte g, byte b, LPCSTR Message);
|
|
|
|
bool checkPortal(short roomIndex, short* portal, Vector4* viewPort, Vector4* clipPort);
|
2019-04-29 13:10:58 +02:00
|
|
|
void getVisibleRooms(int from, int to, Vector4* viewPort, bool water, int count);
|
|
|
|
void collectRooms();
|
2019-12-02 09:11:21 +01:00
|
|
|
inline void collectItems(short roomNumber);
|
|
|
|
inline void collectStatics(short roomNumber);
|
|
|
|
inline void collectLightsForRoom(short roomNumber);
|
|
|
|
inline void collectLightsForItem(short roomNumber, RendererItem* item);
|
|
|
|
inline void collectLightsForEffect(short roomNumber, RendererEffect* effect);
|
|
|
|
inline void collectEffects(short roomNumber);
|
2019-04-29 13:10:58 +02:00
|
|
|
void prepareLights();
|
|
|
|
void clearSceneItems();
|
2019-12-02 09:11:21 +01:00
|
|
|
bool updateConstantBuffer(ID3D11Buffer* buffer, void* data, int size);
|
2019-04-29 13:10:58 +02:00
|
|
|
void updateLaraAnimations();
|
|
|
|
void updateItemsAnimations();
|
|
|
|
void updateEffects();
|
2019-12-14 22:41:38 +01:00
|
|
|
int getFrame(short animation, short frame, short** framePtr, int* rate);
|
2019-12-02 09:11:21 +01:00
|
|
|
bool drawAmbientCubeMap(short roomNumber);
|
2019-04-29 13:10:58 +02:00
|
|
|
bool sphereBoxIntersection(Vector3 boxMin, Vector3 boxMax, Vector3 sphereCentre, float sphereRadius);
|
|
|
|
bool drawHorizonAndSky();
|
|
|
|
bool drawRooms(bool transparent, bool animated);
|
|
|
|
bool drawStatics(bool transparent);
|
|
|
|
bool drawItems(bool transparent, bool animated);
|
|
|
|
bool drawAnimatingItem(RendererItem* item, bool transparent, bool animated);
|
|
|
|
bool drawWaterfalls();
|
|
|
|
bool drawShadowMap();
|
2019-12-02 09:11:21 +01:00
|
|
|
bool drawObjectOn2DPosition(short x, short y, short objectNum, short rotX, short rotY, short rotZ);
|
2019-04-29 13:10:58 +02:00
|
|
|
bool drawLara(bool transparent, bool shadowMap);
|
2019-12-14 22:41:38 +01:00
|
|
|
void printDebugMessage(LPCSTR message, ...);
|
2019-04-29 13:10:58 +02:00
|
|
|
void drawFires();
|
|
|
|
void drawSparks();
|
|
|
|
void drawSmokes();
|
|
|
|
void drawBlood();
|
|
|
|
void drawDrips();
|
|
|
|
void drawBubbles();
|
2019-09-22 21:14:43 +02:00
|
|
|
bool drawEffects(bool transparent);
|
|
|
|
bool drawEffect(RendererEffect* effect, bool transparent);
|
2019-04-29 13:10:58 +02:00
|
|
|
void drawSplahes();
|
|
|
|
bool drawSprites();
|
|
|
|
bool drawLines3D();
|
|
|
|
bool drawLines2D();
|
|
|
|
bool drawOverlays();
|
|
|
|
bool drawRopes();
|
|
|
|
bool drawBats();
|
|
|
|
bool drawRats();
|
|
|
|
bool drawSpiders();
|
|
|
|
bool drawGunFlashes();
|
|
|
|
bool drawGunShells();
|
2019-12-02 09:11:21 +01:00
|
|
|
bool drawBar(int x, int y, int w, int h, int percent, int color1, int color2);
|
|
|
|
void insertLine2D(int x1, int y1, int x2, int y2, byte r, byte g, byte b, byte a);
|
2019-04-29 13:10:58 +02:00
|
|
|
bool drawDebris(bool transparent);
|
2019-12-14 22:41:38 +01:00
|
|
|
int drawInventoryScene();
|
|
|
|
int drawFinalPass();
|
2019-04-29 13:10:58 +02:00
|
|
|
void updateAnimatedTextures();
|
|
|
|
void createBillboardMatrix(Matrix* out, Vector3* particlePos, Vector3* cameraPos, float rotation);
|
|
|
|
void drawShockwaves();
|
|
|
|
void drawRipples();
|
|
|
|
void drawUnderwaterDust();
|
|
|
|
bool doRain();
|
|
|
|
bool doSnow();
|
|
|
|
bool drawFullScreenQuad(ID3D11ShaderResourceView* texture, Vector3 color, bool cinematicBars);
|
2019-05-09 13:50:55 +02:00
|
|
|
bool drawFullScreenImage(ID3D11ShaderResourceView* texture, float fade);
|
2019-12-02 09:11:21 +01:00
|
|
|
bool isRoomUnderwater(short roomNumber);
|
|
|
|
bool isInRoom(int x, int y, int z, short roomNumber);
|
2019-04-29 13:10:58 +02:00
|
|
|
void addSpriteBillboard(RendererSprite* sprite, float x, float y, float z, byte r, byte g, byte b, float rotation, float scale, float width, float height, BLEND_MODES blendMode);
|
|
|
|
void addSprite3D(RendererSprite* sprite, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, byte r, byte g, byte b, float rotation, float scale, float width, float height, BLEND_MODES blendMode);
|
2019-12-02 09:11:21 +01:00
|
|
|
void addLine3D(int x1, int y1, int z1, int x2, int y2, int z2, byte r, byte g, byte b);
|
|
|
|
bool drawColoredQuad(int x, int y, int w, int h, Vector4 color);
|
|
|
|
bool initialiseScreen(int w, int h, int refreshRate, bool windowed, HWND handle, bool reset);
|
2019-01-13 21:57:16 +01:00
|
|
|
|
|
|
|
public:
|
2019-04-29 13:10:58 +02:00
|
|
|
Matrix View;
|
|
|
|
Matrix Projection;
|
|
|
|
Matrix ViewProjection;
|
|
|
|
float FieldOfView;
|
2019-12-14 22:41:38 +01:00
|
|
|
int ScreenWidth;
|
|
|
|
int ScreenHeight;
|
2019-04-29 13:10:58 +02:00
|
|
|
bool Windowed;
|
2019-12-14 22:41:38 +01:00
|
|
|
int NumTexturePages;
|
2019-01-13 21:57:16 +01:00
|
|
|
|
|
|
|
Renderer11();
|
|
|
|
~Renderer11();
|
|
|
|
|
2019-04-29 13:10:58 +02:00
|
|
|
bool Create();
|
|
|
|
bool EnumerateVideoModes();
|
2019-12-02 09:11:21 +01:00
|
|
|
bool Initialise(int w, int h, int refreshRate, bool windowed, HWND handle);
|
2019-12-14 22:41:38 +01:00
|
|
|
int Draw();
|
2019-04-29 13:10:58 +02:00
|
|
|
bool PrepareDataForTheRenderer();
|
|
|
|
void UpdateCameraMatrices(float posX, float posY, float posZ, float targetX, float targetY, float targetZ, float roll, float fov);
|
2019-12-14 22:41:38 +01:00
|
|
|
int DumpGameScene();
|
|
|
|
int DrawInventory();
|
|
|
|
int DrawPickup(short objectNum);
|
|
|
|
int SyncRenderer();
|
2019-12-02 09:11:21 +01:00
|
|
|
bool PrintString(int x, int y, char* string, D3DCOLOR color, int flags);
|
2019-04-29 13:10:58 +02:00
|
|
|
void DrawDashBar();
|
2019-12-02 09:11:21 +01:00
|
|
|
void DrawHealthBar(int percentual);
|
|
|
|
void DrawAirBar(int percentual);
|
2019-04-29 13:10:58 +02:00
|
|
|
void ClearDynamicLights();
|
2019-12-02 09:11:21 +01:00
|
|
|
void AddDynamicLight(int x, int y, int z, short falloff, byte r, byte g, byte b);
|
2019-04-29 13:10:58 +02:00
|
|
|
void FreeRendererData();
|
|
|
|
void EnableCinematicBars(bool value);
|
|
|
|
void FadeIn();
|
|
|
|
void FadeOut();
|
|
|
|
void DrawLoadingScreen(char* fileName);
|
|
|
|
void UpdateProgress(float value);
|
|
|
|
bool IsFading();
|
2019-12-02 09:11:21 +01:00
|
|
|
void GetLaraBonePosition(Vector3* pos, int bone);
|
2019-04-29 13:10:58 +02:00
|
|
|
bool ToggleFullScreen();
|
|
|
|
bool IsFullsScreen();
|
|
|
|
vector<RendererVideoAdapter>* GetAdapters();
|
2019-05-09 13:50:55 +02:00
|
|
|
bool DoTitleImage();
|
2019-12-02 09:11:21 +01:00
|
|
|
bool ChangeScreenResolution(int width, int height, int frequency, bool windowed);
|
2019-01-13 21:57:16 +01:00
|
|
|
};
|