Vulkan-Hpp
SurfaceFormats.cpp
Go to the documentation of this file.
1 // Copyright(c) 2019, NVIDIA CORPORATION. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // VulkanHpp Samples : SurfaceFormats
16 // Get surface formats.
17 
18 #include "../utils/utils.hpp"
19 
20 #include <iomanip>
21 #include <sstream>
22 #include <vector>
24 
25 static char const * AppName = "SurfaceFormats";
26 static char const * EngineName = "Vulkan.hpp";
27 
28 int main( int /*argc*/, char ** /*argv*/ )
29 {
30  try
31  {
32  vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
33 #if !defined( NDEBUG )
35 #endif
36 
37  // enumerate the physicalDevices
38  std::vector<vk::PhysicalDevice> physicalDevices = instance.enumeratePhysicalDevices();
39 
40  vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 500, 500 ) );
41 
42  /* VULKAN_KEY_START */
43 
44  std::cout << std::boolalpha;
45  for ( size_t i = 0; i < physicalDevices.size(); i++ )
46  {
47  std::cout << "PhysicalDevice " << i << "\n";
48  std::vector<vk::SurfaceFormatKHR> surfaceFormats = physicalDevices[i].getSurfaceFormatsKHR( surfaceData.surface );
49  for ( size_t j = 0; j < surfaceFormats.size(); j++ )
50  {
51  std::cout << std::string( "\t" ) << "Format " << j << "\n";
52  std::cout << std::string( "\t\t" ) << "colorSpace = " << vk::to_string( surfaceFormats[j].colorSpace ) << "\n";
53  std::cout << std::string( "\t\t" ) << "format = " << vk::to_string( surfaceFormats[j].format ) << "\n";
54  std::cout << "\n";
55  }
56  }
57 
58  /* VULKAN_KEY_END */
59 
60  instance.destroySurfaceKHR( surfaceData.surface );
61 #if !defined( NDEBUG )
62  instance.destroyDebugUtilsMessengerEXT( debugUtilsMessenger );
63 #endif
64  instance.destroy();
65  }
66  catch ( vk::SystemError & err )
67  {
68  std::cout << "vk::SystemError: " << err.what() << std::endl;
69  exit( -1 );
70  }
71  catch ( std::exception & err )
72  {
73  std::cout << "std::exception: " << err.what() << std::endl;
74  exit( -1 );
75  }
76  catch ( ... )
77  {
78  std::cout << "unknown error\n";
79  exit( -1 );
80  }
81  return 0;
82 }
void cout(vk::SurfaceCapabilitiesKHR const &surfaceCapabilities)
int main(int, char **)
VULKAN_HPP_NODISCARD Result createDebugUtilsMessengerEXT(const vk::DebugUtilsMessengerCreateInfoEXT *pCreateInfo, const vk::AllocationCallbacks *pAllocator, vk::DebugUtilsMessengerEXT *pMessenger, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void destroy(const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
VULKAN_HPP_NODISCARD Result enumeratePhysicalDevices(uint32_t *pPhysicalDeviceCount, vk::PhysicalDevice *pPhysicalDevices, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void destroySurfaceKHR(vk::SurfaceKHR surface, const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void destroyDebugUtilsMessengerEXT(vk::DebugUtilsMessengerEXT messenger, const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
virtual const char * what() const VULKAN_HPP_NOEXCEPT
Definition: vulkan.hpp:6206
vk::DebugUtilsMessengerCreateInfoEXT makeDebugUtilsMessengerCreateInfoEXT()
Definition: utils.cpp:1025
vk::Instance createInstance(std::string const &appName, std::string const &engineName, std::vector< std::string > const &layers, std::vector< std::string > const &extensions, uint32_t apiVersion)
Definition: utils.cpp:279
std::vector< std::string > getInstanceExtensions()
Definition: utils.cpp:477
VULKAN_HPP_INLINE std::string to_string(FormatFeatureFlags value)
vk::SurfaceKHR surface
Definition: utils.hpp:205