-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.h
More file actions
84 lines (69 loc) · 2.17 KB
/
Application.h
File metadata and controls
84 lines (69 loc) · 2.17 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
#pragma once
#include "webgpu/webgpu.hpp"
#include "VertexAttr.h"
#include "Camera.h"
#include <GLFW/glfw3.h>
#include <glm/ext.hpp>
#include <vector>
#include <filesystem>
using namespace wgpu;
class Application {
public:
bool Initialize();
void Terminate();
void MainLoop();
bool IsRunning();
private:
GLFWwindow* window;
Device device;
Adapter adapter;
Queue queue;
Surface surface;
std::unique_ptr<ErrorCallback> uncapturedErrorCallbackHandle; // TODO
RenderPipeline pipeline;
TextureFormat surfaceFormat = TextureFormat::Undefined;
// uniform bindings
BindGroupLayout bindGroupLayout;
BindGroup bindGroup;
PipelineLayout layout;
// buffers
Buffer vertexBuffer;
// Buffer indexBuffer;
Buffer uniformBuffer;
struct Uniforms {
glm::mat4x4 projMatrix; // alignment: 16
glm::mat4x4 viewMatrix;
glm::mat4x4 modelMatrix;
glm::mat4x4 modelInvTranspose;
float time;
float padding[3]; // padding: time + pad = 16 bytes for alignment!
glm::vec3 cameraPos;
float padding1; // cameraPos + pad1 = 16 bytes for alignment!
};
uint32_t indexCount = 0;
//depth setup
Texture depthTexture;
TextureView depthTextureView;
TextureFormat depthTextureFormat = TextureFormat::Undefined;
TextureView colorTextureView; // TODO: textureformat?
Sampler sampler;
Texture cubemap;
TextureView cubemapTextureView;
Camera viewCamera;
private:
TextureView GetNextSurfaceTextureView();
void InitializePipeline();
RequiredLimits GetRequiredLimits(Adapter adapter) const;
void InitializeSurface();
void InitializeBuffers();
void InitializeBindGroups();
void InitializeDepthTexture();
Texture InitializeCubeMapTexture(const std::filesystem::path& basePath, TextureView* textureView = nullptr);
Texture getObjTexture(const std::filesystem::path& path, Device device, TextureView* textureView = nullptr);
void reSizeScreen();
// camera methods
void updateViewMatrix();
void onClick(int button, int action, int);
void onDrag(double xpos, double ypos);
void onScroll(double xoffset, double yoffset);
};