91 lines
2.6 KiB
C++
91 lines
2.6 KiB
C++
// Wrappers for extension functions that must be located using vkGetInstanceProcAddr
|
|
VkResult CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
|
|
const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback) {
|
|
auto func = (PFN_vkCreateDebugReportCallbackEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT");
|
|
if(func != nullptr) {
|
|
return func(instance, pCreateInfo, pAllocator, pCallback);
|
|
} else {
|
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
|
}
|
|
}
|
|
|
|
void DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator) {
|
|
auto func = (PFN_vkDestroyDebugReportCallbackEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT");
|
|
if(func != nullptr) {
|
|
func(instance, callback, pAllocator);
|
|
}
|
|
}
|
|
|
|
// VDeleter utility class that automatically destroys objects when they fall out of scope.
|
|
template <typename T>
|
|
class VDeleter {
|
|
public:
|
|
VDeleter() : VDeleter([](T, VkAllocationCallbacks*) {}) {}
|
|
|
|
VDeleter(std::function<void(T, VkAllocationCallbacks*)> deletef) {
|
|
this->deleter = [=](T obj) { deletef(obj, nullptr); };
|
|
}
|
|
|
|
VDeleter(const VDeleter<VkInstance>& instance, std::function<void(VkInstance, T, VkAllocationCallbacks*)> deletef) {
|
|
this->deleter = [&instance, deletef](T obj) { deletef(instance, obj, nullptr); };
|
|
}
|
|
|
|
VDeleter(const VDeleter<VkDevice>& device, std::function<void(VkDevice, T, VkAllocationCallbacks*)> deletef) {
|
|
this->deleter = [&device, deletef](T obj) { deletef(device, obj, nullptr); };
|
|
}
|
|
|
|
~VDeleter() {
|
|
cleanup();
|
|
}
|
|
|
|
const T* operator &() const {
|
|
return &object;
|
|
}
|
|
|
|
T* replace() {
|
|
cleanup();
|
|
return &object;
|
|
}
|
|
|
|
operator T() const {
|
|
return object;
|
|
}
|
|
|
|
void operator=(T rhs) {
|
|
if (rhs != object) {
|
|
cleanup();
|
|
object = rhs;
|
|
}
|
|
}
|
|
|
|
template<typename V>
|
|
bool operator==(V rhs) {
|
|
return object == T(rhs);
|
|
}
|
|
|
|
private:
|
|
T object{VK_NULL_HANDLE};
|
|
std::function<void(T)> deleter;
|
|
|
|
void cleanup() {
|
|
if (object != VK_NULL_HANDLE) {
|
|
deleter(object);
|
|
}
|
|
object = VK_NULL_HANDLE;
|
|
}
|
|
};
|
|
|
|
struct QueueFamilyIndices {
|
|
int graphicsFamily = -1;
|
|
int presentFamily = -1;
|
|
|
|
bool isComplete() {
|
|
return graphicsFamily >= 0 && presentFamily >= 0;
|
|
}
|
|
};
|
|
|
|
struct SwapChainSupportDetails {
|
|
VkSurfaceCapabilitiesKHR capabilities;
|
|
std::vector<VkSurfaceFormatKHR> formats;
|
|
std::vector<VkPresentModeKHR> presentModes;
|
|
};
|