Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
SamplerManager.h
Go to the documentation of this file.
1/* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_RENDERER_BACKEND_VULKAN_SAMPLERMANAGER
19#define INCLUDED_RENDERER_BACKEND_VULKAN_SAMPLERMANAGER
20
22
23#include <glad/vulkan.h>
24#include <memory>
25#include <unordered_map>
26
27namespace Renderer
28{
29
30namespace Backend
31{
32
33namespace Vulkan
34{
35
36class CDevice;
37
38/**
39 * A helper class to store unique samplers. The manager doesn't track usages of
40 * its samplers but keep them alive until its end. So before destroying the
41 * manager its owner should guarantee no usage.
42 */
44{
45public:
46 CSamplerManager(CDevice* device);
48
49 /**
50 * @return a sampler matches the description. The returned sampler is owned by
51 * the manager.
52 */
53 VkSampler GetOrCreateSampler(const Sampler::Desc& samplerDesc);
54
55private:
56 CDevice* m_Device = nullptr;
57
59 {
60 size_t operator()(const Sampler::Desc& samplerDesc) const;
61 };
63 {
64 bool operator()(const Sampler::Desc& lhs, const Sampler::Desc& rhs) const;
65 };
66 std::unordered_map<Sampler::Desc, VkSampler, SamplerDescHash, SamplerDescEqual> m_SamplerMap;
67};
68
69} // namespace Vulkan
70
71} // namespace Backend
72
73} // namespace Renderer
74
75#endif // INCLUDED_RENDERER_BACKEND_VULKAN_SAMPLERMANAGER
Definition: Device.h:60
A helper class to store unique samplers.
Definition: SamplerManager.h:44
std::unordered_map< Sampler::Desc, VkSampler, SamplerDescHash, SamplerDescEqual > m_SamplerMap
Definition: SamplerManager.h:66
CSamplerManager(CDevice *device)
Definition: SamplerManager.cpp:75
~CSamplerManager()
Definition: SamplerManager.cpp:80
VkSampler GetOrCreateSampler(const Sampler::Desc &samplerDesc)
Definition: SamplerManager.cpp:91
CDevice * m_Device
Definition: SamplerManager.h:56
Backend
Definition: Backend.h:28
Definition: VideoMode.h:29
Definition: Sampler.h:57
bool operator()(const Sampler::Desc &lhs, const Sampler::Desc &rhs) const
Definition: SamplerManager.cpp:58
size_t operator()(const Sampler::Desc &samplerDesc) const
Definition: SamplerManager.cpp:36