Add create comand_pool and command_buffers. Fix CMake file for TestGame
This commit is contained in:
@@ -394,7 +394,7 @@ void RenderEngine::create_render_pass()
|
||||
VK_CHECK(vkCreateRenderPass(device_, &render_pass_info, nullptr, &render_pass_));
|
||||
}
|
||||
|
||||
void RenderEngine::create_graphycs_pipeline()
|
||||
void RenderEngine::create_graphics_pipeline()
|
||||
{
|
||||
std::ifstream vertex_shader_file("Shaders/vertex.spv", std::ios::binary);
|
||||
if (!vertex_shader_file.is_open())
|
||||
@@ -550,6 +550,31 @@ void RenderEngine::create_framebuffers()
|
||||
}
|
||||
}
|
||||
|
||||
void RenderEngine::create_command_pool()
|
||||
{
|
||||
QueueFamilyIndices queue_family_indices = find_queue_family_indices(physical_device_, surface_);
|
||||
|
||||
VkCommandPoolCreateInfo command_pool_info{};
|
||||
command_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||
command_pool_info.queueFamilyIndex = queue_family_indices.graphycs_family.value();
|
||||
command_pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
||||
|
||||
VK_CHECK(vkCreateCommandPool(device_, &command_pool_info, nullptr, &command_pool_));
|
||||
}
|
||||
|
||||
void RenderEngine::allocate_command_buffers()
|
||||
{
|
||||
command_buffers_.resize(MAX_FRAMES_IN_FLIGHT);
|
||||
|
||||
VkCommandBufferAllocateInfo command_buffer_allocate_info{};
|
||||
command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
command_buffer_allocate_info.commandPool = command_pool_;
|
||||
command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
command_buffer_allocate_info.commandBufferCount = static_cast<uint32_t>(command_buffers_.size());
|
||||
|
||||
VK_CHECK(vkAllocateCommandBuffers(device_, &command_buffer_allocate_info, command_buffers_.data()));
|
||||
}
|
||||
|
||||
void RenderEngine::create_surface()
|
||||
{
|
||||
VK_CHECK(glfwCreateWindowSurface(instance_, window_, nullptr, &surface_));
|
||||
@@ -569,11 +594,17 @@ window_(window)
|
||||
create_swapchain(desired_present_mode);
|
||||
create_image_views();
|
||||
create_render_pass();
|
||||
create_graphycs_pipeline();
|
||||
create_graphics_pipeline();
|
||||
}
|
||||
|
||||
RenderEngine::~RenderEngine()
|
||||
{
|
||||
if (command_buffers_.size() > 0)
|
||||
vkFreeCommandBuffers(device_, command_pool_, static_cast<uint32_t>(command_buffers_.size()), command_buffers_.data());
|
||||
|
||||
if (command_pool_ != VK_NULL_HANDLE)
|
||||
vkDestroyCommandPool(device_, command_pool_, nullptr);
|
||||
|
||||
for (auto& i : framebuffers_)
|
||||
vkDestroyFramebuffer(device_, i, nullptr);
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@ class RenderEngine
|
||||
|
||||
static const std::vector<const char*> deviceExtensions;
|
||||
|
||||
const int MAX_FRAMES_IN_FLIGHT = 2;
|
||||
int current_frame_ = 0;
|
||||
|
||||
CoreInstance& core_;
|
||||
GLFWwindow* window_;
|
||||
VkInstance instance_ = VK_NULL_HANDLE;
|
||||
@@ -52,6 +55,8 @@ class RenderEngine
|
||||
VkPipelineLayout pipeline_layout_ = VK_NULL_HANDLE;
|
||||
VkPipeline graphycs_pipeline_ = VK_NULL_HANDLE;
|
||||
std::vector<VkFramebuffer> framebuffers_;
|
||||
VkCommandPool command_pool_ = VK_NULL_HANDLE;
|
||||
std::vector<VkCommandBuffer> command_buffers_;
|
||||
|
||||
#ifdef _DEBUG
|
||||
VkResult enable_layer_validation(VkDebugUtilsMessengerCreateInfoEXT* create_info);
|
||||
@@ -75,8 +80,10 @@ class RenderEngine
|
||||
void create_swapchain(VkPresentModeKHR desired_present_mode);
|
||||
void create_image_views();
|
||||
void create_render_pass();
|
||||
void create_graphycs_pipeline();
|
||||
void create_graphics_pipeline();
|
||||
void create_framebuffers();
|
||||
void create_command_pool();
|
||||
void allocate_command_buffers();
|
||||
|
||||
public:
|
||||
// Can throw the exception
|
||||
|
||||
Reference in New Issue
Block a user