
.. _program_listing_file_Src_GraphicsEngineVulkan_common_FormatHelper.hpp:

Program Listing for File FormatHelper.hpp
=========================================

|exhale_lsh| :ref:`Return to documentation for file <file_Src_GraphicsEngineVulkan_common_FormatHelper.hpp>` (``Src/GraphicsEngineVulkan/common/FormatHelper.hpp``)

.. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS

.. code-block:: cpp

   #pragma once
   
   #include <vulkan/vulkan.hpp>
   
   #include <stdexcept>
   #include <vector>
   
   #include "spdlog/spdlog.h"
   
   namespace Kataglyphis {
   static vk::Format choose_supported_format(vk::PhysicalDevice physical_device,
     const std::vector<vk::Format> &formats,
     vk::ImageTiling tiling,
     vk::FormatFeatureFlags feature_flags)
   {
       // loop through options and find compatible one
       for (vk::Format format : formats) {
           // get properties for give format on this device
           vk::FormatProperties properties = physical_device.getFormatProperties(format);
   
           // depending on tiling choice, need to check for different bit flag
           if (tiling == vk::ImageTiling::eLinear && (properties.linearTilingFeatures & feature_flags) == feature_flags) {
               return format;
   
           } else if (tiling == vk::ImageTiling::eOptimal
                      && (properties.optimalTilingFeatures & feature_flags) == feature_flags) {
               return format;
           }
       }
   
       spdlog::error("Failed to find supported format!");
       return vk::Format::eUndefined;
   }
   }// namespace Kataglyphis
