SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
FrameBuffer.h
1#pragma once
2
3#include "spark/render/CommandBuffer.h"
4#include "spark/render/Export.h"
5#include "spark/render/Image.h"
6
7#include "spark/math/Vector2.h"
8
9#include <memory>
10
11namespace spark::render
12{
16 class SPARK_RENDER_EXPORT IFrameBuffer
17 {
18 public:
19 virtual ~IFrameBuffer() noexcept = default;
20
28 [[nodiscard]] virtual unsigned int bufferIndex() const noexcept = 0;
29
34 [[nodiscard]] virtual spark::math::Vector2<unsigned> size() const noexcept = 0;
35
40 [[nodiscard]] std::vector<std::shared_ptr<const ICommandBuffer>> commandBuffers() const noexcept { return genericCommandBuffers(); }
41
49 [[nodiscard]] std::shared_ptr<const ICommandBuffer> commandBuffer(unsigned int index) const { return genericCommandBuffer(index); }
50
55 [[nodiscard]] std::vector<const IImage*> images() const noexcept { return genericImages(); }
56
62 [[nodiscard]] const IImage& image(unsigned int location) const { return genericImage(location); }
63
73 virtual void resize(const spark::math::Vector2<unsigned>& render_area) = 0;
74
75 private:
78 [[nodiscard]] virtual std::vector<std::shared_ptr<const ICommandBuffer>> genericCommandBuffers() const noexcept = 0;
79 [[nodiscard]] virtual std::shared_ptr<const ICommandBuffer> genericCommandBuffer(unsigned int index) const = 0;
80 [[nodiscard]] virtual std::vector<const IImage*> genericImages() const noexcept = 0;
81 [[nodiscard]] virtual const IImage& genericImage(unsigned int location) const = 0;
83 };
84
89 template <typename CommandBufferType>
91 {
92 public:
93 using command_buffer_type = CommandBufferType;
94 using image_type = typename command_buffer_type::image_type;
95
96 public:
98 [[nodiscard]] virtual std::vector<std::shared_ptr<const command_buffer_type>> commandBuffers() const noexcept = 0;
99
101 [[nodiscard]] virtual std::shared_ptr<const command_buffer_type> commandBuffer(unsigned index) const = 0;
102
104 [[nodiscard]] virtual std::vector<const image_type*> images() const noexcept = 0;
105
107 [[nodiscard]] virtual const image_type& image(unsigned location) const = 0;
108
109 private:
110 [[nodiscard]] std::vector<std::shared_ptr<const ICommandBuffer>> genericCommandBuffers() const noexcept final
111 {
112 auto tmp = commandBuffers();
113 std::vector<std::shared_ptr<const ICommandBuffer>> command_buffers_vector;
114 command_buffers_vector.reserve(tmp.size());
115 std::ranges::transform(tmp,
116 std::back_inserter(command_buffers_vector),
117 [](const auto& command_buffer) { return static_cast<std::shared_ptr<const ICommandBuffer>>(command_buffer); });
118 return command_buffers_vector;
119 }
120
121 [[nodiscard]] std::shared_ptr<const ICommandBuffer> genericCommandBuffer(unsigned index) const final { return commandBuffer(index); }
122
123 [[nodiscard]] std::vector<const IImage*> genericImages() const noexcept final
124 {
125 auto tmp = images();
126 std::vector<const IImage*> images_vector;
127 images_vector.reserve(tmp.size());
128 std::ranges::transform(tmp, std::back_inserter(images_vector), [](const auto& image) { return static_cast<const IImage*>(image); });
129 return images_vector;
130 }
131
132 [[nodiscard]] const IImage& genericImage(unsigned location) const final { return image(location); }
133 };
134}
A vector with two components.
Definition Vector2.h:13
Stores the images for the output attachments for a back buffer of a IRenderPass>, as well as a Comman...
Definition FrameBuffer.h:91
virtual std::vector< std::shared_ptr< const command_buffer_type > > commandBuffers() const noexcept=0
Gets all command buffers of the frame buffer.
Interface for a command buffer.
Definition CommandBuffer.h:24
Interface for a frame buffer.
Definition FrameBuffer.h:17
std::vector< const IImage * > images() const noexcept
Gets all images storing the output attachments for the render targets of the IRenderPass.
Definition FrameBuffer.h:55
std::shared_ptr< const ICommandBuffer > commandBuffer(unsigned int index) const
Gets the command buffer that records draw commands for the frame buffer.
Definition FrameBuffer.h:49
virtual unsigned int bufferIndex() const noexcept=0
Gets the index of the frame buffer within the IRenderPass.
virtual void resize(const spark::math::Vector2< unsigned > &render_area)=0
Invalidate and resize the frame buffer with given render_area.
const IImage & image(unsigned int location) const
Gets the image storing the output attachment for the render target mapped at given location.
Definition FrameBuffer.h:62
Definition Image.h:131