PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
render_target.h
1#pragma once
2
3#include "pixelbullet/graphics/descriptors/descriptor.h"
4#include "pixelbullet/graphics/images/image_2d.h"
5
6#include <glm/glm.hpp>
7#include <volk.h>
8
9#include <memory>
10#include <string>
11#include <vector>
12
13namespace pixelbullet
14{
15class Graphics;
16class Image2D;
17
18enum class RenderTargetExtentMode
19{
20 SwapchainScaled,
21 Fixed
22};
23
25{
26 std::string name;
27 RenderTargetExtentMode extent_mode = RenderTargetExtentMode::SwapchainScaled;
28 glm::vec2 scale{ 1.0f, 1.0f };
29 glm::uvec2 FixedExtent{ 0, 0 };
30 VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
31 VkFilter filter = VK_FILTER_LINEAR;
32 VkSamplerAddressMode address_mode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
33
34 [[nodiscard]] glm::uvec2 ResolveExtent(const glm::uvec2& baseExtent) const;
35};
36
37class RenderTarget2D final : public Descriptor
38{
39public:
40 explicit RenderTarget2D(RenderTargetSpecification specification);
41
42 void Rebuild(const Graphics& graphics, uint32_t imageCount, const VkExtent2D& swapchainExtent);
43 void SetActiveImageIndex(uint32_t activeImageIndex);
44
45 WriteDescriptorSet GetWriteDescriptor(uint32_t binding, VkDescriptorType descriptorType,
46 const std::optional<OffsetSize>& offsetSize) const override;
47 uint64_t GetRevision() const override
48 {
49 return revision_;
50 }
51
52 const RenderTargetSpecification& GetSpecification() const
53 {
54 return specification_;
55 }
56 const std::string& GetName() const
57 {
58 return specification_.name;
59 }
60 const glm::uvec2& GetExtent() const
61 {
62 return extent_;
63 }
64 uint32_t GetImageCount() const
65 {
66 return static_cast<uint32_t>(images_.size());
67 }
68 const Image2D* GetActiveImage() const;
69 const Image2D* GetImage(uint32_t imageIndex) const;
70 const VkImageView& GetImageView(uint32_t imageIndex) const;
71
72private:
73 RenderTargetSpecification specification_;
74 glm::uvec2 extent_{ 0, 0 };
75 uint32_t active_image_index_ = 0;
76 uint64_t revision_ = 1;
77 std::vector<std::unique_ptr<Image2D>> images_;
78};
79} // namespace pixelbullet
Definition descriptor.h:75
Module that manages the Vulkan instance_, Surface, Window and the renderpass structure.
Definition graphics.h:35
Resource that represents a 2D image.
Definition image_2d.h:20
Definition render_target.h:38
Definition descriptor.h:45
Definition render_target.h:25