-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathRenderer.hpp
133 lines (96 loc) · 3.04 KB
/
Renderer.hpp
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
#pragma once
#include <vector>
#include <string>
#include <DirectXMath.h>
#include <d3d11_1.h>
#pragma comment (lib, "d3d11.lib")
#define CB_COUNT 3
struct MouseState {
float scroll = 0.f;
int currentX = 0;
int currentY = 0;
int clickedX = 0;
int clickedY = 0;
bool pressed = false;
bool held = false;
};
class Renderer
{
public:
Renderer( HWND windows );
~Renderer();
void resize( unsigned int w, unsigned int h );
void update(const MouseState& mouse, double time, double deltaTime);
bool draw();
private:
void rebuildSwapchainDepthAndViews();
struct Object {
ID3D11Buffer* vertexBuffer{nullptr};
ID3D11Buffer* indexBuffer{nullptr};
unsigned int vbCount{ 0 };
unsigned int ibCount{ 0 };
DirectX::XMMATRIX model;
void load(const std::string& name, ID3D11Device* device);
};
struct ShadedObject : public Object {
ID3D11Texture2D* diffuseTexture{nullptr};
ID3D11ShaderResourceView* diffuse{nullptr};
ID3D11Texture2D* normalTexture{nullptr};
ID3D11ShaderResourceView* normal{nullptr};
float shininess;
void load(const std::string& name, ID3D11Device* device, ID3D11DeviceContext* context );
};
struct Skybox : public Object {
ID3D11Texture2D* cubemapTexture{nullptr};
ID3D11ShaderResourceView* cubemap{nullptr};
void load(const std::string& name, ID3D11Device* device, ID3D11DeviceContext* context );
};
// Device and context
ID3D11Device* _device{nullptr};
ID3D11DeviceContext1* _context{nullptr};
// Backbuffer and views
IDXGISwapChain* _swapchain{ nullptr };
ID3D11Texture2D* _swapchainColor{ nullptr };
ID3D11RenderTargetView* _swapchainColorRT{nullptr};
ID3D11Texture2D* _swapchainDepth{nullptr};
ID3D11DepthStencilView* _swapchainDepthRT{nullptr};
// Shadow map resource and views
ID3D11Texture2D* _shadowMapDepth{nullptr};
ID3D11DepthStencilView* _shadowMapDepthRT{nullptr};
ID3D11ShaderResourceView* _shadowMap{nullptr};
// Global constant buffer
ID3D11Buffer* _constantBuffers[CB_COUNT];
// Shaders and layout for lit/unlit/shadow
ID3D11InputLayout* _litLayout{nullptr};
ID3D11VertexShader* _litVertexShader{nullptr};
ID3D11PixelShader* _litPixelShader{nullptr};
ID3D11InputLayout* _unlitLayout{nullptr};
ID3D11VertexShader* _unlitVertexShader{nullptr};
ID3D11PixelShader* _unlitPixelShader{nullptr};
ID3D11InputLayout* _shadowLayout{nullptr};
ID3D11VertexShader* _shadowVertexShader{nullptr};
// TODO: need different states for shadow and main passes?
ID3D11RasterizerState* _rasterState{nullptr};
ID3D11DepthStencilState* _depthState{nullptr};
ID3D11BlendState* _blendState{nullptr};
ID3D11SamplerState* _anisoSampler{nullptr};
ID3D11SamplerState* _shadowSampler{nullptr};
std::vector<ShadedObject> _objects;
Skybox _skybox;
struct Camera {
DirectX::XMMATRIX matrix;
float radius;
float horizontalAngle;
float verticalAngle;
void update();
};
Camera _camera;
DirectX::XMMATRIX _proj;
DirectX::XMMATRIX _lightView;
DirectX::XMMATRIX _lightProj;
DirectX::XMVECTOR _worldLightDir;
unsigned int _w{ 800 };
unsigned int _h{ 600 };
HWND _window{ 0 };
UINT _cbIndex = 0;
};