-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolylines.cpp
More file actions
83 lines (67 loc) · 3.38 KB
/
Copy pathpolylines.cpp
File metadata and controls
83 lines (67 loc) · 3.38 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
#include <polylines.hpp>
#include <polylines/cpu_generated_polylines.hpp>
#include <polylines/gpu_generated_polylines.hpp>
#include <polylines/instancing_based_polylines.hpp>
#include <polylines/indirect_based_polylines.hpp>
#include <polylines/texture_based_polylines.hpp>
namespace lines {
std::unique_ptr<Polylines> Polylines::create(const std::vector<LinesVertex> &points, LinesTypes type) {
const bgfx::Caps* caps = bgfx::getCaps();
switch (type) {
case LinesTypes::CPU_GENERATED: {
return std::make_unique<CPUGeneratedPolylines>(points);
}
case LinesTypes::GPU_GENERATED: {
bool computeSupported = !!(caps->supported & BGFX_CAPS_COMPUTE);
assert((void("GPU compute not supported"), computeSupported));
return std::make_unique<GPUGeneratedPolylines>(points);
}
case LinesTypes::INSTANCING_BASED: {
const bool instancingSupported = !!(caps->supported & BGFX_CAPS_INSTANCING);
assert((void("Instancing not supported"), instancingSupported));
return std::make_unique<InstancingBasedPolylines>(points);
}
case LinesTypes::INDIRECT_BASED: {
const bool computeSupported = !!(caps->supported & BGFX_CAPS_COMPUTE);
const bool indirectSupported = !!(caps->supported & BGFX_CAPS_DRAW_INDIRECT);
const bool instancingSupported = !!(caps->supported & BGFX_CAPS_INSTANCING);
assert((void("Instancing or compute are not supported"), instancingSupported && computeSupported && indirectSupported));
return std::make_unique<IndirectBasedPolylines>(points);
}
case LinesTypes::TEXTURE_BASED: {
const bool computeSupported = !!(caps->supported & BGFX_CAPS_COMPUTE);
const bool indirectSupported = !!(caps->supported & BGFX_CAPS_DRAW_INDIRECT);
const bool instancingSupported = !!(caps->supported & BGFX_CAPS_INSTANCING);
const bool textureSupported = !!(caps->supported & BGFX_CAPS_TEXTURE_2D_ARRAY);
assert((void("Instancing or compute or indirect or texture are not supported"), instancingSupported && computeSupported && indirectSupported && textureSupported));
return std::make_unique<TextureBasedPolylines>(points, caps->limits.maxTextureSize);
}
}
assert((void("Lines type is incorrect"), true));
throw std::invalid_argument("Invalid enum case");
}
Polylines::Polylines(const std::string& vs_name, const std::string& fs_name) :
vs_name(vs_name), fs_name(fs_name)
{
mLinesPH = LoadProgram(vs_name, fs_name);
assert(bgfx::isValid(mLinesPH));
}
Polylines::Polylines(const Polylines& other) {
vs_name = other.vs_name;
fs_name = other.fs_name;
mSettings = other.mSettings;
mLinesPH = LoadProgram(vs_name, fs_name);
assert(bgfx::isValid(mLinesPH));
}
Polylines::Polylines(Polylines&& other) {
vs_name = other.vs_name;
fs_name = other.fs_name;
mSettings = other.mSettings;
mLinesPH = LoadProgram(vs_name, fs_name);
assert(bgfx::isValid(mLinesPH));
}
Polylines::~Polylines() {
if(bgfx::isValid(mLinesPH))
bgfx::destroy(mLinesPH);
}
}