jGL
Loading...
Searching...
No Matches
vulkanInstance.h
Go to the documentation of this file.
1#ifndef VULKANINSTANCE_H
2#define VULKANINSTANCE_H
3
4#ifndef ANDROID
5#define GLFW_INCLUDE_VULKAN
6#include <GLFW/glfw3.h>
7#endif
8
9#include <version.h>
10#include <jGL/Vulkan/vkDebug.h>
11
12#include <jGL/jGL.h>
13
15#include <jGL/Vulkan/surface.h>
20#include <jGL/Vulkan/pipeline.h>
21
26
28
29namespace jGL::Vulkan
30{
31 class vkTexture;
32
34 {
35
36 public:
37
38 VulkanInstance(const DesktopDisplay & display);
39
41
42 void finish()
43 {
44 closing = true;
45 vkDeviceWaitIdle(device.getVkDevice());
46 }
47
48 void text
49 (
50 std::string characters,
51 glm::vec2 position,
52 float scale,
53 glm::vec4 colour,
54 glm::bvec2 centre = glm::bvec2(false,false)
55 )
56 {
57 textRenderer->renderText
58 (
59 device,
60 command,
61 commandBuffer,
62 currentFrame,
63 characters,
64 position,
65 scale,
66 colour,
67 centre
68 );
69 }
70
71 void clear() {/*TODO*/}
72
73 void setMSAA(uint8_t samples) {/*TODO*/}
74
75 void setClear(glm::vec4 colour) {/*TODO*/}
76 void setProjection(glm::mat4 proj) {/*TODO*/}
77 void setTextProjection(glm::mat4 p) {textRenderer->setProjection(p);}
78 void setViewport(glm::vec4 view)
79 {
80 viewport.x = view.x;
81 viewport.y = view.y;
82 viewport.width = view.z;
83 viewport.height = view.w;
84 }
85
86 std::shared_ptr<Particles> createParticles(size_t sizeHint)
87 {
88 return std::static_pointer_cast<Particles>(std::make_shared<vkParticles>(sizeHint));
89 }
90 std::shared_ptr<Texture> createTexture(std::filesystem::path imageFile, Texture::Type type)
91 {
92 return std::static_pointer_cast<Texture>
93 (
94 std::make_shared<vkTexture>
95 (
96 device,
97 command,
98 imageFile,
99 type
100 )
101 );
102 }
103 std::shared_ptr<Texture> createTexture(std::vector<std::byte> data, Texture::Type type)
104 {
105 TODO("VulkanInstance::createTexture from bytes undefined");
106 return std::static_pointer_cast<Texture>
107 (
108 std::make_shared<vkTexture>
109 (
110 device
111 )
112 );
113 }
114
115 std::shared_ptr<SpriteRenderer> createSpriteRenderer(size_t sizeHint)
116 {
117 return std::static_pointer_cast<SpriteRenderer>
118 (
119 std::make_shared<vkSpriteRenderer>
120 (
121 sizeHint
122 )
123 );
124 }
125
126 std::shared_ptr<ShapeRenderer> createShapeRenderer(size_t sizeHint)
127 {
128 return std::static_pointer_cast<ShapeRenderer>
129 (
130 std::make_shared<vkShapeRenderer>
131 (
132 sizeHint
133 )
134 );
135 }
136
137 const Device & getDevice() const { return device; }
138 const Command & getCommand() const { return command; }
139 const VkInstance & getVkInstance() const { return instance; }
140 const Swapchain & getSwapchain() const { return swapchain; }
141 const RenderPass & getRenderPass() const { return renderPass; }
142 const unsigned getConcurrentFrames() const { return concurrentFrames; }
143
144 void beginFrame();
145 void endFrame();
146
147 void createSyncObjects();
148
149 private:
150
151 const unsigned concurrentFrames = 2;
152
153 unsigned currentFrame = 0;
154
155 bool midFrame = false;
156
157 glm::vec4 clearColour = glm::vec4(1.0,1.0,1.0,1.0);
158
159 std::vector<VkSemaphore> imageAvailableSemaphores, renderFinsihedSemaphores;
160 std::vector<VkFence> framesFinished;
161
162 VkInstance instance;
163
164 VkDebugUtilsMessengerEXT debugMessenger;
165
166 std::vector<VkLayerProperties> availableLayers;
167
168 Surface surface;
169 Device device;
170 uint32_t swapchainImageIndex = 0;
171 Swapchain swapchain;
172 Command command;
173 RenderPass renderPass;
174 VkCommandBuffer commandBuffer;
175 std::vector<std::unique_ptr<Framebuffer>> framebuffers;
176
177 std::unique_ptr<TextRenderer> textRenderer;
178
179 VkRect2D scissor;
180 VkViewport viewport;
181
182 VkImage framebufferImage;
183 VkImageView framebufferImageView;
184 VkDeviceMemory framebufferDeviceMemory;
185
186 void supportedValidationLayers(bool print = false);
187 bool checkValidationLayerSupport();
188
189 };
190}
191
192#endif /* VULKANINSTANCE_H */
Definition desktopDisplay.h:61
Type
Definition texture.h:21
Definition command.h:12
Definition device.h:10
const VkDevice & getVkDevice() const
Definition device.h:24
Definition renderPass.h:11
Definition surface.h:12
Definition swapchain.h:15
Definition vulkanInstance.h:34
void setMSAA(uint8_t samples)
Definition vulkanInstance.h:73
void text(std::string characters, glm::vec2 position, float scale, glm::vec4 colour, glm::bvec2 centre=glm::bvec2(false, false))
Definition vulkanInstance.h:49
std::shared_ptr< Texture > createTexture(std::vector< std::byte > data, Texture::Type type)
Definition vulkanInstance.h:103
void setClear(glm::vec4 colour)
Definition vulkanInstance.h:75
void setViewport(glm::vec4 view)
Definition vulkanInstance.h:78
const VkInstance & getVkInstance() const
Definition vulkanInstance.h:139
void createSyncObjects()
Definition vulkanInstance.cpp:395
void setTextProjection(glm::mat4 p)
Definition vulkanInstance.h:77
~VulkanInstance()
Definition vulkanInstance.cpp:196
const unsigned getConcurrentFrames() const
Definition vulkanInstance.h:142
const Device & getDevice() const
Definition vulkanInstance.h:137
void clear()
Definition vulkanInstance.h:71
const Swapchain & getSwapchain() const
Definition vulkanInstance.h:140
std::shared_ptr< SpriteRenderer > createSpriteRenderer(size_t sizeHint)
Definition vulkanInstance.h:115
void setProjection(glm::mat4 proj)
Definition vulkanInstance.h:76
void finish()
Definition vulkanInstance.h:42
std::shared_ptr< Texture > createTexture(std::filesystem::path imageFile, Texture::Type type)
Definition vulkanInstance.h:90
void endFrame()
Definition vulkanInstance.cpp:337
const RenderPass & getRenderPass() const
Definition vulkanInstance.h:141
const Command & getCommand() const
Definition vulkanInstance.h:138
std::shared_ptr< Particles > createParticles(size_t sizeHint)
Definition vulkanInstance.h:86
void beginFrame()
Definition vulkanInstance.cpp:268
std::shared_ptr< ShapeRenderer > createShapeRenderer(size_t sizeHint)
Definition vulkanInstance.h:126
Definition jGL.h:21
bool closing
Definition jGL.h:65
Definition buffer.h:10
void TODO(std::string context)
Definition warning.cpp:3