Blender V4.3
workbench_shader_cache.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7namespace blender::workbench {
8
9ShaderCache *ShaderCache::static_cache = nullptr;
10
12{
13 if (!ShaderCache::static_cache) {
14 ShaderCache::static_cache = new ShaderCache();
15 }
16 return *ShaderCache::static_cache;
17}
18
20{
21 if (ShaderCache::static_cache) {
22 delete ShaderCache::static_cache;
23 ShaderCache::static_cache = nullptr;
24 }
25}
26
28{
29 const std::string geometries[] = {"_mesh", "_curves", "_ptcloud"};
30 const std::string pipelines[] = {"_opaque", "_transparent"};
31 const std::string lightings[] = {"_flat", "_studio", "_matcap"};
32 const std::string shaders[] = {"_material", "_texture"};
33 const std::string clip[] = {"_no_clip", "_clip"};
34 static_assert(std::size(geometries) == geometry_type_len);
35 static_assert(std::size(pipelines) == pipeline_type_len);
36 static_assert(std::size(lightings) == lighting_type_len);
37 static_assert(std::size(shaders) == shader_type_len);
38
39 for (auto g : IndexRange(geometry_type_len)) {
40 for (auto p : IndexRange(pipeline_type_len)) {
41 for (auto l : IndexRange(lighting_type_len)) {
42 for (auto s : IndexRange(shader_type_len)) {
43 for (auto c : IndexRange(2) /*clip*/) {
44 prepass_[g][p][l][s][c] = {"workbench_prepass" + geometries[g] + pipelines[p] +
45 lightings[l] + shaders[s] + clip[c]};
46 }
47 }
48 }
49 }
50 }
51
52 const std::string cavity[] = {"_no_cavity", "_cavity"};
53 const std::string curvature[] = {"_no_curvature", "_curvature"};
54 const std::string shadow[] = {"_no_shadow", "_shadow"};
55
56 for (auto l : IndexRange(lighting_type_len)) {
57 for (auto ca : IndexRange(2) /*cavity*/) {
58 for (auto cu : IndexRange(2) /*curvature*/) {
59 for (auto s : IndexRange(2) /*shadow*/) {
60 resolve_[l][ca][cu][s] = {"workbench_resolve_opaque" + lightings[l] + cavity[ca] +
61 curvature[cu] + shadow[s]};
62 }
63 }
64 }
65 }
66
67 const std::string pass[] = {"_fail", "_pass"};
68 const std::string manifold[] = {"_no_manifold", "_manifold"};
69 const std::string caps[] = {"_no_caps", "_caps"};
70
71 for (auto p : IndexRange(2) /*pass*/) {
72 for (auto m : IndexRange(2) /*manifold*/) {
73 for (auto c : IndexRange(2) /*caps*/) {
74 shadow_[p][m][c] = {"workbench_shadow" + pass[p] + manifold[m] + caps[c] +
75 (DEBUG_SHADOW_VOLUME ? "_debug" : "")};
76 }
77 }
78 }
79
80 const std::string smoke[] = {"_object", "_smoke"};
81 const std::string interpolation[] = {"_linear", "_cubic", "_closest"};
82 const std::string coba[] = {"_no_coba", "_coba"};
83 const std::string slice[] = {"_no_slice", "_slice"};
84
85 for (auto sm : IndexRange(2) /*smoke*/) {
86 for (auto i : IndexRange(3) /*interpolation*/) {
87 for (auto c : IndexRange(2) /*coba*/) {
88 for (auto sl : IndexRange(2) /*slice*/) {
89 volume_[sm][i][c][sl] = {"workbench_volume" + smoke[sm] + interpolation[i] + coba[c] +
90 slice[sl]};
91 }
92 }
93 }
94 }
95}
96
97} // namespace blender::workbench
ATTR_WARN_UNUSED_RESULT const BMLoop * l
static constexpr int geometry_type_len
static constexpr int lighting_type_len
static constexpr int shader_type_len
static constexpr int pipeline_type_len
#define DEBUG_SHADOW_VOLUME