FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_uniformBuffer.hpp
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_VULKAN_C_UNIFORMBUFFER_HPP_INCLUDED
18#define _FGE_VULKAN_C_UNIFORMBUFFER_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "FastEngine/vulkan/C_contextAware.hpp"
22#include "FastEngine/vulkan/vulkanGlobal.hpp"
23#include <cstdint>
24#ifdef FGE_DEF_SERVER
25 #include <vector>
26#endif
27
28namespace fge::vulkan
29{
30
31class FGE_API UniformBuffer : public ContextAware
32{
33public:
34 enum class Types
35 {
36 UNIFORM_BUFFER,
37 STORAGE_BUFFER,
38 INDIRECT_BUFFER
39 };
40
41 explicit UniformBuffer(Context const& context, Types type = Types::UNIFORM_BUFFER);
43 UniformBuffer(UniformBuffer&& r) noexcept;
44 ~UniformBuffer() override;
45
46 UniformBuffer& operator=(UniformBuffer const& r);
47 UniformBuffer& operator=(UniformBuffer&& r) noexcept;
48
49 void create(VkDeviceSize bufferSize, Types type = Types::UNIFORM_BUFFER);
50 void resize(VkDeviceSize bufferSize, bool shrink = false);
51 void shrinkToFit();
52 void destroy() final;
53
54 [[nodiscard]] VkBuffer getBuffer() const;
55 [[nodiscard]] VmaAllocation getBufferAllocation() const;
56 [[nodiscard]] void* getBufferMapped() const;
57 [[nodiscard]] VkDeviceSize getBufferSize() const;
58 [[nodiscard]] VkDeviceSize getBufferCapacity() const;
59 [[nodiscard]] Types getType() const;
60
61 void copyData(void const* data, std::size_t size) const;
62
63private:
64#ifndef FGE_DEF_SERVER
65 void createBuffer(VkDeviceSize bufferSize, VkBuffer& buffer, VmaAllocation& bufferAllocation);
66
67 VkBuffer g_uniformBuffer;
68 VmaAllocation g_uniformBufferAllocation;
69 void* g_uniformBufferMapped;
70 VkDeviceSize g_bufferSize;
71 VkDeviceSize g_bufferCapacity;
72#else
73 mutable std::vector<uint8_t> g_uniformBuffer;
74#endif
75 Types g_type;
76};
77
78} // namespace fge::vulkan
79
80#endif //_FGE_VULKAN_C_UNIFORMBUFFER_HPP_INCLUDED
Definition C_contextAware.hpp:28
Vulkan context.
Definition C_context.hpp:70
Definition C_uniformBuffer.hpp:32