Vulkan-Hpp
10_InitRenderPass.cpp
Go to the documentation of this file.
1 // Copyright(c) 2018-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 : 10_InitRenderPass
16 // Initialize a render pass
17 
18 #if defined( _MSC_VER )
19 # pragma warning( disable : 4201 ) // disable warning C4201: nonstandard extension used: nameless struct/union; needed
20  // to get glm/detail/type_vec?.hpp without warnings
21 #elif defined( __GNUC__ )
22 // don't know how to switch off that warning here
23 #else
24 // unknow compiler... just ignore the warnings for yourselves ;)
25 #endif
26 
27 #include "../utils/utils.hpp"
28 
29 #include <iostream>
30 
31 #define GLM_FORCE_RADIANS
32 #include <glm/gtc/matrix_transform.hpp>
33 
34 static char const * AppName = "10_InitRenderPass";
35 static char const * EngineName = "Vulkan.hpp";
36 
37 int main( int /*argc*/, char ** /*argv*/ )
38 {
39  try
40  {
41  vk::Instance instance = vk::su::createInstance( AppName, EngineName, {}, vk::su::getInstanceExtensions() );
42 #if !defined( NDEBUG )
44 #endif
45 
46  vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
47 
48  vk::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 64, 64 ) );
49 
50  std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = vk::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface );
51  vk::Device device = vk::su::createDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() );
52 
53  vk::Format colorFormat = vk::su::pickSurfaceFormat( physicalDevice.getSurfaceFormatsKHR( surfaceData.surface ) ).format;
54  vk::Format depthFormat = vk::Format::eD16Unorm;
55 
56  /* VULKAN_HPP_KEY_START */
57 
58  std::array<vk::AttachmentDescription, 2> attachmentDescriptions;
59  attachmentDescriptions[0] = vk::AttachmentDescription( vk::AttachmentDescriptionFlags(),
60  colorFormat,
68  attachmentDescriptions[1] = vk::AttachmentDescription( vk::AttachmentDescriptionFlags(),
69  depthFormat,
77 
80  vk::SubpassDescription subpass( vk::SubpassDescriptionFlags(), vk::PipelineBindPoint::eGraphics, {}, colorReference, {}, &depthReference );
81 
82  vk::RenderPass renderPass = device.createRenderPass( vk::RenderPassCreateInfo( vk::RenderPassCreateFlags(), attachmentDescriptions, subpass ) );
83 
84  device.destroyRenderPass( renderPass );
85 
86  /* VULKAN_HPP_KEY_END */
87 
88  device.destroy();
89  instance.destroySurfaceKHR( surfaceData.surface );
90 #if !defined( NDEBUG )
91  instance.destroyDebugUtilsMessengerEXT( debugUtilsMessenger );
92 #endif
93  instance.destroy();
94  }
95  catch ( vk::SystemError & err )
96  {
97  std::cout << "vk::SystemError: " << err.what() << std::endl;
98  exit( -1 );
99  }
100  catch ( std::exception & err )
101  {
102  std::cout << "std::exception: " << err.what() << std::endl;
103  exit( -1 );
104  }
105  catch ( ... )
106  {
107  std::cout << "unknown error\n";
108  exit( -1 );
109  }
110  return 0;
111 }
int main(int, char **)
void cout(vk::SurfaceCapabilitiesKHR const &surfaceCapabilities)
void destroy(const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
VULKAN_HPP_NODISCARD Result createRenderPass(const vk::RenderPassCreateInfo *pCreateInfo, const vk::AllocationCallbacks *pAllocator, vk::RenderPass *pRenderPass, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void destroyRenderPass(vk::RenderPass renderPass, const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
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
VULKAN_HPP_NODISCARD Result getSurfaceFormatsKHR(vk::SurfaceKHR surface, uint32_t *pSurfaceFormatCount, vk::SurfaceFormatKHR *pSurfaceFormats, 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
vk::Device createDevice(vk::PhysicalDevice const &physicalDevice, uint32_t queueFamilyIndex, std::vector< std::string > const &extensions, vk::PhysicalDeviceFeatures const *physicalDeviceFeatures, void const *pNext)
Definition: utils.cpp:86
std::pair< uint32_t, uint32_t > findGraphicsAndPresentQueueFamilyIndex(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR const &surface)
Definition: utils.cpp:420
std::vector< std::string > getInstanceExtensions()
Definition: utils.cpp:477
vk::SurfaceFormatKHR pickSurfaceFormat(std::vector< vk::SurfaceFormatKHR > const &formats)
Definition: utils.cpp:539
std::vector< std::string > getDeviceExtensions()
Definition: utils.cpp:472
@ eDepthStencilAttachmentOptimal
vk::SurfaceKHR surface
Definition: utils.hpp:205