Clear code
This commit is contained in:
@@ -78,10 +78,13 @@ VkVertexInputBindingDescription RenderEngine::Vertex::get_binding_description()
|
||||
std::array<VkVertexInputAttributeDescription, 2> RenderEngine::Vertex::get_vertex_attribute_descriptions()
|
||||
{
|
||||
std::array<VkVertexInputAttributeDescription, 2> descriptions;
|
||||
// Bind vertex loc
|
||||
descriptions[0].binding = 0;
|
||||
descriptions[0].location = 0;
|
||||
descriptions[0].format = VK_FORMAT_R32G32_SFLOAT;
|
||||
descriptions[0].offset = offsetof(Vertex, pos);
|
||||
|
||||
// Bind color
|
||||
descriptions[1].binding = 0;
|
||||
descriptions[1].location = 1;
|
||||
descriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
@@ -98,6 +101,7 @@ bool RenderEngine::is_device_suitable(VkPhysicalDevice device, VkSurfaceKHR surf
|
||||
vkGetPhysicalDeviceFeatures(device, &device_features);
|
||||
|
||||
try {
|
||||
// Ловить исключения имеет смысыл только здесь
|
||||
QueueFamilyIndices indices = find_queue_family_indices(device, surface);
|
||||
} catch (...) {
|
||||
return false;
|
||||
@@ -155,8 +159,10 @@ RenderEngine::QueueFamilyIndices RenderEngine::find_queue_family_indices(VkPhysi
|
||||
// Find present
|
||||
VkBool32 present_support = false;
|
||||
VK_CHECK(vkGetPhysicalDeviceSurfaceSupportKHR(physical_device, queue_family_indices.graphics_family.value(), surface, &present_support));
|
||||
// Если графическая очередь поддерживет презентацию кадров, то используем её
|
||||
if (present_support == VK_TRUE)
|
||||
queue_family_indices.present_family = queue_family_indices.graphics_family;
|
||||
// иначе ищем другую подходящую очередь
|
||||
else
|
||||
{
|
||||
for(uint32_t i = 0; i < family_properties.size(); ++i)
|
||||
@@ -174,6 +180,8 @@ RenderEngine::QueueFamilyIndices RenderEngine::find_queue_family_indices(VkPhysi
|
||||
if (queue_family_indices.present_family.has_value() == false)
|
||||
throw std::runtime_error("Failed to find a present queue family");
|
||||
|
||||
// С начала пытаемся найти очередь специалезированную
|
||||
// для копирования отличную от графической
|
||||
for(uint32_t i = 0; i < family_properties.size(); ++i)
|
||||
{
|
||||
if (i == queue_family_indices.graphics_family.value())
|
||||
@@ -181,6 +189,7 @@ RenderEngine::QueueFamilyIndices RenderEngine::find_queue_family_indices(VkPhysi
|
||||
if (family_properties[i].queueFlags & VK_QUEUE_TRANSFER_BIT)
|
||||
queue_family_indices.transfer_family = i;
|
||||
}
|
||||
// Если не находим, то используем графическую
|
||||
if (queue_family_indices.transfer_family.has_value() == false)
|
||||
queue_family_indices.transfer_family = queue_family_indices.graphics_family;
|
||||
return queue_family_indices;
|
||||
@@ -208,6 +217,7 @@ VkPresentModeKHR RenderEngine::choose_present_mode(const std::vector<VkPresentMo
|
||||
|
||||
VkExtent2D RenderEngine::choose_extent(const VkSurfaceCapabilitiesKHR& capabilities, GLFWwindow* window)
|
||||
{
|
||||
// Здесь вычисляется допустимое разрешение рендера
|
||||
if (capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max())
|
||||
return capabilities.currentExtent;
|
||||
else
|
||||
|
||||
@@ -60,7 +60,9 @@ class RenderEngine
|
||||
int current_frame_ = 0;
|
||||
|
||||
CoreInstance& core_;
|
||||
|
||||
GLFWwindow* window_;
|
||||
|
||||
VkInstance instance_ = VK_NULL_HANDLE;
|
||||
VkSurfaceKHR surface_ = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
|
||||
@@ -80,6 +82,7 @@ class RenderEngine
|
||||
VkCommandPool command_pool_ = VK_NULL_HANDLE;
|
||||
std::vector<VkCommandBuffer> command_buffers_;
|
||||
|
||||
// Sync objects
|
||||
std::vector<VkSemaphore> image_available_semaphores_, render_finished_semaphores_;
|
||||
std::vector<VkFence> in_flight_fences_;
|
||||
|
||||
@@ -123,4 +126,6 @@ public:
|
||||
|
||||
void start();
|
||||
void stop_render() const;
|
||||
|
||||
GLFWwindow* get_window() const { return window_; }
|
||||
};
|
||||
Reference in New Issue
Block a user