Minor Update - Log pour plus de fichier
This commit is contained in:
parent
56e58f88a6
commit
a84e42ce2c
@ -23,6 +23,8 @@ ColorShaderClass::~ColorShaderClass()
|
||||
|
||||
bool ColorShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
logger.Log("Initializing ColorShaderClass", __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
wchar_t vsFilename[128];
|
||||
wchar_t psFilename[128];
|
||||
@ -33,6 +35,7 @@ bool ColorShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(vsFilename, 128, L"../enginecustom/Color.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -40,6 +43,7 @@ bool ColorShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(psFilename, 128, L"../enginecustom/Color.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -47,9 +51,12 @@ bool ColorShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("ColorShaderClass initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -71,6 +78,7 @@ bool ColorShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -82,6 +90,8 @@ bool ColorShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount
|
||||
|
||||
bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
|
||||
{
|
||||
logger.Log("Initializing shader", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
ID3D10Blob* errorMessage;
|
||||
ID3D10Blob* vertexShaderBuffer;
|
||||
@ -109,7 +119,7 @@ bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -128,7 +138,7 @@ bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
// If there was nothing in the error message then it simply could not find the file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -138,6 +148,7 @@ bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -145,6 +156,7 @@ bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -174,6 +186,7 @@ bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
vertexShaderBuffer->GetBufferSize(), &m_layout);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -196,14 +209,19 @@ bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Shader initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ColorShaderClass::ShutdownShader()
|
||||
{
|
||||
logger.Log("Shutting down shader", __FILE__, __LINE__);
|
||||
|
||||
// Release the matrix constant buffer.
|
||||
if (m_matrixBuffer)
|
||||
{
|
||||
@ -232,6 +250,8 @@ void ColorShaderClass::ShutdownShader()
|
||||
m_vertexShader = 0;
|
||||
}
|
||||
|
||||
logger.Log("Shader shut down", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -273,6 +293,8 @@ void ColorShaderClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage, HWND h
|
||||
bool ColorShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
|
||||
XMMATRIX projectionMatrix)
|
||||
{
|
||||
logger.Log("Setting shader parameters", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||
MatrixBufferType* dataPtr;
|
||||
@ -287,6 +309,7 @@ bool ColorShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
||||
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <directxmath.h>
|
||||
@ -51,6 +52,8 @@ private:
|
||||
ID3D11PixelShader* m_pixelShader;
|
||||
ID3D11InputLayout* m_layout;
|
||||
ID3D11Buffer* m_matrixBuffer;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -30,6 +30,8 @@ LightShaderClass::~LightShaderClass()
|
||||
|
||||
bool LightShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
logger.Log("Initializing LightShaderClass", __FILE__, __LINE__);
|
||||
|
||||
wchar_t vsFilename[128];
|
||||
wchar_t psFilename[128];
|
||||
int error;
|
||||
@ -39,6 +41,7 @@ bool LightShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(vsFilename, 128, L"light.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -46,15 +49,19 @@ bool LightShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(psFilename, 128, L"light.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
// Initialize the vertex and pixel shaders.
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("LightShaderClass initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -77,6 +84,7 @@ bool LightShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition);
|
||||
if(!result)
|
||||
{
|
||||
logger.Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -119,7 +127,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -137,7 +145,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
// If there was nothing in the error message then it simply could not find the file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -147,6 +155,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -154,6 +163,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -191,6 +201,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
&m_layout);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -220,6 +231,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateSamplerState(&samplerDesc, &m_sampleState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -235,6 +247,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -252,6 +265,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateBuffer(&cameraBufferDesc, NULL, &m_cameraBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create camera buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -267,6 +281,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateBuffer(&lightColorBufferDesc, NULL, &m_lightColorBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create light color buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -282,15 +297,20 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateBuffer(&lightPositionBufferDesc, NULL, &m_lightPositionBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create light position buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Shader initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void LightShaderClass::ShutdownShader()
|
||||
{
|
||||
logger.Log("Shutting down LightShaderClass", __FILE__, __LINE__);
|
||||
|
||||
// Release the light constant buffers.
|
||||
if (m_lightColorBuffer)
|
||||
{
|
||||
@ -353,6 +373,8 @@ void LightShaderClass::ShutdownShader()
|
||||
m_vertexShader = 0;
|
||||
}
|
||||
|
||||
logger.Log("LightShaderClass shut down", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -412,6 +434,7 @@ bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
||||
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to map matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -436,6 +459,7 @@ bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
||||
result = deviceContext->Map(m_cameraBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to map camera buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -443,6 +467,7 @@ bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
||||
result = deviceContext->Map(m_lightPositionBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to map light position buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -471,6 +496,7 @@ bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
||||
result = deviceContext->Map(m_lightColorBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to map light color buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ const int NUM_LIGHTS = 4;
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <directxmath.h>
|
||||
@ -87,6 +88,8 @@ private:
|
||||
ID3D11Buffer* m_lightBuffer;
|
||||
ID3D11Buffer* m_lightColorBuffer;
|
||||
ID3D11Buffer* m_lightPositionBuffer;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -26,6 +26,8 @@ MultiTextureShaderClass::~MultiTextureShaderClass()
|
||||
|
||||
bool MultiTextureShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
logger.Log("Initializing MultiTextureShaderClass", __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
wchar_t vsFilename[128];
|
||||
wchar_t psFilename[128];
|
||||
@ -35,6 +37,7 @@ bool MultiTextureShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(vsFilename, 128, L"multitexture.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to set the filename of the vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -42,6 +45,7 @@ bool MultiTextureShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(psFilename, 128, L"multitexture.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to set the filename of the pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -49,6 +53,7 @@ bool MultiTextureShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize the vertex and pixel shaders", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -73,6 +78,7 @@ bool MultiTextureShaderClass::Render(ID3D11DeviceContext* deviceContext, int ind
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to set the shader parameters that it will use for rendering", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -84,6 +90,8 @@ bool MultiTextureShaderClass::Render(ID3D11DeviceContext* deviceContext, int ind
|
||||
|
||||
bool MultiTextureShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
|
||||
{
|
||||
logger.Log("Initializing the shader", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
ID3D10Blob* errorMessage;
|
||||
ID3D10Blob* vertexShaderBuffer;
|
||||
@ -112,7 +120,7 @@ bool MultiTextureShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd,
|
||||
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Failed to compile the vertex shader code", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -131,7 +139,7 @@ bool MultiTextureShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd,
|
||||
// If there was nothing in the error message then it simply could not find the file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Failed to compile the pixel shader code", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -141,6 +149,7 @@ bool MultiTextureShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd,
|
||||
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the vertex shader from the buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -148,6 +157,7 @@ bool MultiTextureShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd,
|
||||
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the pixel shader from the buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -184,6 +194,7 @@ bool MultiTextureShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd,
|
||||
vertexShaderBuffer->GetBufferSize(), &m_layout);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the vertex input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -206,6 +217,7 @@ bool MultiTextureShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd,
|
||||
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the constant buffer pointer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -228,14 +240,19 @@ bool MultiTextureShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd,
|
||||
result = device->CreateSamplerState(&samplerDesc, &m_sampleState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the texture sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Shader initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MultiTextureShaderClass::ShutdownShader()
|
||||
{
|
||||
logger.Log("Shutting down the shader", __FILE__, __LINE__);
|
||||
|
||||
// Release the sampler state.
|
||||
if (m_sampleState)
|
||||
{
|
||||
@ -271,6 +288,8 @@ void MultiTextureShaderClass::ShutdownShader()
|
||||
m_vertexShader = 0;
|
||||
}
|
||||
|
||||
logger.Log("Shader shut down", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -327,6 +346,7 @@ bool MultiTextureShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceCon
|
||||
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to lock the constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <directxmath.h>
|
||||
@ -52,6 +53,8 @@ private:
|
||||
ID3D11InputLayout* m_layout;
|
||||
ID3D11Buffer* m_matrixBuffer;
|
||||
ID3D11SamplerState* m_sampleState;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -23,6 +23,8 @@ AlphaMapShaderClass::~AlphaMapShaderClass()
|
||||
|
||||
bool AlphaMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
logger.Log("Initializing AlphaMapShaderClass", __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
wchar_t vsFilename[128];
|
||||
wchar_t psFilename[128];
|
||||
@ -32,6 +34,7 @@ bool AlphaMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(vsFilename, 128, L"alphamap.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Error copying string ", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -39,6 +42,7 @@ bool AlphaMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(psFilename, 128, L"alphamap.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -46,6 +50,7 @@ bool AlphaMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -84,6 +89,8 @@ bool AlphaMapShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCo
|
||||
|
||||
bool AlphaMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
|
||||
{
|
||||
logger.Log("Initializing shader", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
ID3D10Blob* errorMessage;
|
||||
ID3D10Blob* vertexShaderBuffer;
|
||||
@ -112,7 +119,7 @@ bool AlphaMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -131,7 +138,7 @@ bool AlphaMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
// If there was nothing in the error message then it simply could not find the file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -141,6 +148,7 @@ bool AlphaMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -148,6 +156,7 @@ bool AlphaMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -184,6 +193,7 @@ bool AlphaMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
vertexShaderBuffer->GetBufferSize(), &m_layout);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -206,6 +216,7 @@ bool AlphaMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -228,15 +239,21 @@ bool AlphaMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
result = device->CreateSamplerState(&samplerDesc, &m_sampleState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Shader initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void AlphaMapShaderClass::ShutdownShader()
|
||||
{
|
||||
|
||||
logger.Log("Shutting down shader", __FILE__, __LINE__);
|
||||
|
||||
// Release the sampler state.
|
||||
if (m_sampleState)
|
||||
{
|
||||
@ -272,6 +289,8 @@ void AlphaMapShaderClass::ShutdownShader()
|
||||
m_vertexShader = 0;
|
||||
}
|
||||
|
||||
logger.Log("Shader shutdown complete", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -330,6 +349,7 @@ bool AlphaMapShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext
|
||||
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -361,6 +381,7 @@ bool AlphaMapShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext
|
||||
|
||||
void AlphaMapShaderClass::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount)
|
||||
{
|
||||
|
||||
// Set the vertex input layout.
|
||||
deviceContext->IASetInputLayout(m_layout);
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <directxmath.h>
|
||||
@ -49,6 +50,8 @@ private:
|
||||
ID3D11InputLayout* m_layout;
|
||||
ID3D11Buffer* m_matrixBuffer;
|
||||
ID3D11SamplerState* m_sampleState;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -5,8 +5,6 @@
|
||||
///////////////////////
|
||||
// MY CLASS INCLUDES //
|
||||
///////////////////////
|
||||
#include "Logger.h"
|
||||
|
||||
#include "d3dclass.h"
|
||||
#include "cameraclass.h"
|
||||
#include "object.h"
|
||||
@ -166,7 +164,6 @@ private :
|
||||
// ------------------------------------------------- //
|
||||
// ------------------- LOGGER ---------------------- //
|
||||
// ------------------------------------------------- //
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
|
@ -20,6 +20,8 @@ BitmapClass::~BitmapClass()
|
||||
|
||||
bool BitmapClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, int screenWidth, int screenHeight, char* textureFilename, int renderX, int renderY)
|
||||
{
|
||||
logger.Log("Initializing bitmap class", __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
|
||||
// Store the screen size.
|
||||
@ -34,6 +36,7 @@ bool BitmapClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCo
|
||||
result = InitializeBuffers(device);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize buffers", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -41,9 +44,12 @@ bool BitmapClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCo
|
||||
result = LoadTexture(device, deviceContext, textureFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to load texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Bitmap class initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -67,6 +73,7 @@ bool BitmapClass::Render(ID3D11DeviceContext* deviceContext)
|
||||
result = UpdateBuffers(deviceContext);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to update buffers", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -88,6 +95,8 @@ ID3D11ShaderResourceView* BitmapClass::GetTexture()
|
||||
|
||||
bool BitmapClass::InitializeBuffers(ID3D11Device* device)
|
||||
{
|
||||
logger.Log("Initializing buffers", __FILE__, __LINE__);
|
||||
|
||||
VertexType* vertices;
|
||||
unsigned long* indices;
|
||||
D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
|
||||
@ -137,6 +146,7 @@ bool BitmapClass::InitializeBuffers(ID3D11Device* device)
|
||||
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -157,6 +167,7 @@ bool BitmapClass::InitializeBuffers(ID3D11Device* device)
|
||||
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create index buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -167,6 +178,8 @@ bool BitmapClass::InitializeBuffers(ID3D11Device* device)
|
||||
delete[] indices;
|
||||
indices = 0;
|
||||
|
||||
logger.Log("Buffers initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -247,6 +260,7 @@ bool BitmapClass::UpdateBuffers(ID3D11DeviceContext* deviceContent)
|
||||
result = deviceContent->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to map vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -302,6 +316,7 @@ bool BitmapClass::LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceC
|
||||
result = m_Texture->Initialize(device, deviceContext, filename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize texture object", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,8 @@ private:
|
||||
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
|
||||
int m_vertexCount, m_indexCount, m_screenWidth, m_screenHeight, m_bitmapWidth, m_bitmapHeight, m_renderX, m_renderY, m_prevPosX, m_prevPosY;
|
||||
TextureClass* m_Texture;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -32,6 +32,8 @@ D3DClass::~D3DClass()
|
||||
|
||||
bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen, float screenDepth, float screenNear)
|
||||
{
|
||||
logger.Log("Initializing D3Dclass", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
IDXGIFactory* factory;
|
||||
IDXGIAdapter* adapter;
|
||||
@ -59,6 +61,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create DXGIFactory", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -66,6 +69,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = factory->EnumAdapters(0, &adapter);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create adapter", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -73,6 +77,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = adapter->EnumOutputs(0, &adapterOutput);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create adapter output", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -80,6 +85,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to get display mode list", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -87,6 +93,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
displayModeList = new DXGI_MODE_DESC[numModes];
|
||||
if (!displayModeList)
|
||||
{
|
||||
logger.Log("Failed to create display mode list", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -94,6 +101,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to fill display mode list", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -115,6 +123,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = adapter->GetDesc(&adapterDesc);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to get adapter description", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -125,6 +134,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
error = wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128);
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to convert video card name to character array", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -207,6 +217,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create swap chain, device and device context", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -214,6 +225,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferPtr);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to get pointer to back buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -221,6 +233,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = m_device->CreateRenderTargetView(backBufferPtr, NULL, &m_renderTargetView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create render target view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -248,6 +261,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create texture for depth buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -279,6 +293,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = m_device->CreateDepthStencilState(&depthStencilDesc, &m_depthStencilState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create depth stencil state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -297,7 +312,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
MessageBox(hwnd, L"Could not create the depth stencil view.", L"Error", MB_OK);
|
||||
logger.Log("Failed to create depth stencil view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -320,6 +335,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = m_device->CreateRasterizerState(&rasterDesc, &m_rasterState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create rasterizer state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -374,6 +390,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = m_device->CreateDepthStencilState(&depthDisabledStencilDesc, &m_depthDisabledStencilState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create depth disabled stencil state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -394,6 +411,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = m_device->CreateBlendState(&blendStateDescription, &m_alphaEnableBlendingState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create alpha enabled blend state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -404,6 +422,7 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
result = m_device->CreateBlendState(&blendStateDescription, &m_alphaDisableBlendingState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create alpha disabled blend state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -413,6 +432,9 @@ bool D3DClass::Initialize(int screenWidth, int screenHeight, bool vsync, HWND hw
|
||||
|
||||
void D3DClass::Shutdown()
|
||||
{
|
||||
|
||||
logger.Log("Shutting down D3Dclass", __FILE__, __LINE__);
|
||||
|
||||
// Before shutting down set to windowed mode or when you release the swap chain it will throw an exception.
|
||||
if (m_swapChain)
|
||||
{
|
||||
@ -485,6 +507,8 @@ void D3DClass::Shutdown()
|
||||
m_swapChain = 0;
|
||||
}
|
||||
|
||||
logger.Log("D3Dclass shutdown", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -590,6 +614,8 @@ void D3DClass::ResetViewport()
|
||||
|
||||
void D3DClass::ReleaseResources()
|
||||
{
|
||||
logger.Log("Releasing D3D resources", __FILE__, __LINE__);
|
||||
|
||||
// libere la vue
|
||||
if (m_renderTargetView)
|
||||
{
|
||||
@ -610,15 +636,38 @@ void D3DClass::ReleaseResources()
|
||||
m_depthStencilView->Release();
|
||||
m_depthStencilView = 0;
|
||||
}
|
||||
|
||||
logger.Log("D3D resources released", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
// Reset the resources for the swap chain
|
||||
void D3DClass::ResetResources(int newWidth, int newHeight)
|
||||
{
|
||||
logger.Log("Resetting D3D resources", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
|
||||
ID3D11Texture2D* backBuffer;
|
||||
m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer);
|
||||
m_device->CreateRenderTargetView(backBuffer, NULL, &m_renderTargetView);
|
||||
backBuffer->Release();
|
||||
result = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to get back buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
result = m_device->CreateRenderTargetView(backBuffer, NULL, &m_renderTargetView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create render target view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
result = backBuffer->Release();
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to release back buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Recreate the depth/stencil buffer and view
|
||||
D3D11_TEXTURE2D_DESC depthBufferDesc;
|
||||
@ -642,8 +691,19 @@ void D3DClass::ResetResources(int newWidth, int newHeight)
|
||||
depthStencilViewDesc.Texture2D.MipSlice = 0;
|
||||
|
||||
// Other depthStencilDesc settings...
|
||||
m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
|
||||
m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
||||
result = m_device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create depth stencil buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
result = m_device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create depth stencil view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the new render target and depth/stencil views for rendering
|
||||
m_deviceContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthStencilView);
|
||||
@ -656,6 +716,9 @@ IDXGISwapChain* D3DClass::GetSwapChain()
|
||||
|
||||
void D3DClass::ResizeSwapChain(int newWidth, int newHeight)
|
||||
{
|
||||
|
||||
logger.Log("Resizing swap chain", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
|
||||
// Release existing DirectX resources
|
||||
@ -666,7 +729,7 @@ void D3DClass::ResizeSwapChain(int newWidth, int newHeight)
|
||||
result = m_swapChain->ResizeBuffers(0, newWidth, newHeight, DXGI_FORMAT_UNKNOWN, 0);
|
||||
if (FAILED(result))
|
||||
{
|
||||
MessageBox(NULL, L"Failed to resize the swap chain.", L"Error", MB_OK);
|
||||
logger.Log("Failed to resize swap chain", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,9 @@ private:
|
||||
ID3D11DepthStencilState* m_depthDisabledStencilState;
|
||||
ID3D11BlendState* m_alphaEnableBlendingState;
|
||||
ID3D11BlendState* m_alphaDisableBlendingState;
|
||||
|
||||
// Logger
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -19,6 +19,7 @@ DisplayPlaneClass::~DisplayPlaneClass()
|
||||
|
||||
bool DisplayPlaneClass::Initialize(ID3D11Device* device, float width, float height)
|
||||
{
|
||||
logger.Log("Initializing DisplayPlaneClass, width: " + std::to_string(width) + ", height: " + std::to_string(height), __FILE__, __LINE__);
|
||||
bool result;
|
||||
|
||||
|
||||
@ -26,6 +27,7 @@ bool DisplayPlaneClass::Initialize(ID3D11Device* device, float width, float heig
|
||||
result = InitializeBuffers(device, width, height);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Could not initialize buffers", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -58,6 +60,8 @@ int DisplayPlaneClass::GetIndexCount()
|
||||
|
||||
bool DisplayPlaneClass::InitializeBuffers(ID3D11Device* device, float width, float height)
|
||||
{
|
||||
logger.Log("Initializing buffers", __FILE__, __LINE__);
|
||||
|
||||
VertexType* vertices;
|
||||
unsigned long* indices;
|
||||
D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
|
||||
@ -122,6 +126,7 @@ bool DisplayPlaneClass::InitializeBuffers(ID3D11Device* device, float width, flo
|
||||
result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Could not create vertex buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -142,6 +147,7 @@ bool DisplayPlaneClass::InitializeBuffers(ID3D11Device* device, float width, flo
|
||||
result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Could not create index buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -152,6 +158,8 @@ bool DisplayPlaneClass::InitializeBuffers(ID3D11Device* device, float width, flo
|
||||
delete[] indices;
|
||||
indices = 0;
|
||||
|
||||
logger.Log("Buffers initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,8 @@ private:
|
||||
private:
|
||||
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
|
||||
int m_vertexCount, m_indexCount;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -18,6 +18,8 @@ FontClass::~FontClass()
|
||||
|
||||
bool FontClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, int fontChoice)
|
||||
{
|
||||
logger.Log("Initializing font class", __FILE__, __LINE__);
|
||||
|
||||
char fontFilename[128];
|
||||
char fontTextureFilename[128];
|
||||
bool result;
|
||||
@ -47,6 +49,7 @@ bool FontClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCont
|
||||
result = LoadFontData(fontFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to load font data", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -54,9 +57,12 @@ bool FontClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCont
|
||||
result = LoadTexture(device, deviceContext, fontTextureFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to load font texture", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Font class initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -73,6 +79,8 @@ void FontClass::Shutdown()
|
||||
|
||||
bool FontClass::LoadFontData(char* filename)
|
||||
{
|
||||
logger.Log(("Loading font data from %s", filename), __FILE__, __LINE__);
|
||||
|
||||
std::ifstream fin;
|
||||
int i;
|
||||
char temp;
|
||||
@ -84,6 +92,7 @@ bool FontClass::LoadFontData(char* filename)
|
||||
fin.open(filename);
|
||||
if (fin.fail())
|
||||
{
|
||||
logger.Log("Failed to open font file", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -109,6 +118,8 @@ bool FontClass::LoadFontData(char* filename)
|
||||
// Close the file.
|
||||
fin.close();
|
||||
|
||||
logger.Log("Font data loaded", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -126,6 +137,8 @@ void FontClass::ReleaseFontData()
|
||||
|
||||
bool FontClass::LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* filename)
|
||||
{
|
||||
logger.Log(("Loading font texture from %s", filename), __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
|
||||
|
||||
@ -135,9 +148,12 @@ bool FontClass::LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceCon
|
||||
result = m_Texture->Initialize(device, deviceContext, filename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize font texture", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Font texture loaded", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,8 @@ private:
|
||||
TextureClass* m_Texture;
|
||||
float m_fontHeight;
|
||||
int m_spaceSize;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -24,6 +24,8 @@ FontShaderClass::~FontShaderClass()
|
||||
|
||||
bool FontShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
logger.Log("Initializing FontShaderClass", __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
wchar_t vsFilename[128];
|
||||
wchar_t psFilename[128];
|
||||
@ -33,6 +35,7 @@ bool FontShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(vsFilename, 128, L"font.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -40,6 +43,7 @@ bool FontShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(psFilename, 128, L"font.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -47,8 +51,11 @@ bool FontShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("FontShaderClass initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -71,6 +78,7 @@ bool FontShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount,
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, pixelColor);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -82,6 +90,8 @@ bool FontShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount,
|
||||
|
||||
bool FontShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
|
||||
{
|
||||
logger.Log("Initializing shader", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
ID3D10Blob* errorMessage;
|
||||
ID3D10Blob* vertexShaderBuffer;
|
||||
@ -111,7 +121,7 @@ bool FontShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* v
|
||||
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -130,7 +140,7 @@ bool FontShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* v
|
||||
// If there was nothing in the error message then it simply could not find the file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -140,6 +150,7 @@ bool FontShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* v
|
||||
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -147,6 +158,7 @@ bool FontShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* v
|
||||
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -175,6 +187,7 @@ bool FontShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* v
|
||||
vertexShaderBuffer->GetBufferSize(), &m_layout);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -197,6 +210,7 @@ bool FontShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* v
|
||||
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -219,6 +233,7 @@ bool FontShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* v
|
||||
result = device->CreateSamplerState(&samplerDesc, &m_sampleState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -234,14 +249,19 @@ bool FontShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* v
|
||||
result = device->CreateBuffer(&pixelBufferDesc, NULL, &m_pixelBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Shader initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FontShaderClass::ShutdownShader()
|
||||
{
|
||||
logger.Log("Shutting down shader", __FILE__, __LINE__);
|
||||
|
||||
// Release the pixel constant buffer.
|
||||
if (m_pixelBuffer)
|
||||
{
|
||||
@ -284,6 +304,8 @@ void FontShaderClass::ShutdownShader()
|
||||
m_vertexShader = 0;
|
||||
}
|
||||
|
||||
logger.Log("Shader shut down", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -325,6 +347,7 @@ void FontShaderClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage, HWND hw
|
||||
bool FontShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
|
||||
XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture, XMFLOAT4 pixelColor)
|
||||
{
|
||||
|
||||
HRESULT result;
|
||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||
MatrixBufferType* dataPtr;
|
||||
@ -341,6 +364,7 @@ bool FontShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XM
|
||||
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -368,6 +392,7 @@ bool FontShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XM
|
||||
result = deviceContext->Map(m_pixelBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <directxmath.h>
|
||||
@ -55,6 +56,8 @@ private:
|
||||
ID3D11Buffer* m_matrixBuffer;
|
||||
ID3D11SamplerState* m_sampleState;
|
||||
ID3D11Buffer* m_pixelBuffer;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -20,6 +20,8 @@ InputClass::~InputClass()
|
||||
|
||||
bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight)
|
||||
{
|
||||
logger.Log("Initializing input class", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
int i;
|
||||
|
||||
@ -42,6 +44,7 @@ bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int
|
||||
result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create direct input interface", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -49,6 +52,7 @@ bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int
|
||||
result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create direct input interface for the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -56,6 +60,7 @@ bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int
|
||||
result = m_keyboard->SetDataFormat(&c_dfDIKeyboard);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to set data format for the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -63,6 +68,7 @@ bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int
|
||||
result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to set cooperative level of the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -70,6 +76,7 @@ bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int
|
||||
result = m_keyboard->Acquire();
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to acquire the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -77,6 +84,7 @@ bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int
|
||||
result = m_directInput->CreateDevice(GUID_SysMouse, &m_mouse, NULL);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create direct input interface for the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -84,6 +92,7 @@ bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int
|
||||
result = m_mouse->SetDataFormat(&c_dfDIMouse);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to set data format for the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -91,6 +100,7 @@ bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int
|
||||
result = m_mouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to set cooperative level of the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -98,9 +108,12 @@ bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int
|
||||
result = m_mouse->Acquire();
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to acquire the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Input class initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -131,6 +144,8 @@ bool InputClass::IsKeyDown(unsigned int key)
|
||||
|
||||
void InputClass::Shutdown()
|
||||
{
|
||||
logger.Log("Shutting down input class", __FILE__, __LINE__);
|
||||
|
||||
// Release the mouse.
|
||||
if (m_mouse)
|
||||
{
|
||||
@ -154,6 +169,8 @@ void InputClass::Shutdown()
|
||||
m_directInput = 0;
|
||||
}
|
||||
|
||||
logger.Log("Input class shut down", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -166,6 +183,7 @@ bool InputClass::Frame()
|
||||
result = ReadKeyboard();
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to read keyboard state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -173,6 +191,7 @@ bool InputClass::Frame()
|
||||
result = ReadMouse();
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to read mouse state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -198,6 +217,7 @@ bool InputClass::ReadKeyboard()
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Log("Failed to get keyboard device state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -221,6 +241,7 @@ bool InputClass::ReadMouse()
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Log("Failed to get mouse device state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <dinput.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -64,6 +65,8 @@ private:
|
||||
DIMOUSESTATE m_mouseState;
|
||||
|
||||
int m_screenWidth, m_screenHeight, m_mouseX, m_mouseY;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -23,6 +23,8 @@ LightMapShaderClass::~LightMapShaderClass()
|
||||
|
||||
bool LightMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
logger.Log("Initializing LightMapShaderClass", __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
wchar_t vsFilename[128];
|
||||
wchar_t psFilename[128];
|
||||
@ -32,6 +34,7 @@ bool LightMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(vsFilename, 128, L"lightmap.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -39,6 +42,7 @@ bool LightMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(psFilename, 128, L"lightmap.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -46,9 +50,12 @@ bool LightMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("LightMapShaderClass initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -72,6 +79,7 @@ bool LightMapShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCo
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -112,7 +120,7 @@ bool LightMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -131,7 +139,7 @@ bool LightMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
// If there was nothing in the error message then it simply could not find the file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -141,6 +149,7 @@ bool LightMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -148,6 +157,7 @@ bool LightMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -184,6 +194,7 @@ bool LightMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
vertexShaderBuffer->GetBufferSize(), &m_layout);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -206,6 +217,7 @@ bool LightMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -228,15 +240,20 @@ bool LightMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHA
|
||||
result = device->CreateSamplerState(&samplerDesc, &m_sampleState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Shader initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void LightMapShaderClass::ShutdownShader()
|
||||
{
|
||||
logger.Log("Shutting down LightMapShaderClass", __FILE__, __LINE__);
|
||||
|
||||
// Release the sampler state.
|
||||
if (m_sampleState)
|
||||
{
|
||||
@ -272,6 +289,8 @@ void LightMapShaderClass::ShutdownShader()
|
||||
m_vertexShader = 0;
|
||||
}
|
||||
|
||||
logger.Log("LightMapShaderClass shut down", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -330,6 +349,7 @@ bool LightMapShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext
|
||||
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <directxmath.h>
|
||||
@ -50,6 +51,8 @@ private:
|
||||
ID3D11InputLayout* m_layout;
|
||||
ID3D11Buffer* m_matrixBuffer;
|
||||
ID3D11SamplerState* m_sampleState;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -30,6 +30,8 @@ LightShaderClass::~LightShaderClass()
|
||||
|
||||
bool LightShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
logger.Log("Initializing LightShaderClass", __FILE__, __LINE__);
|
||||
|
||||
wchar_t vsFilename[128];
|
||||
wchar_t psFilename[128];
|
||||
int error;
|
||||
@ -39,6 +41,7 @@ bool LightShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(vsFilename, 128, L"light.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -46,15 +49,19 @@ bool LightShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(psFilename, 128, L"light.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
// Initialize the vertex and pixel shaders.
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("LightShaderClass initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -77,6 +84,7 @@ bool LightShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, lightPosition);
|
||||
if(!result)
|
||||
{
|
||||
logger.Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -119,7 +127,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -137,7 +145,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
// If there was nothing in the error message then it simply could not find the file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -147,6 +155,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -154,6 +163,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -191,6 +201,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
&m_layout);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -220,6 +231,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateSamplerState(&samplerDesc, &m_sampleState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -235,6 +247,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -252,6 +265,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateBuffer(&cameraBufferDesc, NULL, &m_cameraBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create camera buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -267,6 +281,7 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateBuffer(&lightColorBufferDesc, NULL, &m_lightColorBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create light color buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -282,15 +297,20 @@ bool LightShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR*
|
||||
result = device->CreateBuffer(&lightPositionBufferDesc, NULL, &m_lightPositionBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create light position buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Shader initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void LightShaderClass::ShutdownShader()
|
||||
{
|
||||
logger.Log("Shutting down LightShaderClass", __FILE__, __LINE__);
|
||||
|
||||
// Release the light constant buffers.
|
||||
if (m_lightColorBuffer)
|
||||
{
|
||||
@ -353,6 +373,8 @@ void LightShaderClass::ShutdownShader()
|
||||
m_vertexShader = 0;
|
||||
}
|
||||
|
||||
logger.Log("LightShaderClass shut down", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -412,6 +434,7 @@ bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
||||
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to map matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -436,6 +459,7 @@ bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
||||
result = deviceContext->Map(m_cameraBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to map camera buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -443,6 +467,7 @@ bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
||||
result = deviceContext->Map(m_lightPositionBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to map light position buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -471,6 +496,7 @@ bool LightShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, X
|
||||
result = deviceContext->Map(m_lightColorBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to map light color buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ const int NUM_LIGHTS = 4;
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <directxmath.h>
|
||||
@ -87,6 +88,8 @@ private:
|
||||
ID3D11Buffer* m_lightBuffer;
|
||||
ID3D11Buffer* m_lightColorBuffer;
|
||||
ID3D11Buffer* m_lightPositionBuffer;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -24,6 +24,8 @@ NormalMapShaderClass::~NormalMapShaderClass()
|
||||
|
||||
bool NormalMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
logger.Log("Initializing normal map shader", __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
wchar_t vsFilename[128];
|
||||
wchar_t psFilename[128];
|
||||
@ -33,6 +35,7 @@ bool NormalMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(vsFilename, 128, L"normalmap.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to set the filename of the vertex shader", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -40,6 +43,7 @@ bool NormalMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(psFilename, 128, L"normalmap.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to set the filename of the pixel shader", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -47,6 +51,7 @@ bool NormalMapShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize the vertex and pixel shaders", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -72,6 +77,7 @@ bool NormalMapShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexC
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, lightDirection, diffuseColor);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to set the shader parameters that will be used for rendering", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -84,6 +90,8 @@ bool NormalMapShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexC
|
||||
|
||||
bool NormalMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
|
||||
{
|
||||
logger.Log("Initializing normal map shader", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
ID3D10Blob* errorMessage;
|
||||
ID3D10Blob* vertexShaderBuffer;
|
||||
@ -113,7 +121,7 @@ bool NormalMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCH
|
||||
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Failed to compile the vertex shader code", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -132,7 +140,7 @@ bool NormalMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCH
|
||||
// If there was nothing in the error message then it simply could not find the file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Failed to compile the pixel shader code", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -142,6 +150,7 @@ bool NormalMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCH
|
||||
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the vertex shader from the buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -149,6 +158,7 @@ bool NormalMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCH
|
||||
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the pixel shader from the buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -201,6 +211,7 @@ bool NormalMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCH
|
||||
vertexShaderBuffer->GetBufferSize(), &m_layout);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the vertex input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -223,6 +234,7 @@ bool NormalMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCH
|
||||
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the constant buffer pointer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -245,6 +257,7 @@ bool NormalMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCH
|
||||
result = device->CreateSamplerState(&samplerDesc, &m_sampleState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the texture sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -260,15 +273,20 @@ bool NormalMapShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCH
|
||||
result = device->CreateBuffer(&lightBufferDesc, NULL, &m_lightBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create the light constant buffer pointer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Successfully initialized normal map shader", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void NormalMapShaderClass::ShutdownShader()
|
||||
{
|
||||
logger.Log("Shutting down normal map shader", __FILE__, __LINE__);
|
||||
|
||||
// Release the light constant buffer.
|
||||
if (m_lightBuffer)
|
||||
{
|
||||
@ -311,6 +329,8 @@ void NormalMapShaderClass::ShutdownShader()
|
||||
m_vertexShader = 0;
|
||||
}
|
||||
|
||||
logger.Log("Successfully shut down normal map shader", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -370,6 +390,7 @@ bool NormalMapShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContex
|
||||
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to lock the constant buffer so it can be written to", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -398,6 +419,7 @@ bool NormalMapShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContex
|
||||
result = deviceContext->Map(m_lightBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to lock the light constant buffer so it can be written to", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <directxmath.h>
|
||||
@ -57,6 +58,8 @@ private:
|
||||
ID3D11Buffer* m_matrixBuffer;
|
||||
ID3D11SamplerState* m_sampleState;
|
||||
ID3D11Buffer* m_lightBuffer;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -21,6 +21,8 @@ ReflectionShaderClass::~ReflectionShaderClass()
|
||||
|
||||
bool ReflectionShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
logger.Log("Initializing reflection shader", __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
wchar_t vsFilename[128];
|
||||
wchar_t psFilename[128];
|
||||
@ -30,6 +32,7 @@ bool ReflectionShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(vsFilename, 128, L"../Engine/reflection.vs");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -37,6 +40,7 @@ bool ReflectionShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
error = wcscpy_s(psFilename, 128, L"../Engine/reflection.ps");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Error copying string", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -44,6 +48,7 @@ bool ReflectionShaderClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = InitializeShader(device, hwnd, vsFilename, psFilename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -68,6 +73,7 @@ bool ReflectionShaderClass::Render(ID3D11DeviceContext* deviceContext, int index
|
||||
result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, reflectionTexture, reflectionMatrix);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error setting shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -79,6 +85,8 @@ bool ReflectionShaderClass::Render(ID3D11DeviceContext* deviceContext, int index
|
||||
|
||||
bool ReflectionShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
|
||||
{
|
||||
logger.Log("Initializing reflection shader", __FILE__, __LINE__);
|
||||
|
||||
HRESULT result;
|
||||
ID3D10Blob* errorMessage;
|
||||
ID3D10Blob* vertexShaderBuffer;
|
||||
@ -108,7 +116,7 @@ bool ReflectionShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WC
|
||||
// If there was nothing in the error message then it simply could not find the shader file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -126,7 +134,7 @@ bool ReflectionShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WC
|
||||
// If there was nothing in the error message then it simply could not find the file itself.
|
||||
else
|
||||
{
|
||||
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
|
||||
logger.Log("Error compiling shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -136,6 +144,7 @@ bool ReflectionShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WC
|
||||
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -143,6 +152,7 @@ bool ReflectionShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WC
|
||||
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -171,6 +181,7 @@ bool ReflectionShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WC
|
||||
vertexShaderBuffer->GetBufferSize(), &m_layout);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating input layout", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -193,6 +204,7 @@ bool ReflectionShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WC
|
||||
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
// Create a texture sampler state description.
|
||||
@ -214,6 +226,7 @@ bool ReflectionShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WC
|
||||
result = device->CreateSamplerState(&samplerDesc, &m_sampleState);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating sampler state", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
// Setup the description of the reflection dynamic constant buffer that is in the vertex shader.
|
||||
@ -228,14 +241,18 @@ bool ReflectionShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WC
|
||||
result = device->CreateBuffer(&reflectionBufferDesc, NULL, &m_reflectionBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error creating constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("Reflection shader initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ReflectionShaderClass::ShutdownShader()
|
||||
{
|
||||
logger.Log("Shutting down reflection shader", __FILE__, __LINE__);
|
||||
|
||||
// Release the reflection constant buffer.
|
||||
if (m_reflectionBuffer)
|
||||
@ -279,6 +296,8 @@ void ReflectionShaderClass::ShutdownShader()
|
||||
m_vertexShader = 0;
|
||||
}
|
||||
|
||||
logger.Log("Reflection shader shut down", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -340,6 +359,7 @@ bool ReflectionShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceConte
|
||||
result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -364,6 +384,7 @@ bool ReflectionShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceConte
|
||||
result = deviceContext->Map(m_reflectionBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Error mapping constant buffer", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <directxmath.h>
|
||||
@ -58,6 +59,8 @@ private:
|
||||
ID3D11Buffer* m_matrixBuffer;
|
||||
ID3D11SamplerState* m_sampleState;
|
||||
ID3D11Buffer* m_reflectionBuffer;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -21,6 +21,8 @@ RenderTextureClass::~RenderTextureClass()
|
||||
|
||||
bool RenderTextureClass::Initialize(ID3D11Device * device, int textureWidth, int textureHeight, float screenDepth, float screenNear, int format)
|
||||
{
|
||||
logger.Log("Initializing RenderTextureClass", __FILE__, __LINE__);
|
||||
|
||||
D3D11_TEXTURE2D_DESC textureDesc;
|
||||
HRESULT result;
|
||||
D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
|
||||
@ -68,6 +70,7 @@ bool RenderTextureClass::Initialize(ID3D11Device * device, int textureWidth, int
|
||||
result = device->CreateTexture2D(&textureDesc, NULL, &m_renderTargetTexture);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create render target texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -80,6 +83,7 @@ bool RenderTextureClass::Initialize(ID3D11Device * device, int textureWidth, int
|
||||
result = device->CreateRenderTargetView(m_renderTargetTexture, &renderTargetViewDesc, &m_renderTargetView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create render target view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -93,6 +97,7 @@ bool RenderTextureClass::Initialize(ID3D11Device * device, int textureWidth, int
|
||||
result = device->CreateShaderResourceView(m_renderTargetTexture, &shaderResourceViewDesc, &m_shaderResourceView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create shader resource view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -116,6 +121,7 @@ bool RenderTextureClass::Initialize(ID3D11Device * device, int textureWidth, int
|
||||
result = device->CreateTexture2D(&depthBufferDesc, NULL, &m_depthStencilBuffer);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create depth buffer texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -131,6 +137,7 @@ bool RenderTextureClass::Initialize(ID3D11Device * device, int textureWidth, int
|
||||
result = device->CreateDepthStencilView(m_depthStencilBuffer, &depthStencilViewDesc, &m_depthStencilView);
|
||||
if (FAILED(result))
|
||||
{
|
||||
logger.Log("Failed to create depth stencil view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -148,11 +155,15 @@ bool RenderTextureClass::Initialize(ID3D11Device * device, int textureWidth, int
|
||||
// Create an orthographic projection matrix for 2D rendering.
|
||||
m_orthoMatrix = XMMatrixOrthographicLH((float)textureWidth, (float)textureHeight, screenNear, screenDepth);
|
||||
|
||||
logger.Log("RenderTextureClass initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderTextureClass::Shutdown()
|
||||
{
|
||||
logger.Log("Shutting down RenderTextureClass", __FILE__, __LINE__);
|
||||
|
||||
if (m_depthStencilView)
|
||||
{
|
||||
m_depthStencilView->Release();
|
||||
@ -183,6 +194,8 @@ void RenderTextureClass::Shutdown()
|
||||
m_renderTargetTexture = 0;
|
||||
}
|
||||
|
||||
logger.Log("RenderTextureClass shut down", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <directxmath.h>
|
||||
using namespace DirectX;
|
||||
@ -46,6 +47,8 @@ private:
|
||||
D3D11_VIEWPORT m_viewport;
|
||||
XMMATRIX m_projectionMatrix;
|
||||
XMMATRIX m_orthoMatrix;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -24,6 +24,8 @@ ShaderManagerClass::~ShaderManagerClass()
|
||||
|
||||
bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
{
|
||||
logger.Log("Initializing ShaderManagerClass", __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
|
||||
// Create and initialize the texture shader object.
|
||||
@ -32,6 +34,7 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = m_TextureShader->Initialize(device, hwnd);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing TextureShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -41,6 +44,7 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = m_NormalMapShader->Initialize(device, hwnd);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing NormalMapShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -50,6 +54,7 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = m_MultitextureShader->Initialize(device, hwnd);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing MultiTextureShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -59,6 +64,7 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = m_TranslateShader->Initialize(device, hwnd);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing TranslateShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -68,6 +74,7 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = m_AlphaMapShader->Initialize(device, hwnd);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing AlphaMapShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -77,6 +84,7 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = m_SpecMapShader->Initialize(device, hwnd);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing SpecMapShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -86,14 +94,19 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd)
|
||||
result = m_TransparentShader->Initialize(device, hwnd);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error initializing TransparentShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.Log("ShaderManagerClass initialized", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ShaderManagerClass::Shutdown()
|
||||
{
|
||||
logger.Log("Shutting down ShaderManagerClass", __FILE__, __LINE__);
|
||||
|
||||
// Release the normal map shader object.
|
||||
if (m_NormalMapShader)
|
||||
{
|
||||
@ -150,6 +163,8 @@ void ShaderManagerClass::Shutdown()
|
||||
m_TransparentShader = 0;
|
||||
}
|
||||
|
||||
logger.Log("ShaderManagerClass shut down", __FILE__, __LINE__);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
@ -163,6 +178,7 @@ bool ShaderManagerClass::RenderTextureShader(ID3D11DeviceContext* deviceContext,
|
||||
result = m_TextureShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error rendering TextureShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -178,6 +194,7 @@ bool ShaderManagerClass::RenderNormalMapShader(ID3D11DeviceContext* deviceContex
|
||||
result = m_NormalMapShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, colorTexture, normalTexture, lightDirection, diffuseColor);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error rendering NormalMapShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -193,6 +210,7 @@ bool ShaderManagerClass::RenderMultitextureShader(ID3D11DeviceContext* deviceCon
|
||||
result = m_MultitextureShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error rendering MultiTextureShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -208,6 +226,7 @@ bool ShaderManagerClass::RenderTranslateShader(ID3D11DeviceContext* deviceContex
|
||||
result = m_TranslateShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, valeur);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error rendering TranslateShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -223,6 +242,7 @@ bool ShaderManagerClass::RenderAlphaMapShader(ID3D11DeviceContext* deviceContext
|
||||
result = m_AlphaMapShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, texture2, texture3);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error rendering AlphaMapShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -240,6 +260,7 @@ bool ShaderManagerClass::RenderSpecMapShader(ID3D11DeviceContext* deviceContext,
|
||||
diffuseColor, cameraPosition, specularColor, specularPower);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error rendering SpecMapShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -255,6 +276,7 @@ bool ShaderManagerClass::RenderTransparentShader(ID3D11DeviceContext* deviceCont
|
||||
result = m_TransparentShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture1, blendAmount);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Error rendering TransparentShaderClass", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@ private:
|
||||
AlphaMapShaderClass* m_AlphaMapShader;
|
||||
SpecMapShaderClass* m_SpecMapShader;
|
||||
TransparentShaderClass* m_TransparentShader;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
@ -19,6 +19,8 @@ TextureClass::~TextureClass()
|
||||
|
||||
bool TextureClass::Initialize(ID3D11Device * device, ID3D11DeviceContext * deviceContext, char* filename)
|
||||
{
|
||||
logger.Log(("Iinitializing texture: %s", filename), __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
D3D11_TEXTURE2D_DESC textureDesc;
|
||||
HRESULT hResult;
|
||||
@ -28,6 +30,7 @@ bool TextureClass::Initialize(ID3D11Device * device, ID3D11DeviceContext * devic
|
||||
result = LoadTarga(filename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to load targa data", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
// Setup the description of the texture.
|
||||
@ -47,6 +50,7 @@ bool TextureClass::Initialize(ID3D11Device * device, ID3D11DeviceContext * devic
|
||||
hResult = device->CreateTexture2D(&textureDesc, NULL, &m_texture);
|
||||
if (FAILED(hResult))
|
||||
{
|
||||
logger.Log("Failed to create texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -64,6 +68,7 @@ bool TextureClass::Initialize(ID3D11Device * device, ID3D11DeviceContext * devic
|
||||
hResult = device->CreateShaderResourceView(m_texture, &srvDesc, &m_textureView);
|
||||
if (FAILED(hResult))
|
||||
{
|
||||
logger.Log("Failed to create shader resource view", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -121,6 +126,7 @@ bool TextureClass::LoadTarga(char* filename)
|
||||
error = fopen_s(&filePtr, filename, "rb");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to open targa file", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -128,6 +134,7 @@ bool TextureClass::LoadTarga(char* filename)
|
||||
count = (unsigned int)fread(&targaFileHeader, sizeof(TargaHeader), 1, filePtr);
|
||||
if (count != 1)
|
||||
{
|
||||
logger.Log("Failed to read targa file header", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -139,6 +146,7 @@ bool TextureClass::LoadTarga(char* filename)
|
||||
// Check that it is 32 bit and not 24 bit.
|
||||
if (bpp != 32 && bpp != 24)
|
||||
{
|
||||
logger.Log("Targa file is not 32 or 24 bit", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -152,6 +160,7 @@ bool TextureClass::LoadTarga(char* filename)
|
||||
count = (unsigned int)fread(targaImage, 1, imageSize, filePtr);
|
||||
if (count != imageSize)
|
||||
{
|
||||
logger.Log("Failed to read targa image data", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -159,6 +168,7 @@ bool TextureClass::LoadTarga(char* filename)
|
||||
error = fclose(filePtr);
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to close targa file", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -176,12 +186,20 @@ bool TextureClass::LoadTarga(char* filename)
|
||||
{
|
||||
for (i = 0; i < m_width; i++)
|
||||
{
|
||||
m_targaData[index + 0] = targaImage[k + 2]; // Red.
|
||||
m_targaData[index + 1] = targaImage[k + 1]; // Green.
|
||||
m_targaData[index + 2] = targaImage[k + 0]; // Blue
|
||||
if (bpp == 32)
|
||||
if (index + 3 < imageSize) // Ajout de la vérification ici
|
||||
{
|
||||
m_targaData[index + 3] = targaImage[k + 3]; // Alpha
|
||||
m_targaData[index + 0] = targaImage[k + 2]; // Red.
|
||||
m_targaData[index + 1] = targaImage[k + 1]; // Green.
|
||||
m_targaData[index + 2] = targaImage[k + 0]; // Blue
|
||||
if (bpp == 32)
|
||||
{
|
||||
m_targaData[index + 3] = targaImage[k + 3]; // Alpha
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Log("Index out of bounds", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Increment the indexes into the targa data.
|
||||
@ -193,10 +211,13 @@ bool TextureClass::LoadTarga(char* filename)
|
||||
k -= (m_width * (bpp / 8) * 2);
|
||||
}
|
||||
|
||||
|
||||
// Release the targa image data now that it was copied into the destination array.
|
||||
delete[] targaImage;
|
||||
targaImage = 0;
|
||||
|
||||
logger.Log("Targa file loaded", __FILE__, __LINE__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
//////////////
|
||||
// INCLUDES //
|
||||
//////////////
|
||||
#include "Logger.h"
|
||||
#include <d3d11.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -45,6 +46,8 @@ private:
|
||||
ID3D11Texture2D* m_texture;
|
||||
ID3D11ShaderResourceView* m_textureView;
|
||||
int m_width, m_height;
|
||||
|
||||
Logger logger;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user