diff --git a/include/gryphn/gryphn_utils.h b/include/gryphn/gryphn_utils.h index 2880276..ab08808 100644 --- a/include/gryphn/gryphn_utils.h +++ b/include/gryphn/gryphn_utils.h @@ -20,4 +20,3 @@ typedef float gnFloat; typedef size_t gnSize; #define GN_EXPORT extern "C" -#define GN_RETURN_ERROR(errorString) return { GN_FAILED, errorString } diff --git a/rendering_api/metal/src/core/devices/metal_output_device.cpp b/rendering_api/metal/src/core/devices/metal_output_device.cpp index 17f8c1b..f425367 100644 --- a/rendering_api/metal/src/core/devices/metal_output_device.cpp +++ b/rendering_api/metal/src/core/devices/metal_output_device.cpp @@ -62,7 +62,7 @@ GN_EXPORT gnReturnCode gnRegisterOutputDeviceFn(gnOutputDevice* outputDevice, co MTL::CompileOptions* options = nullptr; MTL::Library* library = physicalDevice.physicalOutputDevice->device->newLibrary(NS::String::string(shaderSrc, NS::UTF8StringEncoding), options, &error); if (!library) { - GN_RETURN_ERROR(error->localizedDescription()->utf8String()); + return gnReturnError(GN_FAILED_CREATE_DEVICE, error->localizedDescription()->utf8String()); } MTL::Function* vs = library->newFunction(NS::String::string("vs_main", NS::UTF8StringEncoding)); MTL::Function* fs = library->newFunction(NS::String::string("fs_main", NS::UTF8StringEncoding)); @@ -74,61 +74,7 @@ GN_EXPORT gnReturnCode gnRegisterOutputDeviceFn(gnOutputDevice* outputDevice, co instance.instance->framebufferRenderer = outputDevice->outputDevice->device->newRenderPipelineState(pipelineDesc, &error); if (!instance.instance->framebufferRenderer) { - GN_RETURN_ERROR(error->localizedDescription()->utf8String()); - } - } - - { - const char* shaderSrc = R"metal( - #include - using namespace metal; - - struct VertexIn { - float3 position; - float2 uv; - }; - - struct VertexOut { - float4 position [[position]]; - }; - - vertex VertexOut vs_main(uint vertexID [[vertex_id]]) { - float2 positions[6] = { - {-0.5, -0.5}, - { 0.5, -0.5}, - {-0.5, 0.5}, - { 0.5, -0.5}, - {-0.5, 0.5}, - { 0.5, 0.5} - }; - - VertexOut out; - out.position = float4(positions[vertexID], 0.0, 1.0); - return out; - } - - fragment float4 fs_main(VertexOut in [[stage_in]]) { - return float4(1.0, 1.0, 1.0, 1.0); - } - )metal"; - - NS::Error* error = nullptr; - MTL::CompileOptions* options = nullptr; - MTL::Library* library = physicalDevice.physicalOutputDevice->device->newLibrary(NS::String::string(shaderSrc, NS::UTF8StringEncoding), options, &error); - if (!library) { - GN_RETURN_ERROR(error->localizedDescription()->utf8String()); - } - MTL::Function* vs = library->newFunction(NS::String::string("vs_main", NS::UTF8StringEncoding)); - MTL::Function* fs = library->newFunction(NS::String::string("fs_main", NS::UTF8StringEncoding)); - - MTL::RenderPipelineDescriptor* pipelineDesc = MTL::RenderPipelineDescriptor::alloc()->init(); - pipelineDesc->setVertexFunction(vs); - pipelineDesc->setFragmentFunction(fs); - pipelineDesc->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatBGRA8Unorm); - - instance.instance->testSquareRenderer = outputDevice->outputDevice->device->newRenderPipelineState(pipelineDesc, &error); - if (!instance.instance->framebufferRenderer) { - GN_RETURN_ERROR(error->localizedDescription()->utf8String()); + return gnReturnError(GN_FAILED_CREATE_DEVICE, error->localizedDescription()->utf8String()); } } diff --git a/rendering_api/metal/src/core/framebuffers/metal_framebuffer.cpp b/rendering_api/metal/src/core/framebuffers/metal_framebuffer.cpp index a979777..c66d403 100644 --- a/rendering_api/metal/src/core/framebuffers/metal_framebuffer.cpp +++ b/rendering_api/metal/src/core/framebuffers/metal_framebuffer.cpp @@ -42,7 +42,7 @@ GN_EXPORT gnReturnCode gnCreateFramebufferFn(gnFramebuffer* framebuffer, const g stencilAttachment->setStoreAction(MTL::StoreActionStore); stencilAttachment->release(); } else { - GN_RETURN_ERROR("fuck you (line 46 in metal_framebuffer.cpp)"); + return gnReturnError(GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, "GN_DEPTH_ATTACHMENT and GN_STENCIL_ATTACHMENT are unsupported on metal for now"); } } return GN_SUCCESS; diff --git a/rendering_api/metal/src/core/graphics_pipeline/metal_graphics_pipeline.cpp b/rendering_api/metal/src/core/graphics_pipeline/metal_graphics_pipeline.cpp index 860a41a..e9475dd 100644 --- a/rendering_api/metal/src/core/graphics_pipeline/metal_graphics_pipeline.cpp +++ b/rendering_api/metal/src/core/graphics_pipeline/metal_graphics_pipeline.cpp @@ -117,12 +117,12 @@ GN_EXPORT void gnGraphicsPipelineAddPushConstantFn(gnGraphicsPipeline& graphicsP } GN_EXPORT gnReturnCode gnCreateGraphicsPipelineFn(gnGraphicsPipeline* graphicsPipeline, gnOutputDevice& outputDevice) { - if (graphicsPipeline->graphicsPipeline == nullptr) GN_RETURN_ERROR("Need to call one gnGraphicsPipeline function to create a graphics pipeline"); + if (graphicsPipeline->graphicsPipeline == nullptr) graphicsPipeline->graphicsPipeline = new gnPlatformGraphicsPipeline(); NS::Error* error = nullptr; graphicsPipeline->graphicsPipeline->renderPipelineDescriptor->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatBGRA8Unorm); graphicsPipeline->graphicsPipeline->renderPipelineState = outputDevice.outputDevice->device->newRenderPipelineState(graphicsPipeline->graphicsPipeline->renderPipelineDescriptor, &error); if (!graphicsPipeline->graphicsPipeline->renderPipelineState) - GN_RETURN_ERROR(error->localizedDescription()->utf8String()); + return gnReturnError(GN_FAILED_CREATE_GRAPHICS_PIPELINE, error->localizedDescription()->utf8String()); graphicsPipeline->graphicsPipeline->depthStencilState = outputDevice.outputDevice->device->newDepthStencilState(graphicsPipeline->graphicsPipeline->depthStateDescriptor); graphicsPipeline->graphicsPipeline->outputDevice = &outputDevice; diff --git a/rendering_api/metal/src/core/graphics_pipeline/metal_render_pass.cpp b/rendering_api/metal/src/core/graphics_pipeline/metal_render_pass.cpp index f7ed891..9aa2048 100644 --- a/rendering_api/metal/src/core/graphics_pipeline/metal_render_pass.cpp +++ b/rendering_api/metal/src/core/graphics_pipeline/metal_render_pass.cpp @@ -24,7 +24,7 @@ GN_EXPORT gnReturnCode gnCreateRenderPassFn(gnRenderPass* renderPass, const gnOu else if (renderPass->attachments[i].colorMode == GN_DEPTH8_STENCIL24) {} else { std::string return_code = "GN_RENDERPASS_ATTATCHMENT_(" + std::to_string(i) + ")" + "_UNSUPPORTED_COLOR_MODE"; - GN_RETURN_ERROR(return_code.c_str()); + return gnReturnError(GN_UNKNOWN_COLOR_FORMAT, return_code.c_str()); } } diff --git a/rendering_api/metal/src/core/shaders/metal_shader.cpp b/rendering_api/metal/src/core/shaders/metal_shader.cpp index 4abf5fe..e91978d 100644 --- a/rendering_api/metal/src/core/shaders/metal_shader.cpp +++ b/rendering_api/metal/src/core/shaders/metal_shader.cpp @@ -1,7 +1,7 @@ #include "metal_shader_module.h" -#include "metal_shader.h" #include "spirv_msl.hpp" #include "core/devices/metal_output_devices.h" +#include "core/shaders/gryphn_shader.h" static uint32_t* chars_to_uint32s(const char* chars, size_t num_chars) { if (chars == NULL || num_chars == 0) { @@ -93,7 +93,7 @@ GN_EXPORT gnReturnCode gnBuildShaderModuleFn(gnShaderModule* shaderModule, const shaderModule->shaderModule->uniformBufferOffset = 0; shaderModule->shaderModule->pushConstantOffset = largestBinding + 1; } else { - GN_RETURN_ERROR("GN_UNKNOWN_SHADER_MODULE_TYPE_(I prolly lazy)"); + return gnReturnError(GN_UNKNOWN_SHADER_MODULE, "unknown shader module type (vertex and fragment are the only supported ones for now)"); } // std::cout << shaderSource << "\n"; @@ -103,9 +103,9 @@ GN_EXPORT gnReturnCode gnBuildShaderModuleFn(gnShaderModule* shaderModule, const NS::String* sourceCode = NS::String::string(shaderSource.c_str(), NS::StringEncoding::UTF8StringEncoding); MTL::Library* shaderLib = outputDeviec.outputDevice->device->newLibrary(sourceCode, mtloptions, &error); if (!shaderLib) - GN_RETURN_ERROR(error->localizedDescription()->utf8String()); + return gnReturnError(GN_SHADER_FAILED_TO_COMPILE, error->localizedDescription()->utf8String()); if (shaderLib->functionNames()->count() > 1) - GN_RETURN_ERROR("More than one shader function in shader"); + return gnReturnError(GN_SHADER_FAILED_TO_COMPILE, "More than one shader function in shader"); shaderModule->shaderModule->shaderFunction = shaderLib->newFunction(reinterpret_cast(shaderLib->functionNames()->object(0))); return GN_SUCCESS; diff --git a/rendering_api/metal/src/core/textures/metal_texture.cpp b/rendering_api/metal/src/core/textures/metal_texture.cpp index 91d39db..438409a 100644 --- a/rendering_api/metal/src/core/textures/metal_texture.cpp +++ b/rendering_api/metal/src/core/textures/metal_texture.cpp @@ -49,14 +49,14 @@ GN_EXPORT gnErrorCode gnCreateTextureFn(gnTexture* texture, const gnOutputDevice if (texture->textureColorFormat == GN_RED) textureDescriptor->setPixelFormat(MTL::PixelFormatR8Unorm); else if (texture->textureColorFormat == GN_RGB8) - return gnReturnError("GN_RGB8_UNSUPPORTED"); + return gnReturnError(GN_UNSUPPORTED_COLOR_FORMAT, "GN_RGB8_UNSUPPORTED"); else if (texture->textureColorFormat == GN_RGBA8) textureDescriptor->setPixelFormat(MTL::PixelFormatRGBA8Unorm); else if (texture->textureColorFormat == GN_BGRA8) textureDescriptor->setPixelFormat(MTL::PixelFormatBGRA8Unorm); else if (texture->textureColorFormat == GN_DEPTH_STENCIL) textureDescriptor->setPixelFormat(MTL::PixelFormatDepth32Float_Stencil8); - else return gnReturnError("GN_UNSUPPORTED_PIXEL_FORMAT"); + else return gnReturnError(GN_UNKNOWN_COLOR_FORMAT, "unknown pixel format"); textureDescriptor->setWidth(texture->textureExtent.x); textureDescriptor->setHeight(texture->textureExtent.y); diff --git a/rendering_api/vulkan/src/framebuffers/vulkan_framebuffer.cpp b/rendering_api/vulkan/src/framebuffers/vulkan_framebuffer.cpp index 6e41e1b..35a5258 100644 --- a/rendering_api/vulkan/src/framebuffers/vulkan_framebuffer.cpp +++ b/rendering_api/vulkan/src/framebuffers/vulkan_framebuffer.cpp @@ -30,7 +30,7 @@ GN_EXPORT gnReturnCode gnCreateFramebufferFn(gnFramebuffer* framebuffer, const g if (vkCreateFramebuffer(renderpass.renderpass->outputDevice->outputDevice->device, &framebufferInfo, nullptr, &framebuffer->framebuffer->framebuffer) != VK_SUCCESS) { - GN_RETURN_ERROR("Failed to create framebuffer"); + return gnReturnError(GN_FAILED_TO_CREATE_FRAMEBUFFER, "im to lazy to query vulkan why"); } return GN_SUCCESS; diff --git a/rendering_api/vulkan/src/graphics_pipeline/vulkan_renderpass.cpp b/rendering_api/vulkan/src/graphics_pipeline/vulkan_renderpass.cpp index 19ffb86..3c4f951 100644 --- a/rendering_api/vulkan/src/graphics_pipeline/vulkan_renderpass.cpp +++ b/rendering_api/vulkan/src/graphics_pipeline/vulkan_renderpass.cpp @@ -60,7 +60,7 @@ GN_EXPORT gnReturnCode gnCreateRenderPassFn(gnRenderPass* renderPass, const gnOu colorAttachmentRef.attachment = i; if (renderPass->presentationQueue == nullptr) { - GN_RETURN_ERROR("the presentation queue has not been set"); + return gnReturnError(GN_FAILED_CREATE_RENDERPASS, "the presentation queue has not been set"); } if (renderPass->attachments[i].colorMode == GN_RGBA8) { diff --git a/rendering_api/vulkan/src/instance/vulkan_instance.cpp b/rendering_api/vulkan/src/instance/vulkan_instance.cpp index 7e26487..1341fc9 100644 --- a/rendering_api/vulkan/src/instance/vulkan_instance.cpp +++ b/rendering_api/vulkan/src/instance/vulkan_instance.cpp @@ -70,7 +70,7 @@ void gnInstanceSetAppInfoFn(gnInstance& instance, gnAppInfo& info) { GN_EXPORT gnReturnCode gnCreateInstanceFn(gnInstance* instance) { if (instance->debugger != nullptr && !checkValidationLayerSupport(instance->debugger->debug_layers)) { - GN_RETURN_ERROR("validation layers requested, but not available!"); + return gnReturnError(GN_FAILED_CREATE_INSTANCE, "validation layers requested, but not available!"); } gnInstanceSetAppInfoFn(*instance, instance->AppInfo); @@ -103,7 +103,7 @@ GN_EXPORT gnReturnCode gnCreateInstanceFn(gnInstance* instance) { } if (vkCreateInstance(&createInfo, nullptr, &instance->instance->vk_instance) != VK_SUCCESS) { - return GN_FAILED; + return gnReturnError(GN_FAILED_CREATE_INSTANCE, "im to lazy to query vulkan why"); } if (instance->debugger->debugger == nullptr) instance->debugger->debugger = new gnPlatformDebugger(); @@ -121,11 +121,11 @@ GN_EXPORT gnReturnCode gnInstanceSetWindowFn(gnInstance& instance, GLFWwindow* w instance.instance->window = window; if (glfwVulkanSupported() != GLFW_TRUE) { - GN_RETURN_ERROR("vulkan is not actually supported\n"); + return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "vulkan is not actually supported\n"); } VkResult result = glfwCreateWindowSurface(instance.instance->vk_instance, window, nullptr, &instance.instance->window_surface);\ if (result != VK_SUCCESS) - GN_RETURN_ERROR(std::to_string(result).c_str()); + return gnReturnError(GN_FAILED_TO_ATTACH_WINDOW, std::to_string(result).c_str()); return GN_SUCCESS; } diff --git a/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.cpp b/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.cpp index 53fa4d7..0808fa0 100644 --- a/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.cpp +++ b/rendering_api/vulkan/src/presentation_queue/vulkan_presentation_queue.cpp @@ -56,7 +56,7 @@ GN_EXPORT gnReturnCode gnCreatePresentationQueueFn(gnPresentationQueue* presenta createInfo.oldSwapchain = VK_NULL_HANDLE; if (vkCreateSwapchainKHR(device.outputDevice->device, &createInfo, nullptr, &presentationQueue->presentationQueue->swapChain) != VK_SUCCESS) { - GN_RETURN_ERROR("failed to create swap chain!"); + gnReturnError(GN_FAILED_CREATE_PRESENTATION_QUEUE, "too lazy to query vulkan why"); } std::vector swapChainImages; diff --git a/rendering_api/vulkan/src/textures/vulkan_texture.cpp b/rendering_api/vulkan/src/textures/vulkan_texture.cpp index 7cf8d67..6eba8b8 100644 --- a/rendering_api/vulkan/src/textures/vulkan_texture.cpp +++ b/rendering_api/vulkan/src/textures/vulkan_texture.cpp @@ -179,11 +179,11 @@ GN_EXPORT gnReturnCode gnCreateTextureFn(gnTexture* texture, const gnOutputDevic if (vulkanCreateImage(outputDevice, texture->textureExtent.x, texture->textureExtent.y, depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, texture->texture->textureImage, texture->texture->textureImageMemory) != GN_SUCCESS) { - GN_RETURN_ERROR("Failed to create depth image"); + return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, "Failed to create depth image"); } gnReturnCode errorCode = createImageView(outputDevice, texture->texture->textureImage, depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT, &texture->texture->textureImageView); - if (transitionImageLayout(outputDevice, texture->texture->textureImage, depthFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) != GN_FAILED) GN_RETURN_ERROR("Failed to transition image layout"); + if (transitionImageLayout(outputDevice, texture->texture->textureImage, depthFormat, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) != GN_SUCCESS) return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, "Failed to transition image layout"); } } else { if (vulkanCreateCubeMap(outputDevice, texture->textureExtent.x, texture->textureExtent.y, texture->texture->textureImage, texture->texture->textureImageMemory) != GN_SUCCESS) @@ -217,7 +217,7 @@ GN_EXPORT gnReturnCode gnCreateTextureFn(gnTexture* texture, const gnOutputDevic samplerInfo.maxLod = 0.0f; if (vkCreateSampler(outputDevice.outputDevice->device, &samplerInfo, nullptr, &texture->texture->textureSampler) != VK_SUCCESS) - GN_RETURN_ERROR("Failed to create texture sampler"); + return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, "Failed to create texture sampler"); } return GN_SUCCESS; diff --git a/rendering_api/vulkan/src/textures/vulkan_texture_helpers.cpp b/rendering_api/vulkan/src/textures/vulkan_texture_helpers.cpp index 40c6f13..e80ac5e 100644 --- a/rendering_api/vulkan/src/textures/vulkan_texture_helpers.cpp +++ b/rendering_api/vulkan/src/textures/vulkan_texture_helpers.cpp @@ -182,7 +182,7 @@ gnReturnCode vulkanCreateImage(const gnOutputDevice& outputDevice, VkResult result = vkCreateImage(outputDevice.outputDevice->device, &imageInfo, nullptr, &image); if (result != VK_SUCCESS) { - GN_RETURN_ERROR(std::to_string(result).c_str()); + return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, std::to_string(result).c_str()); } VkMemoryRequirements memRequirements; @@ -197,12 +197,12 @@ gnReturnCode vulkanCreateImage(const gnOutputDevice& outputDevice, outputDevice.physicalOutputDevice->physicalOutputDevice->device, memRequirements.memoryTypeBits, properties, &memoryTypeIndex) != GN_SUCCESS) { - GN_RETURN_ERROR("Failed to find memory type"); + return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, "Failed to find memory type"); } allocInfo.memoryTypeIndex = memoryTypeIndex; if (vkAllocateMemory(outputDevice.outputDevice->device, &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) { - GN_RETURN_ERROR("Failed to allocate memory"); + return gnReturnError(GN_FAILED_TO_CREATE_IMAGE, "Failed to allocate memory"); } vkBindImageMemory(outputDevice.outputDevice->device, image, imageMemory, 0); diff --git a/src/core/commands/gryphn_command_buffer.h b/src/core/commands/gryphn_command_buffer.h index a987253..9b55a1b 100644 --- a/src/core/commands/gryphn_command_buffer.h +++ b/src/core/commands/gryphn_command_buffer.h @@ -1,5 +1,6 @@ #pragma once #include +#include "vector" struct gnPlatformCommandBuffer; struct gnOutputDevice; diff --git a/src/core/init/gryphn_init.cpp b/src/core/init/gryphn_init.cpp index 6693abe..47fe87f 100644 --- a/src/core/init/gryphn_init.cpp +++ b/src/core/init/gryphn_init.cpp @@ -15,41 +15,41 @@ static void* gnRenderingAPILIB; #define gnLoadDLLFunction(dll, func, func_name) \ gnPlatformLoadDLLFunction(dll, func, func_name); \ - if (func == nullptr) return gnReturnError(gnString("GN_FUNC_(") + gnString(#func) + ")_NOT_LOADED") + if (func == nullptr) return gnReturnError(GN_FUNCTION_NOT_FOUND, gnString("GN_FUNC_(") + gnString(#func) + ")_NOT_LOADED") gnReturnCode gnInit(gnRenderingAPI RenderingAPI) { gnString libName = ""; switch (RenderingAPI) { case GN_RENDERINGAPI_NONE: { - return { GN_FAILED, "GN_ERROR_RENDERINGAPI_NONE_UNSUPPORTED" }; + return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api_none unsupported"); } case GN_RENDERINGAPI_SOFTWARE: { - return { GN_FAILED, "GN_ERROR_SOFRWARE_UNSUPPORTED" }; + return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api_software unsupported"); } case GN_RENDERINGAPI_OPENGL: { - return { GN_FAILED, "GN_ERROR_OPENGL_UNSUPPORTED" }; + return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api_opengl unsupported"); } case GN_RENDERINGAPI_VULKAN: { - if (!RenderingAPISupported(GN_RENDERINGAPI_VULKAN)) return { GN_FAILED, "GN_ERROR_VUKAN_UNSUPPORTED" }; + if (!RenderingAPISupported(GN_RENDERINGAPI_VULKAN)) return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api vulkan unsupported"); libName = "GryphnVulkanImpl"; break; } case GN_RENDERINGAPI_DIRECTX11: { - return { GN_FAILED, "GN_ERROR_DIRECTX11_UNSUPPORTED" }; + return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api directx11 unsupported"); } case GN_RENDERINGAPI_DIRECTX12: { - return { GN_FAILED, "GN_ERROR_DIRECTX12_UNSUPPORTED" }; + return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api directx12 unsupported"); } case GN_RENDERINGAPI_METAL: { - if (!RenderingAPISupported(GN_RENDERINGAPI_METAL)) return { GN_FAILED, "GN_ERROR_METAL_UNSUPPORTED" }; + if (!RenderingAPISupported(GN_RENDERINGAPI_METAL)) return gnReturnError(GN_UNSUPPORTED_RENDERING_API, "rendering api metal unsupported"); libName = "GryphnMetalImpl"; break; } } gnRenderingAPILIB = gnPlatformLoadDLL(gnString("gryphn/rendering_apis/") + libName); - if (!gnRenderingAPILIB) { return gnReturnError("GN_ERROR_UNABLE_TO_LOAD_DLL"); } + if (!gnRenderingAPILIB) { return gnReturnError(GN_UNABLE_TO_LOAD_DLL, "GN_ERROR_UNABLE_TO_LOAD_DLL"); } gnLoadDLLFunction(gnRenderingAPILIB, gnCreateInstance, "gnCreateInstanceFn"); gnLoadDLLFunction(gnRenderingAPILIB, gnDestroyInstance, "gnDestroyInstanceFn"); diff --git a/src/utils/gryphn_error_code.cpp b/src/utils/gryphn_error_code.cpp deleted file mode 100644 index 25f3274..0000000 --- a/src/utils/gryphn_error_code.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -gnString gnGetErrorString() { - return lastReturnCode; -} diff --git a/src/utils/gryphn_error_code.h b/src/utils/gryphn_error_code.h index ff89bb9..af46cbf 100644 --- a/src/utils/gryphn_error_code.h +++ b/src/utils/gryphn_error_code.h @@ -1,22 +1,63 @@ -#include -#include -#include -#include +// #include +// #include +// #include +// #include -enum gnReturnCodeLevel { GN_FAILED = 0, GN_SUCCESS = 1 }; +// enum gnReturnCodeLevel { GN_FAILED = 0, GN_SUCCESS = 1 }; -inline gnString lastReturnCode = gnCreateString(); +// inline gnString lastReturnCode = gnCreateString(); -typedef struct gnReturnCode { -ACCESS_LEVEL: - gnBool success; - gnString returnCodeMessage = ""; -public: - bool operator==(gnReturnCodeLevel level) { return success; } - gnReturnCode(gnReturnCodeLevel level, gnString message) : success(level), returnCodeMessage(message) { lastReturnCode = returnCodeMessage; } - gnReturnCode(gnReturnCodeLevel level) : success(level) { lastReturnCode = returnCodeMessage; } - gnReturnCode() { lastReturnCode = returnCodeMessage; } -} gnErrorCode; +// typedef struct gnReturnCode { +// ACCESS_LEVEL: +// gnBool success; +// gnString returnCodeMessage = ""; +// public: +// bool operator==(gnReturnCodeLevel level) { return success; } +// gnReturnCode(gnReturnCodeLevel level, gnString message) : success(level), returnCodeMessage(message) { lastReturnCode = returnCodeMessage; } +// gnReturnCode(gnReturnCodeLevel level) : success(level) { lastReturnCode = returnCodeMessage; } +// gnReturnCode() { lastReturnCode = returnCodeMessage; } +// } gnErrorCode; -gnString gnGetErrorString(); -static gnReturnCode gnReturnError(gnString errorMessage) { return { GN_FAILED, errorMessage }; } +// gnString gnGetErrorString(); +// static gnReturnCode gnReturnError(gnString errorMessage) { return { GN_FAILED, errorMessage }; } + +#include "utils/strings/gryphn_string.h" + +typedef enum gnReturnCode { + GN_SUCCESS, GN_FAILED, GN_FATAL, + GN_ERROR = GN_FAILED +} gnReturnCode; + +typedef gnReturnCode gnErrorCode; + +typedef enum gnReturnMessage { + GN_UNKNOWN_ERROR, + GN_UNKNOWN_FRAMEBUFFER_ATTACHMENT, + GN_UNKNOWN_SHADER_MODULE, + GN_SHADER_FAILED_TO_COMPILE, + GN_UNSUPPORTED_COLOR_FORMAT, + GN_UNKNOWN_COLOR_FORMAT, + GN_UNSUPPORTED_RENDERING_API, + GN_FUNCTION_NOT_FOUND, + GN_UNABLE_TO_LOAD_DLL, + GN_FAILED_CREATE_DEVICE, + GN_FAILED_CREATE_GRAPHICS_PIPELINE, + GN_FAILED_CREATE_PRESENTATION_QUEUE, + GN_FAILED_TO_CREATE_FRAMEBUFFER, + GN_FAILED_CREATE_RENDERPASS, + GN_FAILED_CREATE_INSTANCE, + GN_FAILED_TO_ATTACH_WINDOW, + GN_FAILED_TO_CREATE_IMAGE +} gnReturnMessage; + +inline gnString lastReturnAPIMessage = ""; +inline gnReturnMessage lastReturnMessage = GN_UNKNOWN_ERROR; + +static const gnString gnGetErrorString() { return lastReturnAPIMessage; } +static const gnReturnMessage gnGetErrorMessage() { return lastReturnMessage; } + +static gnReturnCode gnReturnError(gnReturnMessage message, gnString errorMessage) { + lastReturnAPIMessage = errorMessage; + lastReturnMessage = message; + return GN_ERROR; +}