-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPixelShader.cpp
40 lines (34 loc) · 932 Bytes
/
PixelShader.cpp
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
#include "PixelShader.h"
#include <cassert>
PixelShader::PixelShader(ID3D11Device* device, const ShaderSource* source)
{
assert(source->IsCompiled());
CreateInternal(device, source);
}
PixelShader::~PixelShader()
{
if (shader_ != nullptr)
{
shader_->Release();
shader_ = nullptr;
}
}
bool PixelShader::Create(ID3D11Device* device, const ShaderSource* source)
{
return CreateInternal(device, source);
}
bool PixelShader::CreateInternal(ID3D11Device* device, const ShaderSource* source)
{
if (device == nullptr || source == nullptr)
return false;
if (source->Type() != ShaderType::PIXEL_SHADER)
return false;
ID3D11PixelShader* shader = nullptr;
auto blob = source->Blob();
const auto result = device->CreatePixelShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, &shader);
if (FAILED(result))
return false;
shader_ = shader;
name_ = source->Name();
return true;
}