Using Smart Pointers

This commit is contained in:
Raildex 2020-08-09 22:15:32 +02:00
parent b58d18ade2
commit 94eabe8918
16 changed files with 269 additions and 314 deletions

View file

@ -14,14 +14,24 @@ constexpr auto WALL_SIZE = 1024;
constexpr auto STEPUP_HEIGHT = ((STEP_SIZE * 3) / 2);
constexpr auto BAD_JUMP_CEILING = ((STEP_SIZE * 3) / 4);
#define SQUARE(x) ((x)*(x))
#define CLAMP(x, a, b) ((x)<(a)?(a):((x)>(b)?(b):(x)))
#define SIGN(x) ((0 < (x)) - ((x) < 0))
#define CLAMPADD(x, a, b) ((x)<(a)?((x)+(a)):((x)>(b)?((x)-(b)):0))
#define CLICK(x) ((x) * STEP_SIZE)
#define SECTOR(x) ((x) * WALL_SIZE)
#define HIDWORD(l) ((DWORD)(((DWORDLONG)(l)>>32)&0xFFFFFFFF))
template<typename T>
constexpr auto SQUARE(T x) { return ((x)*(x)); }
template<typename T1, typename T2, typename T3>
constexpr auto CLAMP(T1 x, T2 a, T3 b) { return ((x)<(a)?(a):((x)>(b)?(b):(x))); }
template<typename T>
constexpr auto SIGN(T x) { return ((0 < (x)) - ((x) < 0)); }
template<typename T1, typename T2, typename T3>
constexpr auto CLAMPADD(T1 x, T2 a, T3 b) { return ((x)<(a)?((x)+(a)):((x)>(b)?((x)-(b)):0)); }
template<typename T>
constexpr auto CLICK(T x) { return ((x) * STEP_SIZE); }
template<typename T>
constexpr auto SECTOR(T x) { return ((x) * WALL_SIZE); }
template<typename T>
constexpr auto HIDWORD(T l) { return ((DWORD)(((DWORDLONG)(l)>>32)&0xFFFFFFFF)); }
template<typename T>
constexpr auto MESH_BITS(T x) {
return (1 << x);
}
short ANGLE(float angle);
float TO_DEGREES(short angle);
float TO_RAD(short angle);

View file

@ -16,6 +16,7 @@ namespace T5M::Renderer {
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
Utils::throwIfFailed(device->CreateBuffer(&desc, NULL, buffer.GetAddressOf()));
buffer->SetPrivateData(WKPDID_D3DDebugObjectName, 32, typeid(CBuff).name());
}
ID3D11Buffer** get() {
return buffer.GetAddressOf();

View file

@ -5,8 +5,9 @@ namespace T5M::Renderer {
using namespace Utils;
RenderPipelineState::RenderPipelineState(ID3D11Device* device, const ShaderCompileOptions& vertexShader, const ShaderCompileOptions& pixelShader, const BlendStateOptions& blendingOptions)
{
this->vertexShader = compileVertexShader(device, vertexShader.fileName.c_str(), vertexShader.functionName.c_str(), vertexShader.profile.c_str(),nullptr, nullptr);
this->pixelShader = compilePixelShader(device, pixelShader.fileName.c_str(), pixelShader.functionName.c_str(), pixelShader.profile.c_str(), nullptr, nullptr);
ComPtr<ID3D10Blob> blob;
this->vertexShader = compileVertexShader(device, vertexShader.fileName.c_str(), vertexShader.functionName.c_str(), vertexShader.profile.c_str(),nullptr, blob);
this->pixelShader = compilePixelShader(device, pixelShader.fileName.c_str(), pixelShader.functionName.c_str(), pixelShader.profile.c_str(), nullptr, blob);
D3D11_BLEND_DESC blndDesc = {};
blndDesc.IndependentBlendEnable = blendingOptions.blendingEnabled;
blndDesc.AlphaToCoverageEnable = false;

View file

@ -15,8 +15,7 @@ namespace T5M::Renderer {
static_cast<FLOAT>(resolution),
static_cast<FLOAT>(resolution),
0,
1,
1
};
}
public:

View file

@ -34,39 +34,6 @@ namespace T5M::Renderer {
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_swapChain);
DX11_RELEASE(m_context);
DX11_RELEASE(m_device);
}
void Renderer11::freeRendererData()

View file

@ -20,20 +20,16 @@
#include "ConstantBuffers\SpriteBuffer.h"
#include "RenderTargetCube\RenderTargetCube.h"
#include "RenderView/RenderView.h"
struct CAMERA_INFO;
#include <level.h>
#include "ConstantBuffer/ConstantBuffer.h"
#include "RenderTargetCubeArray/RenderTargetCubeArray.h"
struct CAMERA_INFO;
#include <wrl/client.h>
namespace T5M::Renderer
{
constexpr size_t MAX_DYNAMIC_SHADOWS = 1;
using TexturePair = std::tuple<Texture2D, Texture2D>;
#define MESH_BITS(x) (1 << x)
#define DX11_RELEASE(x) if (x != NULL) x->Release()
#define DX11_DELETE(x) if (x != NULL) { delete x; x = NULL; }
constexpr auto NUM_ANIMATED_SETS = 1024;
constexpr auto MAX_LIGHTS_DRAW = 16384;
constexpr auto MAX_DYNAMIC_LIGHTS = 16384;
@ -143,10 +139,6 @@ namespace T5M::Renderer
float In;
float Out;
float Range;
RendererLight()
{
}
};
struct RendererAnimatedTexture
@ -355,13 +347,12 @@ namespace T5M::Renderer
{
private:
// Core DX11 objects
ID3D11Device* m_device = nullptr;
ID3D11DeviceContext* m_context = nullptr;
IDXGISwapChain* m_swapChain = nullptr;
IDXGIDevice* m_dxgiDevice = nullptr;
CommonStates* m_states = nullptr;
ID3D11BlendState* m_subtractiveBlendState = nullptr;
ID3D11InputLayout* m_inputLayout = nullptr;
Microsoft::WRL::ComPtr<ID3D11Device> m_device = nullptr;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_context = nullptr;
Microsoft::WRL::ComPtr<IDXGISwapChain> m_swapChain = nullptr;
std::unique_ptr<CommonStates> m_states = nullptr;
Microsoft::WRL::ComPtr<ID3D11BlendState> m_subtractiveBlendState = nullptr;
Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout = nullptr;
D3D11_VIEWPORT m_viewport;
D3D11_VIEWPORT m_shadowMapViewport;
Viewport* m_viewportToolkit;
@ -381,37 +372,31 @@ namespace T5M::Renderer
T5M::Renderer::RenderTarget2D m_shadowMap;
T5M::Renderer::RenderTargetCube m_reflectionCubemap;
// Shaders
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;
ID3D11VertexShader* m_vsHUD;
ID3D11PixelShader* m_psHUDColor;
ID3D11PixelShader* m_psHUDTexture;
ID3D11PixelShader* m_psHUDBarColor;
ID3D11SamplerState* m_shadowSampler;
ID3D11ShaderResourceView* m_shadowMapRV;
ID3D11Texture2D* m_shadowMapTexture;
ID3D11DepthStencilView* m_shadowMapDSV;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsRooms;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psRooms;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsItems;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psItems;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsHairs;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psHairs;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsStatics;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psStatics;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsSky;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psSky;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsSprites;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psSprites;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsSolid;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psSolid;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsInventory;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psInventory;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsFullScreenQuad;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psFullScreenQuad;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsShadowMap;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psShadowMap;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vsHUD;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psHUDColor;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psHUDTexture;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_psHUDBarColor;
Microsoft::WRL::ComPtr<ID3D11SamplerState> m_shadowSampler;
// Constant buffers
@ -436,12 +421,12 @@ namespace T5M::Renderer
CSpriteBuffer m_stSprite;
ConstantBuffer<CSpriteBuffer> m_cbSprite;
// Text and sprites
SpriteFont* m_gameFont;
SpriteBatch* m_spriteBatch;
std::unique_ptr<SpriteFont> m_gameFont;
std::unique_ptr<SpriteBatch> m_spriteBatch;
std::vector<RendererStringToDraw> m_strings;
int m_blinkColorValue;
int m_blinkColorDirection;
PrimitiveBatch<RendererVertex>* m_primitiveBatch;
std::unique_ptr<PrimitiveBatch<RendererVertex>> m_primitiveBatch;
// System resources
T5M::Renderer::Texture2D m_HUDBarBorderTexture;
@ -624,12 +609,6 @@ namespace T5M::Renderer
int ScreenHeight;
bool Windowed;
int NumTexturePages;
ID3D11Device* getDevice() const {
return m_device;
}
ID3D11DeviceContext* getContext() const {
return m_context;
};
Renderer11();
~Renderer11();
@ -685,7 +664,7 @@ namespace T5M::Renderer
template <typename C>
ConstantBuffer<C> createConstantBuffer() {
return ConstantBuffer<C>(m_device);
return ConstantBuffer<C>(m_device.Get());
}
};

View file

@ -114,9 +114,9 @@ namespace T5M::Renderer
if (texture->normalMapData.size() < 1) {
normal = createDefaultNormalTexture();
} else {
normal = Texture2D(m_device, texture->normalMapData.data(), texture->normalMapData.size());
normal = Texture2D(m_device.Get(), texture->normalMapData.data(), texture->normalMapData.size());
}
TexturePair tex =std::make_tuple(Texture2D(m_device, texture->colorMapData.data(), texture->colorMapData.size()), normal);
TexturePair tex =std::make_tuple(Texture2D(m_device.Get(), texture->colorMapData.data(), texture->colorMapData.size()), normal);
m_roomTextures.push_back(tex);
}
@ -127,9 +127,9 @@ namespace T5M::Renderer
if (texture->normalMapData.size() < 1) {
normal = createDefaultNormalTexture();
} else {
normal = Texture2D(m_device, texture->normalMapData.data(), texture->normalMapData.size());
normal = Texture2D(m_device.Get(), texture->normalMapData.data(), texture->normalMapData.size());
}
TexturePair tex = std::make_tuple(Texture2D(m_device, texture->colorMapData.data(), texture->colorMapData.size()), normal);
TexturePair tex = std::make_tuple(Texture2D(m_device.Get(), texture->colorMapData.data(), texture->colorMapData.size()), normal);
m_moveablesTextures.push_back(tex);
}
@ -140,19 +140,19 @@ namespace T5M::Renderer
if (texture->normalMapData.size() < 1) {
normal = createDefaultNormalTexture();
} else {
normal = Texture2D(m_device, texture->normalMapData.data(), texture->normalMapData.size());
normal = Texture2D(m_device.Get(), texture->normalMapData.data(), texture->normalMapData.size());
}
TexturePair tex = std::make_tuple(Texture2D(m_device, texture->colorMapData.data(), texture->colorMapData.size()), normal);
TexturePair tex = std::make_tuple(Texture2D(m_device.Get(), texture->colorMapData.data(), texture->colorMapData.size()), normal);
m_staticsTextures.push_back(tex);
}
for (int i = 0; i < g_Level.SpritesTextures.size(); i++)
{
TEXTURE *texture = &g_Level.SpritesTextures[i];
m_spritesTextures.push_back(Texture2D(m_device, texture->colorMapData.data(), texture->colorMapData.size()));
m_spritesTextures.push_back(Texture2D(m_device.Get(), texture->colorMapData.data(), texture->colorMapData.size()));
}
m_skyTexture = Texture2D(m_device, g_Level.MiscTextures.colorMapData.data(), g_Level.MiscTextures.colorMapData.size());
m_skyTexture = Texture2D(m_device.Get(), g_Level.MiscTextures.colorMapData.data(), g_Level.MiscTextures.colorMapData.size());
// Step 2: prepare rooms
vector<RendererVertex> roomVertices;
@ -314,8 +314,8 @@ namespace T5M::Renderer
// Create a single vertex buffer and a single index buffer for all rooms
// NOTICE: in theory, a 1,000,000 vertices scene should have a VB of 52 MB and an IB of 4 MB
m_roomsVertexBuffer = VertexBuffer(m_device, roomVertices.size(), roomVertices.data());
m_roomsIndexBuffer = IndexBuffer(m_device, roomIndices.size(), roomIndices.data());
m_roomsVertexBuffer = VertexBuffer(m_device.Get(), roomVertices.size(), roomVertices.data());
m_roomsIndexBuffer = IndexBuffer(m_device.Get(), roomIndices.size(), roomIndices.data());
m_numHairVertices = 0;
m_numHairIndices = 0;
@ -644,8 +644,8 @@ namespace T5M::Renderer
}
// Create a single vertex buffer and a single index buffer for all moveables
m_moveablesVertexBuffer = VertexBuffer(m_device, moveablesVertices.size(), moveablesVertices.data());
m_moveablesIndexBuffer = IndexBuffer(m_device, moveablesIndices.size(), moveablesIndices.data());
m_moveablesVertexBuffer = VertexBuffer(m_device.Get(), moveablesVertices.size(), moveablesVertices.data());
m_moveablesIndexBuffer = IndexBuffer(m_device.Get(), moveablesIndices.size(), moveablesIndices.data());
// Step 4: prepare static meshes
vector<RendererVertex> staticsVertices;
@ -688,8 +688,8 @@ namespace T5M::Renderer
}
// Create a single vertex buffer and a single index buffer for all statics
m_staticsVertexBuffer = VertexBuffer(m_device, staticsVertices.size(), staticsVertices.data());
m_staticsIndexBuffer = IndexBuffer(m_device, staticsIndices.size(), staticsIndices.data());
m_staticsVertexBuffer = VertexBuffer(m_device.Get(), staticsVertices.size(), staticsVertices.data());
m_staticsIndexBuffer = IndexBuffer(m_device.Get(), staticsIndices.size(), staticsIndices.data());
// Step 5: prepare sprites
m_sprites.resize(g_Level.Sprites.size());

View file

@ -76,12 +76,12 @@ namespace T5M::Renderer
// Set vertex buffer
m_context->IASetVertexBuffers(0, 1, m_moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
// Set shaders
m_context->VSSetShader(m_vsInventory, NULL, 0);
m_context->PSSetShader(m_psInventory, NULL, 0);
m_context->VSSetShader(m_vsInventory.Get(), NULL, 0);
m_context->PSSetShader(m_psInventory.Get(), NULL, 0);
// Set texture
m_context->PSSetShaderResources(0, 1, (std::get<0>(m_moveablesTextures[0])).ShaderResourceView.GetAddressOf());
@ -93,7 +93,7 @@ namespace T5M::Renderer
// Set matrices
CCameraMatrixBuffer HudCamera;
HudCamera.ViewProjection = view * projection;
m_cbCameraMatrices.updateData(HudCamera, m_context);
m_cbCameraMatrices.updateData(HudCamera, m_context.Get());
m_context->VSSetConstantBuffers(0, 1, m_cbCameraMatrices.get());
for (int n = 0; n < moveableObj.ObjectMeshes.size(); n++)
@ -113,7 +113,7 @@ namespace T5M::Renderer
else
m_stItem.World = (moveableObj.BindPoseTransforms[n] * world);
m_stItem.AmbientLight = Vector4(0.5f, 0.5f, 0.5f, 1.0f);
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_context->PSSetConstantBuffers(1, 1, m_cbItem.get());
@ -129,7 +129,7 @@ namespace T5M::Renderer
m_context->OMSetBlendState(m_states->Additive(), NULL, 0xFFFFFFFF);
m_stMisc.AlphaTest = (m < 2);
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
m_context->DrawIndexed(bucket->Indices.size(), bucket->StartIndex, 0);
@ -242,12 +242,12 @@ namespace T5M::Renderer
UINT offset = 0;
// Set shaders
m_context->VSSetShader(m_vsShadowMap, NULL, 0);
m_context->PSSetShader(m_psShadowMap, NULL, 0);
m_context->VSSetShader(m_vsShadowMap.Get(), NULL, 0);
m_context->PSSetShader(m_psShadowMap.Get(), NULL, 0);
m_context->IASetVertexBuffers(0, 1, m_moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
// Set texture
@ -265,13 +265,13 @@ namespace T5M::Renderer
(m_shadowLight->Type == LIGHT_TYPE_POINT ? m_shadowLight->Out : m_shadowLight->Range) * 1.2f);
CCameraMatrixBuffer shadowProjection;
shadowProjection.ViewProjection = view * projection;
m_cbCameraMatrices.updateData(shadowProjection, m_context);
m_cbCameraMatrices.updateData(shadowProjection, m_context.Get());
m_context->VSSetConstantBuffers(0, 1, m_cbCameraMatrices.get());
m_stShadowMap.LightViewProjection = (view * projection);
m_stMisc.AlphaTest = true;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
RendererObject &laraObj = *m_moveableObjects[ID_LARA];
@ -282,7 +282,7 @@ namespace T5M::Renderer
m_stItem.Position = Vector4(LaraItem->pos.xPos, LaraItem->pos.yPos, LaraItem->pos.zPos, 1.0f);
m_stItem.AmbientLight = room.AmbientLight;
memcpy(m_stItem.BonesMatrices, laraObj.AnimationTransforms.data(), sizeof(Matrix) * 32);
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_context->PSSetConstantBuffers(1, 1, m_cbItem.get());
@ -357,7 +357,7 @@ namespace T5M::Renderer
matrices[i + 1] = world;
}
memcpy(m_stItem.BonesMatrices, matrices, sizeof(Matrix) * 7);
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_context->PSSetConstantBuffers(1, 1, m_cbItem.get());
@ -386,7 +386,7 @@ namespace T5M::Renderer
std::mbstowcs(introFileChars, g_GameFlow->Intro, 255);
std::wstring titleStringFileName(introFileChars);
Texture2D texture = Texture2D(m_device, titleStringFileName);
Texture2D texture = Texture2D(m_device.Get(), titleStringFileName);
float currentFade = 0;
while (currentFade <= 1.0f)
@ -425,11 +425,11 @@ namespace T5M::Renderer
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
m_cbLights.updateData(m_stLights, m_context);
m_cbLights.updateData(m_stLights, m_context.Get());
m_context->PSSetConstantBuffers(2, 1, m_cbLights.get());
m_stMisc.AlphaTest = true;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
for (int i = 0; i < 24; i++)
@ -446,7 +446,7 @@ namespace T5M::Renderer
Matrix world = rotation * translation;
m_stItem.World = world;
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
RendererMesh *mesh = moveableObj.ObjectMeshes[0];
@ -511,12 +511,12 @@ namespace T5M::Renderer
// Set vertex buffer
m_context->IASetVertexBuffers(0, 1, m_moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
// Set shaders
m_context->VSSetShader(m_vsInventory, NULL, 0);
m_context->PSSetShader(m_psInventory, NULL, 0);
m_context->VSSetShader(m_vsInventory.Get(), NULL, 0);
m_context->PSSetShader(m_psInventory.Get(), NULL, 0);
// Set texture
m_context->PSSetShaderResources(0, 1, (std::get<0>(m_moveablesTextures[0])).ShaderResourceView.GetAddressOf());
@ -537,7 +537,7 @@ namespace T5M::Renderer
Matrix::CreatePerspectiveFieldOfView(80.0f * RADIAN,
g_Renderer.ScreenWidth / (float)g_Renderer.ScreenHeight, 1.0f, 200000.0f);
m_cbCameraMatrices.updateData(inventoryCam, m_context);
m_cbCameraMatrices.updateData(inventoryCam, m_context.Get());
m_context->VSSetConstantBuffers(0, 1, m_cbCameraMatrices.get());
for (int k = 0; k < NUM_INVENTORY_RINGS; k++)
@ -634,7 +634,7 @@ namespace T5M::Renderer
else
m_stItem.World = (moveableObj.BindPoseTransforms[n] * transform);
m_stItem.AmbientLight = Vector4(0.5f, 0.5f, 0.5f, 1.0f);
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_context->PSSetConstantBuffers(1, 1, m_cbItem.get());
@ -650,7 +650,7 @@ namespace T5M::Renderer
m_context->OMSetBlendState(m_states->Additive(), NULL, 0xFFFFFFFF);
m_stMisc.AlphaTest = (m < 2);
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
m_context->DrawIndexed(bucket->Indices.size(), bucket->StartIndex, 0);
@ -1218,15 +1218,15 @@ namespace T5M::Renderer
vertices[3].Color = Vector4(color.x, color.y, color.z, 1.0f);
}
m_context->VSSetShader(m_vsFullScreenQuad, NULL, 0);
m_context->PSSetShader(m_psFullScreenQuad, NULL, 0);
m_context->VSSetShader(m_vsFullScreenQuad.Get(), NULL, 0);
m_context->PSSetShader(m_psFullScreenQuad.Get(), NULL, 0);
m_context->PSSetShaderResources(0, 1, &texture);
ID3D11SamplerState *sampler = m_states->AnisotropicClamp();
m_context->PSSetSamplers(0, 1, &sampler);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_primitiveBatch->Begin();
m_primitiveBatch->DrawQuad(vertices[0], vertices[1], vertices[2], vertices[3]);
@ -1358,12 +1358,12 @@ namespace T5M::Renderer
m_context->OMSetBlendState(m_states->Opaque(), NULL, 0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthRead(), 0);
m_context->VSSetShader(m_vsSolid, NULL, 0);
m_context->PSSetShader(m_psSolid, NULL, 0);
m_context->VSSetShader(m_vsSolid.Get(), NULL, 0);
m_context->PSSetShader(m_psSolid.Get(), NULL, 0);
Matrix world = Matrix::CreateOrthographicOffCenter(0, ScreenWidth, ScreenHeight, 0, m_viewport.MinDepth, m_viewport.MaxDepth);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_primitiveBatch->Begin();
@ -1479,7 +1479,7 @@ namespace T5M::Renderer
m_context->IASetVertexBuffers(0, 1, m_moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
if (Objects[ID_RATS_EMITTER].loaded)
@ -1504,7 +1504,7 @@ namespace T5M::Renderer
m_stItem.World = world;
m_stItem.Position = Vector4(rat->pos.xPos, rat->pos.yPos, rat->pos.zPos, 1.0f);
m_stItem.AmbientLight = m_rooms[rat->roomNumber].AmbientLight;
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
for (int b = 0; b < 2; b++)
{
@ -1529,7 +1529,7 @@ namespace T5M::Renderer
m_context->IASetVertexBuffers(0, 1, m_moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
if (Objects[ID_BATS_EMITTER].loaded)
@ -1561,7 +1561,7 @@ namespace T5M::Renderer
m_stItem.World = world;
m_stItem.Position = Vector4(bat->pos.xPos, bat->pos.yPos, bat->pos.zPos, 1.0f);
m_stItem.AmbientLight = m_rooms[bat->roomNumber].AmbientLight;
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->DrawIndexed(bucket->Indices.size(), bucket->StartIndex, 0);
m_numDrawCalls++;
@ -1579,7 +1579,7 @@ namespace T5M::Renderer
m_context->IASetVertexBuffers(0, 1, m_moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
if (Objects[ID_LITTLE_BEETLE].loaded)
@ -1604,7 +1604,7 @@ namespace T5M::Renderer
m_stItem.World = world;
m_stItem.Position = Vector4(beetle->pos.xPos, beetle->pos.yPos, beetle->pos.zPos, 1.0f);
m_stItem.AmbientLight = m_rooms[beetle->roomNumber].AmbientLight;
m_cbItem.updateData(m_stItem,m_context);
m_cbItem.updateData(m_stItem,m_context.Get());
for (int b = 0; b < 2; b++)
{
@ -1759,11 +1759,11 @@ namespace T5M::Renderer
m_context->OMSetBlendState(m_states->Additive(), NULL, 0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthRead(), 0);
m_context->VSSetShader(m_vsSolid, NULL, 0);
m_context->PSSetShader(m_psSolid, NULL, 0);
m_context->VSSetShader(m_vsSolid.Get(), NULL, 0);
m_context->PSSetShader(m_psSolid.Get(), NULL, 0);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_primitiveBatch->Begin();
@ -1974,7 +1974,7 @@ namespace T5M::Renderer
view.fillConstantBuffer(cameraConstantBuffer);
cameraConstantBuffer.Frame = GnFrameCounter;
cameraConstantBuffer.CameraUnderwater = g_Level.Rooms[cameraConstantBuffer.RoomNumber].flags & ENV_FLAG_WATER;
m_cbCameraMatrices.updateData(cameraConstantBuffer, m_context);
m_cbCameraMatrices.updateData(cameraConstantBuffer, m_context.Get());
m_context->VSSetConstantBuffers(0, 1, m_cbCameraMatrices.get());
drawHorizonAndSky(depthTarget);
drawRooms(false, false, view);
@ -2126,7 +2126,7 @@ namespace T5M::Renderer
view.fillConstantBuffer(cameraConstantBuffer);
cameraConstantBuffer.Frame = GnFrameCounter;
cameraConstantBuffer.CameraUnderwater = g_Level.Rooms[cameraConstantBuffer.RoomNumber].flags & ENV_FLAG_WATER;
m_cbCameraMatrices.updateData(cameraConstantBuffer, m_context);
m_cbCameraMatrices.updateData(cameraConstantBuffer, m_context.Get());
m_context->VSSetConstantBuffers(0, 1, m_cbCameraMatrices.get());
drawHorizonAndSky(depthTarget);
drawRooms(false, false, view);
@ -2147,14 +2147,14 @@ namespace T5M::Renderer
m_context->IASetVertexBuffers(0, 1, m_moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
RendererItem *item = &m_items[Lara.itemNumber];
// Set shaders
m_context->VSSetShader(m_vsItems, NULL, 0);
m_context->PSSetShader(m_psItems, NULL, 0);
m_context->VSSetShader(m_vsItems.Get(), NULL, 0);
m_context->PSSetShader(m_psItems.Get(), NULL, 0);
// Set texture
m_context->PSSetShaderResources(0, 1, (std::get<0>(m_moveablesTextures[0])).ShaderResourceView.GetAddressOf());
@ -2164,7 +2164,7 @@ namespace T5M::Renderer
m_context->PSSetSamplers(0, 1, &sampler);
m_stMisc.AlphaTest = !transparent;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
for (int i = 0; i < view.itemsToDraw.size(); i++)
@ -2221,18 +2221,18 @@ namespace T5M::Renderer
m_stItem.Position = Vector4(item->Item->pos.xPos, item->Item->pos.yPos, item->Item->pos.zPos, 1.0f);
m_stItem.AmbientLight = room.AmbientLight;
memcpy(m_stItem.BonesMatrices, item->AnimationTransforms, sizeof(Matrix) * 32);
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_context->PSSetConstantBuffers(1, 1, m_cbItem.get());
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
m_cbLights.updateData(m_stLights, m_context);
m_cbLights.updateData(m_stLights, m_context.Get());
m_context->PSSetConstantBuffers(2, 1, m_cbLights.get());
m_stMisc.AlphaTest = !transparent;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
for (int k = 0; k < moveableObj.ObjectMeshes.size(); k++)
@ -2344,12 +2344,12 @@ namespace T5M::Renderer
m_context->IASetVertexBuffers(0, 1, m_staticsVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_staticsIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
// Set shaders
m_context->VSSetShader(m_vsStatics, NULL, 0);
m_context->PSSetShader(m_psStatics, NULL, 0);
m_context->VSSetShader(m_vsStatics.Get(), NULL, 0);
m_context->PSSetShader(m_psStatics.Get(), NULL, 0);
// Set texture
m_context->PSSetShaderResources(0, 1, (std::get<0>(m_staticsTextures[0])).ShaderResourceView.GetAddressOf());
@ -2374,7 +2374,7 @@ namespace T5M::Renderer
m_stStatic.World = (Matrix::CreateRotationY(TO_RAD(msh->yRot)) * Matrix::CreateTranslation(msh->x, msh->y, msh->z));
m_stStatic.Color = Vector4(((msh->shade >> 10) & 0xFF) / 255.0f, ((msh->shade >> 5) & 0xFF) / 255.0f, ((msh->shade >> 0) & 0xFF) / 255.0f, 1.0f);
m_cbStatic.updateData(m_stStatic, m_context);
m_cbStatic.updateData(m_stStatic, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbStatic.get());
for (int j = firstBucket; j < lastBucket; j++)
@ -2405,13 +2405,13 @@ namespace T5M::Renderer
// Set vertex buffer
m_context->IASetVertexBuffers(0, 1, m_roomsVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_roomsIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
}
// Set shaders
m_context->VSSetShader(m_vsRooms, NULL, 0);
m_context->PSSetShader(m_psRooms, NULL, 0);
m_context->VSSetShader(m_vsRooms.Get(), NULL, 0);
m_context->PSSetShader(m_psRooms.Get(), NULL, 0);
// Set texture
m_context->PSSetShaderResources(0, 1, (std::get<0>(m_roomTextures[0])).ShaderResourceView.GetAddressOf());
@ -2419,7 +2419,7 @@ namespace T5M::Renderer
ID3D11SamplerState *sampler = m_states->AnisotropicWrap();
m_context->PSSetSamplers(0, 1, &sampler);
m_context->PSSetShaderResources(1, 1, m_caustics[m_currentCausticsFrame / 2].ShaderResourceView.GetAddressOf());
m_context->PSSetSamplers(1, 1, &m_shadowSampler);
m_context->PSSetSamplers(1, 1, m_shadowSampler.GetAddressOf());
m_context->PSSetShaderResources(2, 1, m_shadowMap.ShaderResourceView.GetAddressOf());
// Set shadow map data
@ -2434,7 +2434,7 @@ namespace T5M::Renderer
{
m_stShadowMap.CastShadows = false;
}
m_cbShadowMap.updateData(m_stShadowMap, m_context);
m_cbShadowMap.updateData(m_stShadowMap, m_context.Get());
m_context->VSSetConstantBuffers(4, 1, m_cbShadowMap.get());
m_context->PSSetConstantBuffers(4, 1, m_cbShadowMap.get());
@ -2448,16 +2448,16 @@ namespace T5M::Renderer
m_stLights.NumLights = view.lightsToDraw.size();
for (int j = 0; j < view.lightsToDraw.size(); j++)
memcpy(&m_stLights.Lights[j], view.lightsToDraw[j], sizeof(ShaderLight));
m_cbLights.updateData(m_stLights, m_context);
m_cbLights.updateData(m_stLights, m_context.Get());
m_context->PSSetConstantBuffers(1, 1, m_cbLights.get());
m_stMisc.Caustics = (room->Room->flags & ENV_FLAG_WATER);
m_stMisc.AlphaTest = !transparent;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
m_stRoom.AmbientColor = room->AmbientLight;
m_stRoom.water = (room->Room->flags & ENV_FLAG_WATER) != 0 ? 1 : 0;
m_cbRoom.updateData(m_stRoom, m_context);
m_cbRoom.updateData(m_stRoom, m_context.Get());
m_context->VSSetConstantBuffers(5, 1, m_cbRoom.get());
m_context->PSSetConstantBuffers(5, 1, m_cbRoom.get());
for (int j = firstBucket; j < lastBucket; j++)
@ -2584,11 +2584,11 @@ namespace T5M::Renderer
vertices[3].Color.z = 1.0f;
vertices[3].Color.w = 1.0f;
m_context->VSSetShader(m_vsSky, NULL, 0);
m_context->PSSetShader(m_psSky, NULL, 0);
m_context->VSSetShader(m_vsSky.Get(), NULL, 0);
m_context->PSSetShader(m_psSky.Get(), NULL, 0);
m_stMisc.AlphaTest = true;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
m_context->PSSetShaderResources(0, 1, m_skyTexture.ShaderResourceView.GetAddressOf());
@ -2596,7 +2596,7 @@ namespace T5M::Renderer
m_context->PSSetSamplers(0, 1, &sampler);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
for (int i = 0; i < 2; i++)
{
@ -2605,7 +2605,7 @@ namespace T5M::Renderer
m_stStatic.World = (rotation * translation);
m_stStatic.Color = color;
m_cbStatic.updateData(m_stStatic, m_context);
m_cbStatic.updateData(m_stStatic, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbStatic.get());
m_context->PSSetConstantBuffers(1, 1, m_cbStatic.get());
@ -2619,7 +2619,7 @@ namespace T5M::Renderer
{
m_context->IASetVertexBuffers(0, 1, m_moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
m_context->PSSetShaderResources(0, 1, (std::get<0>(m_moveablesTextures[0])).ShaderResourceView.GetAddressOf());
@ -2632,12 +2632,12 @@ namespace T5M::Renderer
m_stStatic.World = Matrix::CreateTranslation(Camera.pos.x, Camera.pos.y, Camera.pos.z);
m_stStatic.Position = Vector4::Zero;
m_stStatic.Color = Vector4::One;
m_cbStatic.updateData(m_stStatic, m_context);
m_cbStatic.updateData(m_stStatic, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbStatic.get());
m_context->PSSetConstantBuffers(1, 1, m_cbStatic.get());
m_stMisc.AlphaTest = true;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
for (int k = 0; k < moveableObj.ObjectMeshes.size(); k++)

View file

@ -69,27 +69,27 @@ namespace T5M::Renderer {
Vector4(0.18f,0.3f,0.72f,1),
Vector4(0.18f,0.3f,0.72f,1),
};
g_HealthBar = new RendererHUDBar(m_device, 20, 32, 150, 8, 1, healthColors);
g_AirBar = new RendererHUDBar(m_device, 630, 32, 150, 8, 1, airColors);
g_DashBar = new RendererHUDBar(m_device, 630, 32 + 8 + 4, 150, 8, 1, dashColors);
g_MusicVolumeBar = new RendererHUDBar(m_device, 400, 212, 150, 8, 1, soundSettingColors);
g_SFXVolumeBar = new RendererHUDBar(m_device, 400, 230, 150, 8, 1, soundSettingColors);
g_HealthBar = new RendererHUDBar(m_device.Get(), 20, 32, 150, 8, 1, healthColors);
g_AirBar = new RendererHUDBar(m_device.Get(), 630, 32, 150, 8, 1, airColors);
g_DashBar = new RendererHUDBar(m_device.Get(), 630, 32 + 8 + 4, 150, 8, 1, dashColors);
g_MusicVolumeBar = new RendererHUDBar(m_device.Get(), 400, 212, 150, 8, 1, soundSettingColors);
g_SFXVolumeBar = new RendererHUDBar(m_device.Get(), 400, 230, 150, 8, 1, soundSettingColors);
}
void Renderer11::drawBar(float percent, const RendererHUDBar* const bar) {
UINT strides = sizeof(RendererVertex);
UINT offset = 0;
float color[] = { 0,0,0,1.0f };
m_context->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xFF);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetVertexBuffers(0, 1, bar->vertexBufferBorder.Buffer.GetAddressOf(), &strides, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetIndexBuffer(bar->indexBufferBorder.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
m_context->VSSetConstantBuffers(0, 1, m_cbHUD.get());
m_context->VSSetShader(m_vsHUD, NULL, 0);
m_context->VSSetShader(m_vsHUD.Get(), NULL, 0);
m_context->PSSetShaderResources(0, 1, m_HUDBarBorderTexture.ShaderResourceView.GetAddressOf());
ID3D11SamplerState* sampler = m_states->LinearClamp();
m_context->PSSetSamplers(0, 1, &sampler);
m_context->PSSetShader(m_psHUDTexture, NULL, 0);
m_context->PSSetShader(m_psHUDTexture.Get(), NULL, 0);
m_context->OMSetBlendState(m_states->Opaque(), NULL, 0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthNone(), NULL);
m_context->RSSetState(m_states->CullNone());
@ -97,16 +97,16 @@ namespace T5M::Renderer {
m_context->ClearDepthStencilView(m_depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xFF);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetVertexBuffers(0, 1, bar->vertexBuffer.Buffer.GetAddressOf(), &strides, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetIndexBuffer(bar->indexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
m_stHUDBar.Percent = percent;
m_cbHUDBar.updateData(m_stHUDBar, m_context);
m_cbHUDBar.updateData(m_stHUDBar, m_context.Get());
m_context->VSSetConstantBuffers(0, 1, m_cbHUD.get());
m_context->PSSetConstantBuffers(0, 1, m_cbHUDBar.get());
m_context->VSSetShader(m_vsHUD, NULL, 0);
m_context->PSSetShader(m_psHUDBarColor, NULL, 0);
m_context->VSSetShader(m_vsHUD.Get(), NULL, 0);
m_context->PSSetShader(m_psHUDBarColor.Get(), NULL, 0);
m_context->OMSetBlendState(m_states->Opaque(), NULL, 0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthNone(), NULL);
m_context->RSSetState(m_states->CullNone());
@ -164,11 +164,11 @@ namespace T5M::Renderer {
vertices[3].UV.y = 1.0f;
vertices[3].Color = Vector4(1.0f, 0.0f, 0.0f, 1.0f);
m_context->VSSetShader(m_vsFullScreenQuad, NULL, 0);
m_context->PSSetShader(m_psFullScreenQuad, NULL, 0);
m_context->VSSetShader(m_vsFullScreenQuad.Get(), NULL, 0);
m_context->PSSetShader(m_psFullScreenQuad.Get(), NULL, 0);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_primitiveBatch->Begin();
m_primitiveBatch->DrawQuad(vertices[0], vertices[1], vertices[2], vertices[3]);

View file

@ -501,11 +501,11 @@ namespace T5M::Renderer {
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
m_cbLights.updateData(m_stLights, m_context);
m_cbLights.updateData(m_stLights, m_context.Get());
m_context->PSSetConstantBuffers(2, 1, m_cbLights.get());
m_stMisc.AlphaTest = true;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
short length = 0;
@ -556,7 +556,7 @@ namespace T5M::Renderer {
world = rotation2 * world;
m_stItem.World = world;
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_context->DrawIndexed(flashBucket->Indices.size(), flashBucket->StartIndex, 0);
@ -569,7 +569,7 @@ namespace T5M::Renderer {
world = rotation2 * world;
m_stItem.World = world;
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_context->DrawIndexed(flashBucket->Indices.size(), flashBucket->StartIndex, 0);
@ -609,11 +609,11 @@ namespace T5M::Renderer {
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
m_cbLights.updateData(m_stLights, m_context);
m_cbLights.updateData(m_stLights, m_context.Get());
m_context->PSSetConstantBuffers(2, 1, m_cbLights.get());
m_stMisc.AlphaTest = true;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
m_context->OMSetBlendState(m_states->Additive(), NULL, 0xFFFFFFFF);
@ -645,7 +645,7 @@ namespace T5M::Renderer {
world = rotationZ * world;
m_stItem.World = world;
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_context->DrawIndexed(flashBucket->Indices.size(), flashBucket->StartIndex, 0);
@ -662,7 +662,7 @@ namespace T5M::Renderer {
Texture2D Renderer11::createDefaultNormalTexture() {
vector<byte> data = {128,128,255,1};
return Texture2D(m_device,1,1,data.data());
return Texture2D(m_device.Get(),1,1,data.data());
}
void Renderer11::drawFootprints() {
@ -741,15 +741,15 @@ namespace T5M::Renderer {
m_context->RSSetState(m_states->CullNone());
m_context->OMSetDepthStencilState(m_states->DepthRead(), 0);
m_context->VSSetShader(m_vsSprites, NULL, 0);
m_context->PSSetShader(m_psSprites, NULL, 0);
m_context->VSSetShader(m_vsSprites.Get(), NULL, 0);
m_context->PSSetShader(m_psSprites.Get(), NULL, 0);
m_stMisc.AlphaTest = true;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetVertexBuffers(0, 1, quadVertexBuffer.GetAddressOf(), &stride, &offset);
for (int b = 0; b < 4; b++) {
BLEND_MODES currentBlendMode = (BLEND_MODES)b;
@ -769,7 +769,7 @@ namespace T5M::Renderer {
m_context->OMSetBlendState(m_states->Opaque(), NULL, 0xFFFFFFFF);
break;
case BLENDMODE_SUBTRACTIVE:
m_context->OMSetBlendState(m_subtractiveBlendState, NULL, 0xFFFFFFFF);
m_context->OMSetBlendState(m_subtractiveBlendState.Get(), NULL, 0xFFFFFFFF);
break;
}
@ -793,7 +793,7 @@ namespace T5M::Renderer {
m_stSprite.billboardMatrix = billboardMatrix;
m_stSprite.color = spr->color;
m_stSprite.isBillboard = true;
m_cbSprite.updateData(m_stSprite, m_context);
m_cbSprite.updateData(m_stSprite, m_context.Get());
m_context->VSSetConstantBuffers(4, 1, m_cbSprite.get());
m_context->Draw(4, 0);
} else if (spr->Type == RENDERER_SPRITE_TYPE::SPRITE_TYPE_BILLBOARD_CUSTOM) {
@ -809,7 +809,7 @@ namespace T5M::Renderer {
m_stSprite.billboardMatrix = billboardMatrix;
m_stSprite.color = spr->color;
m_stSprite.isBillboard = true;
m_cbSprite.updateData(m_stSprite, m_context);
m_cbSprite.updateData(m_stSprite, m_context.Get());
m_context->VSSetConstantBuffers(4, 1, m_cbSprite.get());
m_context->Draw(4, 0);
} else if (spr->Type == RENDERER_SPRITE_TYPE::SPRITE_TYPE_BILLBOARD_LOOKAT) {
@ -820,7 +820,7 @@ namespace T5M::Renderer {
m_stSprite.billboardMatrix = billboardMatrix;
m_stSprite.color = spr->color;
m_stSprite.isBillboard = true;
m_cbSprite.updateData(m_stSprite, m_context);
m_cbSprite.updateData(m_stSprite, m_context.Get());
m_context->VSSetConstantBuffers(4, 1, m_cbSprite.get());
m_context->Draw(4, 0);
}else if (spr->Type == RENDERER_SPRITE_TYPE::SPRITE_TYPE_3D) {
@ -863,7 +863,7 @@ namespace T5M::Renderer {
v3.Color = spr->color;
m_stSprite.color = spr->color;
m_stSprite.isBillboard = false;
m_cbSprite.updateData(m_stSprite, m_context);
m_cbSprite.updateData(m_stSprite, m_context.Get());
m_context->VSSetConstantBuffers(4, 1, m_cbSprite.get());
m_primitiveBatch->DrawQuad(v0, v1, v2, v3);
m_primitiveBatch->End();
@ -893,17 +893,17 @@ namespace T5M::Renderer {
m_stItem.AmbientLight = room.AmbientLight;
Matrix matrices[1] = { Matrix::Identity };
memcpy(m_stItem.BonesMatrices, matrices, sizeof(Matrix));
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_stLights.NumLights = effect->Lights.size();
for (int j = 0; j < effect->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], effect->Lights[j], sizeof(ShaderLight));
m_cbLights.updateData(m_stLights, m_context);
m_cbLights.updateData(m_stLights, m_context.Get());
m_context->PSSetConstantBuffers(2, 1, m_cbLights.get());
m_stMisc.AlphaTest = !transparent;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
RendererMesh* mesh = effect->Mesh;
@ -930,7 +930,7 @@ namespace T5M::Renderer {
m_context->IASetVertexBuffers(0, 1, m_moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
for (int i = 0; i < m_effectsToDraw.size(); i++) {
@ -966,17 +966,17 @@ namespace T5M::Renderer {
m_stItem.Position = Vector4(item->Item->pos.xPos, item->Item->pos.yPos, item->Item->pos.zPos, 1.0f);
m_stItem.AmbientLight = room.AmbientLight; //Vector4::One * 0.1f; // room->AmbientLight;
memcpy(m_stItem.BonesMatrices, item->AnimationTransforms, sizeof(Matrix) * 32);
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
m_cbLights.updateData(m_stLights, m_context);
m_cbLights.updateData(m_stLights, m_context.Get());
m_context->PSSetConstantBuffers(2, 1, m_cbLights.get());
m_stMisc.AlphaTest = false;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
m_primitiveBatch->Begin();
@ -1139,8 +1139,8 @@ namespace T5M::Renderer {
Matrix rotation = Matrix::CreateFromQuaternion(deb->rotation);
Matrix world = rotation * translation;
m_primitiveBatch->Begin();
m_context->VSSetShader(m_vsStatics, NULL, 0);
m_context->PSSetShader(m_psStatics, NULL, 0);
m_context->VSSetShader(m_vsStatics.Get(), NULL, 0);
m_context->PSSetShader(m_psStatics.Get(), NULL, 0);
m_context->PSSetShaderResources(0, 1, (std::get<0>(m_staticsTextures[0])).ShaderResourceView.GetAddressOf());
ID3D11SamplerState* sampler = m_states->AnisotropicClamp();
m_context->PSSetSamplers(0, 1, &sampler);
@ -1149,11 +1149,11 @@ namespace T5M::Renderer {
//updateConstantBuffer(m_cbCameraMatrices, &m_stCameraMatrices, sizeof(CCameraMatrixBuffer));
//m_context->VSSetConstantBuffers(0, 1, m_cbCameraMatrices);
m_stMisc.AlphaTest = !transparent;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
m_stStatic.World = world;
m_stStatic.Color = Vector4::One;
m_cbStatic.updateData(m_stStatic, m_context);
m_cbStatic.updateData(m_stStatic, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbStatic.get());
RendererVertex vtx0 = deb->mesh.vertices[0];
RendererVertex vtx1 = deb->mesh.vertices[1];

View file

@ -5,6 +5,7 @@
#include "GameFlowScript.h"
#include "Quad/RenderQuad.h"
#include <string>
#include <memory>
using namespace T5M::Renderer;
using std::vector;
extern GameConfiguration g_Configuration;
@ -15,7 +16,7 @@ void T5M::Renderer::Renderer11::Initialise(int w, int h, int refreshRate, bool w
HRESULT res;
//DB_Log(2, "Renderer::Initialise - DLL");
printf("Initialising DX11\n");
logD("Initializing DX11");
CoInitialize(NULL);
@ -25,7 +26,7 @@ void T5M::Renderer::Renderer11::Initialise(int w, int h, int refreshRate, bool w
initialiseScreen(w, h, refreshRate, windowed, handle, false);
// Initialise render states
m_states = new CommonStates(m_device);
m_states = std::make_unique<CommonStates>(m_device.Get());
// Load caustics
const char* causticsNames[NUM_CAUSTICS_TEXTURES] = {
@ -52,27 +53,27 @@ void T5M::Renderer::Renderer11::Initialise(int w, int h, int refreshRate, bool w
wchar_t causticsFile[255];
std::mbstowcs(causticsFile, causticsNames[i], 255);
std::wstring causticsFilename = std::wstring(causticsFile);
m_caustics[i] = Texture2D(m_device, causticsFilename);
m_caustics[i] = Texture2D(m_device.Get(), causticsFilename);
}
m_HUDBarBorderTexture = Texture2D(m_device, L"bar_border.png");
m_HUDBarBorderTexture = Texture2D(m_device.Get(), L"bar_border.png");
wchar_t titleScreenFile[255];
std::wstring titleFile = std::wstring(titleScreenFile);
std::mbstowcs(titleScreenFile, g_GameFlow->GetLevel(0)->Background.c_str(),255);
m_titleScreen = Texture2D(m_device, titleScreenFile);
m_titleScreen = Texture2D(m_device.Get(), titleScreenFile);
m_binocularsTexture = Texture2D(m_device, L"Binoculars.png");
m_whiteTexture = Texture2D(m_device, L"WhiteSprite.png");
m_binocularsTexture = Texture2D(m_device.Get(), L"Binoculars.png");
m_whiteTexture = Texture2D(m_device.Get(), L"WhiteSprite.png");
m_logo = Texture2D(m_device, L"Logo.png");
m_shadowMaps = RenderTargetCubeArray(m_device, g_Configuration.shadowMapSize, MAX_DYNAMIC_SHADOWS, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_D16_UNORM);
m_logo = Texture2D(m_device.Get(), L"Logo.png");
m_shadowMaps = RenderTargetCubeArray(m_device.Get(), g_Configuration.shadowMapSize, MAX_DYNAMIC_SHADOWS, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_D16_UNORM);
// Load shaders
ID3D10Blob * blob;
ComPtr<ID3D10Blob> blob;
//char shadowMapStringBuff[4];
//_itoa(g_Configuration.shadowMapSize, shadowMapStringBuff,10);
std::string shadowSizeString = std::to_string(g_Configuration.shadowMapSize);
const D3D_SHADER_MACRO roomDefines[] = {"SHADOW_MAP_SIZE",shadowSizeString.c_str(),nullptr,nullptr};
m_vsRooms = Utils::compileVertexShader(m_device,L"Shaders\\DX11_Rooms.fx", "VS", "vs_4_0", &roomDefines[0], &blob);
m_vsRooms = Utils::compileVertexShader(m_device.Get(),L"Shaders\\DX11_Rooms.fx", "VS", "vs_4_0", &roomDefines[0], blob);
// Initialise input layout using the first vertex shader
D3D11_INPUT_ELEMENT_DESC inputLayout[] =
@ -85,34 +86,32 @@ void T5M::Renderer::Renderer11::Initialise(int w, int h, int refreshRate, bool w
{"BITANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 60, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"BLENDINDICES", 0, DXGI_FORMAT_R32_FLOAT, 0, 72, D3D11_INPUT_PER_VERTEX_DATA, 0}
};
m_inputLayout = NULL;
Utils::throwIfFailed(m_device->CreateInputLayout(inputLayout, 7, blob->GetBufferPointer(), blob->GetBufferSize(), &m_inputLayout));
m_psRooms = Utils::compilePixelShader(m_device, L"Shaders\\DX11_Rooms.fx", "PS", "ps_4_0", &roomDefines[0], &blob);
m_vsItems = Utils::compileVertexShader(m_device, L"Shaders\\DX11_Items.fx", "VS", "vs_4_0", nullptr, &blob);
m_psItems = Utils::compilePixelShader(m_device, L"Shaders\\DX11_Items.fx", "PS", "ps_4_0", nullptr, &blob);
m_vsStatics = Utils::compileVertexShader(m_device, L"Shaders\\DX11_Statics.fx", "VS", "vs_4_0", nullptr, &blob);
m_psStatics = Utils::compilePixelShader(m_device, L"Shaders\\DX11_Statics.fx", "PS", "ps_4_0", nullptr, &blob);
m_vsHairs = Utils::compileVertexShader(m_device, L"Shaders\\DX11_Hairs.fx", "VS", "vs_4_0", nullptr, &blob);
m_psHairs = Utils::compilePixelShader(m_device, L"Shaders\\DX11_Hairs.fx", "PS", "ps_4_0", nullptr, &blob);
m_vsSky = Utils::compileVertexShader(m_device, L"Shaders\\DX11_Sky.fx", "VS", "vs_4_0", nullptr, &blob);
m_psSky = Utils::compilePixelShader(m_device, L"Shaders\\DX11_Sky.fx", "PS", "ps_4_0", nullptr, &blob);
m_vsSprites = Utils::compileVertexShader(m_device, L"Shaders\\DX11_Sprites.fx", "VS", "vs_4_0", nullptr, &blob);
m_psSprites = Utils::compilePixelShader(m_device, L"Shaders\\DX11_Sprites.fx", "PS", "ps_4_0", nullptr, &blob);
m_vsSolid = Utils::compileVertexShader(m_device, L"Shaders\\DX11_Solid.fx", "VS", "vs_4_0", nullptr, &blob);
m_psSolid = Utils::compilePixelShader(m_device, L"Shaders\\DX11_Solid.fx", "PS", "ps_4_0", nullptr, &blob);
m_vsInventory = Utils::compileVertexShader(m_device, L"Shaders\\DX11_Inventory.fx", "VS", "vs_4_0",nullptr, &blob);
m_psInventory = Utils::compilePixelShader(m_device, L"Shaders\\DX11_Inventory.fx", "PS", "ps_4_0", nullptr, &blob);
m_vsFullScreenQuad = Utils::compileVertexShader(m_device, L"Shaders\\DX11_FullScreenQuad.fx", "VS", "vs_4_0",nullptr, &blob);
m_psFullScreenQuad = Utils::compilePixelShader(m_device, L"Shaders\\DX11_FullScreenQuad.fx", "PS", "ps_4_0", nullptr, &blob);
m_vsShadowMap = Utils::compileVertexShader(m_device, L"Shaders\\DX11_ShadowMap.fx", "VS", "vs_4_0", nullptr, &blob);
m_psShadowMap = Utils::compilePixelShader(m_device, L"Shaders\\DX11_ShadowMap.fx", "PS", "ps_4_0", nullptr, &blob);
m_vsHUD = Utils::compileVertexShader(m_device, L"Shaders\\HUD\\DX11_VS_HUD.hlsl", "VS", "vs_4_0", nullptr, &blob);
m_psHUDColor = Utils::compilePixelShader(m_device, L"Shaders\\HUD\\DX11_PS_HUD.hlsl", "PSColored", "ps_4_0", nullptr, &blob);
m_psHUDTexture = Utils::compilePixelShader(m_device,L"Shaders\\HUD\\DX11_PS_HUD.hlsl", "PSTextured", "ps_4_0", nullptr, &blob);
m_psHUDBarColor = Utils::compilePixelShader(m_device,L"Shaders\\HUD\\DX11_PS_HUDBar.hlsl", "PSColored", "ps_4_0", nullptr, &blob);
m_shadowMap = RenderTarget2D(m_device, g_Configuration.shadowMapSize, g_Configuration.shadowMapSize, DXGI_FORMAT_R32_FLOAT,DXGI_FORMAT_D16_UNORM);
m_psRooms = Utils::compilePixelShader(m_device.Get(), L"Shaders\\DX11_Rooms.fx", "PS", "ps_4_0", &roomDefines[0], blob);
m_vsItems = Utils::compileVertexShader(m_device.Get(), L"Shaders\\DX11_Items.fx", "VS", "vs_4_0", nullptr, blob);
m_psItems = Utils::compilePixelShader(m_device.Get(), L"Shaders\\DX11_Items.fx", "PS", "ps_4_0", nullptr, blob);
m_vsStatics = Utils::compileVertexShader(m_device.Get(), L"Shaders\\DX11_Statics.fx", "VS", "vs_4_0", nullptr, blob);
m_psStatics = Utils::compilePixelShader(m_device.Get(), L"Shaders\\DX11_Statics.fx", "PS", "ps_4_0", nullptr, blob);
m_vsHairs = Utils::compileVertexShader(m_device.Get(), L"Shaders\\DX11_Hairs.fx", "VS", "vs_4_0", nullptr, blob);
m_psHairs = Utils::compilePixelShader(m_device.Get(), L"Shaders\\DX11_Hairs.fx", "PS", "ps_4_0", nullptr, blob);
m_vsSky = Utils::compileVertexShader(m_device.Get(), L"Shaders\\DX11_Sky.fx", "VS", "vs_4_0", nullptr, blob);
m_psSky = Utils::compilePixelShader(m_device.Get(), L"Shaders\\DX11_Sky.fx", "PS", "ps_4_0", nullptr, blob);
m_vsSprites = Utils::compileVertexShader(m_device.Get(), L"Shaders\\DX11_Sprites.fx", "VS", "vs_4_0", nullptr, blob);
m_psSprites = Utils::compilePixelShader(m_device.Get(), L"Shaders\\DX11_Sprites.fx", "PS", "ps_4_0", nullptr, blob);
m_vsSolid = Utils::compileVertexShader(m_device.Get(), L"Shaders\\DX11_Solid.fx", "VS", "vs_4_0", nullptr, blob);
m_psSolid = Utils::compilePixelShader(m_device.Get(), L"Shaders\\DX11_Solid.fx", "PS", "ps_4_0", nullptr, blob);
m_vsInventory = Utils::compileVertexShader(m_device.Get(), L"Shaders\\DX11_Inventory.fx", "VS", "vs_4_0",nullptr, blob);
m_psInventory = Utils::compilePixelShader(m_device.Get(), L"Shaders\\DX11_Inventory.fx", "PS", "ps_4_0", nullptr, blob);
m_vsFullScreenQuad = Utils::compileVertexShader(m_device.Get(), L"Shaders\\DX11_FullScreenQuad.fx", "VS", "vs_4_0",nullptr, blob);
m_psFullScreenQuad = Utils::compilePixelShader(m_device.Get(), L"Shaders\\DX11_FullScreenQuad.fx", "PS", "ps_4_0", nullptr, blob);
m_vsShadowMap = Utils::compileVertexShader(m_device.Get(), L"Shaders\\DX11_ShadowMap.fx", "VS", "vs_4_0", nullptr, blob);
m_psShadowMap = Utils::compilePixelShader(m_device.Get(), L"Shaders\\DX11_ShadowMap.fx", "PS", "ps_4_0", nullptr, blob);
m_vsHUD = Utils::compileVertexShader(m_device.Get(), L"Shaders\\HUD\\DX11_VS_HUD.hlsl", "VS", "vs_4_0", nullptr, blob);
m_psHUDColor = Utils::compilePixelShader(m_device.Get(), L"Shaders\\HUD\\DX11_PS_HUD.hlsl", "PSColored", "ps_4_0", nullptr, blob);
m_psHUDTexture = Utils::compilePixelShader(m_device.Get(),L"Shaders\\HUD\\DX11_PS_HUD.hlsl", "PSTextured", "ps_4_0", nullptr, blob);
m_psHUDBarColor = Utils::compilePixelShader(m_device.Get(),L"Shaders\\HUD\\DX11_PS_HUDBar.hlsl", "PSColored", "ps_4_0", nullptr, blob);
m_shadowMap = RenderTarget2D(m_device.Get(), g_Configuration.shadowMapSize, g_Configuration.shadowMapSize, DXGI_FORMAT_R32_FLOAT,DXGI_FORMAT_D16_UNORM);
// Initialise constant buffers
m_cbCameraMatrices = createConstantBuffer<CCameraMatrixBuffer>();
@ -128,7 +127,7 @@ void T5M::Renderer::Renderer11::Initialise(int w, int h, int refreshRate, bool w
m_cbSprite = createConstantBuffer<CSpriteBuffer>();
m_stHUD.View = Matrix::CreateLookAt(Vector3::Zero, Vector3(0, 0, 1), Vector3(0, -1, 0));
m_stHUD.Projection =Matrix::CreateOrthographicOffCenter(0, REFERENCE_RES_WIDTH, 0, REFERENCE_RES_HEIGHT, 0, 1.0f);
m_cbHUD.updateData(m_stHUD, m_context);
m_cbHUD.updateData(m_stHUD, m_context.Get());
m_currentCausticsFrame = 0;
m_firstWeather = true;
@ -165,16 +164,17 @@ void T5M::Renderer::Renderer11::Initialise(int w, int h, int refreshRate, bool w
blendStateDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
blendStateDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendStateDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
Utils::throwIfFailed(m_device->CreateBlendState(&blendStateDesc, &m_subtractiveBlendState));
Utils::throwIfFailed(m_device->CreateBlendState(&blendStateDesc, m_subtractiveBlendState.GetAddressOf()));
D3D11_SAMPLER_DESC shadowSamplerDesc = {};
shadowSamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
shadowSamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
shadowSamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
shadowSamplerDesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
shadowSamplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
Utils::throwIfFailed(m_device->CreateSamplerState(&shadowSamplerDesc,&m_shadowSampler));
Utils::throwIfFailed(m_device->CreateSamplerState(&shadowSamplerDesc,m_shadowSampler.GetAddressOf()));
Utils::setName(m_shadowSampler.Get(), "ShadowSampler");
initialiseBars();
initQuad(m_device);
initQuad(m_device.Get());
}
void T5M::Renderer::Renderer11::initialiseScreen(int w, int h, int refreshRate, bool windowed, HWND handle, bool reset)
@ -214,8 +214,7 @@ void T5M::Renderer::Renderer11::initialiseScreen(int w, int h, int refreshRate,
m_swapChain->Release();
}
m_swapChain = NULL;
Utils::throwIfFailed(dxgiFactory->CreateSwapChain(m_device, &sd, &m_swapChain));
Utils::throwIfFailed(dxgiFactory->CreateSwapChain(m_device.Get(), &sd, &m_swapChain));
dxgiFactory->MakeWindowAssociation(handle, 0);
@ -259,14 +258,14 @@ void T5M::Renderer::Renderer11::initialiseScreen(int w, int h, int refreshRate,
m_context->OMSetRenderTargets(1, &m_backBufferRTV, m_depthStencilView);
// Initialise sprites and font
m_spriteBatch = new SpriteBatch(m_context);
m_gameFont = new SpriteFont(m_device, L"Font.spritefont");
m_primitiveBatch = new PrimitiveBatch<RendererVertex>(m_context);
m_spriteBatch = std::make_unique<SpriteBatch>(m_context.Get());
m_gameFont = std::make_unique<SpriteFont>(m_device.Get(), L"Font.spritefont");
m_primitiveBatch = std::make_unique<PrimitiveBatch<RendererVertex>>(m_context.Get());
// Initialise buffers
m_renderTarget = RenderTarget2D(m_device, w, h, DXGI_FORMAT_R8G8B8A8_UNORM);
m_dumpScreenRenderTarget = RenderTarget2D(m_device, w, h, DXGI_FORMAT_R8G8B8A8_UNORM);
m_reflectionCubemap = RenderTargetCube(m_device, 128, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
m_renderTarget = RenderTarget2D(m_device.Get(), w, h, DXGI_FORMAT_R8G8B8A8_UNORM);
m_dumpScreenRenderTarget = RenderTarget2D(m_device.Get(), w, h, DXGI_FORMAT_R8G8B8A8_UNORM);
m_reflectionCubemap = RenderTargetCube(m_device.Get(), 128, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
// Shadow map
/*D3D11_TEXTURE2D_DESC depthTexDesc;
ZeroMemory(&depthTexDesc, sizeof(D3D11_TEXTURE2D_DESC));

View file

@ -152,7 +152,7 @@ void T5M::Renderer::Renderer11::drawLara(bool transparent, bool shadowMap)
m_context->IASetVertexBuffers(0, 1, m_moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
m_context->IASetInputLayout(m_inputLayout);
m_context->IASetInputLayout(m_inputLayout.Get());
m_context->IASetIndexBuffer(m_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
RendererItem *item = &m_items[Lara.itemNumber];
@ -160,13 +160,13 @@ void T5M::Renderer::Renderer11::drawLara(bool transparent, bool shadowMap)
// Set shaders
if (shadowMap)
{
m_context->VSSetShader(m_vsShadowMap, NULL, 0);
m_context->PSSetShader(m_psShadowMap, NULL, 0);
m_context->VSSetShader(m_vsShadowMap.Get(), NULL, 0);
m_context->PSSetShader(m_psShadowMap.Get(), NULL, 0);
}
else
{
m_context->VSSetShader(m_vsItems, NULL, 0);
m_context->PSSetShader(m_psItems, NULL, 0);
m_context->VSSetShader(m_vsItems.Get(), NULL, 0);
m_context->PSSetShader(m_psItems.Get(), NULL, 0);
}
// Set texture
@ -177,7 +177,7 @@ void T5M::Renderer::Renderer11::drawLara(bool transparent, bool shadowMap)
m_context->PSSetSamplers(0, 1, &sampler);
m_stMisc.AlphaTest = !transparent;
m_cbMisc.updateData(m_stMisc, m_context);
m_cbMisc.updateData(m_stMisc, m_context.Get());
m_context->PSSetConstantBuffers(3, 1, m_cbMisc.get());
RendererObject &laraObj = *m_moveableObjects[ID_LARA];
@ -188,7 +188,7 @@ void T5M::Renderer::Renderer11::drawLara(bool transparent, bool shadowMap)
m_stItem.Position = Vector4(LaraItem->pos.xPos, LaraItem->pos.yPos, LaraItem->pos.zPos, 1.0f);
m_stItem.AmbientLight = room.AmbientLight;
memcpy(m_stItem.BonesMatrices, laraObj.AnimationTransforms.data(), sizeof(Matrix) * 32);
m_cbItem.updateData(m_stItem, m_context);
m_cbItem.updateData(m_stItem, m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_context->PSSetConstantBuffers(1, 1, m_cbItem.get());
@ -197,7 +197,7 @@ void T5M::Renderer::Renderer11::drawLara(bool transparent, bool shadowMap)
m_stLights.NumLights = item->Lights.size();
for (int j = 0; j < item->Lights.size(); j++)
memcpy(&m_stLights.Lights[j], item->Lights[j], sizeof(ShaderLight));
m_cbLights.updateData(m_stLights, m_context);
m_cbLights.updateData(m_stLights, m_context.Get());
m_context->PSSetConstantBuffers(2, 1, m_cbLights.get());
}
@ -256,7 +256,7 @@ void T5M::Renderer::Renderer11::drawLara(bool transparent, bool shadowMap)
matrices[i + 1] = world;
}
memcpy(m_stItem.BonesMatrices, matrices, sizeof(Matrix) * 7);
m_cbItem.updateData(m_stItem,m_context);
m_cbItem.updateData(m_stItem,m_context.Get());
m_context->VSSetConstantBuffers(1, 1, m_cbItem.get());
m_context->PSSetConstantBuffers(1, 1, m_cbItem.get());

View file

@ -134,10 +134,6 @@ namespace T5M::Renderer {
ID3D11RenderTargetView* nullViews[] = { nullptr };
m_context->OMSetRenderTargets(0, nullViews, NULL);
DX11_DELETE(m_gameFont);
DX11_DELETE(m_spriteBatch);
DX11_DELETE(m_primitiveBatch);
m_backBufferTexture->Release();
m_backBufferRTV->Release();
m_depthStencilView->Release();

View file

@ -70,11 +70,11 @@ namespace T5M::Renderer {
// Draw shadow if needed
if (str->Flags & PRINTSTRING_OUTLINE)
m_gameFont->DrawString(m_spriteBatch, str->String.c_str(), Vector2(str->X + 1, str->Y + 1),
m_gameFont->DrawString(m_spriteBatch.get(), str->String.c_str(), Vector2(str->X + 1, str->Y + 1),
Vector4(0.0f, 0.0f, 0.0f, 1.0f));
// Draw string
m_gameFont->DrawString(m_spriteBatch, str->String.c_str(), Vector2(str->X, str->Y),
m_gameFont->DrawString(m_spriteBatch.get(), str->String.c_str(), Vector2(str->X, str->Y),
Vector4(str->Color.x / 255.0f, str->Color.y / 255.0f, str->Color.z / 255.0f, 1.0f));
}

View file

@ -2,9 +2,12 @@
#include "Utils.h"
#include <winerror.h>
#include <iostream>
#include <wrl/client.h>
namespace T5M::Renderer::Utils {
using std::wstring;
using std::string;
using Microsoft::WRL::ComPtr;
using std::vector;
void Utils::throwIfFailed(const HRESULT& res) noexcept {
if(FAILED(res)){
std::string message = std::system_category().message(res);
@ -14,32 +17,26 @@ namespace T5M::Renderer::Utils {
}
ID3D11VertexShader* compileVertexShader(ID3D11Device* device, const wstring& fileName, const string& function, const string& model, const D3D_SHADER_MACRO* defines, ID3D10Blob** bytecode) {
HRESULT res;
*bytecode = nullptr;
ID3DBlob* errors = nullptr;
ComPtr<ID3D11VertexShader> compileVertexShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO * defines, ComPtr<ID3D10Blob>& bytecode) noexcept {
ComPtr<ID3D10Blob> errors;
logD("Compiling vertex shader");
res = D3DCompileFromFile(fileName.c_str(), defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, function.c_str(), model.c_str(), GetShaderFlags(), 0, bytecode, &errors);
throwIfFailed(res);
throwIfFailed(D3DCompileFromFile(fileName.c_str(), defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, function.c_str(), model.c_str(), GetShaderFlags(), 0, bytecode.GetAddressOf(),errors.GetAddressOf()));
ID3D11VertexShader* shader = nullptr;
res = device->CreateVertexShader((*bytecode)->GetBufferPointer(), (*bytecode)->GetBufferSize(), nullptr, &shader);
throwIfFailed(res);
throwIfFailed(device->CreateVertexShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), nullptr, &shader));
return shader;
}
ID3D11PixelShader* compilePixelShader(ID3D11Device* device, const wstring& fileName, const string& function, const string& model, const D3D_SHADER_MACRO* defines, ID3D10Blob** bytecode) noexcept {
HRESULT res;
*bytecode = nullptr;
ID3DBlob* errors = nullptr;
ComPtr<ID3D11PixelShader> compilePixelShader(ID3D11Device* device, const wstring& fileName, const string& function, const string& model, const D3D_SHADER_MACRO* defines, ComPtr<ID3D10Blob>& bytecode) noexcept {
ComPtr<ID3D10Blob> errors;
logD("Compiling pixel shader");
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR | D3DCOMPILE_SKIP_OPTIMIZATION;
throwIfFailed(D3DCompileFromFile(fileName.c_str(), defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, function.c_str(), model.c_str(), GetShaderFlags(), 0, bytecode, &errors));
throwIfFailed(D3DCompileFromFile(fileName.c_str(), defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, function.c_str(), model.c_str(), GetShaderFlags(), 0, bytecode.GetAddressOf(), errors.GetAddressOf()));
ID3D11PixelShader* shader = nullptr;
throwIfFailed(device->CreatePixelShader((*bytecode)->GetBufferPointer(), (*bytecode)->GetBufferSize(), nullptr, &shader));
throwIfFailed(device->CreatePixelShader(bytecode->GetBufferPointer(), bytecode->GetBufferSize(), nullptr, &shader));
return shader;
}
UINT Utils::GetShaderFlags()
UINT Utils::GetShaderFlags() noexcept
{
UINT flags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
if constexpr(DebugBuild){

View file

@ -1,15 +1,21 @@
#pragma once
#include <winerror.h>
#include <string>
#include <wrl/client.h>
namespace T5M {
namespace Renderer {
namespace Utils {
//throws a std::exception when the result contains a FAILED result
//In most cases we cannot run the game if some Direct3D operation failed
void throwIfFailed(const HRESULT& res) noexcept;
ID3D11VertexShader* compileVertexShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO * defines, ID3D10Blob** bytecode);
UINT GetShaderFlags();
ID3D11PixelShader* compilePixelShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO * defines, ID3D10Blob** bytecode) noexcept;
[[nodiscard]]Microsoft::WRL::ComPtr<ID3D11VertexShader> compileVertexShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO* defines, Microsoft::WRL::ComPtr<ID3D10Blob>& bytecode) noexcept;
[[nodiscard]]UINT GetShaderFlags() noexcept;
[[nodiscard]]Microsoft::WRL::ComPtr<ID3D11PixelShader> compilePixelShader(ID3D11Device* device, const std::wstring& fileName, const std::string& function, const std::string& model, const D3D_SHADER_MACRO* defines, Microsoft::WRL::ComPtr<ID3D10Blob>& bytecode) noexcept;
template<typename T>
void setName(T* object, const std::string& name)
{
ID3D11DeviceChild* childPtr = nullptr;
object->QueryInterface<ID3D11DeviceChild>(&childPtr);
childPtr->SetPrivateData(WKPDID_D3DDebugObjectName, name.length(), name.c_str());
};
}
}
}