1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsRenderBeastPrerequisites.h" |
6 | |
7 | namespace bs { namespace ct |
8 | { |
9 | /** @addtogroup RenderBeast |
10 | * @{ |
11 | */ |
12 | |
13 | /** Contains data about an overridden sampler states for a single pass. */ |
14 | struct PassSamplerOverrides |
15 | { |
16 | UINT32** stateOverrides; |
17 | UINT32 numSets; |
18 | }; |
19 | |
20 | /** Contains data about a single overriden sampler state. */ |
21 | struct SamplerOverride |
22 | { |
23 | UINT32 paramIdx; |
24 | UINT64 originalStateHash; |
25 | SPtr<SamplerState> state; |
26 | UINT32 set; |
27 | UINT32 slot; |
28 | }; |
29 | |
30 | /** Contains data about an overridden sampler states in the entire material. */ |
31 | struct MaterialSamplerOverrides |
32 | { |
33 | PassSamplerOverrides* passes; |
34 | SamplerOverride* overrides; |
35 | UINT32 numPasses; |
36 | UINT32 numOverrides; |
37 | UINT32 refCount; |
38 | bool isDirty; |
39 | }; |
40 | |
41 | /** Key used for uniquely identifying a sampler override entry. */ |
42 | struct SamplerOverrideKey |
43 | { |
44 | SamplerOverrideKey(const SPtr<Material>& material, UINT32 techniqueIdx) |
45 | :material(material), techniqueIdx(techniqueIdx) |
46 | { } |
47 | |
48 | bool operator== (const SamplerOverrideKey& rhs) const |
49 | { |
50 | return material == rhs.material && techniqueIdx == rhs.techniqueIdx; |
51 | } |
52 | |
53 | bool operator!= (const SamplerOverrideKey& rhs) const |
54 | { |
55 | return !(*this == rhs); |
56 | } |
57 | |
58 | SPtr<Material> material; |
59 | UINT32 techniqueIdx; |
60 | }; |
61 | |
62 | /** Helper class for generating sampler overrides. */ |
63 | class SamplerOverrideUtility |
64 | { |
65 | public: |
66 | /** |
67 | * Generates a set of sampler overrides for the specified set of GPU program parameters. Overrides are generates |
68 | * according to the provided render options. |
69 | */ |
70 | static MaterialSamplerOverrides* generateSamplerOverrides(const SPtr<Shader>& shader, |
71 | const SPtr<MaterialParams>& params, |
72 | const SPtr<GpuParamsSet>& paramsSet, |
73 | const SPtr<RenderBeastOptions>& options); |
74 | |
75 | /** Destroys sampler overrides previously generated with generateSamplerOverrides(). */ |
76 | static void destroySamplerOverrides(MaterialSamplerOverrides* overrides); |
77 | |
78 | /** |
79 | * Checks if the provided sampler state requires an override, in case the render options have requirements not |
80 | * fulfilled by current sampler state (for example filtering type). |
81 | */ |
82 | static bool checkNeedsOverride(const SPtr<SamplerState>& samplerState, |
83 | const SPtr<RenderBeastOptions>& options); |
84 | |
85 | /** |
86 | * Generates a new sampler state override using the provided state as the basis. Overridden properties are taken |
87 | * from the provided render options. |
88 | */ |
89 | static SPtr<SamplerState> generateSamplerOverride(const SPtr<SamplerState>& samplerState, |
90 | const SPtr<RenderBeastOptions>& options); |
91 | }; |
92 | |
93 | /** @} */ |
94 | }} |
95 | |
96 | /** @cond STDLIB */ |
97 | |
98 | namespace std |
99 | { |
100 | /** Hash value generator for SamplerOverrideKey. */ |
101 | template<> |
102 | struct hash<bs::ct::SamplerOverrideKey> |
103 | { |
104 | size_t operator()(const bs::ct::SamplerOverrideKey& key) const |
105 | { |
106 | size_t hash = 0; |
107 | bs::bs_hash_combine(hash, key.material); |
108 | bs::bs_hash_combine(hash, key.techniqueIdx); |
109 | |
110 | return hash; |
111 | } |
112 | }; |
113 | } |
114 | |
115 | /** @endcond */ |