diff --git a/include/gryphn/gryphn.h b/include/gryphn/gryphn.h index eeb144c..76af1aa 100644 --- a/include/gryphn/gryphn.h +++ b/include/gryphn/gryphn.h @@ -2,6 +2,7 @@ #include #include #include +#include // #pragma once diff --git a/rendering_api/metal/src/core/debugger/metal_layers.cpp b/rendering_api/metal/src/core/debugger/metal_layers.cpp deleted file mode 100644 index 70b1284..0000000 --- a/rendering_api/metal/src/core/debugger/metal_layers.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#undef GN_UTILS_CPP -#include - -GN_EXPORT gnString gnGetPlatformLayerNameFn(const gnString& gnName) { - if (gnStringEquals(gnName, "GN_DEFAULT_DEBUG_LAYER")) return gnCreateString("METAL_DEBUG_LAYER"); - return gnCreateString("GN_NO_LAYER"); -} diff --git a/rendering_api/vulkan/CMakeLists.txt b/rendering_api/vulkan/CMakeLists.txt index 1597a87..3bf4f52 100644 --- a/rendering_api/vulkan/CMakeLists.txt +++ b/rendering_api/vulkan/CMakeLists.txt @@ -1,4 +1,5 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS on) +set(CMAKE_CXX_STANDARD 17) project(GryphnVulkanImpl) file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS diff --git a/rendering_api/vulkan/src/debugger/vulkan_debugger.cpp b/rendering_api/vulkan/src/debugger/vulkan_debugger.cpp index 26d67fd..656886f 100644 --- a/rendering_api/vulkan/src/debugger/vulkan_debugger.cpp +++ b/rendering_api/vulkan/src/debugger/vulkan_debugger.cpp @@ -1,5 +1,34 @@ -#include "iostream" #include "vulkan_debugger.h" +#include "instance/vulkan_instance.h" + +bool checkValidationLayerSupport(std::vector layers_to_validate) { + uint32_t layerCount; + vkEnumerateInstanceLayerProperties(&layerCount, nullptr); + + std::vector availableLayers(layerCount); + vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data()); + + for (int i = 0; i < layers_to_validate.size(); i++) { + bool layerFound = false; + + for (const auto& layerProperties : availableLayers) { + if (strcmp(layers_to_validate[i].c_str(), layerProperties.layerName) == 0) { + layerFound = true; + break; + } + } + + if (!layerFound) + return false; + } + + return true; +} + +typedef struct vk_userData_t { + gnDebuggerCallback debuggerCallback; + void* userData; +} vkUserData; static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, @@ -7,22 +36,42 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL vk_debuggerDebugCallback( const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData) { - if (messageSeverity >= VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) - std::cerr << "validation layer error: " << pCallbackData->pMessage << std::endl; - else - std::cout << "validation layer: " << pCallbackData->pMessage << std::endl; + vk_userData_t userData = *(struct vk_userData_t*)pUserData; + gnMessageSeverity severity; + gnMessageType type; + gnMessageData data = { + .message = gnCreateString(pCallbackData->pMessage) + }; + + switch (messageSeverity) { + default: break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT: severity = GN_MESSAGE_VERBOSE; break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT: severity = GN_MESSAGE_INFO; break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT: severity = GN_MESSAGE_WARNING; break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT: severity = GN_MESSAGE_ERROR; break; + } + + switch (messageType) { + default: break; + case VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT: type = GN_DEBUG_MESSAGE_GENERAL; break; + case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT: type = GN_DEBUG_MESSAGE_VALIDATION; break; + case VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT: type = GN_DEBUG_MESSAGE_PERFORMANCE; break; + } + + gnDebuggerCallback callback = *userData.debuggerCallback; + gnBool result = callback(severity, type, data, userData.userData); + if (result == gnFalse) return VK_FALSE; + else if (result == gnTrue) return VK_TRUE; return VK_FALSE; } -// zero fucking clue what this does but the guy who wrote vulkan-tutorial.com does -VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger) { - auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"); - if (func != nullptr) { - return func(instance, pCreateInfo, pAllocator, pDebugMessenger); - } else { +VkResult vk_createDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger) { + PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT"); + if (vkCreateDebugUtilsMessengerEXT != nullptr) + return vkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pDebugMessenger); + else return VK_ERROR_EXTENSION_NOT_PRESENT; - } } void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo) { @@ -33,25 +82,33 @@ void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& create createInfo.pfnUserCallback = vk_debuggerDebugCallback; } -void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) { - auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT"); - if (func != nullptr) { - func(instance, debugMessenger, pAllocator); +void vk_destroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) { + PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT"); + if (vkDestroyDebugUtilsMessengerEXT != nullptr) { + vkDestroyDebugUtilsMessengerEXT(instance, debugMessenger, pAllocator); } } -GN_EXPORT gnReturnCode gnCreateDebuggerFn(gnDebugger* debugger) { - if (debugger->debugger == nullptr) debugger->debugger = new gnPlatformDebugger(); +GN_EXPORT gnReturnCode gnCreateDebuggerFn(gnDebugger* debugger, gnInstance* instance, const gnDebuggerInfo_t info) { + debugger->debugger = new gnPlatformDebugger(); + + if (!checkValidationLayerSupport({"VK_LAYER_KHRONOS_validation"})) + return GN_FAILED_TO_CREATE_DEBUGGER; VkDebugUtilsMessengerCreateInfoEXT createInfo; - populateDebugMessengerCreateInfo(createInfo); - if (CreateDebugUtilsMessengerEXT(*debugger->debugger->instance, &createInfo, nullptr, &debugger->debugger->debugMessenger) != VK_SUCCESS) { - return GN_FAILED; - } + vk_userData_t* userData = (vk_userData_t*)malloc(sizeof(vk_userData_t)); + userData->debuggerCallback = info.callback; + userData->userData = info.userData; + + populateDebugMessengerCreateInfo(createInfo); + createInfo.pUserData = (void*)userData; + + if (vk_createDebugUtilsMessengerEXT(instance->instance->vk_instance, &createInfo, nullptr, &debugger->debugger->debugMessenger) != VK_SUCCESS) + return GN_FAILED_TO_CREATE_DEBUGGER; return GN_SUCCESS; } GN_EXPORT void gnDestroyDebuggerFn(gnDebugger& debugger) { - DestroyDebugUtilsMessengerEXT(*debugger.debugger->instance, debugger.debugger->debugMessenger, nullptr); + vk_destroyDebugUtilsMessengerEXT(*debugger.debugger->instance, debugger.debugger->debugMessenger, nullptr); } diff --git a/rendering_api/vulkan/src/debugger/vulkan_layers.cpp b/rendering_api/vulkan/src/debugger/vulkan_layers.cpp deleted file mode 100644 index 49fe90e..0000000 --- a/rendering_api/vulkan/src/debugger/vulkan_layers.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#undef GN_UTILS_CPP -#include - -GN_EXPORT gnString gnGetPlatformLayerNameFn(const gnString& gnName) { - if (gnStringEquals(gnName, "GN_DEFAULT_DEBUG_LAYER")) return gnCreateString("VK_LAYER_KHRONOS_validation"); - return gnCreateString("GN_NO_LAYER"); -} diff --git a/rendering_api/vulkan/src/instance/vulkan_instance.cpp b/rendering_api/vulkan/src/instance/vulkan_instance.cpp index 3b08687..71b2c90 100644 --- a/rendering_api/vulkan/src/instance/vulkan_instance.cpp +++ b/rendering_api/vulkan/src/instance/vulkan_instance.cpp @@ -1,57 +1,10 @@ #include "gryphn/gryphn_utils.h" #include "vector" -#include -// #include "debugger/vulkan_debugger.h" #include "vulkan_instance.h" - - -// now I gotta do some shit to setup debug layers -bool checkValidationLayerSupport(std::vector layers_to_validate) { - uint32_t layerCount; - vkEnumerateInstanceLayerProperties(&layerCount, nullptr); - - std::vector availableLayers(layerCount); - vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data()); - - for (int i = 0; i < layers_to_validate.size(); i++) { - bool layerFound = false; - - for (const auto& layerProperties : availableLayers) { - if (strcmp(layers_to_validate[i].c_str(), layerProperties.layerName) == 0) { - layerFound = true; - break; - } - } - - if (!layerFound) - return false; - } - - return true; -} - -// void gnInstanceSetAppInfoFn(gnInstance& instance, gnInstanceInfo& info) { - // if (instance.instance == nullptr) instance.instance = new gnPlatformInstanceData(); - -// instance.AppInfo = info; -// instance.instance->appInfo = {}; -// instance.instance->appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; -// instance.instance->appInfo.pApplicationName = "Hello Triangle"; -// instance.instance->appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0); -// instance.instance->appInfo.pEngineName = "No Engine"; -// instance.instance->appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0); -// instance.instance->appInfo.apiVersion = VK_API_VERSION_1_3; -// } - GN_EXPORT gnReturnCode gnCreateInstanceFn(gnInstance* instance, gnInstanceInfo instanceInfo) { instance->instance = new gnPlatformInstance(); - // if (instance->debugger != nullptr && !checkValidationLayerSupport(instance->debugger->debug_layers)) { - // return gnReturnError(GN_FAILED_CREATE_INSTANCE, "validation layers requested, but not available!"); - // } - // gnInstanceSetAppInfoFn(*instance, instance->AppInfo); - instance->valid = true; #ifdef GN_PLATFORM_LINUX @@ -73,8 +26,7 @@ GN_EXPORT gnReturnCode gnCreateInstanceFn(gnInstance* instance, gnInstanceInfo i instance->instance->extensions.push_back("VK_KHR_surface"); - // if (instance->debugger) - // instance->instance->extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); + instance->instance->extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); VkApplicationInfo appInfo = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, @@ -89,34 +41,14 @@ GN_EXPORT gnReturnCode gnCreateInstanceFn(gnInstance* instance, gnInstanceInfo i createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; createInfo.pApplicationInfo = &appInfo; createInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; - // auto extensions = getRequiredExtensions(instance->debugger); createInfo.enabledExtensionCount = static_cast(instance->instance->extensions.size());; createInfo.ppEnabledExtensionNames = instance->instance->extensions.data(); - // VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo{}; - // if (instance->debugger != nullptr) { - // auto validation_layers = instance->debugger->debug_layers; - - // gnList validation_layers_c = gnCreateList(); - // for (int i = 0; i < gnListLength(validation_layers); i++) - // gnListAdd(validation_layers_c, gnToCString(validation_layers[i])); - - // createInfo.enabledLayerCount = static_cast(gnListLength(validation_layers_c)); - // createInfo.ppEnabledLayerNames = gnListData(validation_layers_c); - - // populateDebugMessengerCreateInfo(debugCreateInfo); - // createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo; - // } else { - createInfo.enabledLayerCount = 0; - // } - if (vkCreateInstance(&createInfo, nullptr, &instance->instance->vk_instance) != VK_SUCCESS) { return GN_FAILED_CREATE_INSTANCE; } - // if (instance->debugger->debugger == nullptr) instance->debugger->debugger = new gnPlatformDebugger(); - // instance->debugger->debugger->instance = &instance->instance->vk_instance; return GN_SUCCESS; } diff --git a/src/core/debugger/gryphn_debugger.c b/src/core/debugger/gryphn_debugger.c index ad80572..48aebdb 100644 --- a/src/core/debugger/gryphn_debugger.c +++ b/src/core/debugger/gryphn_debugger.c @@ -1,17 +1,11 @@ -#undef GN_UTILS_CPP #include "gryphn_debugger.h" +#include "core/gryphn_platform_functions.h" +#include "stdio.h" -static gnReturnCode (*_gnCreateDebugger)(gnDebugger* debugger, const struct gnDebuggerInfo_t info); -static void (*_gnDestroyDebugger)(gnDebugger* debugger); - -void gn_load_functions() { - +gnReturnCode gnCreateDebugger(gnDebugger* debugger, gnInstance* instance, const struct gnDebuggerInfo_t info) { + debugger->instance = instance; + return instance->functions->_gnCreateDebugger(debugger, instance, info); +} +void gnDestroyDebugger(gnDebugger* debugger) { + debugger->instance->functions->_gnDestroyDebugger(debugger); } - -// void gnAddDebugLayer(gnDebugger& debugger, const gnString& layer) { -// gnListAdd(debugger.debug_layers, layer); -// } - -// const gnList& gnDebuggerGetDebugLayers(gnDebugger& debugger) { -// return debugger.debug_layers; -// } diff --git a/src/core/debugger/gryphn_debugger.h b/src/core/debugger/gryphn_debugger.h index f835408..1f5660a 100644 --- a/src/core/debugger/gryphn_debugger.h +++ b/src/core/debugger/gryphn_debugger.h @@ -1,17 +1,53 @@ #pragma once #include "utils/strings/gryphn_string.h" #include "utils/gryphn_error_code.h" +#include "core/instance/gryphn_instance.h" struct gnPlatformDebugger; +typedef enum gnMessageSeverity_e { + GN_MESSAGE_VERBOSE = 0x00000001, + GN_MESSAGE_INFO = 0x00000010, + GN_MESSAGE_WARNING = 0x00000100, + GN_MESSAGE_ERROR = 0x00001000, +} gnMessageSeverity; + +typedef enum gnMessageType_e { + GN_DEBUG_MESSAGE_GENERAL = 0x00000001, + GN_DEBUG_MESSAGE_VALIDATION = 0x00000002, + GN_DEBUG_MESSAGE_PERFORMANCE = 0x00000004, + // GN_DEBUG_MESSAGE_ADDRESS_BINDING = 0x00000008, vulkan had this but imma leave it out +} gnMessageType; + +typedef struct gnMessageData { + // const char* pMessageIdName; + // int32_t messageIdNumber; + // uint32_t queueLabelCount; + // const VkDebugUtilsLabelEXT* pQueueLabels; + // uint32_t cmdBufLabelCount; + // const VkDebugUtilsLabelEXT* pCmdBufLabels; + // uint32_t objectCount; + // const VkDebugUtilsObjectNameInfoEXT* pObjects; + // + // If i ever figure out what this shit does il add it + gnString message; +} gnMessageData; + +typedef gnBool (*gnDebuggerCallback)( + gnMessageSeverity messageSeverity, + gnMessageType messageType, + gnMessageData messageData, + void* userData); + typedef struct gnDebuggerInfo_t { - int layerCount; - gnString* layerNames; + gnDebuggerCallback callback; + void* userData; } gnDebuggerInfo; typedef struct gnDebugger_t { struct gnPlatformDebugger* debugger; + gnInstance* instance; } gnDebugger; -gnReturnCode gnCreateDebugger(gnDebugger* debugger, const struct gnDebuggerInfo_t info); -gnReturnCode gnDestroyDebugger(gnDebugger* debugger); +gnReturnCode gnCreateDebugger(gnDebugger* debugger, gnInstance* instance, const struct gnDebuggerInfo_t info); +void gnDestroyDebugger(gnDebugger* debugger); diff --git a/src/core/gryphn_platform_functions.h b/src/core/gryphn_platform_functions.h index 6ec4b87..5ad04fd 100644 --- a/src/core/gryphn_platform_functions.h +++ b/src/core/gryphn_platform_functions.h @@ -1,10 +1,13 @@ #pragma once // theoretically you could have multible gryphn instances running in one application, // why I dont know -#include "utils/gryphn_error_code.h" #include "instance/gryphn_instance.h" +#include "debugger/gryphn_debugger.h" typedef struct gnFunctions_t { gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info); void (*_gnDestroyInstance)(gnInstance* instance); + + gnReturnCode (*_gnCreateDebugger)(gnDebugger* debugger, gnInstance* instance, const struct gnDebuggerInfo_t info); + void (*_gnDestroyDebugger)(gnDebugger* debugger); } gnFunctions; diff --git a/src/core/instance/init/gryphn_init.c b/src/core/instance/init/gryphn_init.c index 131930e..9d48850 100644 --- a/src/core/instance/init/gryphn_init.c +++ b/src/core/instance/init/gryphn_init.c @@ -38,131 +38,6 @@ struct gnDynamicLibrary_t* gnLoadRenderingDLL(gnRenderingAPI renderingAPI) { void gnLoadFunctions(struct gnDynamicLibrary_t* lib, struct gnFunctions_t* functions) { gnLoadDLLFunction(lib, functions->_gnCreateInstance, "gnCreateInstanceFn"); gnLoadDLLFunction(lib, functions->_gnDestroyInstance, "gnDestroyInstanceFn"); + gnLoadDLLFunction(lib, functions->_gnCreateDebugger, "gnCreateDebuggerFn"); + gnLoadDLLFunction(lib, functions->_gnDestroyDebugger, "gnDestroyDebuggerFn"); } - -// gnReturnCode gnInit(gnRenderingAPI RenderingAPI) { - -// gnRenderingAPILIB = gnLoadDLL(gnCombineStrings(gnCreateString("gryphn/rendering_apis/"), libName)); -// if (!gnRenderingAPILIB.isValid) { return GN_UNABLE_TO_LOAD_DLL; } - -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateInstance, "gnCreateInstanceFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyInstance, "gnDestroyInstanceFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGetPlatformLayerName, "gnGetPlatformLayerNameFn"); - -// // LOAD THE SET WINDOW FUNCTIONS -// // #ifdef GN_PLATFORM_LINUX -// // #ifdef GN_WINDOW_X11 -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateX11WindowSurface, "gnCreateX11WindowSurfaceFn"); -// // #endif -// // #ifdef GN_WINDOW_WAYLAND -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateWaylandWindowSurface, "gnCreateWaylandWindowSurfaceFn"); -// // #endif -// // #endif - - -// // #ifdef GN_PLATFORM_WIN32 -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateWindowsWindowSurface, "gnCreateWindowsWindowSurfaceFn"); -// // #endif - -// // #ifdef GN_PLATFORM_MACOS -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateMacOSWindowSurface, "gnCreateMacOSWindowSurfaceFn"); -// // #endif -// // This is stupid - -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateDebugger, "gnCreateDebuggerFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyDebugger, "gnDestroyDebuggerFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGetPhysicalOutputDevices, "gnGetPhysicalOutputDevicesFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDeviceSupportsAPI, "gnDeviceSupportsAPIFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnRegisterOutputDevice, "gnRegisterOutputDeviceFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnWaitForDevice, "gnWaitForDeviceFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyOutputDevice, "gnDestroyOutputDeviceFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGetDevicePresentationDetails, "gnGetDevicePresentationDetailsFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnPresentationQueueGetNextImageAsync, "gnPresentationQueueGetNextImageAsyncFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnPresentationQueueGetState, "gnPresentationQueueGetStateFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreatePresentationQueue, "gnCreatePresentationQueueFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyPresentationQueue, "gnDestroyPresentationQueueFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnVertexDescriptionSetBindingDescription, "gnVertexDescriptionSetBindingDescriptionFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnVertexDescriptionSetPropertiesCount, "gnVertexDescriptionSetPropertiesCountFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnVertexDescriptionSetProperty, "gnVertexDescriptionSetPropertyFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateBuffer, "gnCreateBufferFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnBufferData, "gnBufferDataFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnBufferMapData, "gnBufferMapDataFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyBuffer, "gnDestroyBufferFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnBufferSubData, "gnBufferSubDataFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnBufferClearData, "gnBufferClearDataFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnTextureData, "gnTextureDataFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnTextureCubeMapData, "gnTextureCubeMapDataFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateTexture, "gnCreateTextureFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyTexture, "gnDestroyTextureFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateUniformLayout, "gnCreateUniformLayoutFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyUniformLayout, "gnDestroyUniformLayoutFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateRenderPass, "gnCreateRenderPassFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyRenderPass, "gnDestroyRenderPassFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateFence, "gnCreateFenceFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnWaitForFence, "gnWaitForFenceFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnResetFence, "gnResetFenceFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyFence, "gnDestroyFenceFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateCommandBuffer, "gnCreateCommandBufferFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, _gnCreateCommandBuffers, "_gnCreateCommandBuffersFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBufferReset, "gnCommandBufferResetFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyCommandBuffer, "gnDestroyCommandBufferFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnBuildShaderModule, "gnBuildShaderModuleFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyShaderModule, "gnDestroyShaderModuleFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnBuildShader, "gnBuildShaderFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateUniform, "gnCreateUniformFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyUniform, "gnDestroyUniformFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnUpdateSamplerUniform, "gnUpdateSamplerUniformFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnUpdateBufferUniform, "gnUpdateBufferUniformFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnAPISupports, "gnAPISupportsFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetPrimative, "gnGraphicsPipelineSetPrimativeFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineEnableDynamicStates, "gnGraphicsPipelineEnableDynamicStatesFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineEnableDynamicState, "gnGraphicsPipelineEnableDynamicStateFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, _gnGraphicsPipelineSetViewport, "_gnGraphicsPipelineSetViewportFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetCrop, "gnGraphicsPipelineSetCropFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetDepthClamp, "gnGraphicsPipelineSetDepthClampFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetFillMode, "gnGraphicsPipelineSetFillModeFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetLineWidth, "gnGraphicsPipelineSetLineWidthFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetCullMode, "gnGraphicsPipelineSetCullModeFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetMultisampling, "gnGraphicsPipelineSetMultisamplingFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineEnableDepthTest, "gnGraphicsPipelineEnableDepthTestFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetColorBlend, "gnGraphicsPipelineSetColorBlendFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetVertexDescription, "gnGraphicsPipelineSetVertexDescriptionFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineBindShader, "gnGraphicsPipelineBindShaderFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineSetRenderPass, "gnGraphicsPipelineSetRenderPassFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineAddUniformLayout, "gnGraphicsPipelineAddUniformLayoutFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnGraphicsPipelineAddPushConstant, "gnGraphicsPipelineAddPushConstantFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateGraphicsPipeline, "gnCreateGraphicsPipelineFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyGraphicsPipeline, "gnDestroyGraphicsPipelineFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateFramebuffer, "gnCreateFramebufferFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyFramebuffer, "gnDestroyFramebufferFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateFramebufferAttachment, "gnCreateFramebufferAttachmentFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCreateSyncSemaphore, "gnCreateSyncSemaphoreFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnDestroySyncSemaphore, "gnDestroySyncSemaphoreFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBufferStart, "gnCommandBufferStartFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBufferEnd, "gnCommandBufferEndFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBeginRenderPass, "gnCommandBeginRenderPassFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSetGraphicsPipeline, "gnCommandSetGraphicsPipelineFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBindSamplerUniform, "gnCommandBindSamplerUniformFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBindBuffer, "gnCommandBindBufferFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandBindBufferUniform, "gnCommandBindBufferUniformFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandPushConstant, "gnCommandPushConstantFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandDrawIndexed, "gnCommandDrawIndexedFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSetViewport, "gnCommandSetViewportFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSetScissor, "gnCommandSetScissorFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, _gnCommandDraw, "gnCommandDrawFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandEndRenderPass, "gnCommandEndRenderPassFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSubmitGetValidPresentationQueue, "gnCommandSubmitGetValidPresentationQueueFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandSubmit, "gnCommandSubmitFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandPresentGetValidPresentationQueue, "gnCommandPresentGetValidPresentationQueueFn"); -// // gnLoadDLLFunction(gnRenderingAPILIB, gnCommandPresent, "gnCommandPresentFn"); - -// return GN_SUCCESS; -// } - -// void* gnLoadFunction(gnString name) { -// return gnLoadFunctionPtr(gnRenderingAPILIB, name); -// } - -// void gnDestroy() { -// gnUnloadDLL(&gnRenderingAPILIB); -// } diff --git a/src/utils/gryphn_bool.h b/src/utils/gryphn_bool.h index eab0a5e..dd4f2a6 100644 --- a/src/utils/gryphn_bool.h +++ b/src/utils/gryphn_bool.h @@ -1,8 +1,14 @@ #pragma once #include "stdlib.h" +#ifdef __cplusplus +extern "C" { +#endif typedef int gnBool; -#define gnFalse 0; -#define gnTrue 1; +#define gnFalse 0 +#define gnTrue 1 +#ifdef __cplusplus +} +#endif typedef size_t gnSize; diff --git a/src/utils/gryphn_error_code.h b/src/utils/gryphn_error_code.h index ec193e3..73eeccf 100644 --- a/src/utils/gryphn_error_code.h +++ b/src/utils/gryphn_error_code.h @@ -5,7 +5,8 @@ typedef enum gnReturnCode_t { GN_UNKNOWN_RENDERINGAPI, GN_UNSUPPORTED_RENDERING_API, GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY, - GN_FAILED_CREATE_INSTANCE + GN_FAILED_CREATE_INSTANCE, + GN_FAILED_TO_CREATE_DEBUGGER // GN_UNKNOWN_ERROR, // GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, @@ -25,3 +26,14 @@ typedef enum gnReturnCode_t { } gnReturnCode; typedef gnReturnCode gnErrorCode; +static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) { + switch (returnCode) { + default: return "GN_FORGOT"; + case GN_SUCCESS: return "GN_SUCCESS"; + case GN_UNKNOWN_RENDERINGAPI: return "GN_UNKNOWN_RENDERINGAPI"; + case GN_UNSUPPORTED_RENDERING_API: return "GN_UNSUPPORTED_RENDERING_API"; + case GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY: return "GN_UNABLE_TO_LOAD_DYNAMIC_LIBARRY"; + case GN_FAILED_CREATE_INSTANCE: return "GN_FAILED_CREATE_INSTANCE"; + case GN_FAILED_TO_CREATE_DEBUGGER: return "GN_FAILED_TO_CREATE_DEBUGGER"; + } +}