FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_renderWindow.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_GRAPHIC_C_RENDERWINDOW_HPP_INCLUDED
18#define _FGE_GRAPHIC_C_RENDERWINDOW_HPP_INCLUDED
19
20/*
21 * Original from : https://github.com/SFML/SFML
22 * Copyright (C) 2007-2022 Laurent Gomila
23 *
24 * Altered/Modified by Guillaume Guillet
25 */
26
27#include "FastEngine/fge_extern.hpp"
28#include "FastEngine/graphic/C_renderTarget.hpp"
29#include "FastEngine/vulkan/C_descriptorSet.hpp"
30#include "FastEngine/vulkan/C_descriptorSetLayout.hpp"
31#include "FastEngine/vulkan/C_swapChain.hpp"
32#include "FastEngine/vulkan/C_textureImage.hpp"
33#include "FastEngine/vulkan/C_uniformBuffer.hpp"
34#include <array>
35#include <string>
36
37#define FGE_RENDER_FPS_NOT_LIMITED std::numeric_limits<unsigned int>::max()
38
39namespace fge
40{
41
42namespace vulkan
43{
44
45class Context;
46class SurfaceWindow;
47
48} // namespace vulkan
49
50class FGE_API RenderWindow : public fge::RenderTarget
51{
52public:
53 explicit RenderWindow(fge::vulkan::Context const& context, fge::vulkan::SurfaceWindow& surfaceWindow);
54 ~RenderWindow() override;
55
56 void destroy() final;
57
58 [[nodiscard]] uint32_t prepareNextFrame(VkCommandBufferInheritanceInfo const* inheritanceInfo,
59 uint64_t timeout_ns) override;
60 void beginRenderPass(uint32_t imageIndex) override;
61 void endRenderPass() override;
62 void display(uint32_t imageIndex) override;
63
64 [[nodiscard]] Vector2u getSize() const override;
65
66 void setPresentMode(VkPresentModeKHR presentMode);
67 [[nodiscard]] VkPresentModeKHR getPresentMode() const;
68
69 void setTargetFrameRate(unsigned int frameRate);
70 [[nodiscard]] unsigned int getTargetFrameRate() const;
71
72 [[nodiscard]] VkExtent2D getExtent2D() const override;
73 [[nodiscard]] fge::vulkan::CommandBuffer& getCommandBuffer() const override;
74 [[nodiscard]] VkRenderPass getRenderPass() const override;
75 [[nodiscard]] fge::vulkan::SurfaceWindow& getSurface() const;
76
77 [[nodiscard]] VkCommandBufferInheritanceInfo getInheritanceInfo(uint32_t imageIndex) const;
78
79 [[nodiscard]] uint32_t getCurrentFrame() const;
80
81 void onResize();
82
83private:
84 void init();
85
86 void recreateSwapChain();
87
88 void createRenderPass();
89 void createFramebuffers();
90 void createSyncObjects();
91
92 fge::vulkan::SurfaceWindow* g_surfaceWindow;
93
94 fge::vulkan::SwapChain g_swapChain;
95
96 VkRenderPass g_renderPass = VK_NULL_HANDLE;
97
98 std::vector<VkFramebuffer> g_swapChainFramebuffers;
99
100 mutable std::array<fge::vulkan::CommandBuffer, FGE_MAX_FRAMES_IN_FLIGHT> g_commandBuffers;
101
102 std::array<VkSemaphore, FGE_MAX_FRAMES_IN_FLIGHT> g_imageAvailableSemaphores;
103 std::array<VkSemaphore, FGE_MAX_FRAMES_IN_FLIGHT> g_renderFinishedSemaphores;
104 std::array<VkFence, FGE_MAX_FRAMES_IN_FLIGHT> g_inFlightFences;
105
106 uint32_t g_currentFrame = 0;
107
108 VkPresentModeKHR g_presentMode = VK_PRESENT_MODE_FIFO_KHR;
109 std::chrono::steady_clock::time_point g_lastFrameTime;
110 unsigned int g_targetFrameRate = FGE_RENDER_FPS_NOT_LIMITED;
111
112 bool g_framebufferResized = false;
113 bool g_isCreated = false;
114};
115
116} // namespace fge
117
118
119#endif // _FGE_GRAPHIC_C_RENDERWINDOW_HPP_INCLUDED
Definition C_renderTarget.hpp:56
Definition C_renderWindow.hpp:51
Vulkan command buffer wrapper.
Definition C_commandBuffer.hpp:36
Vulkan context.
Definition C_context.hpp:70
Vulkan OS window surface.
Definition vulkan/C_surface.hpp:97
Definition C_swapChain.hpp:32