-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShaders.cpp
More file actions
74 lines (52 loc) · 1.89 KB
/
Copy pathShaders.cpp
File metadata and controls
74 lines (52 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "Shaders.h"
VertexShader::VertexShader() {
shader = nullptr;
shaderBuffer = nullptr;
}
bool VertexShader::Initialize(Microsoft::WRL::ComPtr<ID3D11Device>& device, std::wstring shaderpath, D3D11_INPUT_ELEMENT_DESC* layoutDesc, UINT elementCount) {
HRESULT hr = D3DReadFileToBlob(shaderpath.c_str(), this->shaderBuffer.GetAddressOf());
if (FAILED(hr)) {
Logger::Log(hr, "Failed to read vertex shader from file.");
return false;
}
hr = device->CreateVertexShader(this->shaderBuffer.Get()->GetBufferPointer(), this->shaderBuffer->GetBufferSize(), 0, this->shader.GetAddressOf());
if (FAILED(hr)) {
Logger::Log(hr, "Failed to create vertex shader.");
return false;
}
hr = device->CreateInputLayout(layoutDesc, elementCount, this->shaderBuffer->GetBufferPointer(), this->shaderBuffer->GetBufferSize(), this->inputLayout.GetAddressOf());
if (FAILED(hr)) {
Logger::Log(hr, "Failed to create input layout.");
return false;
}
return true;
}
ID3D11VertexShader* VertexShader::GetShader() {
return this->shader.Get();
}
ID3D10Blob* VertexShader::GetBuffer() {
return this->shaderBuffer.Get();
;
}
ID3D11InputLayout* VertexShader::GetInputLayout() {
return this->inputLayout.Get();
}
bool PixelShader::Initialize(Microsoft::WRL::ComPtr<ID3D11Device>& device, std::wstring shaderpath) {
HRESULT hr = D3DReadFileToBlob(shaderpath.c_str(), this->shaderBuffer.GetAddressOf());
if (FAILED(hr)) {
Logger::Log(hr, "Failed to read pixel shader from file.");
return false;
}
hr = device->CreatePixelShader(this->shaderBuffer.Get()->GetBufferPointer(), this->shaderBuffer.Get()->GetBufferSize(), 0, this->shader.GetAddressOf());
if(FAILED(hr)) {
Logger::Log(hr, "Failed to create pixel shader.");
return false;
}
return true;
}
ID3D11PixelShader* PixelShader::GetShader() {
return this->shader.Get();
}
ID3D10Blob* PixelShader::GetShaderBuffer() {
return this->shaderBuffer.Get();
}