Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
VulkanWindow.hpp
1/*
2Copyright (C) 2017-2021,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGAMES_VULKANWINDOW_HPP
17#define AEONGAMES_VULKANWINDOW_HPP
18
19#include <cstdint>
20#include <vector>
21#include <vulkan/vulkan.h>
23#include "aeongames/Frustum.hpp"
24#include "VulkanMemoryPoolBuffer.hpp"
25#include "VulkanPipeline.hpp"
26
27namespace AeonGames
28{
29 class Mesh;
30 class Material;
31 class Pipeline;
32 class BufferAccessor;
33 class VulkanRenderer;
36 {
37 public:
39 VulkanWindow ( VulkanRenderer& aVulkanRenderer, void* aWindowId );
42 VulkanWindow ( VulkanWindow&& aVulkanWindow );
43 VulkanWindow ( const VulkanWindow& aVulkanWindow ) = delete;
44 VulkanWindow& operator= ( const VulkanWindow& aVulkanWindow ) = delete;
45 VulkanWindow& operator= ( VulkanWindow&& aVulkanWindow ) = delete;
46
47 void BeginRender();
49 void EndRender();
62 void Render ( const Matrix4x4& aModelMatrix,
63 const Mesh& aMesh,
64 const Pipeline& aPipeline,
65 const Material* aMaterial = nullptr,
66 const BufferAccessor* aSkeleton = nullptr,
68 uint32_t aVertexStart = 0,
69 uint32_t aVertexCount = 0xffffffff,
70 uint32_t aInstanceCount = 1,
71 uint32_t aFirstInstance = 0 ) const;
73 void SetProjectionMatrix ( const Matrix4x4& aMatrix );
75 void SetViewMatrix ( const Matrix4x4& aMatrix );
77 const Matrix4x4& GetProjectionMatrix() const;
79 const Matrix4x4& GetViewMatrix() const;
81 const Frustum& GetFrustum() const;
83 void ResizeViewport ( int32_t aX, int32_t aY, uint32_t aWidth, uint32_t aHeight );
87 VkRenderPass GetRenderPass() const;
89 VkCommandBuffer GetCommandBuffer() const;
90 private:
91 void Initialize();
92 void Finalize();
93 void InitializeSurface();
94 void InitializeSwapchain();
95 void InitializeImageViews();
96 void InitializeDepthStencil();
97 void InitializeRenderPass();
98 void InitializeFrameBuffers();
99 void InitializeCommandBuffer();
100 void InitializeMatrices();
101 void FinalizeSurface();
102 void FinalizeSwapchain();
103 void FinalizeImageViews();
104 void FinalizeDepthStencil();
105 void FinalizeRenderPass();
106 void FinalizeFrameBuffers();
107 void FinalizeCommandBuffer();
108 void FinalizeMatrices();
109
110 VulkanRenderer& mVulkanRenderer;
111 void* mWindowId{};
112 Frustum mFrustum{};
113 VulkanMemoryPoolBuffer mMemoryPoolBuffer;
114 Matrix4x4 mProjectionMatrix{};
115 Matrix4x4 mViewMatrix{};
116 VulkanBuffer mMatrices;
117 VkFormat mVkDepthStencilFormat{ VK_FORMAT_UNDEFINED };
118 VkSurfaceFormatKHR mVkSurfaceFormatKHR{};
119 VkRenderPass mVkRenderPass{ VK_NULL_HANDLE };
120 VkSurfaceKHR mVkSurfaceKHR{ VK_NULL_HANDLE };
121 VkSurfaceCapabilitiesKHR mVkSurfaceCapabilitiesKHR {};
122 uint32_t mSwapchainImageCount{ 2 };
123 VkSwapchainKHR mVkSwapchainKHR{ VK_NULL_HANDLE };
124 VkImage mVkDepthStencilImage{ VK_NULL_HANDLE };
125 VkDeviceMemory mVkDepthStencilImageMemory{ VK_NULL_HANDLE };
126 VkImageView mVkDepthStencilImageView { VK_NULL_HANDLE};
127 VkCommandPool mVkCommandPool{ VK_NULL_HANDLE };
128 VkCommandBuffer mVkCommandBuffer{ VK_NULL_HANDLE };
129 bool mHasStencil{ false };
130 uint32_t mActiveImageIndex{ UINT32_MAX };
131 VkViewport mVkViewport{0, 0, 1, 1, 0, 1};
132 VkRect2D mVkScissor{};
133
134 VkDescriptorPool mMatricesDescriptorPool{VK_NULL_HANDLE};
135 VkDescriptorSet mMatricesDescriptorSet{VK_NULL_HANDLE};
136 VkSemaphore mVkAcquireSemaphore{VK_NULL_HANDLE};
137 VkFence mVkFence{ VK_NULL_HANDLE };
138
139 ::std::vector<VkImage> mVkSwapchainImages{};
140 ::std::vector<VkImageView> mVkSwapchainImageViews{};
141 ::std::vector<VkFramebuffer> mVkFramebuffers{};
142 ::std::vector<VkSemaphore> mVkSubmitSemaphores{};
143 };
144}
145#endif
Header for the frustum class.
Header for 4x4 matrix class.
Provides access to a region within a memory pool buffer.
View frustum defined by six clipping planes, extracted from a projection (or view-projection) matrix.
Definition Frustum.hpp:35
Represents a surface material with uniform properties and texture samplers.
Definition Material.hpp:38
4 by 4 matrix in colum mayor order.
Definition Matrix4x4.hpp:35
Represents a polygon mesh with vertex attributes and index data.
Definition Mesh.hpp:31
Rendering pipeline resource.
Definition Pipeline.hpp:122
Vulkan GPU buffer wrapper implementing the Buffer interface.
Vulkan memory pool buffer for transient per-frame uniform allocations.
Vulkan rendering backend implementing the Renderer interface.
VkRenderPass GetRenderPass() const
Get the Vulkan render pass for this window.
void SetViewMatrix(const Matrix4x4 &aMatrix)
Set the view matrix for this window.
VulkanWindow(VulkanRenderer &aVulkanRenderer, void *aWindowId)
Construct from a renderer and native window handle.
BufferAccessor AllocateSingleFrameUniformMemory(size_t aSize)
Allocate transient uniform memory for the current frame.
void EndRender()
End the current frame, submit commands, and present.
const Matrix4x4 & GetProjectionMatrix() const
Get the current projection matrix.
VkCommandBuffer GetCommandBuffer() const
Get the current command buffer being recorded.
void ResizeViewport(int32_t aX, int32_t aY, uint32_t aWidth, uint32_t aHeight)
Resize the rendering viewport.
void Render(const Matrix4x4 &aModelMatrix, const Mesh &aMesh, const Pipeline &aPipeline, const Material *aMaterial=nullptr, const BufferAccessor *aSkeleton=nullptr, Topology aTopology=Topology::TRIANGLE_LIST, uint32_t aVertexStart=0, uint32_t aVertexCount=0xffffffff, uint32_t aInstanceCount=1, uint32_t aFirstInstance=0) const
Render a mesh with the given pipeline, material, and transform.
const Frustum & GetFrustum() const
Get the view frustum derived from the current matrices.
const Matrix4x4 & GetViewMatrix() const
Get the current view matrix.
void SetProjectionMatrix(const Matrix4x4 &aMatrix)
Set the projection matrix for this window.
<- This is here just for the literals
Definition AABB.hpp:31
Topology
Primitive topology types for rendering.
Definition Pipeline.hpp:38
@ TRIANGLE_LIST
Independent triangles.
Definition Pipeline.hpp:45