FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
vulkan/C_surface.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_SURFACE_HPP_INCLUDED
18#define _FGE_VULKAN_C_SURFACE_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21#include "volk.h"
22#include "FastEngine/C_vector.hpp"
23#include "SDL_video.h"
24#include <string_view>
25
26#define FGE_WINDOWPOS_UNDEFINED {SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED}
27#define FGE_WINDOWPOS_CENTERED {SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED}
28
29namespace fge::vulkan
30{
31
32class Instance;
33
41class FGE_API Surface
42{
43public:
44 explicit Surface(Instance& instance);
45 Surface(Surface const& r) = delete;
46 Surface(Surface&& r) noexcept;
47 virtual ~Surface() = default;
48
49 Surface& operator=(Surface const& r) = delete;
50 Surface& operator=(Surface&& r) noexcept = delete;
51
52 virtual void destroy() = 0;
53
54 [[nodiscard]] VkSurfaceKHR get() const;
55 [[nodiscard]] bool isCreated() const;
56
57 [[nodiscard]] Instance& getInstance();
58 [[nodiscard]] Instance const& getInstance() const;
59
60 [[nodiscard]] virtual VkExtent2D getExtent() const;
61
62protected:
63 VkSurfaceKHR _g_surface;
64
65private:
66 Instance* g_instance;
67};
68
69class FGE_API SurfaceHeadless final : public Surface
70{
71public:
72 explicit SurfaceHeadless(Instance& instance, VkExtent2D extent = {0, 0});
73 SurfaceHeadless(SurfaceHeadless&& r) noexcept;
74 ~SurfaceHeadless() override;
75
76 bool create(VkExtent2D extent);
77
78 void setExtent(VkExtent2D extent);
79
80 void destroy() override;
81
82 [[nodiscard]] VkExtent2D getExtent() const override;
83
84private:
85 VkExtent2D g_extent;
86};
87
96class SurfaceWindow : public Surface
97{
98public:
99 enum class Types
100 {
101 UNKNOWN,
102 SDL
103 };
104
105 inline explicit SurfaceWindow(Instance& instance) :
106 Surface(instance)
107 {}
108
109 [[nodiscard]] inline VkExtent2D getExtent() const override
110 {
111 auto const size = this->getSize();
112 return {static_cast<uint32_t>(size.x), static_cast<uint32_t>(size.y)};
113 }
114
115 [[nodiscard]] virtual Types getType() const = 0;
116
117 [[nodiscard]] virtual fge::Vector2i getSize() const = 0;
118 [[nodiscard]] virtual fge::Vector2i getPosition() const = 0;
119};
120
128class FGE_API SurfaceSDLWindow final : public SurfaceWindow
129{
130public:
131 inline explicit SurfaceSDLWindow(Instance& instance) :
132 SurfaceWindow(instance),
133 g_window(nullptr)
134 {}
135 SurfaceSDLWindow(Instance& instance,
136 std::string_view title,
137 fge::Vector2i const& position,
138 fge::Vector2i const& size,
139 uint32_t flags);
140 SurfaceSDLWindow(Instance& instance, fge::Vector2i const& position, fge::Vector2i const& size, uint32_t flags);
142 ~SurfaceSDLWindow() override;
143
153 bool create(SDL_Window* window);
164 bool create(std::string_view title, fge::Vector2i const& position, fge::Vector2i const& size, uint32_t flags);
165 void destroy() override;
166
167 [[nodiscard]] Types getType() const override;
168
169 [[nodiscard]] fge::Vector2i getSize() const override;
170 [[nodiscard]] fge::Vector2i getPosition() const override;
171
172 [[nodiscard]] SDL_Window* getWindow() const;
173
174private:
175 SDL_Window* g_window;
176};
177
178} // namespace fge::vulkan
179
180#endif //_FGE_VULKAN_C_SURFACE_HPP_INCLUDED
Vulkan instance abstraction.
Definition C_instance.hpp:39
Definition vulkan/C_surface.hpp:70
Vulkan OS window surface made with SDL.
Definition vulkan/C_surface.hpp:129
bool create(SDL_Window *window)
Create a surface by taking an already created SDL_Window.
bool create(std::string_view title, fge::Vector2i const &position, fge::Vector2i const &size, uint32_t flags)
Create a surface and the SDL_Window.
Vulkan OS window surface.
Definition vulkan/C_surface.hpp:97
Vulkan surface abstraction.
Definition vulkan/C_surface.hpp:42