libcruft-vk/traits.hpp

114 lines
4.3 KiB
C++
Raw Normal View History

2016-02-24 11:11:41 +11:00
#ifndef __VK_TRAITS_HPP
#define __VK_TRAITS_HPP
#include "./fwd.hpp"
#include "./vk.hpp"
namespace vk {
///////////////////////////////////////////////////////////////////////////
template <typename T> struct id_traits { };
template <> struct id_traits<instance> { using id_t = VkInstance; };
template <> struct id_traits<physical_device> { using id_t = VkPhysicalDevice; };
template <> struct id_traits<device> { using id_t = VkDevice; };
template <> struct id_traits<queue> { using id_t = VkQueue; };
template <> struct id_traits<command_pool> { using id_t = VkCommandPool; };
template <> struct id_traits<command_buffer> { using id_t = VkCommandBuffer; };
template <> struct id_traits<fence> { using id_t = VkFence; };
template <> struct id_traits<semaphore> { using id_t = VkSemaphore; };
template <> struct id_traits<event> { using id_t = VkEvent; };
template <> struct id_traits<render_pass> { using id_t = VkRenderPass; };
template <> struct id_traits<framebuffer> { using id_t = VkFramebuffer; };
template <> struct id_traits<shader_module> { using id_t = VkShaderModule; };
template <> struct id_traits<pipeline> { using id_t = VkPipeline; };
template <> struct id_traits<pipeline_cache> { using id_t = VkPipelineCache; };
template <> struct id_traits<device_memory> { using id_t = VkDeviceMemory; };
template <> struct id_traits<buffer> { using id_t = VkBuffer; };
template <> struct id_traits<buffer_view> { using id_t = VkBufferView; };
///////////////////////////////////////////////////////////////////////////
template <typename T> struct life_traits { };
template <> struct life_traits<instance> {
static constexpr auto create = vkCreateInstance;
static constexpr auto destroy = vkDestroyInstance;
};
template <> struct life_traits<device> {
static constexpr auto create = vkCreateDevice;
static constexpr auto destroy = vkDestroyDevice;
};
template <> struct life_traits<command_pool> {
static constexpr auto create = vkCreateCommandPool;
static constexpr auto destroy = vkDestroyCommandPool;
};
template <> struct life_traits<fence> {
static constexpr auto create = vkCreateFence;
static constexpr auto destroy = vkDestroyFence;
};
template <> struct life_traits<semaphore> {
static constexpr auto create = vkCreateSemaphore;
static constexpr auto destroy = vkDestroySemaphore;
};
template <> struct life_traits<event> {
static constexpr auto create = vkCreateEvent;
static constexpr auto destroy = vkDestroyEvent;
};
template <> struct life_traits<render_pass> {
static constexpr auto create = vkCreateRenderPass;
static constexpr auto destroy = vkDestroyRenderPass;
};
template <> struct life_traits<framebuffer> {
static constexpr auto create = vkCreateFramebuffer;
static constexpr auto destroy = vkDestroyFramebuffer;
};
template <> struct life_traits<shader_module> {
static constexpr auto create = vkCreateShaderModule;
static constexpr auto destroy = vkDestroyShaderModule;
};
template <VkPipelineBindPoint> struct create_traits { };
template <> struct create_traits<VK_PIPELINE_BIND_POINT_COMPUTE> {
static constexpr auto func = vkCreateComputePipelines;
};
template <> struct create_traits<VK_PIPELINE_BIND_POINT_GRAPHICS> {
static constexpr auto func = vkCreateGraphicsPipelines;
};
template <> struct life_traits<pipeline> {
template <VkPipelineBindPoint P>
static constexpr auto create = create_traits<P>::func;
static constexpr auto destroy = vkDestroyPipeline;
};
template <> struct life_traits<pipeline_cache> {
static constexpr auto create = vkCreatePipelineCache;
static constexpr auto destroy = vkDestroyPipelineCache;
};
template <> struct life_traits<device_memory> {
static constexpr auto create = vkAllocateMemory;
static constexpr auto destroy = vkFreeMemory;
};
template <> struct life_traits<buffer> {
static constexpr auto create = vkCreateBuffer;
static constexpr auto destroy = vkDestroyBuffer;
};
template <> struct life_traits<buffer_view> {
static constexpr auto create = vkCreateBufferView;
};
}
#endif