-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEffects.h
160 lines (106 loc) · 3.3 KB
/
Effects.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//***************************************************************************************
// Effects.h by X_Jun(MKXJun) (C) 2018-2020 All Rights Reserved.
// Licensed under the MIT License.
//
// 简易特效管理框架
// Simple effect management framework.
//***************************************************************************************
#ifndef EFFECTS_H
#define EFFECTS_H
#include <memory>
#include "LightHelper.h"
#include "RenderStates.h"
class IEffect
{
public:
// 使用模板别名(C++11)简化类型名
template <class T>
using ComPtr = Microsoft::WRL::ComPtr<T>;
IEffect() = default;
virtual ~IEffect() = default;
// 不允许拷贝,允许移动
IEffect(const IEffect&) = delete;
IEffect& operator=(const IEffect&) = delete;
IEffect(IEffect&&) = default;
IEffect& operator=(IEffect&&) = default;
// 更新并绑定常量缓冲区
virtual void Apply(ID3D11DeviceContext * deviceContext) = 0;
};
class BasicEffect : public IEffect
{
public:
enum RenderType { RenderObject, RenderInstance };
BasicEffect();
virtual ~BasicEffect() override;
BasicEffect(BasicEffect&& moveFrom) noexcept;
BasicEffect& operator=(BasicEffect&& moveFrom) noexcept;
// 获取单例
static BasicEffect& Get();
// 初始化所需资源
bool InitAll(ID3D11Device * device);
//
// 渲染模式的变更
//
// 默认状态来绘制
void SetRenderDefault(ID3D11DeviceContext * deviceContext, RenderType type);
//
// 矩阵设置
//
void XM_CALLCONV SetWorldMatrix(DirectX::FXMMATRIX W);
void XM_CALLCONV SetViewMatrix(DirectX::FXMMATRIX V);
void XM_CALLCONV SetProjMatrix(DirectX::FXMMATRIX P);
//
// 光照、材质和纹理相关设置
//
// 各种类型灯光允许的最大数目
static const int maxLights = 5;
void SetDirLight(size_t pos, const DirectionalLight& dirLight);
void SetPointLight(size_t pos, const PointLight& pointLight);
void SetSpotLight(size_t pos, const SpotLight& spotLight);
void SetMaterial(const Material& material);
void SetTextureUsed(bool isUsed);
void SetTextureDiffuse(ID3D11ShaderResourceView * textureDiffuse);
void SetTextureCube(ID3D11ShaderResourceView * textureCube);
void SetEyePos(const DirectX::XMFLOAT3& eyePos);
//
// 状态开关设置
//
void SetReflectionEnabled(bool isEnable);
// 应用常量缓冲区和纹理资源的变更
void Apply(ID3D11DeviceContext * deviceContext) override;
private:
class Impl;
std::unique_ptr<Impl> pImpl;
};
class SkyEffect : public IEffect
{
public:
SkyEffect();
virtual ~SkyEffect() override;
SkyEffect(SkyEffect&& moveFrom) noexcept;
SkyEffect& operator=(SkyEffect&& moveFrom) noexcept;
// 获取单例
static SkyEffect& Get();
// 初始化所需资源
bool InitAll(ID3D11Device * device);
//
// 渲染模式的变更
//
// 默认状态来绘制
void SetRenderDefault(ID3D11DeviceContext * deviceContext);
//
// 矩阵设置
//
void XM_CALLCONV SetWorldViewProjMatrix(DirectX::FXMMATRIX W, DirectX::CXMMATRIX V, DirectX::CXMMATRIX P);
void XM_CALLCONV SetWorldViewProjMatrix(DirectX::FXMMATRIX WVP);
//
// 纹理立方体映射设置
//
void SetTextureCube(ID3D11ShaderResourceView * textureCube);
// 应用常量缓冲区和纹理资源的变更
void Apply(ID3D11DeviceContext * deviceContext) override;
private:
class Impl;
std::unique_ptr<Impl> pImpl;
};
#endif