-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeshCache.cpp
More file actions
92 lines (69 loc) · 2.44 KB
/
Copy pathMeshCache.cpp
File metadata and controls
92 lines (69 loc) · 2.44 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
#include "stdafx.h"
#include "MeshCache.h"
std::map<std::wstring, MeshCacheObj*> MeshCache::m_mesh_table_;
ID3D12Device* MeshCache::p_device_ = nullptr;
bool MeshCache::GetMesh(std::wstring obj_path, std::wstring png_path, Mesh*& out_mesh) {
const std::wstring full = obj_path + png_path;
if (m_mesh_table_.find(full) == m_mesh_table_.end()) {
Mesh* mesh = new Mesh(obj_path, png_path);
MeshCacheObj* obj = new MeshCacheObj();
obj->mesh = mesh;
obj->ref_counter++;
m_mesh_table_[full] = obj;
out_mesh = m_mesh_table_[full]->mesh;
} else {
if (m_mesh_table_[full]->mesh == nullptr) {
Mesh* mesh = new Mesh(obj_path, png_path);
m_mesh_table_[full]->mesh = mesh;
}
m_mesh_table_[full]->ref_counter++;
out_mesh = m_mesh_table_[full]->mesh;
}
return true;
}
void MeshCache::Release(std::wstring obj_path, std::wstring png_path) {
m_mesh_table_.clear();
}
void MeshCache::Unload(std::wstring obj_path, std::wstring png_path) {
const std::wstring full = obj_path + png_path;
if (!(m_mesh_table_.find(full) == m_mesh_table_.end())) {
m_mesh_table_[full]->ref_counter--;
if (m_mesh_table_[full]->ref_counter == 0) {
m_mesh_table_[full]->mesh->Release();
m_mesh_table_[full]->mesh = nullptr;
}
}
}
void MeshCache::SetBoundingVolume(std::wstring obj_path, std::wstring png_path) {
const std::wstring full = obj_path + png_path;
if (!(m_mesh_table_.find(full) == m_mesh_table_.end())) {
if (m_mesh_table_[full]->bounding_volume == nullptr) {
m_mesh_table_[full]->bounding_volume = new BoundingVolume(*(m_mesh_table_[full]->mesh->GetBoundingVolume()));
}
}
}
BoundingVolume* MeshCache::GetBoundingVolume(std::wstring obj_path, std::wstring png_path) {
const std::wstring full = obj_path + png_path;
if (!(m_mesh_table_.find(full) == m_mesh_table_.end())) {
return m_mesh_table_[full]->bounding_volume;
}
return nullptr;
}
int MeshCache::GetMeshTableSize() {
return m_mesh_table_.size();
}
void MeshCache::SetDevice(ComPtr<ID3D12Device>& device) {
if (p_device_ == nullptr) {
p_device_ = device.Get();
}
}
boolean MeshCache::IsReleased(std::wstring obj_path, std::wstring png_path) {
const std::wstring full = obj_path + png_path;
if (!(m_mesh_table_.find(full) == m_mesh_table_.end())) {
return m_mesh_table_[full]->ref_counter == 0;
}
return true;
}
ComPtr<ID3D12Device> MeshCache::GetDevice() {
return ComPtr<ID3D12Device>(p_device_);
}