-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertexShader.h
55 lines (45 loc) · 1.28 KB
/
VertexShader.h
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
#pragma once
#include "Shader.h"
#include "ShaderSource.h"
#include <cassert>
class VertexShader : public Shader
{
public:
VertexShader() = default;
VertexShader(ID3D11Device* device, const ShaderSource* source)
{
assert(source->IsCompiled());
CreateInternal(device, source);
}
virtual ~VertexShader()
{
if(shader_!=nullptr)
{
shader_->Release();
shader_ = nullptr;
}
}
bool Create(ID3D11Device* device, const ShaderSource* source) override
{
return CreateInternal(device, source);
}
bool CreateInternal(ID3D11Device* device, const ShaderSource* source)
{
if (device == nullptr || source == nullptr)
return false;
if (source->Type() != ShaderType::VERTEX_SHADER)
return false;
ID3D11VertexShader* shader = nullptr;
auto blob = source->Blob();
const auto result = device->CreateVertexShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, &shader);
if (FAILED(result))
return false;
shader_ = shader;
name_ = source->Name();
return true;
}
bool IsCreated() override { return shader_ != nullptr; }
ID3D11VertexShader* VertexShaderPtr() const { return shader_; }
private:
ID3D11VertexShader* shader_ = nullptr;
};