-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMesh.h
More file actions
59 lines (49 loc) · 1.41 KB
/
Copy pathMesh.h
File metadata and controls
59 lines (49 loc) · 1.41 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
#pragma once
#include <d3d12.h>
#include <wrl.h>
#include <DirectXMath.h>
#include "gltf_utils.h"
struct Vertex
{
DirectX::XMFLOAT3 position;
DirectX::XMFLOAT3 normal;
DirectX::XMFLOAT2 texCoord0;
};
class Mesh
{
public:
Microsoft::WRL::ComPtr<ID3D12Resource> vertexBuffer;
Microsoft::WRL::ComPtr<ID3D12Resource> indexBuffer;
D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
D3D12_INDEX_BUFFER_VIEW indexBufferView;
Mesh() = default;
~Mesh() = default;
UINT vertexCount = 0;
UINT indexCount = 0;
UINT materialIndex = 0;
UINT getVertexCount() const { return vertexCount; }
UINT getIndexCount() const { return indexCount; }
UINT getMaterialIndex() const { return materialIndex; }
bool hasIndices = false;
DXGI_FORMAT indexFormat = DXGI_FORMAT_R32_UINT;
void Load(const tinygltf::Model& model, const tinygltf::Primitive& primitive);
void BindBuffers(ID3D12GraphicsCommandList* commandList) const
{
commandList->IASetVertexBuffers(0, 1, &vertexBufferView);
if (hasIndices)
{
commandList->IASetIndexBuffer(&indexBufferView);
}
}
void Draw(ID3D12GraphicsCommandList* commandList) const
{
if (hasIndices)
{
commandList->DrawIndexedInstanced(indexCount, 1, 0, 0, 0);
}
else
{
commandList->DrawInstanced(vertexCount, 1, 0, 0);
}
}
};