-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
625 lines (463 loc) · 20.3 KB
/
Main.cpp
File metadata and controls
625 lines (463 loc) · 20.3 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
#include "Defines.h"
#include "Timer.h"
#include "Camera.h"
#include "WindowHelper.h"
#include "DxHandler.h"
#include "Pipeline.h"
#include "Shaders.h"
#include "Lighting.h"
#include "RenderModels.h"
#include "RenderShadows.h"
#include "QuadTree.h"
#include "Frustum.h"
#include "ParticleManager.h"
//console shite
#include<io.h>
#include<fcntl.h>
// Console Function, got this thingy from canvas
void RedirectIOToConsole()
{
AllocConsole();
HANDLE stdHandle;
int hConsole;
FILE* fp;
stdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
hConsole = _open_osfhandle((intptr_t)stdHandle, _O_TEXT);
fp = _fdopen(hConsole, "w");
freopen_s(&fp, "CONOUT$", "w", stdout);
}
// Function to clear the window
void clearView(ID3D11DeviceContext* context, ID3D11RenderTargetView* rtv, ID3D11DepthStencilView* dsView, const GBuffer& gBuffer)
{
// Background Color
float backGroundColor[4] = { 0.5f, 0.5f, 0.5f, 0 };
// Clean SRVs
ID3D11ShaderResourceView* nullSrvs[gBuffer.NROFBUFFERS] = { nullptr };
context->PSSetShaderResources(0, gBuffer.NROFBUFFERS, nullSrvs);
// Clear the DSV
context->ClearDepthStencilView(dsView, D3D11_CLEAR_DEPTH, 1, 0);
// Reset the RTVs
for (int i = 0; i < gBuffer.NROFBUFFERS; i++)
{
// Clear the RTVs with the BG-color
context->ClearRenderTargetView(gBuffer.gBuffergBufferRtv[i], backGroundColor);
}
context->OMSetRenderTargets(gBuffer.NROFBUFFERS, gBuffer.gBuffergBufferRtv, dsView);
}
bool CreateParticleInputLayout(ID3D11Device* device, ID3D11InputLayout*& inputLayout, std::string& vertexByteCode)
{
const int nrElements = 1;
D3D11_INPUT_ELEMENT_DESC inputDescription[nrElements] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}
};
HRESULT hr = device->CreateInputLayout(inputDescription, nrElements, vertexByteCode.c_str(), vertexByteCode.length(), &inputLayout);
if (hr != S_OK || FAILED(hr) )
{
std::cout << "ERROR! COULD NOT CREATE PARTICLE INPUT LAYOUT" << std::endl;
return false;
}
return !FAILED(hr);
}
// Update function to update the camera, the directional light
void update(ID3D11DeviceContext* context, float deltaTime, Camera& camera,
/*Particles* particlesystem,*/ Lighting& light, ID3D11Buffer* lightBuffer,
const std::vector<Model*> models, Model* monkey, Model* monkey2, Model* monkey3, ParticleManager* particleManager)
{
camera.Update(deltaTime);
particleManager->Update(deltaTime, context);
// Rotation of Monkey-model
XMFLOAT4 tempRotation;
XMStoreFloat4(&tempRotation, monkey->GetRotation());
tempRotation.y += 1.3f * deltaTime;
XMVECTOR rotation = XMVectorSet(tempRotation.x, tempRotation.y, tempRotation.z, tempRotation.z);
monkey->SetRotation(rotation);
monkey->Update();
XMStoreFloat4(&tempRotation, monkey2->GetRotation());
tempRotation.x += 1.3f * deltaTime;
rotation = XMVectorSet(tempRotation.x, tempRotation.y, tempRotation.z, tempRotation.z);
monkey2->SetRotation(rotation);
monkey2->Update();
XMStoreFloat4(&tempRotation, monkey3->GetRotation());
tempRotation.z += 1.3f * deltaTime;
rotation = XMVectorSet(tempRotation.x, tempRotation.y, tempRotation.z, tempRotation.z);
monkey3->SetRotation(rotation);
monkey3->Update();
}
// Geometry Pass for deferred rendering (and shadows)
void RenderGBufferPass(ID3D11DeviceContext* context, ID3D11RenderTargetView* rtv, ID3D11DepthStencilView* dsView,
D3D11_VIEWPORT& viewport, ID3D11PixelShader* pShaderDeferredRender, ID3D11VertexShader* vShaderDeferred,
ID3D11SamplerState* sampler, GBuffer gBuffer, RenderModels* modelRenderer, const std::vector <Model*>& models,
RenderShadows* shadowRenderer, ID3D11RasterizerState*& rasterizerStateWireFrame, ID3D11RasterizerState*& rasterizerStateSolid,
ID3D11Device* device, ID3D11SamplerState* clampSampler, Frustum* frustum, QuadTree* quadTree, Camera camera,
ParticleManager * particleManager, Particle* particle, ID3D11InputLayout* particleInputLayout, bool wireFrame)
{
// Binds the shadowmap (sets resources)
Shaders::shadowmap->Bind(context);
// Set the HS, DS and GS shaders to NULL, used in the different renderers
context->HSSetShader(NULL, NULL, 0);
context->DSSetShader(NULL, NULL, 0);
context->GSSetShader(NULL, NULL, 0);
// Loops through the models-vector and render shadows
for (auto& model : models)
{
shadowRenderer->Render(context, model);
}
// Reset the Viewport for the next pass (geometry pass)
context->RSSetViewports(NULL, NULL);
// Set all the Samplers, Rasterizerstate, viewport and geometryshader (GS used for culling)
context->RSSetViewports(1, &viewport);
context->PSSetSamplers(0, 1, &sampler);
context->PSSetSamplers(1, 1, &clampSampler);
context->DSSetSamplers(0, 1, &sampler);
context->DSSetSamplers(1, 1, &clampSampler);
if (!wireFrame)
{
context->RSSetState(rasterizerStateSolid); // normal
}
else
{
context->RSSetState(rasterizerStateWireFrame); //wireframe
}
clearView(context, rtv, dsView, gBuffer); // Clear the window for next render pass
context->OMSetRenderTargets(gBuffer.NROFBUFFERS, gBuffer.gBuffergBufferRtv, dsView);
modelRenderer->modelsRendered = 0;
context->RSSetViewports(NULL, NULL);
context->RSSetViewports(1, &viewport);
// Time for frustum stuff_________________________________________________________________________________________
frustum->ConstructFrustum(camera.GetFarZ(), camera.GetPerspectiveMatrix(), camera.GetViewMatrix()); //make the actual frustum
quadTree->Render(frustum, device, context, modelRenderer);
//________________________________________________________________________________________________________________
// Render the models using different renderers (modelRenderer, particleRenderer)
for (auto& model : models) //används detta för icke frustum, fixa en annan loop för frustum (
{
if( model->mesh.name == "plane")
modelRenderer->Render(device, context, model, false);
}
std::cout << "Models rendered: " << modelRenderer->modelsRendered << std::endl;
//render particles
context->OMSetRenderTargets(gBuffer.NROFBUFFERS, gBuffer.gBuffergBufferRtv, dsView);
particleManager->ShaderUpdater(context, camera);
particle->setPSResources(context);
particleManager->Draw(context, particleInputLayout);
}
// Light pass -- renders the geometry and lighting on the final screen quad
void RenderLightPass(ID3D11DeviceContext* context, ID3D11RenderTargetView* rtv, ID3D11DepthStencilView* dsView, D3D11_VIEWPORT& viewport,
ID3D11PixelShader* pShaderDeferredRender, ID3D11VertexShader* vShaderDeferred, ID3D11SamplerState* sampler,
GBuffer gBuffer, ID3D11PixelShader* lightPShaderDeferred, ID3D11VertexShader* lightVShaderDeferred,
ID3D11InputLayout* renderTargetMeshInputLayout, ID3D11Buffer* screenQuadMesh, Lighting& light,
ID3D11Buffer* dirLightBuffer, Camera camera, ID3D11Buffer* cameraPos, ID3D11SamplerState* clampSampler
)
{
UINT stride = sizeof(Vertex);
UINT offset = 0;
context->OMSetRenderTargets(1, &rtv, dsView); // Backbuffer
context->IASetVertexBuffers(0, 1, &screenQuadMesh, &stride, &offset); // quads vertexbuffer set
context->IASetInputLayout(renderTargetMeshInputLayout); // set the Input Layout
context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); // triangletstrip since we know how many points we have
context->VSSetShader(lightVShaderDeferred, nullptr, 0); // setting the shaders
context->PSSetShader(lightPShaderDeferred, nullptr, 0); // setting the shaders
context->GSSetShader(nullptr, nullptr, 0);
context->PSSetShaderResources(0, gBuffer.NROFBUFFERS, gBuffer.gBufferSrv);
context->PSSetShaderResources(8, 1, Shaders::shadowmap->GetSRV()); // Get the shadow-map SRV and send it to the PixelShader
context->PSSetConstantBuffers(0, 1, &dirLightBuffer);
context->PSSetConstantBuffers(1, 1, &cameraPos);
context->PSSetSamplers(0, 1, &sampler);
context->RSSetState(nullptr);
context->Draw(4, 0);
}
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
// Width and height of the window
const UINT WIDTH = 1024;
const UINT HEIGHT = 768;
HWND window;
//Console window-function
RedirectIOToConsole();
// Camera
Camera camera(XM_PIDIV4, (float)WINWIDTH / (float)WINHEIGHT, 0.1, 100, 2.5, 5.0f, { 15.0f, 10.0f ,0.0f });
ID3D11Buffer* cameraBuffer;
//
// Time
Timer timer;
float deltatime = 0.0f;
ID3D11Device* device; // Used to create resources.
ID3D11DeviceContext* context; // Generates rendering commands.
IDXGISwapChain* swapChain; // This function changes the back buffer (rtv) and the display screen.
ID3D11RenderTargetView* rtv; // This variable is a pointer to an object that contains all the information about the rendering object.
ID3D11DepthStencilView* dsView; // The Depth / Stencil Buffer stores depth information for the pixels to be rendered.
D3D11_VIEWPORT viewport; // Defines the dimensions of a viewport.
ID3D11Texture2D* dsTexture; // An ID3D11Texture2D is an object that stores a flat image.
ID3D11RasterizerState* rasterizerStateWireFrame; // RasterizerState - wireframe
ID3D11RasterizerState* rasterizerStateSolid; // RasterizerState - solid
ID3D11SamplerState* wrapSampler; // Wrap sampler - wraps or "loops" the texture
ID3D11SamplerState* clampSampler; // Clamp sampler - clamps the UV values [0.0 - 1.0]
//Deferred
ID3D11PixelShader* lightPShaderDeferred; // Pixel Shader for the light pass ( quad )
ID3D11VertexShader* lightVShaderDeferred; // Vertex Shader for the light pass ( quad )
ID3D11PixelShader* pShaderDeferred; // Pixel Shader for the geometry pass
ID3D11VertexShader* vShaderDeferred; // Vertex Shader for the geometry pass
ID3D11InputLayout* renderTargetMeshInputLayout; // Input layout for the quad covering the sqreen
ID3D11Buffer* screenQuadMesh; // Quad covering the screen used in the deferred rendering- light pass
//Gbuffer struct
GBuffer gBuffer;
gBuffer.screenWidth = WINWIDTH;
gBuffer.screenHeight = WINHEIGHT;
for (int i = 0; i < gBuffer.NROFBUFFERS; i++)
{
gBuffer.gBufferTexture[i] = nullptr;
}
// Directional light (both lighting and shadows)
Lighting light(14);
ID3D11Buffer* lightBuffer;
// Creates the window
if (!SetupWindow(hInstance, WIDTH, HEIGHT, nCmdShow, window))
{
std::cerr << "Failed to setup window!" << std::endl;
return -1;
}
// Setups DirectX11
if (!SetupD3D11(WINWIDTH, WINHEIGHT, window, device, context,
swapChain, rtv, dsTexture, dsView, viewport, gBuffer))
{
std::cerr << "Failed to setup d3d11!" << std::endl;
return -2;
}
if (!SetupPipeline(device, wrapSampler, pShaderDeferred, vShaderDeferred, lightPShaderDeferred, lightVShaderDeferred,
renderTargetMeshInputLayout, screenQuadMesh, rasterizerStateWireFrame, rasterizerStateSolid, clampSampler))
{
std::cerr << "Failed to setup pipeline!" << std::endl;
return -3;
}
// Creating a vector that stores the models
std::vector <Model*>models;
// Creating a new model for each mesh in the scene
// "depth" "height" "width"
Model* monkey = new Model(device, "monkey", { 3.0f, 2.5f, 2.0f }, { 0.0f, XM_PIDIV4, 0.0f }, { 0.6f, 0.6f, 0.6f });
models.push_back(monkey);
Model* monkey2 = new Model(device, "monkey", { 1.0f, 2.5f, 0.0f }, { XM_PIDIV4, 0.0f, 0.0f }, { 0.6f, 0.6f, 0.6f });
models.push_back(monkey2);
Model* monkey3 = new Model(device, "monkey", { 5.0f, 2.5f, 0.0f }, { 0.0f, 0.0f, XM_PIDIV4 }, { 0.6f, 0.6f, 0.6f });
models.push_back(monkey3);
Model* ground = new Model(device, "plane", { 3.0f, 1.5f, 0.0f }, { 0.0f, 0.0f, 0.0f }, { 3.0f, 0.001f, 3.0f });
models.push_back(ground);
Model* sphere = new Model(device, "sphere", { 8.0f, 2.5f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere);
Model* sphere2 = new Model(device, "sphere", { -8.0f, 2.5f, -5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere2);
Model* sphere3 = new Model(device, "sphere", { -8.0f, 2.5f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere3);
Model* sphere4 = new Model(device, "sphere", { 8.0f, 2.5f, -5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere4);
Model* sphere5 = new Model(device, "sphere", { 6.0f, 2.5f, -2.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere5);
Model* sphere6 = new Model(device, "sphere", { 6.0f, 2.5f, 2.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere6);
Model* sphere7 = new Model(device, "sphere", { -6.0f, 2.5f, -2.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere7);
Model* sphere8 = new Model(device, "sphere", { -6.0f, 2.5f, 2.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere8);
Model* sphere9 = new Model(device, "sphere", { 7.0f, 2.5f, 2.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere9);
Model* sphere10 = new Model(device, "sphere", { 7.0f, 2.5f, -2.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere10);
Model* sphere11 = new Model(device, "sphere", { 12.0f, 2.5f, -4.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere11);
Model* sphere12 = new Model(device, "sphere", { 10.0f, 2.5f, -7.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere12);
Model* sphere13 = new Model(device, "sphere", { 5.0f, 2.0f, -2.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere13);
Model* sphere14 = new Model(device, "sphere", { 12.0f, 2.5f, 7.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere14);
Model* sphere15 = new Model(device, "sphere", { 11.0f, 2.5f, 12.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere15);
Model* sphere16 = new Model(device, "sphere", { -4.0f, 2.5f, 8.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere16);
Model* sphere17 = new Model(device, "sphere", { -6.0f, 2.0f, 6.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere17);
Model* sphere18 = new Model(device, "sphere", { -4.0f, 3.5f, -4.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere18);
Model* sphere19 = new Model(device, "sphere", { 11.0f, 2.5f, -6.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere19);
Model* sphere20 = new Model(device, "sphere", { -7.0f, 2.0f, -4.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere20);
Model* sphere21 = new Model(device, "sphere", { -8.0f, 2.5f, 8.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere21);
Model* sphere22 = new Model(device, "sphere", { -2.0f, 2.5f, 12.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere22);
Model* sphere23 = new Model(device, "sphere", { -1.0f, 2.0f, 4.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere23);
Model* sphere24 = new Model(device, "sphere", { 0.0f, 2.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere24);
Model* sphere25 = new Model(device, "sphere", { 0, 2.5f, -12.0f }, { 0.0f, 0.0f, 0.0f }, { 0.01f, 0.01f, 0.01f });
models.push_back(sphere25);
//PARTICLE GPU
ID3D11ShaderResourceView* textureSRV;
Texture::makeTexture("Textures/orks.jpeg", device, textureSRV);
ParticleManager* particleManager = new ParticleManager(device, textureSRV, 16, camera, vector_3(0, 5, 0), vector_3(2, 2, 2));
Particle* particle = new Particle(textureSRV);
std::string vCode = particleManager->GetVShaderData();
ID3D11InputLayout* particleInputLayout;
CreateParticleInputLayout(device, particleInputLayout, vCode);
//_______________________
RenderModels* modelRenderer = new RenderModels(device);
RenderShadows* shadowRenderer = new RenderShadows(device);
//for culling
Frustum* frustum = new Frustum;
QuadTree* quadTree = new QuadTree;
bool initSuccessful = quadTree->Initialize(models);
if (!initSuccessful)
{
std::cout << "ERROR! COULD NOT INITIALIZE QUAD TREE IN MAIN!" << std::endl;
return -4;
}
//_______________
Shaders::Initialize(device, modelRenderer->GetByteCode());
CreateBuffer(device, lightBuffer, sizeof(Lighting::Data));
UpdateBuffer(context, lightBuffer, light.data);
CreateBuffer(device, cameraBuffer, sizeof(XMFLOAT4));
MSG msg = {};
bool wireFrame = false;
while (!(GetKeyState(VK_ESCAPE) & 0x8000) && msg.message != WM_QUIT)
{
timer.Start();
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (GetAsyncKeyState('F')) //toggle wireframe, perfect for showing LoD
{
wireFrame = true;
}
if (GetAsyncKeyState('G')) // back to geometry as normal
{
wireFrame = false;
}
update(context, deltatime, camera, light, lightBuffer, models, monkey, monkey2, monkey3, particleManager);
Shaders::Update(context, camera, light);
RenderGBufferPass(context, rtv, dsView, viewport, pShaderDeferred, vShaderDeferred,
wrapSampler, gBuffer,modelRenderer, models, shadowRenderer,
rasterizerStateWireFrame, rasterizerStateSolid, device, clampSampler, frustum, quadTree, camera,
particleManager, particle, particleInputLayout, wireFrame);
RenderLightPass(context, rtv, dsView, viewport, pShaderDeferred, vShaderDeferred,
wrapSampler, gBuffer, lightPShaderDeferred, lightVShaderDeferred, renderTargetMeshInputLayout, screenQuadMesh,
light, lightBuffer, camera, cameraBuffer, clampSampler);
swapChain->Present(0, 0); // Presents a rendered image to the user.
deltatime = timer.DeltaTime();
}
for (int i = 0; i < gBuffer.NROFBUFFERS; i++)
{
gBuffer.gBuffergBufferRtv[i]->Release();
gBuffer.gBufferSrv[i]->Release();
gBuffer.gBufferTexture[i]->Release();
}
// Clear the vector
models.clear();
monkey->Shutdown();
monkey2->Shutdown();
monkey3->Shutdown();
ground->Shutdown();
sphere->Shutdown();
sphere2->Shutdown();
sphere3->Shutdown();
sphere4->Shutdown();
sphere5->Shutdown();
sphere6->Shutdown();
sphere7->Shutdown();
sphere8->Shutdown();
sphere9->Shutdown();
sphere10->Shutdown();
sphere11->Shutdown();
sphere12->Shutdown();
sphere13->Shutdown();
sphere14->Shutdown();
sphere15->Shutdown();
sphere16->Shutdown();
sphere17->Shutdown();
sphere18->Shutdown();
sphere19->Shutdown();
sphere20->Shutdown();
sphere21->Shutdown();
sphere22->Shutdown();
sphere23->Shutdown();
sphere24->Shutdown();
sphere25->Shutdown();
if (quadTree)
{
quadTree->Shutdown();
delete quadTree;
quadTree = 0;
}
if (frustum)
{
delete frustum;
frustum = 0;
}
if (particleManager)
{
delete particleManager;
particleManager = 0;
}
if (particle)
{
delete particle;
particle = 0;
}
delete monkey;
delete monkey2;
delete monkey3;
delete ground;
delete sphere;
delete sphere2;
delete sphere3;
delete sphere4;
delete sphere5;
delete sphere6;
delete sphere7;
delete sphere8;
delete sphere9;
delete sphere10;
delete sphere11;
delete sphere12;
delete sphere13;
delete sphere14;
delete sphere15;
delete sphere16;
delete sphere17;
delete sphere18;
delete sphere19;
delete sphere20;
delete sphere21;
delete sphere22;
delete sphere23;
delete sphere24;
delete sphere25;
shadowRenderer->ShutDown();
modelRenderer->ShutDown();
Shaders::Shutdown();
delete modelRenderer;
delete shadowRenderer;
rasterizerStateWireFrame->Release();
rasterizerStateSolid->Release();
cameraBuffer->Release();
lightBuffer->Release();
vShaderDeferred->Release();
pShaderDeferred->Release();
screenQuadMesh->Release();
renderTargetMeshInputLayout->Release();
lightVShaderDeferred->Release();
lightPShaderDeferred->Release();
clampSampler->Release();
wrapSampler->Release();
dsTexture->Release();
dsView->Release();
rtv->Release();
swapChain->Release();
context->Release();
device->Release();
particleInputLayout->Release();
textureSRV->Release();
return 0;
}